Skip to content

Instantly share code, notes, and snippets.

@sfate
Forked from neoncrumpet/Micro $
Last active December 17, 2015 04:49
Show Gist options
  • Save sfate/5553231 to your computer and use it in GitHub Desktop.
Save sfate/5553231 to your computer and use it in GitHub Desktop.
Micro version of famous library
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);
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