From 8178687298626533c48a94aa3099416e0fbbacda Mon Sep 17 00:00:00 2001 From: Steve Halasz Date: Thu, 10 Sep 2020 17:40:30 -0400 Subject: [PATCH] Better handle destruction when navigator in custom location --- src/button.js | 24 ++++++++++++++++-------- src/control.js | 4 +++- src/viewer.js | 10 +++++++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/button.js b/src/button.js index 7b00f9ee..5668c871 100644 --- a/src/button.js +++ b/src/button.js @@ -399,14 +399,22 @@ $.extend( $.Button.prototype, $.EventSource.prototype, /** @lends OpenSeadragon. }, destroy: function() { - this.element.removeChild(this.imgRest); - this.imgRest = null; - this.element.removeChild(this.imgGroup); - this.imgGroup = null; - this.element.removeChild(this.imgHover); - this.imgHover = null; - this.element.removeChild(this.imgDown); - this.imgDown = null; + if (this.imgRest) { + this.element.removeChild(this.imgRest); + this.imgRest = null; + } + if (this.imgGroup) { + this.element.removeChild(this.imgGroup); + this.imgGroup = null; + } + if (this.imgHover) { + this.element.removeChild(this.imgHover); + this.imgHover = null; + } + if (this.imgDown) { + this.element.removeChild(this.imgDown); + this.imgDown = null; + } this.removeAllHandlers(); this.tracker.destroy(); this.element = null; diff --git a/src/control.js b/src/control.js index 64f762d7..6cb229f8 100644 --- a/src/control.js +++ b/src/control.js @@ -161,7 +161,9 @@ $.Control.prototype = { */ destroy: function() { this.wrapper.removeChild( this.element ); - this.container.removeChild( this.wrapper ); + if (this.anchor !== $.ControlAnchor.NONE) { + this.container.removeChild(this.wrapper); + } }, /** diff --git a/src/viewer.js b/src/viewer.js index b5b24318..9f6e767a 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -775,7 +775,13 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, this.removeAllHandlers(); if (this.buttons) { - this.buttons.destroy(); + if (this.buttons instanceof $.ButtonGroup) { + this.buttons.destroy(); + } else { + while (this.buttons.length) { + this.buttons.pop().destroy(); + } + } } if (this.paging) { @@ -1869,6 +1875,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, {anchor: this.navigationControlAnchor || $.ControlAnchor.TOP_LEFT} ); } + } else { + this.buttons = buttons; } }