setTimeout before triggering events

This commit is contained in:
rlx 2012-06-30 15:05:35 +00:00
parent d57affea4a
commit dc438e2427

View file

@ -120,10 +120,13 @@ Ox.Event = (function() {
data <o> Event data data <o> Event data
*/ */
that.trigger = function(self) { that.trigger = function(self) {
var element = this; var args = arguments, element = this;
if (self.eventHandlers) { self.eventHandlers && setTimeout(function() {
Ox.forEach(Ox.makeObject(Ox.slice(arguments, 1)), function(data, event) { Ox.forEach(Ox.makeObject(Ox.slice(args, 1)), function(data, event) {
var triggered = event.split('.'); var triggered = event.split('.');
eventHandlers.forEach(function(callback) {
callback.call(element, data || {}, event, element);
});
triggered.map(function(v, i) { triggered.map(function(v, i) {
return triggered.slice(0, i + 1).join('.'); return triggered.slice(0, i + 1).join('.');
}).concat('*').forEach(function(triggered) { }).concat('*').forEach(function(triggered) {
@ -133,11 +136,8 @@ Ox.Event = (function() {
handler.callback.call(element, data || {}, event); handler.callback.call(element, data || {}, event);
}); });
}); });
eventHandlers.forEach(function(callback) {
callback.call(element, data || {}, event, element);
}); });
}); });
}
return that; return that;
}; };
@ -166,7 +166,7 @@ Ox.Event = (function() {
if (args.length == 0) { if (args.length == 0) {
eventHandlers = []; eventHandlers = [];
} else if (Ox.isFunction(args[0])) { } else if (Ox.isFunction(args[0])) {
eventHandlers.forEach(function(handler) { eventHandlers.forEach(function(handler, i) {
handler === args[0] && eventHandlers.splice(i, 1); handler === args[0] && eventHandlers.splice(i, 1);
}); });
} else if ((self = args.shift()).eventHandlers) { } else if ((self = args.shift()).eventHandlers) {