Additions to the Motionbox Eventhandler
I've been working on some additions to the Motionbox EventHandler. It hasn't moved to master yet, but you can check out the defer_functions branch.
The two major additions are:
- The ability to subscribe to Objects (rather than just css rules)
- The ability to defer firing of functions (using a setTimeout)
-
var someObj = {
-
foo: 'bar'
-
};
-
-
MBX.EventHandler.subscribe(someObj, "customFunc", function () { alert('hi'); });
-
MBX.EventHandler.fireCustom(someObj, "customFunc", { myCustomPayload: 'hi' });
Since DOM elements are simply objects, you can also use the eventhandler to subscribe "the old fashioned way."
-
MBX.EventHandler.subscribe(document, "click", function () { alert('hi'); });
You can defer the firing of functions (say you don't care that a function execute as soon as an event is fired).
-
MBX.EventHandler.subscribe(document, "dom:loaded", function () { alert('hi'); }, { defer: true });
Speaking of domready, you can now subscribe to DOM ready events:
-
MBX.EventHandler.onDomReady(function() { alert('hi'); });
