mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 22:56:11 +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,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.
|
||||
|
@ -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;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user