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.
This commit is contained in:
Nelson Campos 2018-04-11 11:25:46 +01:00
parent 6e2c1258df
commit b8a4f7e7a0
2 changed files with 17 additions and 17 deletions

View File

@ -1674,7 +1674,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
onFullScreenHandler = $.delegate( this, onFullScreen ), onFullScreenHandler = $.delegate( this, onFullScreen ),
onRotateLeftHandler = $.delegate( this, onRotateLeft ), onRotateLeftHandler = $.delegate( this, onRotateLeft ),
onRotateRightHandler = $.delegate( this, onRotateRight ), onRotateRightHandler = $.delegate( this, onRotateRight ),
onFlipHandler = $.delegate( this, onButtonFlip), onFlipHandler = $.delegate( this, onFlip),
onFocusHandler = $.delegate( this, onFocus ), onFocusHandler = $.delegate( this, onFocus ),
onBlurHandler = $.delegate( this, onBlur ), onBlurHandler = $.delegate( this, onBlur ),
navImages = this.navImages, navImages = this.navImages,
@ -2636,7 +2636,7 @@ function onCanvasKeyPress( event ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
return false; return false;
case 102: //f case 102: //f
onFlip(this); this.viewport.toggleFlip();
return false; return false;
default: default:
// console.log( 'navigator keycode %s', event.keyCode ); // 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 * Note: When pressed flip control button
*/ */
function onButtonFlip() { function onFlip() {
onFlip(this); this.viewport.toggleFlip();
} }
function onPrevious(){ function onPrevious(){

View File

@ -1519,7 +1519,20 @@ $.Viewport.prototype = {
var scale = this._contentBoundsNoRotate.width; var scale = this._contentBoundsNoRotate.width;
var viewportToImageZoomRatio = (imageWidth / containerWidth) / scale; var viewportToImageZoomRatio = (imageWidth / containerWidth) / scale;
return imageZoom * viewportToImageZoomRatio; 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 )); }( OpenSeadragon ));