Merge branch 'master' into ms-mousetracker

* master:
  Changleg for #1878
  Separate properties for buttonGroup and customButtons
  Better handle destruction when navigator in custom location

# Conflicts:
#	src/viewer.js
This commit is contained in:
Mark Salsbery 2021-03-08 09:42:32 -08:00
commit 459fcb9a4e
5 changed files with 48 additions and 29 deletions

View File

@ -7,6 +7,7 @@ OPENSEADRAGON CHANGELOG
* Now when "simple image" tile sources are removed from the viewer, they free the memory used by the pyramid they create (#1789 @TakumaKira)
* Documentation fix (#1814 @kenanchristian)
* Better cleanup on destruction, to avoid memory leaks (#1832 @JoFrMueller)
* Better handle destruction when navigator in custom location (#1884 @woodchuck)
* Miscellaneous code cleanup (#1840 @msalsbery)
* You can now specify tileSize for the Zoomify Tile Source (#1868 @abrlam)
* Better use of IIIF "max" and "full" URL parameters (#1871 @MImranAsghar)

View File

@ -409,14 +409,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;

View File

@ -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);
}
},
/**

View File

@ -415,14 +415,14 @@ $.Viewer = function( options ) {
if (!this.drawer.canRotate()) {
// Disable/remove the rotate left/right buttons since they aren't supported
if (this.rotateLeft) {
i = this.buttons.buttons.indexOf(this.rotateLeft);
this.buttons.buttons.splice(i, 1);
this.buttons.element.removeChild(this.rotateLeft.element);
i = this.buttonGroup.buttons.indexOf(this.rotateLeft);
this.buttonGroup.buttons.splice(i, 1);
this.buttonGroup.element.removeChild(this.rotateLeft.element);
}
if (this.rotateRight) {
i = this.buttons.buttons.indexOf(this.rotateRight);
this.buttons.buttons.splice(i, 1);
this.buttons.element.removeChild(this.rotateRight.element);
i = this.buttonGroup.buttons.indexOf(this.rotateRight);
this.buttonGroup.buttons.splice(i, 1);
this.buttonGroup.element.removeChild(this.rotateRight.element);
}
}
@ -780,8 +780,12 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this.removeAllHandlers();
if (this.buttons) {
this.buttons.destroy();
if (this.buttonGroup) {
this.buttonGroup.destroy();
} else if (this.customButtons) {
while (this.customButtons.length) {
this.customButtons.pop().destroy();
}
}
if (this.paging) {
@ -1855,13 +1859,13 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
}
if ( useGroup ) {
this.buttons = new $.ButtonGroup({
this.buttonGroup = new $.ButtonGroup({
buttons: buttons,
clickTimeThreshold: this.clickTimeThreshold,
clickDistThreshold: this.clickDistThreshold
});
this.navControl = this.buttons.element;
this.navControl = this.buttonGroup.element;
this.addHandler( 'open', $.delegate( this, lightUp ) );
if( this.toolbar ){
@ -1875,6 +1879,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
{anchor: this.navigationControlAnchor || $.ControlAnchor.TOP_LEFT}
);
}
} else {
this.customButtons = buttons;
}
}
@ -3513,8 +3519,10 @@ function doSingleZoomOut() {
function lightUp() {
this.buttons.emulateEnter();
this.buttons.emulateLeave();
if (this.buttonGroup) {
this.buttonGroup.emulateEnter();
this.buttonGroup.emulateLeave();
}
}
@ -3533,8 +3541,8 @@ function onFullScreen() {
this.setFullScreen( !this.isFullPage() );
}
// correct for no mouseout event on change
if ( this.buttons ) {
this.buttons.emulateLeave();
if ( this.buttonGroup ) {
this.buttonGroup.emulateLeave();
}
this.fullPageButton.element.focus();
if ( this.viewport ) {

View File

@ -53,9 +53,9 @@
assert.ok(viewer.showZoomControl, 'showZoomControl should be on');
assert.ok(!!viewer.zoomInButton, "zoomIn button should not be null");
assert.ok(!!viewer.zoomOutButton, "zoomOut button should not be null");
assert.notEqual(viewer.buttons.buttons.indexOf(viewer.zoomInButton), -1,
assert.notEqual(viewer.buttonGroup.buttons.indexOf(viewer.zoomInButton), -1,
"The zoomIn button should be present");
assert.notEqual(viewer.buttons.buttons.indexOf(viewer.zoomOutButton), -1,
assert.notEqual(viewer.buttonGroup.buttons.indexOf(viewer.zoomOutButton), -1,
"The zoomOut button should be present");
var oldZoom = viewer.viewport.getZoom();
@ -108,7 +108,7 @@
viewer.removeHandler('open', openHandler);
assert.ok(viewer.showHomeControl, 'showHomeControl should be on');
assert.ok(!!viewer.homeButton, "Home button should not be null");
assert.notEqual(viewer.buttons.buttons.indexOf(viewer.homeButton), -1,
assert.notEqual(viewer.buttonGroup.buttons.indexOf(viewer.homeButton), -1,
"The home button should be present");
viewer.viewport.zoomBy(1.1);
@ -167,7 +167,7 @@
viewer.removeHandler('open', openHandler);
assert.ok(viewer.showHomeControl, 'showFullPageControl should be on');
assert.ok(!!viewer.fullPageButton, "FullPage button should not be null");
assert.notEqual(viewer.buttons.buttons.indexOf(viewer.fullPageButton), -1,
assert.notEqual(viewer.buttonGroup.buttons.indexOf(viewer.fullPageButton), -1,
"The full page button should be present");
assert.ok(!viewer.isFullPage(), "OSD should not be in full page.");
@ -223,9 +223,9 @@
assert.ok(viewer.drawer, 'Drawer exists');
assert.ok(viewer.drawer.canRotate(), 'drawer.canRotate needs to be true');
assert.ok(viewer.showRotationControl, 'showRotationControl should be true');
assert.notEqual(viewer.buttons.buttons.indexOf(viewer.rotateLeftButton), -1,
assert.notEqual(viewer.buttonGroup.buttons.indexOf(viewer.rotateLeftButton), -1,
"rotateLeft should be found");
assert.notEqual(viewer.buttons.buttons.indexOf(viewer.rotateRightButton), -1,
assert.notEqual(viewer.buttonGroup.buttons.indexOf(viewer.rotateRightButton), -1,
"rotateRight should be found");
// Now simulate the left/right button clicks.