/*@ Ox.Event Basic event handler @*/ Ox.Event = (function() { var self = {}, that = {}; self.$eventHandler = $('
'); /*@ bind Binds a callback to an event (event, callback) -> The event handler ({event: callback, ...}) -> The event handler callback Callback function data <*> Event data event Event name Event names can be namespaced, like 'click.foo' @*/ that.bind = function() { Ox.forEach(Ox.makeObject(arguments), function(callback, event) { var foo = event; self.$eventHandler.bind('ox_' + event, function(event, data) { Ox.Log('Core', 'CALLBACK', foo, data.value); callback(data.value); }); }); return that; }; /*@ bindOnce Binds a callback to an event, once (event, callback) -> The event handler ({event: callback, ...}) -> The event handler callback Callback function data <*> Event data event Event name Event names can be namespaced, like 'click.foo' @*/ that.bindOnce = function() { Ox.forEach(Ox.makeObject(arguments), function(callback, event) { self.$eventHandler.one('ox_' + event, function(event, data) { callback(data.value); }); }); return that; }; /*@ trigger Triggers an event (event) -> The event handler (event, data) -> The event handler ({event: data, ...}) -> The event handler event Event name data <*> Event data @*/ that.trigger = function() { Ox.forEach(Ox.makeObject(arguments), function(data, event) { Ox.Log('Core', 'Ox.Event.trigger', event, data) self.$eventHandler.trigger('ox_' + event, {value: data}); }); return that; }; /*@ unbind Unbinds all callbacks from an event To unbind a specific handler, use namespaced events, like bind('click.foo', callback), and then unbind('click.foo'). () -> The event handler Unbinds all events (event) -> The event handler Unbinds one event (event, event, ...) -> The event handler Unbinds multiple events ([event, event, ...]) -> The event handler Unbinds multiple events event Event name @*/ that.unbind = function() { if (arguments.length == 0) { self.$eventHandler.unbind(); } else { Ox.makeArray(arguments).forEach(function(event) { self.$eventHandler.unbind('ox_' + event); }); } return that; }; return that; }());