2011-12-17 07:14:10 +04:00
|
|
|
|
|
|
|
(function($){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
$.EventHandler = function() {
|
|
|
|
this.events = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
$.EventHandler.prototype = {
|
|
|
|
|
|
|
|
addHandler: function( id, handler ) {
|
|
|
|
var events = this.events[ id ];
|
|
|
|
if( !events ){
|
|
|
|
this.events[ id ] = events = [];
|
|
|
|
}
|
|
|
|
events[ events.length ] = handler;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeHandler: function( id, handler ) {
|
|
|
|
//Start Thatcher - unneccessary indirection. Also, because events were
|
|
|
|
// - not actually being removed, we need to add the code
|
|
|
|
// - to do the removal ourselves. TODO
|
|
|
|
var events = this.events[ id ];
|
|
|
|
if ( !events ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//End Thatcher
|
|
|
|
},
|
2011-12-17 07:14:10 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
getHandler: function( id ) {
|
|
|
|
var events = this.events[ id ];
|
|
|
|
if ( !events || !events.length ){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
events = events.length === 1 ?
|
|
|
|
[ events[ 0 ] ] :
|
|
|
|
Array.apply( null, events );
|
|
|
|
return function( source, args ) {
|
|
|
|
var i,
|
|
|
|
length = events.length;
|
|
|
|
for ( i = 0; i < length; i++ ) {
|
|
|
|
events[ i ]( source, args );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
2011-12-17 07:14:10 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
raiseEvent: function( eventName, eventArgs ) {
|
|
|
|
var handler = this.getHandler( eventName );
|
2011-12-17 07:14:10 +04:00
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
if ( handler ) {
|
|
|
|
if ( !eventArgs ) {
|
|
|
|
eventArgs = new Object();
|
2011-12-17 07:14:10 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
handler( this, eventArgs );
|
2011-12-17 07:14:10 +04:00
|
|
|
}
|
2012-01-25 23:14:02 +04:00
|
|
|
}
|
|
|
|
};
|
2011-12-17 07:14:10 +04:00
|
|
|
|
|
|
|
}( OpenSeadragon ));
|