Commit 1f80305e authored by Adam Lassek's avatar Adam Lassek

EventTarget: set handler for multiple events at once

parent a69b2dcf
......@@ -78,34 +78,40 @@ var EventTarget = exports.EventTarget = {
return object;
},
on: function(eventName, callback, binding) {
var allCallbacks = callbacksFor(this), callbacks;
on: function(eventNames, callback, binding) {
var allCallbacks = callbacksFor(this), callbacks, eventName;
eventNames = eventNames.split(/\s+/);
binding = binding || this;
callbacks = allCallbacks[eventName];
while (eventName = eventNames.shift()) {
callbacks = allCallbacks[eventName];
if (!callbacks) {
callbacks = allCallbacks[eventName] = [];
}
if (!callbacks) {
callbacks = allCallbacks[eventName] = [];
}
if (indexOf(callbacks, callback) === -1) {
callbacks.push([callback, binding]);
if (indexOf(callbacks, callback) === -1) {
callbacks.push([callback, binding]);
}
}
},
off: function(eventName, callback) {
var allCallbacks = callbacksFor(this), callbacks;
off: function(eventNames, callback) {
var allCallbacks = callbacksFor(this), callbacks, eventName, index;
eventNames = eventNames.split(/\s+/);
if (!callback) {
allCallbacks[eventName] = [];
return;
}
while (eventName = eventNames.shift()) {
if (!callback) {
allCallbacks[eventName] = [];
continue;
}
callbacks = allCallbacks[eventName];
callbacks = allCallbacks[eventName];
var index = indexOf(callbacks, callback);
index = indexOf(callbacks, callback);
if (index !== -1) { callbacks.splice(index, 1); }
if (index !== -1) { callbacks.splice(index, 1); }
}
},
trigger: function(eventName, options) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment