-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenviro.js
More file actions
36 lines (29 loc) · 1.13 KB
/
Copy pathenviro.js
File metadata and controls
36 lines (29 loc) · 1.13 KB
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
//Shortands for global variables
window.win = window;
window.doc = win.document;
window.on = win.addEventListener;
//Shortand for doc.createElement and doc.createElementNS
doc.mkNode = function(n1,n2,n3){
if(!n2||typeof n2 != "string"){
return document.createElement(n1);
}else{
return document.createElementNS(n1,n2);
}
}
//Modify the DOM elements
Element.prototype.rm = Element.prototype.remove;
Element.prototype.setAttr = Element.prototype.setAttribute;
Element.prototype.getAttr = Element.prototype.getAttribute;
Element.prototype.hasAttr = Element.prototype.hasAttribute;
Element.prototype.addAttr = function(n){this.setAttr(n,"");};
Element.prototype.rmAttr = Element.prototype.removeAttribute;
Element.prototype.on = Element.prototype.addEventListener;
Element.prototype.rmon = Element.prototype.removeEventListener;
Element.prototype.addChild = Element.prototype.appendChild;
Element.prototype.rmChild = Element.prototype.removeChild;
Element.prototype.mkChild = function(ns,tag,attrs){
//Combination of doc.createElement and node.appendChild
var n = doc.mkNode(ns,tag,attrs);
this.addChild(n);
return n;
};