-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvueonrails.js
45 lines (36 loc) · 1.07 KB
/
vueonrails.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*!
* vueonrails.js
* v1.0.1
* (c) Bryan Lim; MIT License
*/
export function erb(variable){
var element = document.getElementById("vueonrails-" + variable)
if(element == null){ return "" }
return JSON.parse(element.getAttribute("data-" + variable))
}
export function isView(pageClassString){
if(pageClassString == "###") return
if(pageClassString != "") pageClassString = pageClassString.replace(/#/g , " ");
return document.getElementsByClassName(pageClassString).length == 1
}
export function puts(obj){
console.log({obj})
}
export function p(obj){
console.log({obj})
}
export function table(obj){
console.table(obj)
}
export function addClass(identifier, className){
document.getElementById(identifier).classList.addClass(className)
}
export function toggleClass(identifier, className){
document.getElementById(identifier).classList.toggle(className)
}
export function titleize(str){
return str.replace(/\b\S/g, function(t) { return t.toUpperCase() });
}
export function isArray(obj){
return Object.prototype.toString.call(obj) === '[object Array]' ;
}