You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.8 KiB
51 lines
1.8 KiB
/**
|
|
* mui fixed classList
|
|
* @param {type} document
|
|
* @returns {undefined}
|
|
*/
|
|
(function(document) {
|
|
if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
|
|
|
|
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
|
get: function() {
|
|
var self = this;
|
|
function update(fn) {
|
|
return function(value) {
|
|
var classes = self.className.split(/\s+/),
|
|
index = classes.indexOf(value);
|
|
|
|
fn(classes, index, value);
|
|
self.className = classes.join(" ");
|
|
};
|
|
}
|
|
|
|
var ret = {
|
|
add: update(function(classes, index, value) {
|
|
~index || classes.push(value);
|
|
}),
|
|
remove: update(function(classes, index) {
|
|
~index && classes.splice(index, 1);
|
|
}),
|
|
toggle: update(function(classes, index, value) {
|
|
~index ? classes.splice(index, 1) : classes.push(value);
|
|
}),
|
|
contains: function(value) {
|
|
return !!~self.className.split(/\s+/).indexOf(value);
|
|
},
|
|
item: function(i) {
|
|
return self.className.split(/\s+/)[i] || null;
|
|
}
|
|
};
|
|
|
|
Object.defineProperty(ret, 'length', {
|
|
get: function() {
|
|
return self.className.split(/\s+/).length;
|
|
}
|
|
});
|
|
|
|
return ret;
|
|
}
|
|
});
|
|
}
|
|
})(document);
|