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

EventTarget: set handler for multiple events at once

parent a69b2dcf
...@@ -78,10 +78,12 @@ var EventTarget = exports.EventTarget = { ...@@ -78,10 +78,12 @@ var EventTarget = exports.EventTarget = {
return object; return object;
}, },
on: function(eventName, callback, binding) { on: function(eventNames, callback, binding) {
var allCallbacks = callbacksFor(this), callbacks; var allCallbacks = callbacksFor(this), callbacks, eventName;
eventNames = eventNames.split(/\s+/);
binding = binding || this; binding = binding || this;
while (eventName = eventNames.shift()) {
callbacks = allCallbacks[eventName]; callbacks = allCallbacks[eventName];
if (!callbacks) { if (!callbacks) {
...@@ -91,21 +93,25 @@ var EventTarget = exports.EventTarget = { ...@@ -91,21 +93,25 @@ var EventTarget = exports.EventTarget = {
if (indexOf(callbacks, callback) === -1) { if (indexOf(callbacks, callback) === -1) {
callbacks.push([callback, binding]); callbacks.push([callback, binding]);
} }
}
}, },
off: function(eventName, callback) { off: function(eventNames, callback) {
var allCallbacks = callbacksFor(this), callbacks; var allCallbacks = callbacksFor(this), callbacks, eventName, index;
eventNames = eventNames.split(/\s+/);
while (eventName = eventNames.shift()) {
if (!callback) { if (!callback) {
allCallbacks[eventName] = []; allCallbacks[eventName] = [];
return; 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) { 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