diff options
Diffstat (limited to 'elm/0-compat.js')
-rw-r--r-- | elm/0-compat.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/elm/0-compat.js b/elm/0-compat.js new file mode 100644 index 00000000..02179ee3 --- /dev/null +++ b/elm/0-compat.js @@ -0,0 +1,31 @@ +/* classList.toggle() */ +(function() { + var historic = DOMTokenList.prototype.toggle; + DOMTokenList.prototype.toggle = function(token, force) { + if(arguments.length > 0 && this.contains(token) === force) { + return force; + } + return historic.call(this, token); + }; +})(); + + +/* Element.matches() and Element.closest() */ +if(!Element.prototype.matches) + Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; +if(!Element.prototype.closest) + Element.prototype.closest = function(s) { + var el = this; + if(!document.documentElement.contains(el)) return null; + do { + if(el.matches(s)) return el; + el = el.parentElement || el.parentNode; + } while(el !== null && el.nodeType === 1); + return null; + }; + + +/* NodeList.forEach */ +if(window.NodeList && !NodeList.prototype.forEach) { + NodeList.prototype.forEach = Array.prototype.forEach; +} |