mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
fix: calling viewer.destroy() multiple times throw an error. And a simple destroy to mousetracker
This commit is contained in:
parent
4ccb141a42
commit
68f9d675fc
@ -91,26 +91,20 @@ $.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 ) {
|
||||
if (eventName){
|
||||
this.events[ eventName ] = [];
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Remove every event handler for all event types
|
||||
* @function
|
||||
*/
|
||||
removeAllHandlersForAllEvents: function( ) {
|
||||
} else{
|
||||
for (var eventType in this.events) {
|
||||
this.events[eventType] = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Retrive the list of all handlers registered for a given event.
|
||||
* @function
|
||||
|
@ -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
|
||||
|
@ -499,7 +499,9 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
||||
|
||||
this.viewport = this.preserveViewport ? this.viewport : null;
|
||||
//this.profiler = null;
|
||||
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
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user