From 5889f346958dfefd83d633ced681127abd1c678f Mon Sep 17 00:00:00 2001 From: Luis Nieto Date: Thu, 8 Jul 2021 23:43:38 -0500 Subject: [PATCH 1/3] Add keys to change image source in sequence mode Add the keys 'j' and 'k' to change the image source in the viewer. - 'j': previous source - 'k': next source --- src/viewer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/viewer.js b/src/viewer.js index ffbe0f4f..03276a7b 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2782,6 +2782,12 @@ function onCanvasKeyPress( event ) { this.viewport.toggleFlip(); event.preventDefault = true; break; + case 106: //j - previous image source + onPrevious.bind(this)(); + break; + case 107: //k - next image source + onNext.bind(this)(); + break; default: // console.log( 'navigator keycode %s', event.keyCode ); event.preventDefault = false; From 1f73dde983d1b1aafcc408e5f2d9fa7d2799d9e1 Mon Sep 17 00:00:00 2001 From: Luis Nieto Date: Fri, 9 Jul 2021 16:09:46 -0500 Subject: [PATCH 2/3] Move change image source's methods inside viewer Added the methods inside the extend function, so that they appear as properties. Since we cannot reference properties of an object inside said object, we extract them as properties when needed. --- src/viewer.js | 61 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 03276a7b..e6f116bc 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1646,8 +1646,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, ////////////////////////////////////////////////////////////////////////// var onFocusHandler = $.delegate( this, onFocus ), onBlurHandler = $.delegate( this, onBlur ), - onNextHandler = $.delegate( this, onNext ), - onPreviousHandler = $.delegate( this, onPrevious ), + onNextHandler = $.delegate( this, this['goToNextPage'] ), + onPreviousHandler = $.delegate( this, this['goToPreviousPage'] ), navImages = this.navImages, useGroup = true; @@ -2316,7 +2316,40 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, this.world.resetItems(); this.forceRedraw(); } - } + }, + + /** + * Sets the image source to the source with index equal to + * currentIndex - 1. Changes current image in sequence mode. + * If specified, wraps around (see navPrevNextWrap in + * {@link OpenSeadragon.Options}) + * + * @method + */ + + goToPreviousPage: function () { + var previous = this._sequenceIndex - 1; + if(this.navPrevNextWrap && previous < 0){ + previous += this.tileSources.length; + } + this.goToPage( previous ); + }, + + /** + * Sets the image source to the source with index equal to + * currentIndex + 1. Changes current image in sequence mode. + * If specified, wraps around (see navPrevNextWrap in + * {@link OpenSeadragon.Options}) + * + * @method + */ + goToNextPage: function () { + var next = this._sequenceIndex + 1; + if(this.navPrevNextWrap && next >= this.tileSources.length){ + next = 0; + } + this.goToPage( next ); + }, }); @@ -2783,10 +2816,10 @@ function onCanvasKeyPress( event ) { event.preventDefault = true; break; case 106: //j - previous image source - onPrevious.bind(this)(); + this.goToPreviousPage(); break; case 107: //k - next image source - onNext.bind(this)(); + this.goToNextPage(); break; default: // console.log( 'navigator keycode %s', event.keyCode ); @@ -3677,22 +3710,4 @@ function onFlip() { this.viewport.toggleFlip(); } -function onPrevious(){ - var previous = this._sequenceIndex - 1; - if(this.navPrevNextWrap && previous < 0){ - previous += this.tileSources.length; - } - this.goToPage( previous ); -} - - -function onNext(){ - var next = this._sequenceIndex + 1; - if(this.navPrevNextWrap && next >= this.tileSources.length){ - next = 0; - } - this.goToPage( next ); -} - - }( OpenSeadragon )); From 22bb516bc068db5458df1d593f1bfe98f69d5ddc Mon Sep 17 00:00:00 2001 From: Luis Nieto Date: Mon, 12 Jul 2021 13:42:31 -0500 Subject: [PATCH 3/3] Change the way we access some viewer methods --- src/viewer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index e6f116bc..d8e75857 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1646,8 +1646,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, ////////////////////////////////////////////////////////////////////////// var onFocusHandler = $.delegate( this, onFocus ), onBlurHandler = $.delegate( this, onBlur ), - onNextHandler = $.delegate( this, this['goToNextPage'] ), - onPreviousHandler = $.delegate( this, this['goToPreviousPage'] ), + onNextHandler = $.delegate( this, this.goToNextPage ), + onPreviousHandler = $.delegate( this, this.goToPreviousPage ), navImages = this.navImages, useGroup = true;