diff --git a/src/eventhandler.js b/src/eventhandler.js index 430c23fc..b834b214 100644 --- a/src/eventhandler.js +++ b/src/eventhandler.js @@ -91,25 +91,19 @@ $.EventHandler.prototype = { /** - * Remove all event handler for a given event type. + * Remove all event handler for a given event type. If no type is given all event handlers for every event type is removed * @function * @param {String} eventName - Name of event for which all handlers are to be removed. */ removeAllHandlers: function( eventName ) { - this.events[ eventName ] = []; - }, - - - /** - * Remove every event handler for all event types - * @function - */ - removeAllHandlersForAllEvents: function( ) { - for (var eventType in this.events) { - this.events[eventType] = []; + if (eventName){ + this.events[ eventName ] = []; + } else{ + for (var eventType in this.events) { + this.events[eventType] = []; + } } - }, - + }, /** * Retrive the list of all handlers registered for a given event. diff --git a/src/mousetracker.js b/src/mousetracker.js index 4d81dc6b..1b4de92d 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -171,6 +171,15 @@ $.MouseTracker.prototype = { + /** + * Clean up any events or objects created the mouse tracker + * @function + */ + destroy: function() { + stopTracking( this ); + this.element = null; + }, + /** * Are we currently tracking events on this element. * @deprecated Just use this.tracking diff --git a/src/viewer.js b/src/viewer.js index 51eaf7b3..d3dd7579 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -499,7 +499,9 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, this.viewport = this.preserveViewport ? this.viewport : null; //this.profiler = null; - this.canvas.innerHTML = ""; + if (this.canvas){ + this.canvas.innerHTML = ""; + } VIEWERS[ this.hash ] = null; delete VIEWERS[ this.hash ]; @@ -518,19 +520,27 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, destroy: function( ) { this.close(); - this.removeAllHandlersForAllEvents(); + this.removeAllHandlers(); // Go through top element (passed to us) and remove all children // Use removeChild to make sure it handles SVG or any non-html // also it performs better - http://jsperf.com/innerhtml-vs-removechild/15 - while (this.element.firstChild) { - this.element.removeChild(this.element.firstChild); + if (this.element){ + while (this.element.firstChild) { + this.element.removeChild(this.element.firstChild); + } } - // remove the mouse trackers - should we be cleaning up their callbacks? - delete this.keyboardCommandArea.innerTracker; - delete this.innerTracker; - delete this.outerTracker; + // destroy the mouse trackers + if (this.keyboardCommandArea){ + this.keyboardCommandArea.innerTracker.destroy(); + } + if (this.innerTracker){ + this.innerTracker.destroy(); + } + if (this.outerTracker){ + this.outerTracker.destroy(); + } // clear all our references to dom objects this.canvas = null;