Skip to content

Instantly share code, notes, and snippets.

@elmahdim
Last active March 21, 2017 11:11
Show Gist options
  • Save elmahdim/acae3f401aa2f21e1c59c3f5a50401d5 to your computer and use it in GitHub Desktop.
Save elmahdim/acae3f401aa2f21e1c59c3f5a50401d5 to your computer and use it in GitHub Desktop.
Events module
var EventsModule = {
initialize:function(b) {
this._eventHandler(b);
},
_eventHandler:function(b) {
Object.keys(b.events).forEach(function(a) {
var c = a.substr(0, a.indexOf(" ")), e = a.substr(a.indexOf(" ") + 1);
a = b.events[a];
c = document.querySelectorAll(c);
if (c.length && "function" == typeof b[a] && b.hasOwnProperty(a) && e) {
for (var d = 0;d < c.length;d++) {
c[d].addEventListener(e, b[a], !1);
}
}
});
}
};
EventsModule.initialize({
events: {
".foo click" : "foo",
".act click" : "act"
},
foo : function(){},
act : function(){}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment