From 3550dfafd3128642ac956f9d67bb48f38f1aae96 Mon Sep 17 00:00:00 2001 From: achu1998 Date: Sat, 29 Mar 2025 13:47:02 +1030 Subject: [PATCH] Refactored code to minimise the changes required --- src/viewer.js | 92 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 95c9e97f..059f326d 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2005,11 +2005,11 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, ////////////////////////////////////////////////////////////////////////// // Navigation Controls ////////////////////////////////////////////////////////////////////////// - var beginZoomingInHandler = $.delegate( this, this.beginZoomingIn ), - endZoomingHandler = $.delegate( this, this.endZooming ), - doSingleZoomInHandler = $.delegate( this, this.doSingleZoomIn ), - beginZoomingOutHandler = $.delegate( this, this.beginZoomingOut ), - doSingleZoomOutHandler = $.delegate( this, this.doSingleZoomOut ), + var beginZoomingInHandler = $.delegate( this, beginZoomingIn ), + endZoomingHandler = $.delegate( this, endZooming ), + doSingleZoomInHandler = $.delegate( this, doSingleZoomIn ), + beginZoomingOutHandler = $.delegate( this, beginZoomingOut ), + doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ), onHomeHandler = $.delegate( this, onHome ), onFullScreenHandler = $.delegate( this, onFullScreen ), onRotateLeftHandler = $.delegate( this, onRotateLeft ), @@ -2631,11 +2631,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @function * @memberof OpenSeadragon.Viewer.prototype */ - beginZoomingIn: function () { - THIS[ this.hash ].lastZoomTime = $.now(); - THIS[ this.hash ].zoomFactor = this.zoomPerSecond; - THIS[ this.hash ].zooming = true; - scheduleZoom( this ); + startZoomInNavButton: function () { + beginZoomingIn(); }, /** @@ -2643,11 +2640,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @function * @memberof OpenSeadragon.Viewer.prototype */ - beginZoomingOut: function () { - THIS[ this.hash ].lastZoomTime = $.now(); - THIS[ this.hash ].zoomFactor = 1.0 / this.zoomPerSecond; - THIS[ this.hash ].zooming = true; - scheduleZoom( this ); + startZoomOutNavButton: function () { + beginZoomingOut(); }, /** @@ -2655,8 +2649,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @function * @memberof OpenSeadragon.Viewer.prototype */ - endZooming: function () { - THIS[ this.hash ].zooming = false; + endZoomNavButton: function () { + endZooming(); }, /** @@ -2664,14 +2658,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @function * @memberof OpenSeadragon.Viewer.prototype */ - doSingleZoomIn: function () { - if ( this.viewport ) { - THIS[ this.hash ].zooming = false; - this.viewport.zoomBy( - this.zoomPerClick / 1.0 - ); - this.viewport.applyConstraints(); - } + zoomInNavButton: function () { + doSingleZoomIn(); }, /** @@ -2679,14 +2667,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, * @function * @memberof OpenSeadragon.Viewer.prototype */ - doSingleZoomOut: function () { - if ( this.viewport ) { - THIS[ this.hash ].zooming = false; - this.viewport.zoomBy( - 1.0 / this.zoomPerClick - ); - this.viewport.applyConstraints(); - } + zoomOutNavButton: function () { + doSingleZoomOut(); }, }); @@ -4020,6 +4002,28 @@ function resolveUrl( prefix, url ) { } + +function beginZoomingIn() { + THIS[ this.hash ].lastZoomTime = $.now(); + THIS[ this.hash ].zoomFactor = this.zoomPerSecond; + THIS[ this.hash ].zooming = true; + scheduleZoom( this ); +} + + +function beginZoomingOut() { + THIS[ this.hash ].lastZoomTime = $.now(); + THIS[ this.hash ].zoomFactor = 1.0 / this.zoomPerSecond; + THIS[ this.hash ].zooming = true; + scheduleZoom( this ); +} + + +function endZooming() { + THIS[ this.hash ].zooming = false; +} + + function scheduleZoom( viewer ) { $.requestAnimationFrame( $.delegate( viewer, doZoom ) ); } @@ -4043,6 +4047,28 @@ function doZoom() { } +function doSingleZoomIn() { + if ( this.viewport ) { + THIS[ this.hash ].zooming = false; + this.viewport.zoomBy( + this.zoomPerClick / 1.0 + ); + this.viewport.applyConstraints(); + } +} + + +function doSingleZoomOut() { + if ( this.viewport ) { + THIS[ this.hash ].zooming = false; + this.viewport.zoomBy( + 1.0 / this.zoomPerClick + ); + this.viewport.applyConstraints(); + } +} + + function lightUp() { if (this.buttonGroup) { this.buttonGroup.emulateEnter();