From 5c7c1d5b6c46a3dbec0179964f58f483f14090be Mon Sep 17 00:00:00 2001 From: Ian Gilman Date: Tue, 12 Aug 2014 16:44:53 -0700 Subject: [PATCH] Moved Viewport.goHome to Viewer.goHome. --- src/viewer.js | 29 ++++++++++++++++++--- src/viewport.js | 22 ++++------------ test/basic.js | 2 +- test/demo/collections/main.js | 1 + test/demo/fitboundswithconstraints.html | 34 ++++++++++++------------- test/overlays.js | 4 +-- 6 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 69f8ae73..4b91185c 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -333,7 +333,7 @@ $.Viewer = function( options ) { _this.viewport.applyConstraints(); return false; case 48://0|) - _this.viewport.goHome(); + _this.goHome(); _this.viewport.applyConstraints(); return false; case 119://w @@ -622,6 +622,28 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype, this.element = null; }, + /** + * @function + * @param {Boolean} immediately + * @fires OpenSeadragon.Viewer.event:home + */ + goHome: function(immediately) { + /** + * Raised when the "home" operation occurs (see {@link OpenSeadragon.Viewport#goHome}). + * + * @event home + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {Boolean} immediately + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent( 'home', { + immediately: immediately + }); + + this.viewport.fitBounds( this.world.getHomeBounds(), immediately ); + }, /** * @function @@ -1929,6 +1951,7 @@ function openTileSource( viewer, source, options ) { }); _this.world.addItem( tiledImage ); + _this.goHome( true ); // Now that we have a drawer, see if it supports rotate. If not we need to remove the rotate buttons if (!_this.drawer.canRotate()) { @@ -2793,9 +2816,7 @@ function lightUp() { function onHome() { - if ( this.viewport ) { - this.viewport.goHome(); - } + this.goHome(); } diff --git a/src/viewport.js b/src/viewport.js index 7b910c49..5e232157 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -105,7 +105,6 @@ $.Viewport = function( options ) { }); this.resetContentSize( this.contentSize ); - this.goHome( true ); this.update(); }; @@ -178,26 +177,15 @@ $.Viewport.prototype = /** @lends OpenSeadragon.Viewport.prototype */{ /** * @function - * @param {Boolean} immediately - * @fires OpenSeadragon.Viewer.event:home + * @private */ goHome: function( immediately ) { + $.console.error("[Viewport.goHome] this function is deprecated; use Viewer.goHome instead"); if( this.viewer ){ - /** - * Raised when the "home" operation occurs (see {@link OpenSeadragon.Viewport#goHome}). - * - * @event home - * @memberof OpenSeadragon.Viewer - * @type {object} - * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. - * @property {Boolean} immediately - * @property {?Object} userData - Arbitrary subscriber-defined object. - */ - this.viewer.raiseEvent( 'home', { - immediately: immediately - }); + this.viewer.goHome(immediately); } - return this.fitBounds( this.getHomeBounds(), immediately ); + + return this; }, /** diff --git a/test/basic.js b/test/basic.js index 811efd3b..46abc823 100644 --- a/test/basic.js +++ b/test/basic.js @@ -133,7 +133,7 @@ }; viewer.addHandler('animation-finish', homeHandler); - viewport.goHome(true); + viewer.goHome(true); } viewer.addHandler("open", opener); diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index 3713ba26..0f78ab4f 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -38,6 +38,7 @@ var addLayerHandler = function( event ) { if ( event.options === options ) { self.viewer.removeHandler( "add-layer", addLayerHandler ); + self.viewer.goHome(); } }; this.viewer.addHandler( "add-layer", addLayerHandler ); diff --git a/test/demo/fitboundswithconstraints.html b/test/demo/fitboundswithconstraints.html index c0317c98..d0c1f460 100644 --- a/test/demo/fitboundswithconstraints.html +++ b/test/demo/fitboundswithconstraints.html @@ -13,7 +13,7 @@ #highlights li { cursor: pointer; } - + @@ -23,33 +23,33 @@
- + - + diff --git a/test/overlays.js b/test/overlays.js index 223f99de..c90c669f 100644 --- a/test/overlays.js +++ b/test/overlays.js @@ -270,7 +270,7 @@ waitForViewer( function() { checkOverlayPosition( "after zoom and pan using image coordinates" ); - viewer.viewport.goHome(); + viewer.goHome(); waitForViewer( function() { checkOverlayPosition( "after goHome using image coordinates" ); start(); @@ -333,7 +333,7 @@ waitForViewer( function() { checkOverlayPosition( "after zoom and pan using viewport coordinates" ); - viewer.viewport.goHome(); + viewer.goHome(); waitForViewer( function() { checkOverlayPosition( "after goHome using viewport coordinates" ); start();