Created
February 24, 2018 12:11
-
-
Save rupertqin/e548c7db4b4b092c1dfd26166e17d1e6 to your computer and use it in GitHub Desktop.
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
var $ = document.querySelectorAll.bind(document) | |
var $$ = document.querySelector.bind(document) | |
Element.prototype.on = Element.prototype.addEventListener; | |
NodeList.prototype.on = function (event, fn) { | |
[]['forEach'].call(this, function (el) { | |
el.on(event, fn); | |
}); | |
return this; | |
}; | |
Element.prototype.hasClassName = function (a) { | |
return new RegExp("(?:^|\\s+)" + a + "(?:\\s+|$)").test(this.className); | |
}; | |
Element.prototype.addClassName = function (a) { | |
if (!this.hasClassName(a)) { | |
this.className = [this.className, a].join(" "); | |
} | |
}; | |
Element.prototype.removeClassName = function (b) { | |
if (this.hasClassName(b)) { | |
var a = this.className; | |
this.className = a.replace(new RegExp("(?:^|\\s+)" + b + "(?:\\s+|$)", "g"), " "); | |
} | |
}; | |
Element.prototype.toggleClassName = function (a) { | |
this[this.hasClassName(a) ? "removeClassName" : "addClassName"](a); | |
}; | |
// el loop | |
[]['some' | 'map' | 'forEach'].call($('.menu a'), function(el) { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment