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:

  1. The ability to subscribe to Objects (rather than just css rules)
  2. The ability to defer firing of functions (using a setTimeout)
JavaScript:
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."

JavaScript:
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).

JavaScript:
MBX.EventHandler.subscribe(document, "dom:loaded", function () { alert('hi'); }, { defer: true });

Speaking of domready, you can now subscribe to DOM ready events:

JavaScript:
MBX.EventHandler.onDomReady(function() { alert('hi'); });

No Comments Yet

You can be the first to comment!

Speak Your Peace

  • Comment Policy:Could go here if there's a nagging need Login Instructions: Would go here if there's a desire.