-
-
Save sfate/5553231 to your computer and use it in GitHub Desktop.
Micro version of famous library
This file contains hidden or 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 $ = function (d) { | |
| var $ = document.querySelectorAll.bind(document); | |
| Element.prototype.on = Element.prototype.addEventListener; | |
| NodeList.prototype.on = function (event, fn) { | |
| [].forEach.call(this, function (el) { | |
| el.on(event, fn, false); | |
| }); | |
| }; | |
| Element.prototype.trigger = function (type, data) { | |
| var event = document.createEvent('HTMLEvents'); | |
| event.initEvent(type, true, true); | |
| event.data = data || {}; | |
| event.eventName = type; | |
| this.dispatchEvent(event); | |
| }; | |
| NodeList.prototype.trigger = function (event) { | |
| [].forEach.call(this, function (el) { | |
| el.trigger(event); | |
| }); | |
| }; | |
| return function (s) { | |
| return $(s); | |
| }; | |
| }(document); |
This file contains hidden or 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 $=function(e){var t=document.querySelectorAll.bind(document);Element.prototype.on=Element.prototype.addEventListener;NodeList.prototype.on=function(e,t){[].forEach.call(this,function(n){n.on(e,t,false)})};Element.prototype.trigger=function(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(e,true,true);n.data=t||{};n.eventName=e;this.dispatchEvent(n)};NodeList.prototype.trigger=function(e){[].forEach.call(this,function(t){t.trigger(e)})};return function(e){return t(e)}}(document) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment