mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-26 07:06: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,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
|
* @function
|
||||||
* @param {String} eventName - Name of event for which all handlers are to be removed.
|
* @param {String} eventName - Name of event for which all handlers are to be removed.
|
||||||
*/
|
*/
|
||||||
removeAllHandlers: function( eventName ) {
|
removeAllHandlers: function( eventName ) {
|
||||||
this.events[ eventName ] = [];
|
if (eventName){
|
||||||
},
|
this.events[ eventName ] = [];
|
||||||
|
} else{
|
||||||
|
for (var eventType in this.events) {
|
||||||
/**
|
this.events[eventType] = [];
|
||||||
* Remove every event handler for all event types
|
}
|
||||||
* @function
|
|
||||||
*/
|
|
||||||
removeAllHandlersForAllEvents: function( ) {
|
|
||||||
for (var eventType in this.events) {
|
|
||||||
this.events[eventType] = [];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrive the list of all handlers registered for a given event.
|
* Retrive the list of all handlers registered for a given event.
|
||||||
|
@ -171,6 +171,15 @@
|
|||||||
|
|
||||||
$.MouseTracker.prototype = {
|
$.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.
|
* Are we currently tracking events on this element.
|
||||||
* @deprecated Just use this.tracking
|
* @deprecated Just use this.tracking
|
||||||
|
@ -499,7 +499,9 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
|||||||
|
|
||||||
this.viewport = this.preserveViewport ? this.viewport : null;
|
this.viewport = this.preserveViewport ? this.viewport : null;
|
||||||
//this.profiler = null;
|
//this.profiler = null;
|
||||||
this.canvas.innerHTML = "";
|
if (this.canvas){
|
||||||
|
this.canvas.innerHTML = "";
|
||||||
|
}
|
||||||
|
|
||||||
VIEWERS[ this.hash ] = null;
|
VIEWERS[ this.hash ] = null;
|
||||||
delete VIEWERS[ this.hash ];
|
delete VIEWERS[ this.hash ];
|
||||||
@ -518,19 +520,27 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
|||||||
destroy: function( ) {
|
destroy: function( ) {
|
||||||
this.close();
|
this.close();
|
||||||
|
|
||||||
this.removeAllHandlersForAllEvents();
|
this.removeAllHandlers();
|
||||||
|
|
||||||
// Go through top element (passed to us) and remove all children
|
// Go through top element (passed to us) and remove all children
|
||||||
// Use removeChild to make sure it handles SVG or any non-html
|
// Use removeChild to make sure it handles SVG or any non-html
|
||||||
// also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
|
// also it performs better - http://jsperf.com/innerhtml-vs-removechild/15
|
||||||
while (this.element.firstChild) {
|
if (this.element){
|
||||||
this.element.removeChild(this.element.firstChild);
|
while (this.element.firstChild) {
|
||||||
|
this.element.removeChild(this.element.firstChild);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the mouse trackers - should we be cleaning up their callbacks?
|
// destroy the mouse trackers
|
||||||
delete this.keyboardCommandArea.innerTracker;
|
if (this.keyboardCommandArea){
|
||||||
delete this.innerTracker;
|
this.keyboardCommandArea.innerTracker.destroy();
|
||||||
delete this.outerTracker;
|
}
|
||||||
|
if (this.innerTracker){
|
||||||
|
this.innerTracker.destroy();
|
||||||
|
}
|
||||||
|
if (this.outerTracker){
|
||||||
|
this.outerTracker.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
// clear all our references to dom objects
|
// clear all our references to dom objects
|
||||||
this.canvas = null;
|
this.canvas = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user