-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdomHelpers.js
executable file
·39 lines (36 loc) · 1 KB
/
domHelpers.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
//
Array.prototype.flatten = function () {
var toReturn = [];
for (var i = 0, len = this.length; i < len; i++) {
if (this[i] instanceof Array) {
toReturn = toReturn.concat(this[i].flatten());
} else {
toReturn.push(this[i]);
}
}
return toReturn;
};
//
Object.defineProperty(Array.prototype, 'flatten', { enumerable: false });
//
if (window.Element) {
window.Element.prototype.addClassName = function (a) {
var classes = this.className.split(' ');
var args = Array.prototype.flatten.call(arguments);
var n = args.length;
for (var i = 0; i < n; i++) {
var className = args[i];
if (classes.indexOf(className) === -1) {
classes.push(className);
}
}
this.className = classes.join(' ');
};
window.Element.prototype.delClassName = function () {
var classes = this.className.split(' ');
var args = Array.prototype.flatten.call(arguments);
this.className = classes.filter(function (elm) {
return args.indexOf(elm) === -1;
}).join(' ');
};
}