public
Created

New DOM4 classList polyfill for browsers with classList support

  • Download Gist
index.js
JavaScript
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
void function(global, tmp) {
if("classList" in tmp) {
void function(_add, _remove, _Array_forEach_) {
this["add"] = function() {
_Array_forEach_.call(arguments, _add, this);
};
this["remove"] = function() {
_Array_forEach_.call(arguments, _remove, this);
};
this["toggle"] = function(token, forse) {
var result = this.contains(token)
, method = result ?
forse !== true && "remove"
:
forse !== false && "add"
;
if(method) {
this[method](token);
}
return result;
}
}.call((tmp = global["DOMTokenList"].prototype), tmp["add"], tmp["remove"], Array.prototype.forEach);
}
//else {
//Browser does't support classList -> use full DOMTokenList polyfill
//}
}(window, document.createElement("b"));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.