From 4301254fa00983ecdd9b0945bae67532bb3d9cfb Mon Sep 17 00:00:00 2001 From: Cameron Baney Date: Tue, 5 Sep 2017 14:05:36 -0400 Subject: [PATCH 1/9] Allow user to add element option for navigator --- src/navigator.js | 63 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 4c9848cf..f2472575 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -55,43 +55,52 @@ $.Navigator = function( options ){ navigatorSize; //We may need to create a new element and id if they did not - //provide the id for the existing element - if( !options.id ){ - options.id = 'navigator-' + $.now(); - this.element = $.makeNeutralElement( "div" ); - options.controlOptions = { - anchor: $.ControlAnchor.TOP_RIGHT, - attachToViewer: true, - autoFade: options.autoFade - }; + //provide the id for the existing element or the element itself + if( !options.element ){ + if( !options.id ){ + options.id = 'navigator-' + $.now(); + this.element = $.makeNeutralElement( "div" ); + options.controlOptions = { + anchor: $.ControlAnchor.TOP_RIGHT, + attachToViewer: true, + autoFade: options.autoFade + }; - if( options.position ){ - if( 'BOTTOM_RIGHT' == options.position ){ - options.controlOptions.anchor = $.ControlAnchor.BOTTOM_RIGHT; - } else if( 'BOTTOM_LEFT' == options.position ){ - options.controlOptions.anchor = $.ControlAnchor.BOTTOM_LEFT; - } else if( 'TOP_RIGHT' == options.position ){ - options.controlOptions.anchor = $.ControlAnchor.TOP_RIGHT; - } else if( 'TOP_LEFT' == options.position ){ - options.controlOptions.anchor = $.ControlAnchor.TOP_LEFT; - } else if( 'ABSOLUTE' == options.position ){ - options.controlOptions.anchor = $.ControlAnchor.ABSOLUTE; - options.controlOptions.top = options.top; - options.controlOptions.left = options.left; - options.controlOptions.height = options.height; - options.controlOptions.width = options.width; + if( options.position ){ + if( 'BOTTOM_RIGHT' == options.position ){ + options.controlOptions.anchor = $.ControlAnchor.BOTTOM_RIGHT; + } else if( 'BOTTOM_LEFT' == options.position ){ + options.controlOptions.anchor = $.ControlAnchor.BOTTOM_LEFT; + } else if( 'TOP_RIGHT' == options.position ){ + options.controlOptions.anchor = $.ControlAnchor.TOP_RIGHT; + } else if( 'TOP_LEFT' == options.position ){ + options.controlOptions.anchor = $.ControlAnchor.TOP_LEFT; + } else if( 'ABSOLUTE' == options.position ){ + options.controlOptions.anchor = $.ControlAnchor.ABSOLUTE; + options.controlOptions.top = options.top; + options.controlOptions.left = options.left; + options.controlOptions.height = options.height; + options.controlOptions.width = options.width; + } } - } + } else { + this.element = document.getElementById( options.id ); + options.controlOptions = { + anchor: $.ControlAnchor.NONE, + attachToViewer: false, + autoFade: false + }; + } + this.element.id = options.id; } else { - this.element = document.getElementById( options.id ); + this.element = options.element; options.controlOptions = { anchor: $.ControlAnchor.NONE, attachToViewer: false, autoFade: false }; } - this.element.id = options.id; this.element.className += ' navigator'; options = $.extend( true, { From d4dfcd2288be9147c8c5e44f8e26fe4615d6ef9e Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Sun, 29 May 2022 20:53:11 -0400 Subject: [PATCH 2/9] fix inconsistent open-close braces, add warn when using element even when id provided --- src/navigator.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 954ec8d0..f64a1d0a 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -57,14 +57,16 @@ $.Navigator = function( options ){ //We may need to create a new element and id if they did not //provide the id for the existing element or the element itself if( !options.element ){ - if( !options.id ){ - options.id = 'navigator-' + $.now(); - this.element = $.makeNeutralElement( "div" ); - options.controlOptions = { - anchor: $.ControlAnchor.TOP_RIGHT, - attachToViewer: true, - autoFade: options.autoFade - }; + if (!options.id) { + options.id = 'navigator-' + $.now(); + } + + this.element = $.makeNeutralElement( "div" ); + options.controlOptions = { + anchor: $.ControlAnchor.TOP_RIGHT, + attachToViewer: true, + autoFade: options.autoFade + }; if( options.position ){ if( 'BOTTOM_RIGHT' === options.position ){ @@ -94,6 +96,8 @@ $.Navigator = function( options ){ this.element.id = options.id; } else { this.element = options.element; + $.console.warn("Given option.id for Navigator was ignored since option.element was provided and is being used instead."); + options.controlOptions = { anchor: $.ControlAnchor.NONE, attachToViewer: false, From ca368797b0d229233315bc0d6afce297796e8753 Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Sun, 29 May 2022 21:18:28 -0400 Subject: [PATCH 3/9] restructure again to make less confusing, less duplicate code --- src/navigator.js | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index f64a1d0a..c5b56939 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -32,6 +32,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +const { option } = require("grunt"); + (function( $ ){ /** @@ -56,11 +58,25 @@ $.Navigator = function( options ){ //We may need to create a new element and id if they did not //provide the id for the existing element or the element itself - if( !options.element ){ - if (!options.id) { + if( options.element || options.id ){ + if ( options.element ) { + if ( options.id ){ + $.console.warn("Given option.id for Navigator was ignored since option.element was provided and is being used instead."); + } + options.id = 'navigator-' + $.now(); + this.element = options.element; + } else { + this.element = document.getElementById( options.id ); } + options.controlOptions = { + anchor: $.ControlAnchor.NONE, + attachToViewer: false, + autoFade: false + }; + } else { + options.id = 'navigator-' + $.now(); this.element = $.makeNeutralElement( "div" ); options.controlOptions = { anchor: $.ControlAnchor.TOP_RIGHT, @@ -84,26 +100,9 @@ $.Navigator = function( options ){ options.controlOptions.height = options.height; options.controlOptions.width = options.width; } - - } else { - this.element = document.getElementById( options.id ); - options.controlOptions = { - anchor: $.ControlAnchor.NONE, - attachToViewer: false, - autoFade: false - }; } - this.element.id = options.id; - } else { - this.element = options.element; - $.console.warn("Given option.id for Navigator was ignored since option.element was provided and is being used instead."); - - options.controlOptions = { - anchor: $.ControlAnchor.NONE, - attachToViewer: false, - autoFade: false - }; } + this.element.id = options.id; this.element.className += ' navigator'; options = $.extend( true, { From 4a877d60f784eda6eba9ec8bc07bdc2f417ff567 Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Sun, 29 May 2022 21:23:22 -0400 Subject: [PATCH 4/9] remove unneeded code, not sure how it got there --- src/navigator.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index c5b56939..64f24b67 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -32,8 +32,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -const { option } = require("grunt"); - (function( $ ){ /** From 9772901d719b173e1144732ff5bb61b95674e7ea Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Sun, 29 May 2022 21:30:48 -0400 Subject: [PATCH 5/9] Don't overwrite the element's id if it has one already --- src/navigator.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/navigator.js b/src/navigator.js index 64f24b67..6ecddef0 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -32,6 +32,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +const { option } = require("grunt"); + (function( $ ){ /** @@ -60,9 +62,15 @@ $.Navigator = function( options ){ if ( options.element ) { if ( options.id ){ $.console.warn("Given option.id for Navigator was ignored since option.element was provided and is being used instead."); + } else { + // Don't overwrite the element's id if it has one already + if ( option.element.id ) { + options.id = option.element.id; + } else { + options.id = 'navigator-' + $.now(); + } } - options.id = 'navigator-' + $.now(); this.element = options.element; } else { this.element = document.getElementById( options.id ); From 3661d6cae5cba55f6808170489132d2d0b43d83a Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Sun, 29 May 2022 21:31:29 -0400 Subject: [PATCH 6/9] remove auto code --- src/navigator.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index 6ecddef0..d6a7032d 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -32,8 +32,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -const { option } = require("grunt"); - (function( $ ){ /** From df0e598e38081d088e6a5499a9d616b29b12c757 Mon Sep 17 00:00:00 2001 From: Joe DF <3848219+joedf@users.noreply.github.com> Date: Sun, 29 May 2022 21:38:38 -0400 Subject: [PATCH 7/9] fix typo --- src/navigator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/navigator.js b/src/navigator.js index d6a7032d..06a218ab 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -62,8 +62,8 @@ $.Navigator = function( options ){ $.console.warn("Given option.id for Navigator was ignored since option.element was provided and is being used instead."); } else { // Don't overwrite the element's id if it has one already - if ( option.element.id ) { - options.id = option.element.id; + if ( options.element.id ) { + options.id = options.element.id; } else { options.id = 'navigator-' + $.now(); } From ff4f88dc645599ede3b793c17b3e96e21185365f Mon Sep 17 00:00:00 2001 From: Joachim de fourestier Date: Wed, 8 Jun 2022 20:05:43 -0400 Subject: [PATCH 8/9] add some documentation --- src/navigator.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/navigator.js b/src/navigator.js index 06a218ab..c5a4ceca 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -45,7 +45,9 @@ * @memberof OpenSeadragon * @extends OpenSeadragon.Viewer * @extends OpenSeadragon.EventSource - * @param {Object} options + * @param {Object} options - Navigator options + * @param {Element} [options.element] - An element to use for the navigator + * @param {String} [options.id] - Id of the element to use for the navigator. However, this is ignored if {@link options.element} is provided. */ $.Navigator = function( options ){ From 3ca17c1508b980e5f371575df9195a76c006cce5 Mon Sep 17 00:00:00 2001 From: Joachim de fourestier Date: Wed, 8 Jun 2022 20:15:21 -0400 Subject: [PATCH 9/9] missing period --- src/navigator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navigator.js b/src/navigator.js index c5a4ceca..539bad4e 100644 --- a/src/navigator.js +++ b/src/navigator.js @@ -46,7 +46,7 @@ * @extends OpenSeadragon.Viewer * @extends OpenSeadragon.EventSource * @param {Object} options - Navigator options - * @param {Element} [options.element] - An element to use for the navigator + * @param {Element} [options.element] - An element to use for the navigator. * @param {String} [options.id] - Id of the element to use for the navigator. However, this is ignored if {@link options.element} is provided. */ $.Navigator = function( options ){