Last active
March 21, 2017 11:11
-
-
Save elmahdim/acae3f401aa2f21e1c59c3f5a50401d5 to your computer and use it in GitHub Desktop.
Events module
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 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