-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneral.js
48 lines (40 loc) · 1.08 KB
/
general.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
46
47
48
/* General Function Declaration */
function $a(a){return document.querySelectorAll(a)}
function $(a){return document.querySelector(a)}
Element.prototype.$e = function(e,f){
this.addEventListener(e,f)
return this
}
Element.prototype.$tc = function(c,f){
this.classList.toggle(c,f)
return this
}
function $n(a,id,cl){
var e = document.createElement(a)
if(id) e.id = id
var cls = Array.prototype.slice.call(arguments,2)
cls.forEach(function(clss,i,a){
e.classList.add(clss)
})
return e
}
Element.prototype.attr = function(n,v){
if(v) this.setAttribute(n,v)
else return this.getAttribute(n)
}
Element.prototype.apnd = function(e){
//if(!Element.prototype.append)
if(typeof(e) === 'object') this.insertAdjacentElement('beforeend', e)
else this.insertAdjacentHTML('beforeend', e)
//else this.append(e)
return this
}
if(!Array.prototype.forEach){
Array.prototype.forEach = function (f){
for(let i=0;i<this.length;i++)
f(this[i],i,this)
}
}
if(!NodeList.prototype.forEach){
NodeList.prototype.forEach = Array.prototype.forEach
}