Created
October 25, 2012 11:07
-
-
Save termi/3952026 to your computer and use it in GitHub Desktop.
New DOM4 classList polyfill for browsers with classList support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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