From b8a4f7e7a04b1c0158d8516ba24231521baa23f2 Mon Sep 17 00:00:00 2001 From: Nelson Campos Date: Wed, 11 Apr 2018 11:25:46 +0100 Subject: [PATCH] Reorganizes code to match standard calls of viewport object methods. A new viewport function was created (toggleFlip()) to change viewport's flip state and demand new viewers drawing. The onFlip function exists on openseadragon to handle flip control button press and demand viewport toggle flip. --- src/viewer.js | 21 ++++----------------- src/viewport.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 49d972db..76b78094 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -1674,7 +1674,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, onFullScreenHandler = $.delegate( this, onFullScreen ), onRotateLeftHandler = $.delegate( this, onRotateLeft ), onRotateRightHandler = $.delegate( this, onRotateRight ), - onFlipHandler = $.delegate( this, onButtonFlip), + onFlipHandler = $.delegate( this, onFlip), onFocusHandler = $.delegate( this, onFocus ), onBlurHandler = $.delegate( this, onBlur ), navImages = this.navImages, @@ -2636,7 +2636,7 @@ function onCanvasKeyPress( event ) { this.viewport.applyConstraints(); return false; case 102: //f - onFlip(this); + this.viewport.toggleFlip(); return false; default: // console.log( 'navigator keycode %s', event.keyCode ); @@ -3519,24 +3519,11 @@ function onRotateRight() { } } -/** - * Note: When pressed f on keyboard - */ -function onFlip( viewer ){ - viewer.viewport.flipped = !viewer.viewport.flipped; - - if(viewer.navigator){ - viewer.navigator.toggleFlip(); - } - viewer._forceRedraw = !viewer._forceRedraw; - viewer.forceRedraw(); -} - /** * Note: When pressed flip control button */ -function onButtonFlip() { - onFlip(this); +function onFlip() { + this.viewport.toggleFlip(); } function onPrevious(){ diff --git a/src/viewport.js b/src/viewport.js index 95632271..4c30dcee 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -1519,7 +1519,20 @@ $.Viewport.prototype = { var scale = this._contentBoundsNoRotate.width; var viewportToImageZoomRatio = (imageWidth / containerWidth) / scale; return imageZoom * viewportToImageZoomRatio; + }, + + /** + * Toggle flip state and demands a new drawing on navigator and viewer objects. + */ + toggleFlip: function() { + this.flipped = !this.flipped; + if(this.viewer.navigator){ + this.viewer.navigator.toggleFlip(); + } + this.viewer._forceRedraw = !this.viewer._forceRedraw; + this.viewer.forceRedraw(); } + }; }( OpenSeadragon ));