-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter execution events. Fixes #402.
Trying out a new listener handler class.
- Loading branch information
Showing
8 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// namespaces | ||
var dwv = dwv || {}; | ||
dwv.utils = dwv.utils || {}; | ||
|
||
/** | ||
* ListenerHandler class: handles add/removing and firing listeners. | ||
* @constructor | ||
*/ | ||
dwv.utils.ListenerHandler = function () | ||
{ | ||
/** | ||
* listeners. | ||
* @private | ||
*/ | ||
var listeners = {}; | ||
|
||
/** | ||
* Add an event listener. | ||
* @param {String} type The event type. | ||
* @param {Object} callback The method associated with the provided event type, | ||
* will be called with the fired event. | ||
*/ | ||
this.add = function (type, callback) | ||
{ | ||
// create array if not present | ||
if ( typeof listeners[type] === "undefined" ) { | ||
listeners[type] = []; | ||
} | ||
// add callback to listeners array | ||
listeners[type].push(callback); | ||
}; | ||
|
||
/** | ||
* Remove an event listener. | ||
* @param {String} type The event type. | ||
* @param {Object} callback The method associated with the provided event type. | ||
*/ | ||
this.remove = function (type, callback) | ||
{ | ||
// check if the type is present | ||
if( typeof listeners[type] === "undefined" ) { | ||
return; | ||
} | ||
// remove from listeners array | ||
for ( var i = 0; i < listeners[type].length; ++i ) { | ||
if ( listeners[type][i] === callback ) { | ||
listeners[type].splice(i,1); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Fire an event: call all associated listeners with the input event object. | ||
* @param {Object} event The event to fire. | ||
*/ | ||
this.fireEvent = function (event) | ||
{ | ||
// check if they are listeners for the event type | ||
if ( typeof listeners[event.type] === "undefined" ) { | ||
return; | ||
} | ||
// fire events | ||
for ( var i=0; i < listeners[event.type].length; ++i ) { | ||
listeners[event.type][i](event); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters