From b5d977d593557cfffda139a1035b1e7a6b218bca Mon Sep 17 00:00:00 2001 From: Robert Hickman Date: Wed, 29 May 2013 17:10:45 -0600 Subject: [PATCH 1/2] Adding an option that allows the previous and next buttons to wrap around past the end or beginning images. --- changelog.txt | 1 + src/openseadragon.js | 1 + src/viewer.js | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index 9e696ade..af8a9d18 100644 --- a/changelog.txt +++ b/changelog.txt @@ -9,6 +9,7 @@ OPENSEADRAGON CHANGELOG * Keyboard handling is now done in the viewer rather than navigator (#46) * Additional navigator fixes (#46) * Fixed an error in EventHandler.removeHandler() (#48) +* You can now choose to have previous and next buttons wrap using the config.navPrevNextWrap. 0.9.127: diff --git a/src/openseadragon.js b/src/openseadragon.js index 83f417fa..ab899aa0 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -588,6 +588,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ DOWN: 'next_pressed.png' } }, + navPrevNextWrap: false, //DEVELOPER SETTINGS debugMode: false, diff --git a/src/viewer.js b/src/viewer.js index a44717ee..7c7c4722 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -345,6 +345,10 @@ $.Viewer = function( options ) { beginControlsAutoHide( _this ); } ); // initial fade out + if(this.navPrevNextWrap){ + this.previousButton.enable(); + } + }; $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, { @@ -1021,7 +1025,9 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, if( this.nextButton ){ if( ( this.tileSources.length - 1 ) === page ){ //Disable next button - this.nextButton.disable(); + if(!this.navPrevNextWrap){ + this.nextButton.disable(); + } } else { this.nextButton.enable(); } @@ -1031,7 +1037,9 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, //Enable previous button this.previousButton.enable(); } else { - this.previousButton.disable(); + if(!this.navPrevNextWrap){ + this.previousButton.disable(); + } } } @@ -1625,12 +1633,18 @@ function onFullPage() { function onPrevious(){ var previous = THIS[ this.hash ].sequence - 1; + if(this.navPrevNextWrap && previous < 0){ + previous += this.tileSources.length; + } this.goToPage( previous ); } function onNext(){ var next = THIS[ this.hash ].sequence + 1; + if(this.navPrevNextWrap && next >= this.tileSources.length){ + next = 0; + } this.goToPage( next ); } From 699a5dd101e0dbbe99c6e915b8855e87057e2618 Mon Sep 17 00:00:00 2001 From: Robert Hickman Date: Thu, 30 May 2013 12:46:54 -0600 Subject: [PATCH 2/2] Adding documentation about navPrevNextWrap. --- src/openseadragon.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/openseadragon.js b/src/openseadragon.js index ab899aa0..ee5e0dac 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -251,6 +251,11 @@ * these paths, prefer setting the option.prefixUrl rather than overriding * every image path directly through this setting. * + * @param {Boolean} [options.navPrevNextWrap=false] + * If the 'previous' button will wrap to the last image when viewing the first + * image and if the 'next' button will wrap to the first image when viewing + * the last image. + * * @returns {OpenSeadragon.Viewer} */ window.OpenSeadragon = window.OpenSeadragon || function( options ){