Skip to content

Instantly share code, notes, and snippets.

@termi
Created October 25, 2012 11:07
Show Gist options
  • Save termi/3952026 to your computer and use it in GitHub Desktop.
Save termi/3952026 to your computer and use it in GitHub Desktop.
New DOM4 classList polyfill for browsers with classList support
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"));
void function(b,c){"classList"in c&&void function(h,i,a){this.add=function(){a.call(arguments,h,this)};this.remove=function(){a.call(arguments,i,this)};this.toggle=function(a,d){var e=this.contains(a),f=e?!0!==d&&"remove":!1!==d&&"add";if(f)this[f](a);return e}}.call(c=b.DOMTokenList.prototype,c.add,c.remove,Array.prototype.forEach);}(window,document.createElement("b"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment