39 lines
911 B
JavaScript
39 lines
911 B
JavaScript
define(function() {
|
|
function EventObject() {
|
|
var e = this;
|
|
|
|
this.handles = {};
|
|
this.on = function (name, callback) {
|
|
var handleQueue = e.handles[name] || [];
|
|
e.handles[name] = handleQueue;
|
|
handleQueue.push(callback);
|
|
};
|
|
this.off = function (name, callback) {
|
|
var handleQueue = e.handles[name] || [];
|
|
if (callback) {
|
|
for (var i = handleQueue.length - 1; i >= 0; i++) {
|
|
if (handleQueue[i] == callback)
|
|
handleQueue.splice(i, 1);
|
|
}
|
|
} else {
|
|
handleQueue.length = 0;
|
|
}
|
|
e.handles[name] = handleQueue;
|
|
};
|
|
this.fireEvent = function (name, args) {
|
|
var handleQueue = e.handles[name];
|
|
if (!handleQueue) return;
|
|
|
|
for (var i in handleQueue) {
|
|
var handle = handleQueue[i];
|
|
if (!handle) continue;
|
|
if (handle.apply(this, args) === false)
|
|
break;
|
|
}
|
|
};
|
|
|
|
return this;
|
|
}
|
|
|
|
return EventObject;
|
|
}); |