mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-20 01:31:45 +03:00
Add a destroy function on the viewer to clean up and remove elements
created by open seadragon. Add removeAllHandlersForAllEvents to clean up all events on destroy. Clear the onDraw callback on Overlay destroy.
This commit is contained in:
parent
967f2e4f32
commit
4ccb141a42
@ -95,11 +95,22 @@ $.EventHandler.prototype = {
|
||||
* @function
|
||||
* @param {String} eventName - Name of event for which all handlers are to be removed.
|
||||
*/
|
||||
removeAllHandlers: function( eventName ){
|
||||
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] = [];
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Retrive the list of all handlers registered for a given event.
|
||||
* @function
|
||||
|
@ -157,6 +157,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
// clear the onDraw callback
|
||||
this.onDraw = null;
|
||||
|
||||
style.top = "";
|
||||
style.left = "";
|
||||
style.position = "";
|
||||
|
@ -509,6 +509,38 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype,
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Function to destroy the viewer and clean up everything created by Open Seadragon
|
||||
* @function
|
||||
* @name OpenSeadragon.Viewer.prototype.destroy
|
||||
*/
|
||||
destroy: function( ) {
|
||||
this.close();
|
||||
|
||||
this.removeAllHandlersForAllEvents();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// remove the mouse trackers - should we be cleaning up their callbacks?
|
||||
delete this.keyboardCommandArea.innerTracker;
|
||||
delete this.innerTracker;
|
||||
delete this.outerTracker;
|
||||
|
||||
// clear all our references to dom objects
|
||||
this.canvas = null;
|
||||
this.keyboardCommandArea = null;
|
||||
this.container = null;
|
||||
|
||||
// clear our reference to the main element - they will need to pass it in again, creating a new viewer
|
||||
this.element = null;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @function
|
||||
|
Loading…
x
Reference in New Issue
Block a user