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