From 9daa8feec128559a7ed8f811e8d3de785f224a4a Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 14 Dec 2022 09:21:52 -0500 Subject: [PATCH] cleaning up changes; modified demo --- src/viewer.js | 33 +++++++-------------------------- test/demo/resizeviewer.html | 27 +++------------------------ 2 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 4af8a714..d1fe1535 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -205,6 +205,7 @@ $.Viewer = function( options ) { animating: false, forceRedraw: false, needsResize: false, + forceResize: false, mouseInside: false, group: null, // whether we should be continuously zooming @@ -329,14 +330,10 @@ $.Viewer = function( options ) { THIS[ this.hash ].prevContainerSize = _getSafeElemSize( this.container ); - this._onViewerResize = onViewerResize; - this._origViewerResize = origViewerResize; //for testing logic changes if(window.ResizeObserver){ this._autoResizePolling = false; this._resizeObserver = new ResizeObserver(function(){ - if(_this.autoResize){ - THIS[_this.hash].needsResize = true; - } + THIS[_this.hash].needsResize = true; }); this._resizeObserver.observe(this.container, {}); @@ -1704,6 +1701,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, */ forceResize: function() { THIS[this.hash].needsResize = true; + THIS[this.hash].forceResize = true; }, /** @@ -3573,26 +3571,8 @@ function updateMulti( viewer ) { viewer._updateRequestId = false; } } -function origViewerResize(viewer, containerSize){ - var viewport = viewer.viewport; - if (viewer.preserveImageSizeOnResize) { - var resizeRatio = THIS[viewer.hash].prevContainerSize.x / containerSize.x; - var zoom = viewport.getZoom() * resizeRatio; - var center = viewport.getCenter(); - viewport.resize(containerSize, false); - viewport.zoomTo(zoom, null, true); - viewport.panTo(center, true); - } else { - // maintain image position - var oldBounds = viewport.getBounds(); - viewport.resize(containerSize, true); - viewport.fitBoundsWithConstraints(oldBounds, true); - } - THIS[viewer.hash].prevContainerSize = containerSize; - THIS[viewer.hash].forceRedraw = true; -} -function onViewerResize(viewer, containerSize){ +function doViewerResize(viewer, containerSize){ var viewport = viewer.viewport; var zoom = viewport.getZoom(); var center = viewport.getCenter(); @@ -3613,6 +3593,7 @@ function onViewerResize(viewer, containerSize){ THIS[viewer.hash].prevContainerSize = containerSize; THIS[viewer.hash].forceRedraw = true; THIS[viewer.hash].needsResize = false; + THIS[viewer.hash].forceResize = false; } function updateOnce( viewer ) { @@ -3621,7 +3602,7 @@ function updateOnce( viewer ) { if (viewer._opening || !THIS[viewer.hash]) { return; } - if (viewer.autoResize){ + if (viewer.autoResize || THIS[viewer.hash].forceResize){ var containerSize; if(viewer._autoResizePolling){ containerSize = _getSafeElemSize(viewer.container); @@ -3631,7 +3612,7 @@ function updateOnce( viewer ) { } } if(THIS[viewer.hash].needsResize){ - viewer._onViewerResize(viewer, containerSize || _getSafeElemSize(viewer.container)); + doViewerResize(viewer, containerSize || _getSafeElemSize(viewer.container)); } } diff --git a/test/demo/resizeviewer.html b/test/demo/resizeviewer.html index 74777552..faa4cba9 100644 --- a/test/demo/resizeviewer.html +++ b/test/demo/resizeviewer.html @@ -97,12 +97,6 @@

Pick options to test:

These options apply to both of the demo viewers on the left (top and bottom).

-
-
Use v3.1 resize logic
-
-
-
Use new resize logic
-
Use polling
@@ -154,23 +148,15 @@ tileSources: "../data/iiif_2_0_sizes/info.json", minZoomImageRatio: 0, maxZoomPixelRatio: 10, - visibilityRatio:1.0, - constrainDuringPan:true, + visibilityRatio:0.5, + constrainDuringPan:false, + showNavigator: true, }); - var _onViewerResize = viewer._onViewerResize; - var _origViewerResize = viewer._origViewerResize; updateViewer(); - - - - - var actions = ['Resize width only', 'Resize height only', 'Resize with constant aspect ratio'] - - var buttons=$('#buttons button').on('click',function(){ switch($(this).text()){ case 'Resize width only': resizeWidth(this); break; @@ -182,8 +168,6 @@ function updateViewer(){ - viewer._onViewerResize = !!parseInt($('.logic-method.selected').data('value')) ? _onViewerResize : _origViewerResize; - viewer.preserveImageSizeOnResize = !!parseInt($('.preserve-method.selected').data('value')); viewer.autoResize = !!parseInt($('.auto-method.selected').data('value')); @@ -203,11 +187,6 @@ } - $('.logic-method').on('click',function(){ - $('.logic-method').removeClass('selected'); - $(this).addClass('selected'); - }); - $('.preserve-method').on('click',function(){ $('.preserve-method').removeClass('selected'); $(this).addClass('selected');