From 27d28988187f43f2f57ff458af964e9b82a34754 Mon Sep 17 00:00:00 2001 From: thatcher Date: Wed, 13 Feb 2013 17:11:33 -0500 Subject: [PATCH] added removeAllHandlers per macreery's branch, finally implemented removeHandler --- build.properties | 2 +- openseadragon.js | 31 ++++++++++++++++++++++++------- src/eventhandler.js | 27 ++++++++++++++++++++++----- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/build.properties b/build.properties index 36ca2d97..c49d721e 100644 --- a/build.properties +++ b/build.properties @@ -6,7 +6,7 @@ PROJECT: openseadragon BUILD_MAJOR: 0 BUILD_MINOR: 9 -BUILD_ID: 116 +BUILD_ID: 117 BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} diff --git a/openseadragon.js b/openseadragon.js index 885beb86..934fa1df 100644 --- a/openseadragon.js +++ b/openseadragon.js @@ -1,7 +1,7 @@ /*globals OpenSeadragon*/ /** - * @version OpenSeadragon 0.9.116 + * @version OpenSeadragon 0.9.117 * * @fileOverview *

@@ -1924,16 +1924,33 @@ $.EventHandler.prototype = { * @param {Function} handler - Function to be removed. */ removeHandler: function( eventName, 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[ eventName ]; + var events = this.events[ eventName ], + handlers = [], + i; if ( !events ){ return; } - //End Thatcher + if( $.isArray( events ) ){ + for( i = 0; i < events.length; i++ ){ + if( events[ i ] !== handler ){ + handlers.push( handler ); + } + } + this.events[ eventName ] = handlers; + } }, + + /** + * Remove all event handler for a given event type. + * @function + * @param {String} eventName - Name of event for which all handlers are to be removed. + */ + removeAllHandlers: function( eventName ){ + this.events[ eventName ] = []; + }, + + /** * Retrive the list of all handlers registered for a given event. * @function @@ -3500,7 +3517,6 @@ $.Viewer = function( options ) { this.element = this.element || document.getElementById( this.id ); this.canvas = $.makeNeutralElement( "div" ); - //this.container = $.makeNeutralElement( "div" ); this.canvas.className = "openseadragon-canvas"; (function( canvas ){ @@ -3512,6 +3528,7 @@ $.Viewer = function( options ) { canvas.left = "0px"; }( this.canvas.style )); + //the container is created through applying the ControlDock constructor above this.container.className = "openseadragon-container"; (function( container ){ container.width = "100%"; diff --git a/src/eventhandler.js b/src/eventhandler.js index 02f91842..12b99330 100644 --- a/src/eventhandler.js +++ b/src/eventhandler.js @@ -41,16 +41,33 @@ $.EventHandler.prototype = { * @param {Function} handler - Function to be removed. */ removeHandler: function( eventName, 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[ eventName ]; + var events = this.events[ eventName ], + handlers = [], + i; if ( !events ){ return; } - //End Thatcher + if( $.isArray( events ) ){ + for( i = 0; i < events.length; i++ ){ + if( events[ i ] !== handler ){ + handlers.push( handler ); + } + } + this.events[ eventName ] = handlers; + } }, + + /** + * Remove all event handler for a given event type. + * @function + * @param {String} eventName - Name of event for which all handlers are to be removed. + */ + removeAllHandlers: function( eventName ){ + this.events[ eventName ] = []; + }, + + /** * Retrive the list of all handlers registered for a given event. * @function