blob: 30befbc0a54bb5abd3604a37ae14c5ee9654efa9 [file] [log] [blame]
/*
* weinre is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2010, 2011 IBM Corporation
*/
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
class EventListeners
this._listeners = []
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
method add(listener, useCapture)
this._listeners.push([listener, useCapture])
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
method remove(listener, useCapture)
for (var i=0; i<this._listeners.length; i++) {
var listener = this._listeners[i]
if (listener[0] != listener) continue;
if (listener[1] != useCapture) continue;
this._listeners.splice(i,1)
return
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
method fire(event)
this._listeners.slice().forEach(function(listener) {
var listener = listener[0]
if (typeof listener == "function") {
try {
listener.call(null, event)
}
catch(e) {
console.log(arguments.callee.signature + " invocation exception: " + e)
}
return
}
if (typeof listener.handleEvent != "function") {
throw new Error("listener does not implement the handleEvent() method")
}
try {
listener.handleEvent.call(listener, event)
}
catch(e) {
console.log(arguments.callee.signature + " invocation exception: " + e)
}
})