2013-05-01 08:46:16 +04:00
|
|
|
/*
|
2013-05-14 08:00:24 +04:00
|
|
|
* OpenSeadragon - Viewer
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2013-05-14 07:32:09 +04:00
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
2013-05-01 08:46:16 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of CodePlex Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
// dictionary from hash to private properties
|
2012-03-20 10:44:31 +04:00
|
|
|
var THIS = {},
|
|
|
|
// We keep a list of viewers so we can 'wake-up' each viewer on
|
|
|
|
// a page after toggling between fullpage modes
|
2013-06-19 21:33:25 +04:00
|
|
|
VIEWERS = {};
|
2012-02-27 15:56:29 +04:00
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
/**
|
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* The main point of entry into creating a zoomable image on the page.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* We have provided an idiomatic javascript constructor which takes
|
|
|
|
* a single object, but still support the legacy positional arguments.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* The options below are given in order that they appeared in the constructor
|
|
|
|
* as arguments and we translate a positional call into an idiomatic call.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* @class
|
|
|
|
* @extends OpenSeadragon.EventHandler
|
2012-03-09 20:04:28 +04:00
|
|
|
* @extends OpenSeadragon.ControlDock
|
2012-02-01 00:59:09 +04:00
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.element Id of Element to attach to,
|
|
|
|
* @param {String} options.xmlPath Xpath ( TODO: not sure! ),
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {String} options.prefixUrl Url used to prepend to paths, eg button
|
2012-02-01 00:59:09 +04:00
|
|
|
* images, etc.
|
2013-05-02 20:57:23 +04:00
|
|
|
* @param {OpenSeadragon.Control[]} options.controls Array of OpenSeadragon.Control,
|
|
|
|
* @param {OpenSeadragon.Overlay[]} options.overlays Array of OpenSeadragon.Overlay,
|
2013-06-19 21:33:25 +04:00
|
|
|
* @param {OpenSeadragon.Control[]} options.overlayControls An Array of ( TODO:
|
2012-02-01 00:59:09 +04:00
|
|
|
* not sure! )
|
2013-06-19 21:33:25 +04:00
|
|
|
* @property {OpenSeadragon.Viewport} viewport The viewer's viewport, where you
|
2013-05-02 20:57:03 +04:00
|
|
|
* can access zoom, pan, etc.
|
2011-12-07 05:26:06 +04:00
|
|
|
*
|
2013-06-19 21:33:25 +04:00
|
|
|
**/
|
2011-12-07 05:26:06 +04:00
|
|
|
$.Viewer = function( options ) {
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
var args = arguments,
|
2011-12-08 06:10:13 +04:00
|
|
|
_this = this,
|
|
|
|
i;
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
//backward compatibility for positional args while prefering more
|
2012-03-01 17:38:15 +04:00
|
|
|
//idiomatic javascript options object as the only argument
|
2012-02-28 03:29:00 +04:00
|
|
|
if( !$.isPlainObject( options ) ){
|
2011-12-07 05:26:06 +04:00
|
|
|
options = {
|
|
|
|
id: args[ 0 ],
|
|
|
|
xmlPath: args.length > 1 ? args[ 1 ] : undefined,
|
|
|
|
prefixUrl: args.length > 2 ? args[ 2 ] : undefined,
|
|
|
|
controls: args.length > 3 ? args[ 3 ] : undefined,
|
|
|
|
overlays: args.length > 4 ? args[ 4 ] : undefined,
|
2012-03-01 17:38:15 +04:00
|
|
|
overlayControls: args.length > 5 ? args[ 5 ] : undefined
|
2011-12-07 05:26:06 +04:00
|
|
|
};
|
|
|
|
}
|
2012-03-01 17:38:15 +04:00
|
|
|
|
|
|
|
//options.config and the general config argument are deprecated
|
|
|
|
//in favor of the more direct specification of optional settings
|
|
|
|
//being pass directly on the options object
|
|
|
|
if ( options.config ){
|
|
|
|
$.extend( true, options, options.config );
|
|
|
|
delete options.config;
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Public properties
|
2011-12-07 05:26:06 +04:00
|
|
|
//Allow the options object to override global defaults
|
2013-06-19 21:33:25 +04:00
|
|
|
$.extend( true, this, {
|
2012-03-01 17:38:15 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//internal state and dom identifiers
|
|
|
|
id: options.id,
|
|
|
|
hash: options.id,
|
|
|
|
|
|
|
|
//dom nodes
|
|
|
|
element: null,
|
|
|
|
canvas: null,
|
|
|
|
container: null,
|
|
|
|
|
|
|
|
//TODO: not sure how to best describe these
|
|
|
|
overlays: [],
|
|
|
|
overlayControls:[],
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//private state properties
|
2012-04-03 11:08:27 +04:00
|
|
|
previousBody: [],
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
//This was originally initialized in the constructor and so could never
|
|
|
|
//have anything in it. now it can because we allow it to be specified
|
|
|
|
//in the options and is only empty by default if not specified. Also
|
|
|
|
//this array was returned from get_controls which I find confusing
|
|
|
|
//since this object has a controls property which is treated in other
|
|
|
|
//functions like clearControls. I'm removing the accessors.
|
2012-03-01 17:38:15 +04:00
|
|
|
customControls: [],
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
//These are originally not part options but declared as members
|
|
|
|
//in initialize. Its still considered idiomatic to put them here
|
|
|
|
source: null,
|
2013-06-19 21:33:25 +04:00
|
|
|
drawer: null,
|
2013-02-08 18:21:28 +04:00
|
|
|
drawers: [],
|
2012-03-01 17:38:15 +04:00
|
|
|
viewport: null,
|
2013-06-19 21:33:25 +04:00
|
|
|
navigator: null,
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
//A collection viewport is a seperate viewport used to provide
|
2013-01-24 08:00:11 +04:00
|
|
|
//simultanious rendering of sets of tiless
|
|
|
|
collectionViewport: null,
|
|
|
|
collectionDrawer: null,
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//UI image resources
|
|
|
|
//TODO: rename navImages to uiImages
|
|
|
|
navImages: null,
|
|
|
|
|
|
|
|
//interface button controls
|
2013-06-19 21:33:25 +04:00
|
|
|
buttons: null,
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
//TODO: this is defunct so safely remove it
|
2012-03-01 17:38:15 +04:00
|
|
|
profiler: null
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-03-01 17:38:15 +04:00
|
|
|
}, $.DEFAULT_SETTINGS, options );
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Private state properties
|
|
|
|
THIS[ this.hash ] = {
|
|
|
|
"fsBoundsDelta": new $.Point( 1, 1 ),
|
|
|
|
"prevContainerSize": null,
|
|
|
|
"animating": false,
|
|
|
|
"forceRedraw": false,
|
|
|
|
"mouseInside": false,
|
|
|
|
"group": null,
|
|
|
|
// whether we should be continuously zooming
|
|
|
|
"zooming": false,
|
|
|
|
// how much we should be continuously zooming by
|
2013-06-19 21:33:25 +04:00
|
|
|
"zoomFactor": null,
|
2012-04-03 11:08:27 +04:00
|
|
|
"lastZoomTime": null,
|
|
|
|
// did we decide this viewer has a sequence of tile sources
|
|
|
|
"sequenced": false,
|
2013-02-28 23:28:05 +04:00
|
|
|
"sequence": 0,
|
2013-06-19 21:33:25 +04:00
|
|
|
"fullPage": false,
|
2013-02-28 23:28:05 +04:00
|
|
|
"onfullscreenchange": null
|
2012-04-03 11:08:27 +04:00
|
|
|
};
|
|
|
|
|
2013-06-18 22:06:43 +04:00
|
|
|
this._updateRequestId = null;
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Inherit some behaviors and properties
|
2012-03-09 20:04:28 +04:00
|
|
|
$.EventHandler.call( this );
|
|
|
|
$.ControlDock.call( this, options );
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
//Deal with tile sources
|
2013-06-19 01:55:19 +04:00
|
|
|
var initialTileSource;
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
if ( this.xmlPath ){
|
|
|
|
//Deprecated option. Now it is preferred to use the tileSources option
|
|
|
|
this.tileSources = [ this.xmlPath ];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.tileSources ){
|
2012-06-05 15:52:00 +04:00
|
|
|
// tileSources is a complex option...
|
2013-06-19 21:33:25 +04:00
|
|
|
//
|
2012-06-05 15:52:00 +04:00
|
|
|
// It can be a string, object, or an array of any of strings and objects.
|
2013-06-19 21:33:25 +04:00
|
|
|
// At this point we only care about if it is an Array or not.
|
2012-06-05 15:52:00 +04:00
|
|
|
//
|
2012-04-03 11:08:27 +04:00
|
|
|
if( $.isArray( this.tileSources ) ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
//must be a sequence of tileSource since the first item
|
|
|
|
//is a legacy tile source
|
2013-06-19 21:33:25 +04:00
|
|
|
if( this.tileSources.length > 1 ){
|
2012-04-03 11:08:27 +04:00
|
|
|
THIS[ this.hash ].sequenced = true;
|
2013-06-19 21:33:25 +04:00
|
|
|
}
|
2012-06-05 15:52:00 +04:00
|
|
|
initialTileSource = this.tileSources[ 0 ];
|
2012-04-03 11:08:27 +04:00
|
|
|
} else {
|
|
|
|
initialTileSource = this.tileSources;
|
|
|
|
}
|
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
this.open( initialTileSource );
|
2012-04-03 11:08:27 +04:00
|
|
|
}
|
|
|
|
|
2013-04-05 06:30:59 +04:00
|
|
|
this.element = this.element || document.getElementById( this.id );
|
|
|
|
this.canvas = $.makeNeutralElement( "div" );
|
|
|
|
this.keyboardCommandArea = $.makeNeutralElement( "textarea" );
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2013-02-14 01:50:23 +04:00
|
|
|
this.canvas.className = "openseadragon-canvas";
|
2013-03-17 00:35:33 +04:00
|
|
|
(function( style ){
|
|
|
|
style.width = "100%";
|
|
|
|
style.height = "100%";
|
|
|
|
style.overflow = "hidden";
|
|
|
|
style.position = "absolute";
|
|
|
|
style.top = "0px";
|
|
|
|
style.left = "0px";
|
2012-03-09 20:04:28 +04:00
|
|
|
}( this.canvas.style ));
|
|
|
|
|
2013-02-14 01:50:23 +04:00
|
|
|
//the container is created through applying the ControlDock constructor above
|
|
|
|
this.container.className = "openseadragon-container";
|
2013-03-17 00:35:33 +04:00
|
|
|
(function( style ){
|
|
|
|
style.width = "100%";
|
|
|
|
style.height = "100%";
|
|
|
|
style.position = "relative";
|
|
|
|
style.overflow = "hidden";
|
|
|
|
style.left = "0px";
|
|
|
|
style.top = "0px";
|
|
|
|
style.textAlign = "left"; // needed to protect against
|
2012-03-09 20:04:28 +04:00
|
|
|
}( this.container.style ));
|
|
|
|
|
2013-04-05 06:30:59 +04:00
|
|
|
this.keyboardCommandArea.className = "keyboard-command-area";
|
|
|
|
(function( style ){
|
|
|
|
style.width = "100%";
|
|
|
|
style.height = "100%";
|
|
|
|
style.overflow = "hidden";
|
|
|
|
style.position = "absolute";
|
|
|
|
style.top = "0px";
|
|
|
|
style.left = "0px";
|
2013-06-01 22:11:56 +04:00
|
|
|
style.resize = "none";
|
2013-04-05 06:30:59 +04:00
|
|
|
}( this.keyboardCommandArea.style ));
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.container.insertBefore( this.canvas, this.container.firstChild );
|
2013-04-05 06:30:59 +04:00
|
|
|
this.container.insertBefore( this.keyboardCommandArea, this.container.firstChild );
|
2012-03-09 20:04:28 +04:00
|
|
|
this.element.appendChild( this.container );
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
//Used for toggling between fullscreen and default container size
|
2012-02-27 15:56:29 +04:00
|
|
|
//TODO: these can be closure private and shared across Viewer
|
|
|
|
// instances.
|
2012-01-24 17:03:50 +04:00
|
|
|
this.bodyWidth = document.body.style.width;
|
|
|
|
this.bodyHeight = document.body.style.height;
|
|
|
|
this.bodyOverflow = document.body.style.overflow;
|
|
|
|
this.docOverflow = document.documentElement.style.overflow;
|
2012-02-27 15:56:29 +04:00
|
|
|
|
2013-04-05 06:30:59 +04:00
|
|
|
this.keyboardCommandArea.innerTracker = new $.MouseTracker({
|
|
|
|
_this : this,
|
|
|
|
element: this.keyboardCommandArea,
|
|
|
|
focusHandler: function(){
|
|
|
|
var point = $.getElementPosition( this.element );
|
|
|
|
window.scrollTo( 0, point.y );
|
|
|
|
},
|
|
|
|
|
|
|
|
keyHandler: function(tracker, keyCode, shiftKey){
|
|
|
|
switch( keyCode ){
|
|
|
|
case 61://=|+
|
2013-03-17 00:35:33 +04:00
|
|
|
_this.viewport.zoomBy(1.1);
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
case 45://-|_
|
2013-03-17 00:35:33 +04:00
|
|
|
_this.viewport.zoomBy(0.9);
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
case 48://0|)
|
|
|
|
_this.viewport.goHome();
|
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
case 119://w
|
|
|
|
case 87://W
|
|
|
|
case 38://up arrow
|
2013-06-19 01:55:58 +04:00
|
|
|
if (shiftKey) {
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.zoomBy(1.1);
|
2013-06-19 01:55:58 +04:00
|
|
|
} else {
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.panBy(new $.Point(0, -0.05));
|
2013-06-19 01:55:58 +04:00
|
|
|
}
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
case 115://s
|
|
|
|
case 83://S
|
|
|
|
case 40://down arrow
|
2013-06-19 01:55:58 +04:00
|
|
|
if (shiftKey) {
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.zoomBy(0.9);
|
2013-06-19 01:55:58 +04:00
|
|
|
} else {
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.panBy(new $.Point(0, 0.05));
|
2013-06-19 01:55:58 +04:00
|
|
|
}
|
2013-04-05 06:30:59 +04:00
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
case 97://a
|
|
|
|
case 37://left arrow
|
|
|
|
_this.viewport.panBy(new $.Point(-0.05, 0));
|
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
case 100://d
|
|
|
|
case 39://right arrow
|
|
|
|
_this.viewport.panBy(new $.Point(0.05, 0));
|
|
|
|
_this.viewport.applyConstraints();
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
//console.log( 'navigator keycode %s', keyCode );
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-17 00:35:33 +04:00
|
|
|
}
|
2013-04-05 06:30:59 +04:00
|
|
|
}).setTracking( true ); // default state
|
|
|
|
|
2013-03-17 00:35:33 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
this.innerTracker = new $.MouseTracker({
|
2013-06-19 21:33:25 +04:00
|
|
|
element: this.canvas,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
2012-03-01 17:38:15 +04:00
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-02-03 04:12:45 +04:00
|
|
|
clickHandler: $.delegate( this, onCanvasClick ),
|
|
|
|
dragHandler: $.delegate( this, onCanvasDrag ),
|
|
|
|
releaseHandler: $.delegate( this, onCanvasRelease ),
|
|
|
|
scrollHandler: $.delegate( this, onCanvasScroll )
|
2012-03-07 07:20:00 +04:00
|
|
|
}).setTracking( this.mouseNavEnabled ? true : false ); // default state
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
this.outerTracker = new $.MouseTracker({
|
2013-06-19 21:33:25 +04:00
|
|
|
element: this.container,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
2012-03-01 17:38:15 +04:00
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2012-02-03 04:12:45 +04:00
|
|
|
enterHandler: $.delegate( this, onContainerEnter ),
|
|
|
|
exitHandler: $.delegate( this, onContainerExit ),
|
|
|
|
releaseHandler: $.delegate( this, onContainerRelease )
|
2012-03-07 07:20:00 +04:00
|
|
|
}).setTracking( this.mouseNavEnabled ? true : false ); // always tracking
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
if( this.toolbar ){
|
|
|
|
this.toolbar = new $.ControlDock({ element: this.toolbar });
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
this.bindStandardControls();
|
|
|
|
this.bindSequenceControls();
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-03-16 19:36:28 +04:00
|
|
|
for ( i = 0; i < this.customControls.length; i++ ) {
|
|
|
|
this.addControl(
|
2013-06-19 21:33:25 +04:00
|
|
|
this.customControls[ i ].id,
|
2013-03-15 18:59:47 +04:00
|
|
|
{anchor: this.customControls[ i ].anchor}
|
2012-03-16 19:36:28 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:19:48 +04:00
|
|
|
$.requestAnimationFrame( function(){
|
2011-12-08 06:10:13 +04:00
|
|
|
beginControlsAutoHide( _this );
|
2013-02-26 19:19:48 +04:00
|
|
|
} ); // initial fade out
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
$.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isOpen
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
isOpen: function () {
|
|
|
|
return !!this.source;
|
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2013-06-19 21:33:25 +04:00
|
|
|
* A deprecated function, renamed to 'open' to match event name and
|
|
|
|
* match current 'close' method.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.openDzi
|
2013-03-26 17:02:34 +04:00
|
|
|
* @param {String} dzi xml string or the url to a DZI xml document.
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-08-29 22:46:34 +04:00
|
|
|
*
|
|
|
|
* @deprecated - use 'open' instead.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
openDzi: function ( dzi ) {
|
2013-03-26 17:02:34 +04:00
|
|
|
return this.open( dzi );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2013-06-19 21:33:25 +04:00
|
|
|
* A deprecated function, renamed to 'open' to match event name and
|
2013-03-26 17:02:34 +04:00
|
|
|
* match current 'close' method.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.openTileSource
|
|
|
|
* @param {String|Object|Function} See OpenSeadragon.Viewer.prototype.open
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*
|
|
|
|
* @deprecated - use 'open' instead.
|
|
|
|
*/
|
|
|
|
openTileSource: function ( tileSource ) {
|
|
|
|
return this.open( tileSource );
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2013-03-26 17:02:34 +04:00
|
|
|
* Open a TileSource object into the viewer.
|
|
|
|
*
|
2012-06-05 15:52:00 +04:00
|
|
|
* tileSources is a complex option...
|
2013-06-19 21:33:25 +04:00
|
|
|
*
|
2012-06-05 15:52:00 +04:00
|
|
|
* It can be a string, object, function, or an array of any of these:
|
|
|
|
*
|
|
|
|
* - A String implies a url used to determine the tileSource implementation
|
|
|
|
* based on the file extension of url. JSONP is implied by *.js,
|
|
|
|
* otherwise the url is retrieved as text and the resulting text is
|
2013-06-19 21:33:25 +04:00
|
|
|
* introspected to determine if its json, xml, or text and parsed.
|
|
|
|
* - An Object implies an inline configuration which has a single
|
|
|
|
* property sufficient for being able to determine tileSource
|
2012-06-05 15:52:00 +04:00
|
|
|
* implementation. If the object has a property which is a function
|
|
|
|
* named 'getTileUrl', it is treated as a custom TileSource.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
2013-05-14 21:29:15 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.open
|
2013-03-26 17:02:34 +04:00
|
|
|
* @param {String|Object|Function}
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2013-03-26 17:02:34 +04:00
|
|
|
open: function ( tileSource ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
var _this = this,
|
2012-06-05 15:52:00 +04:00
|
|
|
customTileSource,
|
|
|
|
readySource,
|
|
|
|
$TileSource,
|
|
|
|
options;
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2013-03-26 22:35:43 +04:00
|
|
|
//allow plain xml strings or json strings to be parsed here
|
|
|
|
if( $.type( tileSource ) == 'string' ){
|
|
|
|
if( tileSource.match(/\s*<.*/) ){
|
|
|
|
tileSource = $.parseXml( tileSource );
|
|
|
|
}else if( tileSource.match(/\s*[\{\[].*/) ){
|
|
|
|
/*jshint evil:true*/
|
|
|
|
tileSource = eval( '('+tileSource+')' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
setTimeout(function(){
|
|
|
|
if ( $.type( tileSource ) == 'string') {
|
2013-03-26 22:35:43 +04:00
|
|
|
//If its still a string it means it must be a url at this point
|
2012-06-05 15:52:00 +04:00
|
|
|
tileSource = new $.TileSource( tileSource, function( readySource ){
|
2013-03-26 17:02:34 +04:00
|
|
|
openTileSource( _this, readySource );
|
2012-06-05 15:52:00 +04:00
|
|
|
});
|
|
|
|
|
2013-03-26 22:35:43 +04:00
|
|
|
} else if ( $.isPlainObject( tileSource ) || tileSource.nodeType ){
|
2012-06-05 15:52:00 +04:00
|
|
|
if( $.isFunction( tileSource.getTileUrl ) ){
|
|
|
|
//Custom tile source
|
2012-08-30 04:53:42 +04:00
|
|
|
customTileSource = new $.TileSource(tileSource);
|
2012-06-05 15:52:00 +04:00
|
|
|
customTileSource.getTileUrl = tileSource.getTileUrl;
|
2013-03-26 17:02:34 +04:00
|
|
|
openTileSource( _this, customTileSource );
|
2012-06-05 15:52:00 +04:00
|
|
|
} else {
|
|
|
|
//inline configuration
|
|
|
|
$TileSource = $.TileSource.determineType( _this, tileSource );
|
|
|
|
options = $TileSource.prototype.configure.apply( _this, [ tileSource ]);
|
|
|
|
readySource = new $TileSource( options );
|
2013-03-26 17:02:34 +04:00
|
|
|
openTileSource( _this, readySource );
|
2012-06-05 15:52:00 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
} else {
|
|
|
|
//can assume it's already a tile source implementation
|
2013-03-26 17:02:34 +04:00
|
|
|
openTileSource( _this, tileSource );
|
2012-04-03 11:08:27 +04:00
|
|
|
}
|
|
|
|
}, 1);
|
|
|
|
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.close
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-04-03 11:08:27 +04:00
|
|
|
close: function ( ) {
|
2013-06-18 22:06:43 +04:00
|
|
|
if ( this._updateRequestId !== null ) {
|
|
|
|
$.cancelAnimationFrame( this._updateRequestId );
|
|
|
|
this._updateRequestId = null;
|
2013-04-27 06:32:51 +04:00
|
|
|
}
|
|
|
|
|
2013-06-17 22:31:41 +04:00
|
|
|
if ( this.navigator ) {
|
|
|
|
this.navigator.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.drawer ) {
|
2013-02-11 07:53:51 +04:00
|
|
|
this.drawer.clearOverlays();
|
|
|
|
}
|
2013-02-13 07:40:08 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.source = null;
|
|
|
|
this.drawer = null;
|
2013-02-11 07:53:51 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
this.viewport = this.preserveViewport ? this.viewport : null;
|
2012-01-25 23:14:02 +04:00
|
|
|
//this.profiler = null;
|
2011-12-13 07:40:02 +04:00
|
|
|
this.canvas.innerHTML = "";
|
2012-03-16 19:36:28 +04:00
|
|
|
|
|
|
|
VIEWERS[ this.hash ] = null;
|
|
|
|
delete VIEWERS[ this.hash ];
|
2013-02-14 04:44:23 +04:00
|
|
|
|
|
|
|
this.raiseEvent( 'close', { viewer: this } );
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.isMouseNavEnabled
|
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
isMouseNavEnabled: function () {
|
|
|
|
return this.innerTracker.isTracking();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.setMouseNavEnabled
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
setMouseNavEnabled: function( enabled ){
|
|
|
|
this.innerTracker.setTracking( enabled );
|
2013-02-14 04:44:23 +04:00
|
|
|
this.raiseEvent( 'mouse-enabled', { enabled: enabled, viewer: this } );
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-08-29 22:46:34 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.areControlsEnabled
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-20 03:03:58 +04:00
|
|
|
areControlsEnabled: function () {
|
2012-08-29 22:46:34 +04:00
|
|
|
var enabled = this.controls.length,
|
|
|
|
i;
|
|
|
|
for( i = 0; i < this.controls.length; i++ ){
|
|
|
|
enabled = enabled && this.controls[ i ].isVisibile();
|
|
|
|
}
|
|
|
|
return enabled;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2013-05-29 00:54:13 +04:00
|
|
|
* Shows or hides the controls (e.g. the default navigation buttons).
|
2013-06-19 21:33:25 +04:00
|
|
|
*
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
2013-05-29 00:36:09 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.setControlsEnabled
|
2013-05-29 00:54:13 +04:00
|
|
|
* @param {Boolean} true to show, false to hide.
|
2012-03-09 20:04:28 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-20 03:03:58 +04:00
|
|
|
setControlsEnabled: function( enabled ) {
|
|
|
|
if( enabled ){
|
|
|
|
abortControlsAutoHide( this );
|
|
|
|
} else {
|
|
|
|
beginControlsAutoHide( this );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
this.raiseEvent( 'controls-enabled', { enabled: enabled, viewer: this } );
|
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.isFullPage
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
isFullPage: function () {
|
2013-03-26 17:02:34 +04:00
|
|
|
return THIS[ this.hash ].fullPage;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
2012-02-10 07:16:09 +04:00
|
|
|
* Toggle full page mode.
|
2012-02-01 00:59:09 +04:00
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.setFullPage
|
2012-02-10 07:16:09 +04:00
|
|
|
* @param {Boolean} fullPage
|
|
|
|
* If true, enter full page mode. If false, exit full page mode.
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-08 06:10:13 +04:00
|
|
|
setFullPage: function( fullPage ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
var body = document.body,
|
|
|
|
bodyStyle = body.style,
|
|
|
|
docStyle = document.documentElement.style,
|
|
|
|
canvasStyle = this.canvas.style,
|
2013-02-27 07:34:44 +04:00
|
|
|
_this = this,
|
2011-12-08 06:10:13 +04:00
|
|
|
oldBounds,
|
2012-02-10 07:16:09 +04:00
|
|
|
newBounds,
|
2012-03-16 19:36:28 +04:00
|
|
|
viewer,
|
|
|
|
hash,
|
2012-02-10 07:16:09 +04:00
|
|
|
nodes,
|
|
|
|
i;
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
//dont bother modifying the DOM if we are already in full page mode.
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( fullPage == this.isFullPage() ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2013-02-27 07:34:44 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
if ( fullPage ) {
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.bodyOverflow = bodyStyle.overflow;
|
|
|
|
this.docOverflow = docStyle.overflow;
|
2011-12-08 06:10:13 +04:00
|
|
|
bodyStyle.overflow = "hidden";
|
|
|
|
docStyle.overflow = "hidden";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.bodyWidth = bodyStyle.width;
|
|
|
|
this.bodyHeight = bodyStyle.height;
|
2011-12-08 06:10:13 +04:00
|
|
|
bodyStyle.width = "100%";
|
|
|
|
bodyStyle.height = "100%";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
//when entering full screen on the ipad it wasnt sufficient to leave
|
2013-06-19 21:33:25 +04:00
|
|
|
//the body intact as only only the top half of the screen would
|
2012-02-10 07:16:09 +04:00
|
|
|
//respond to touch events on the canvas, while the bottom half treated
|
|
|
|
//them as touch events on the document body. Thus we remove and store
|
|
|
|
//the bodies elements and replace them when we leave full screen.
|
|
|
|
this.previousBody = [];
|
2012-10-13 07:40:59 +04:00
|
|
|
THIS[ this.hash ].prevElementParent = this.element.parentNode;
|
2013-03-26 17:02:34 +04:00
|
|
|
THIS[ this.hash ].prevNextSibling = this.element.nextSibling;
|
2012-10-13 07:40:59 +04:00
|
|
|
THIS[ this.hash ].prevElementSize = $.getElementSize( this.element );
|
2012-03-09 20:04:28 +04:00
|
|
|
nodes = body.childNodes.length;
|
2012-02-10 07:16:09 +04:00
|
|
|
for ( i = 0; i < nodes; i ++ ){
|
2012-03-09 20:04:28 +04:00
|
|
|
this.previousBody.push( body.childNodes[ 0 ] );
|
|
|
|
body.removeChild( body.childNodes[ 0 ] );
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
//If we've got a toolbar, we need to enable the user to use css to
|
|
|
|
//preserve it in fullpage mode
|
|
|
|
if( this.toolbar && this.toolbar.element ){
|
|
|
|
//save a reference to the parent so we can put it back
|
|
|
|
//in the long run we need a better strategy
|
|
|
|
this.toolbar.parentNode = this.toolbar.element.parentNode;
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.nextSibling = this.toolbar.element.nextSibling;
|
2012-03-09 20:04:28 +04:00
|
|
|
body.appendChild( this.toolbar.element );
|
|
|
|
|
|
|
|
//Make sure the user has some ability to style the toolbar based
|
|
|
|
//on the mode
|
2013-05-13 06:53:41 +04:00
|
|
|
$.addClass( this.toolbar.element, 'fullpage' );
|
2012-03-16 19:36:28 +04:00
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-05-13 07:02:18 +04:00
|
|
|
$.addClass( this.element, 'fullpage' );
|
2012-10-13 07:40:59 +04:00
|
|
|
body.appendChild( this.element );
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-02-28 23:28:05 +04:00
|
|
|
if( $.supportsFullScreen ){
|
2013-06-19 01:55:19 +04:00
|
|
|
THIS[ this.hash ].onfullscreenchange = function() {
|
2013-06-20 23:17:44 +04:00
|
|
|
/*
|
|
|
|
fullscreenchange events don't include the new fullscreen status so we need to
|
|
|
|
retrieve the current status from the fullscreen API. See:
|
|
|
|
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/fullscreenchange
|
|
|
|
*/
|
|
|
|
|
2013-02-28 23:28:05 +04:00
|
|
|
if( $.isFullScreen() ){
|
|
|
|
_this.setFullPage( true );
|
|
|
|
} else {
|
|
|
|
_this.setFullPage( false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.requestFullScreen( document.body );
|
|
|
|
|
2013-03-01 00:22:10 +04:00
|
|
|
// The target of the event is always the document,
|
|
|
|
// but it is possible to retrieve the fullscreen element through the API
|
2013-02-28 23:28:05 +04:00
|
|
|
// Note that the API is still vendor-prefixed in browsers implementing it
|
|
|
|
document.addEventListener(
|
2013-06-19 21:33:25 +04:00
|
|
|
$.fullScreenEventName,
|
2013-02-28 23:28:05 +04:00
|
|
|
THIS[ this.hash ].onfullscreenchange
|
|
|
|
);
|
|
|
|
this.element.style.height = '100%';
|
|
|
|
this.element.style.width = '100%';
|
|
|
|
}else{
|
|
|
|
this.element.style.height = $.getWindowSize().y + 'px';
|
|
|
|
this.element.style.width = $.getWindowSize().x + 'px';
|
|
|
|
}
|
|
|
|
|
2012-10-13 07:40:59 +04:00
|
|
|
if( this.toolbar && this.toolbar.element ){
|
|
|
|
this.element.style.height = (
|
2013-02-28 23:28:05 +04:00
|
|
|
$.getElementSize( this.element ).y - $.getElementSize( this.toolbar.element ).y
|
2012-10-13 07:40:59 +04:00
|
|
|
) + 'px';
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
THIS[ this.hash ].fullPage = true;
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
// mouse will be inside container now
|
2013-02-27 02:31:47 +04:00
|
|
|
$.delegate( this, onContainerEnter )();
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
2013-02-27 02:31:47 +04:00
|
|
|
|
2013-02-28 23:28:05 +04:00
|
|
|
if( $.supportsFullScreen ){
|
2013-06-19 21:33:25 +04:00
|
|
|
document.removeEventListener(
|
|
|
|
$.fullScreenEventName,
|
2013-02-28 23:28:05 +04:00
|
|
|
THIS[ this.hash ].onfullscreenchange
|
|
|
|
);
|
|
|
|
$.cancelFullScreen( document );
|
|
|
|
}
|
2013-02-27 02:31:47 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
bodyStyle.overflow = this.bodyOverflow;
|
|
|
|
docStyle.overflow = this.docOverflow;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
bodyStyle.width = this.bodyWidth;
|
|
|
|
bodyStyle.height = this.bodyHeight;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
canvasStyle.backgroundColor = "";
|
2011-12-08 06:10:13 +04:00
|
|
|
canvasStyle.color = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-10-13 07:40:59 +04:00
|
|
|
body.removeChild( this.element );
|
|
|
|
nodes = this.previousBody.length;
|
|
|
|
for ( i = 0; i < nodes; i++ ){
|
|
|
|
body.appendChild( this.previousBody.shift() );
|
|
|
|
}
|
2013-05-13 07:02:18 +04:00
|
|
|
|
|
|
|
$.removeClass( this.element, 'fullpage' );
|
2012-10-13 07:40:59 +04:00
|
|
|
THIS[ this.hash ].prevElementParent.insertBefore(
|
|
|
|
this.element,
|
|
|
|
THIS[ this.hash ].prevNextSibling
|
|
|
|
);
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
//If we've got a toolbar, we need to enable the user to use css to
|
2013-06-19 21:33:25 +04:00
|
|
|
//reset it to its original state
|
2012-03-09 20:04:28 +04:00
|
|
|
if( this.toolbar && this.toolbar.element ){
|
|
|
|
body.removeChild( this.toolbar.element );
|
|
|
|
|
|
|
|
//Make sure the user has some ability to style the toolbar based
|
|
|
|
//on the mode
|
2013-05-13 06:53:41 +04:00
|
|
|
$.removeClass( this.toolbar.element, 'fullpage' );
|
2012-10-13 07:40:59 +04:00
|
|
|
//this.toolbar.element.style.position = 'relative';
|
2013-06-19 21:33:25 +04:00
|
|
|
this.toolbar.parentNode.insertBefore(
|
2012-03-10 06:44:14 +04:00
|
|
|
this.toolbar.element,
|
2012-03-16 19:36:28 +04:00
|
|
|
this.toolbar.nextSibling
|
2012-03-10 06:44:14 +04:00
|
|
|
);
|
|
|
|
delete this.toolbar.parentNode;
|
2012-03-16 19:36:28 +04:00
|
|
|
delete this.toolbar.nextSibling;
|
|
|
|
|
2012-10-13 07:40:59 +04:00
|
|
|
//this.container.style.top = 'auto';
|
2012-03-09 20:04:28 +04:00
|
|
|
}
|
|
|
|
|
2012-10-13 07:40:59 +04:00
|
|
|
this.element.style.height = THIS[ this.hash ].prevElementSize.y + 'px';
|
|
|
|
this.element.style.width = THIS[ this.hash ].prevElementSize.x + 'px';
|
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
THIS[ this.hash ].fullPage = false;
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
// mouse will likely be outside now
|
2013-02-27 02:31:47 +04:00
|
|
|
$.delegate( this, onContainerExit )();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
this.raiseEvent( 'fullpage', { fullpage: fullPage, viewer: this } );
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
if ( this.viewport ) {
|
|
|
|
oldBounds = this.viewport.getBounds();
|
2012-02-27 15:56:29 +04:00
|
|
|
this.viewport.resize( THIS[ this.hash ].prevContainerSize );
|
2011-12-08 06:10:13 +04:00
|
|
|
newBounds = this.viewport.getBounds();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
if ( fullPage ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].fsBoundsDelta = new $.Point(
|
2011-12-08 06:10:13 +04:00
|
|
|
newBounds.width / oldBounds.width,
|
|
|
|
newBounds.height / oldBounds.height
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
} else {
|
|
|
|
this.viewport.update();
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.zoomBy(
|
2013-06-19 21:33:25 +04:00
|
|
|
Math.max(
|
|
|
|
THIS[ this.hash ].fsBoundsDelta.x,
|
|
|
|
THIS[ this.hash ].fsBoundsDelta.y
|
2011-12-08 06:10:13 +04:00
|
|
|
),
|
2013-06-19 21:33:25 +04:00
|
|
|
null,
|
2011-12-08 06:10:13 +04:00
|
|
|
true
|
|
|
|
);
|
2012-03-16 19:36:28 +04:00
|
|
|
//Ensures that if multiple viewers are on a page, the viewers that
|
|
|
|
//were hidden during fullpage are 'reopened'
|
|
|
|
for( hash in VIEWERS ){
|
|
|
|
viewer = VIEWERS[ hash ];
|
|
|
|
if( viewer !== this && viewer != this.navigator ){
|
|
|
|
viewer.open( viewer.source );
|
2012-04-03 11:08:27 +04:00
|
|
|
if( viewer.navigator ){
|
|
|
|
viewer.navigator.open( viewer.source );
|
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].forceRedraw = true;
|
2011-12-23 05:36:17 +04:00
|
|
|
updateOnce( this );
|
2012-03-16 19:36:28 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
2012-03-09 20:04:28 +04:00
|
|
|
* @name OpenSeadragon.Viewer.prototype.isVisible
|
|
|
|
* @return {Boolean}
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-03-09 20:04:28 +04:00
|
|
|
isVisible: function () {
|
|
|
|
return this.container.style.visibility != "hidden";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-03-09 20:04:28 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.setVisible
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-08 06:10:13 +04:00
|
|
|
setVisible: function( visible ){
|
|
|
|
this.container.style.visibility = visible ? "" : "hidden";
|
2013-02-14 04:44:23 +04:00
|
|
|
this.raiseEvent( 'visible', { visible: visible, viewer: this } );
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2012-04-11 01:02:24 +04:00
|
|
|
},
|
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.bindSequenceControls
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*/
|
2012-04-11 01:02:24 +04:00
|
|
|
bindSequenceControls: function(){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Image Sequence Controls
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
var onFocusHandler = $.delegate( this, onFocus ),
|
|
|
|
onBlurHandler = $.delegate( this, onBlur ),
|
|
|
|
onNextHandler = $.delegate( this, onNext ),
|
|
|
|
onPreviousHandler = $.delegate( this, onPrevious ),
|
|
|
|
navImages = this.navImages,
|
|
|
|
useGroup = true ;
|
|
|
|
|
|
|
|
if( this.showSequenceControl && THIS[ this.hash ].sequenced ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-04-11 01:02:24 +04:00
|
|
|
if( this.previousButton || this.nextButton ){
|
2013-06-19 21:33:25 +04:00
|
|
|
//if we are binding to custom buttons then layout and
|
2012-04-11 01:02:24 +04:00
|
|
|
//grouping is the responsibility of the page author
|
|
|
|
useGroup = false;
|
|
|
|
}
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
this.previousButton = new $.Button({
|
2012-04-11 01:02:24 +04:00
|
|
|
element: this.previousButton ? $.getElement( this.previousButton ) : null,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
tooltip: $.getString( "Tooltips.PreviousPage" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.previous.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.previous.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.previous.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.previous.DOWN ),
|
|
|
|
onRelease: onPreviousHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
});
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
this.nextButton = new $.Button({
|
2012-04-11 01:02:24 +04:00
|
|
|
element: this.nextButton ? $.getElement( this.nextButton ) : null,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
tooltip: $.getString( "Tooltips.NextPage" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.next.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.next.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.next.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.next.DOWN ),
|
|
|
|
onRelease: onNextHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
});
|
|
|
|
|
2013-06-19 01:19:09 +04:00
|
|
|
if( !this.navPrevNextWrap ){
|
|
|
|
this.previousButton.disable();
|
|
|
|
}
|
2012-04-11 01:02:24 +04:00
|
|
|
|
|
|
|
if( useGroup ){
|
|
|
|
this.paging = new $.ButtonGroup({
|
2013-06-19 21:33:25 +04:00
|
|
|
buttons: [
|
|
|
|
this.previousButton,
|
|
|
|
this.nextButton
|
2012-04-11 01:02:24 +04:00
|
|
|
],
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold
|
|
|
|
});
|
|
|
|
|
|
|
|
this.pagingControl = this.paging.element;
|
|
|
|
|
|
|
|
if( this.toolbar ){
|
2013-06-19 21:33:25 +04:00
|
|
|
this.toolbar.addControl(
|
|
|
|
this.pagingControl,
|
2013-03-15 18:59:47 +04:00
|
|
|
{anchor: $.ControlAnchor.BOTTOM_RIGHT}
|
2012-04-11 01:02:24 +04:00
|
|
|
);
|
|
|
|
}else{
|
2013-06-19 21:33:25 +04:00
|
|
|
this.addControl(
|
|
|
|
this.pagingControl,
|
2013-03-15 18:59:47 +04:00
|
|
|
{anchor: $.ControlAnchor.TOP_LEFT}
|
2012-04-11 01:02:24 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
return this;
|
2012-04-11 01:02:24 +04:00
|
|
|
},
|
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.bindStandardControls
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*/
|
2012-04-11 01:02:24 +04:00
|
|
|
bindStandardControls: function(){
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
var beginZoomingInHandler = $.delegate( this, beginZoomingIn ),
|
|
|
|
endZoomingHandler = $.delegate( this, endZooming ),
|
|
|
|
doSingleZoomInHandler = $.delegate( this, doSingleZoomIn ),
|
|
|
|
beginZoomingOutHandler = $.delegate( this, beginZoomingOut ),
|
|
|
|
doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ),
|
|
|
|
onHomeHandler = $.delegate( this, onHome ),
|
|
|
|
onFullPageHandler = $.delegate( this, onFullPage ),
|
|
|
|
onFocusHandler = $.delegate( this, onFocus ),
|
|
|
|
onBlurHandler = $.delegate( this, onBlur ),
|
|
|
|
navImages = this.navImages,
|
|
|
|
buttons = [],
|
|
|
|
useGroup = true ;
|
|
|
|
|
|
|
|
|
|
|
|
if( this.showNavigationControl ){
|
|
|
|
|
|
|
|
if( this.zoomInButton || this.zoomOutButton || this.homeButton || this.fullPageButton ){
|
2013-06-19 21:33:25 +04:00
|
|
|
//if we are binding to custom buttons then layout and
|
2012-04-11 01:02:24 +04:00
|
|
|
//grouping is the responsibility of the page author
|
|
|
|
useGroup = false;
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
|
|
|
buttons.push( this.zoomInButton = new $.Button({
|
2012-04-11 01:02:24 +04:00
|
|
|
element: this.zoomInButton ? $.getElement( this.zoomInButton ) : null,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2013-06-19 21:33:25 +04:00
|
|
|
tooltip: $.getString( "Tooltips.ZoomIn" ),
|
2012-04-11 01:02:24 +04:00
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.zoomIn.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.zoomIn.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.zoomIn.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.zoomIn.DOWN ),
|
|
|
|
onPress: beginZoomingInHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomInHandler,
|
|
|
|
onEnter: beginZoomingInHandler,
|
|
|
|
onExit: endZoomingHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
}));
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
buttons.push( this.zoomOutButton = new $.Button({
|
2012-04-11 01:02:24 +04:00
|
|
|
element: this.zoomOutButton ? $.getElement( this.zoomOutButton ) : null,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2013-06-19 21:33:25 +04:00
|
|
|
tooltip: $.getString( "Tooltips.ZoomOut" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.zoomOut.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.zoomOut.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.zoomOut.HOVER ),
|
2012-04-11 01:02:24 +04:00
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.zoomOut.DOWN ),
|
2013-06-19 21:33:25 +04:00
|
|
|
onPress: beginZoomingOutHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomOutHandler,
|
|
|
|
onEnter: beginZoomingOutHandler,
|
2012-04-11 01:02:24 +04:00
|
|
|
onExit: endZoomingHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
}));
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
buttons.push( this.homeButton = new $.Button({
|
2012-04-11 01:02:24 +04:00
|
|
|
element: this.homeButton ? $.getElement( this.homeButton ) : null,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
2013-06-19 21:33:25 +04:00
|
|
|
tooltip: $.getString( "Tooltips.Home" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.home.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.home.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.home.HOVER ),
|
2012-04-11 01:02:24 +04:00
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.home.DOWN ),
|
|
|
|
onRelease: onHomeHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
}));
|
|
|
|
|
2013-06-19 21:33:25 +04:00
|
|
|
buttons.push( this.fullPageButton = new $.Button({
|
2012-04-11 01:02:24 +04:00
|
|
|
element: this.fullPageButton ? $.getElement( this.fullPageButton ) : null,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold,
|
|
|
|
tooltip: $.getString( "Tooltips.FullPage" ),
|
|
|
|
srcRest: resolveUrl( this.prefixUrl, navImages.fullpage.REST ),
|
|
|
|
srcGroup: resolveUrl( this.prefixUrl, navImages.fullpage.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.prefixUrl, navImages.fullpage.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.prefixUrl, navImages.fullpage.DOWN ),
|
|
|
|
onRelease: onFullPageHandler,
|
|
|
|
onFocus: onFocusHandler,
|
|
|
|
onBlur: onBlurHandler
|
|
|
|
}));
|
|
|
|
|
|
|
|
if( useGroup ){
|
|
|
|
this.buttons = new $.ButtonGroup({
|
|
|
|
buttons: buttons,
|
|
|
|
clickTimeThreshold: this.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.clickDistThreshold
|
|
|
|
});
|
|
|
|
|
|
|
|
this.navControl = this.buttons.element;
|
|
|
|
this.addHandler( 'open', $.delegate( this, lightUp ) );
|
|
|
|
|
|
|
|
if( this.toolbar ){
|
2013-06-19 21:33:25 +04:00
|
|
|
this.toolbar.addControl(
|
|
|
|
this.navControl,
|
2013-03-15 18:59:47 +04:00
|
|
|
{anchor: $.ControlAnchor.TOP_LEFT}
|
2012-04-11 01:02:24 +04:00
|
|
|
);
|
|
|
|
}else{
|
2013-06-19 21:33:25 +04:00
|
|
|
this.addControl(
|
|
|
|
this.navControl,
|
2013-03-15 18:59:47 +04:00
|
|
|
{anchor: $.ControlAnchor.TOP_LEFT}
|
2012-04-11 01:02:24 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
return this;
|
2012-06-05 15:52:00 +04:00
|
|
|
},
|
|
|
|
|
2013-02-14 04:44:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.goToPage
|
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
|
|
|
*/
|
2012-06-05 15:52:00 +04:00
|
|
|
goToPage: function( page ){
|
|
|
|
//page is a 1 based index so normalize now
|
|
|
|
//page = page;
|
2013-02-14 04:44:23 +04:00
|
|
|
this.raiseEvent( 'page', { page: page, viewer: this } );
|
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
if( this.tileSources.length > page ){
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
THIS[ this.hash ].sequence = page;
|
|
|
|
|
|
|
|
if( this.nextButton ){
|
|
|
|
if( ( this.tileSources.length - 1 ) === page ){
|
|
|
|
//Disable next button
|
2013-05-30 03:10:45 +04:00
|
|
|
if(!this.navPrevNextWrap){
|
|
|
|
this.nextButton.disable();
|
|
|
|
}
|
2012-06-05 15:52:00 +04:00
|
|
|
} else {
|
|
|
|
this.nextButton.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( this.previousButton ){
|
|
|
|
if( page > 0 ){
|
|
|
|
//Enable previous button
|
|
|
|
this.previousButton.enable();
|
|
|
|
} else {
|
2013-05-30 03:10:45 +04:00
|
|
|
if(!this.navPrevNextWrap){
|
|
|
|
this.previousButton.disable();
|
|
|
|
}
|
2012-06-05 15:52:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
this.open( this.tileSources[ page ] );
|
2012-06-05 15:52:00 +04:00
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
|
2012-06-05 15:52:00 +04:00
|
|
|
if( $.isFunction( this.onPageChange ) ){
|
|
|
|
this.onPageChange({
|
|
|
|
page: page,
|
|
|
|
viewer: this
|
|
|
|
});
|
2012-04-11 01:02:24 +04:00
|
|
|
}
|
2012-10-13 07:40:59 +04:00
|
|
|
if( this.referenceStrip ){
|
|
|
|
this.referenceStrip.setFocus( page );
|
|
|
|
}
|
2013-02-14 04:44:23 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2011-12-15 03:22:02 +04:00
|
|
|
});
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
function openTileSource( viewer, source ) {
|
|
|
|
var _this = viewer,
|
|
|
|
overlay,
|
|
|
|
i;
|
|
|
|
|
|
|
|
if ( _this.source ) {
|
|
|
|
_this.close( );
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
_this.canvas.innerHTML = "";
|
|
|
|
THIS[ _this.hash ].prevContainerSize = $.getElementSize( _this.container );
|
|
|
|
|
|
|
|
|
|
|
|
if( _this.collectionMode ){
|
|
|
|
_this.source = new $.TileSourceCollection({
|
|
|
|
rows: _this.collectionRows,
|
|
|
|
layout: _this.collectionLayout,
|
|
|
|
tileSize: _this.collectionTileSize,
|
|
|
|
tileSources: _this.tileSources,
|
|
|
|
tileMargin: _this.collectionTileMargin
|
|
|
|
});
|
|
|
|
_this.viewport = _this.viewport ? _this.viewport : new $.Viewport({
|
|
|
|
collectionMode: true,
|
|
|
|
collectionTileSource: _this.source,
|
2013-06-19 21:33:25 +04:00
|
|
|
containerSize: THIS[ _this.hash ].prevContainerSize,
|
|
|
|
contentSize: _this.source.dimensions,
|
2013-03-26 17:02:34 +04:00
|
|
|
springStiffness: _this.springStiffness,
|
|
|
|
animationTime: _this.animationTime,
|
|
|
|
showNavigator: false,
|
|
|
|
minZoomImageRatio: 1,
|
|
|
|
maxZoomPixelRatio: 1,
|
|
|
|
viewer: _this //,
|
|
|
|
//TODO: figure out how to support these in a way that makes sense
|
|
|
|
//minZoomLevel: this.minZoomLevel,
|
|
|
|
//maxZoomLevel: this.maxZoomLevel
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
if( source ){
|
|
|
|
_this.source = source;
|
|
|
|
}
|
|
|
|
_this.viewport = _this.viewport ? _this.viewport : new $.Viewport({
|
2013-06-19 21:33:25 +04:00
|
|
|
containerSize: THIS[ _this.hash ].prevContainerSize,
|
|
|
|
contentSize: _this.source.dimensions,
|
2013-03-26 17:02:34 +04:00
|
|
|
springStiffness: _this.springStiffness,
|
|
|
|
animationTime: _this.animationTime,
|
|
|
|
minZoomImageRatio: _this.minZoomImageRatio,
|
|
|
|
maxZoomPixelRatio: _this.maxZoomPixelRatio,
|
|
|
|
visibilityRatio: _this.visibilityRatio,
|
|
|
|
wrapHorizontal: _this.wrapHorizontal,
|
|
|
|
wrapVertical: _this.wrapVertical,
|
|
|
|
defaultZoomLevel: _this.defaultZoomLevel,
|
|
|
|
minZoomLevel: _this.minZoomLevel,
|
|
|
|
maxZoomLevel: _this.maxZoomLevel,
|
|
|
|
viewer: _this
|
|
|
|
});
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-04-24 07:58:58 +04:00
|
|
|
if( _this.preserveViewport ){
|
2013-03-26 17:02:34 +04:00
|
|
|
_this.viewport.resetContentSize( _this.source.dimensions );
|
2013-06-19 21:33:25 +04:00
|
|
|
}
|
2013-03-26 17:02:34 +04:00
|
|
|
|
|
|
|
_this.source.overlays = _this.source.overlays || [];
|
|
|
|
|
|
|
|
_this.drawer = new $.Drawer({
|
2013-05-16 10:49:29 +04:00
|
|
|
viewer: _this,
|
2013-06-19 21:33:25 +04:00
|
|
|
source: _this.source,
|
|
|
|
viewport: _this.viewport,
|
2013-03-26 17:02:34 +04:00
|
|
|
element: _this.canvas,
|
|
|
|
overlays: [].concat( _this.overlays ).concat( _this.source.overlays ),
|
|
|
|
maxImageCacheCount: _this.maxImageCacheCount,
|
|
|
|
imageLoaderLimit: _this.imageLoaderLimit,
|
|
|
|
minZoomImageRatio: _this.minZoomImageRatio,
|
|
|
|
wrapHorizontal: _this.wrapHorizontal,
|
|
|
|
wrapVertical: _this.wrapVertical,
|
|
|
|
immediateRender: _this.immediateRender,
|
|
|
|
blendTime: _this.blendTime,
|
|
|
|
alwaysBlend: _this.alwaysBlend,
|
|
|
|
minPixelRatio: _this.collectionMode ? 0 : _this.minPixelRatio,
|
|
|
|
timeout: _this.timeout,
|
|
|
|
debugMode: _this.debugMode,
|
|
|
|
debugGridColor: _this.debugGridColor
|
|
|
|
});
|
|
|
|
|
|
|
|
//Instantiate a navigator if configured
|
2013-06-17 22:51:02 +04:00
|
|
|
if ( _this.showNavigator && !_this.collectionMode ){
|
|
|
|
// Note: By passing the fully parsed source, the navigator doesn't
|
|
|
|
// have to load it again.
|
|
|
|
if ( _this.navigator ) {
|
|
|
|
_this.navigator.open( source );
|
|
|
|
} else {
|
|
|
|
_this.navigator = new $.Navigator({
|
|
|
|
id: _this.navigatorId,
|
|
|
|
position: _this.navigatorPosition,
|
|
|
|
sizeRatio: _this.navigatorSizeRatio,
|
|
|
|
height: _this.navigatorHeight,
|
|
|
|
width: _this.navigatorWidth,
|
|
|
|
tileSources: source,
|
|
|
|
tileHost: _this.tileHost,
|
|
|
|
prefixUrl: _this.prefixUrl,
|
|
|
|
overlays: _this.overlays,
|
|
|
|
viewer: _this
|
|
|
|
});
|
|
|
|
}
|
2013-03-26 17:02:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//Instantiate a referencestrip if configured
|
|
|
|
if ( _this.showReferenceStrip && !_this.referenceStrip ){
|
|
|
|
_this.referenceStrip = new $.ReferenceStrip({
|
|
|
|
id: _this.referenceStripElement,
|
|
|
|
position: _this.referenceStripPosition,
|
|
|
|
sizeRatio: _this.referenceStripSizeRatio,
|
|
|
|
scroll: _this.referenceStripScroll,
|
|
|
|
height: _this.referenceStripHeight,
|
|
|
|
width: _this.referenceStripWidth,
|
|
|
|
tileSources: _this.tileSources,
|
|
|
|
tileHost: _this.tileHost,
|
|
|
|
prefixUrl: _this.prefixUrl,
|
|
|
|
overlays: _this.overlays,
|
|
|
|
viewer: _this
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//this.profiler = new $.Profiler();
|
|
|
|
|
|
|
|
THIS[ _this.hash ].animating = false;
|
|
|
|
THIS[ _this.hash ].forceRedraw = true;
|
2013-06-18 22:06:43 +04:00
|
|
|
_this._updateRequestId = scheduleUpdate( _this, updateMulti );
|
2013-03-26 17:02:34 +04:00
|
|
|
|
|
|
|
//Assuming you had programatically created a bunch of overlays
|
|
|
|
//and added them via configuration
|
|
|
|
for ( i = 0; i < _this.overlayControls.length; i++ ) {
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
overlay = _this.overlayControls[ i ];
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
if ( overlay.point ) {
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
_this.drawer.addOverlay(
|
2013-06-19 21:33:25 +04:00
|
|
|
overlay.id,
|
|
|
|
new $.Point(
|
|
|
|
overlay.point.X,
|
|
|
|
overlay.point.Y
|
|
|
|
),
|
2013-03-26 17:02:34 +04:00
|
|
|
$.OverlayPlacement.TOP_LEFT
|
|
|
|
);
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
} else {
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
_this.drawer.addOverlay(
|
2013-06-19 21:33:25 +04:00
|
|
|
overlay.id,
|
2013-03-26 17:02:34 +04:00
|
|
|
new $.Rect(
|
2013-06-19 21:33:25 +04:00
|
|
|
overlay.rect.Point.X,
|
|
|
|
overlay.rect.Point.Y,
|
|
|
|
overlay.rect.Width,
|
2013-03-26 17:02:34 +04:00
|
|
|
overlay.rect.Height
|
2013-06-19 21:33:25 +04:00
|
|
|
),
|
2013-03-26 17:02:34 +04:00
|
|
|
overlay.placement
|
|
|
|
);
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-03-26 17:02:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
VIEWERS[ _this.hash ] = _this;
|
|
|
|
|
|
|
|
_this.raiseEvent( 'open', { source: source, viewer: _this } );
|
|
|
|
|
|
|
|
return _this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Schedulers provide the general engine for animation
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2013-06-19 20:58:09 +04:00
|
|
|
function scheduleUpdate( viewer, updateFunc ){
|
2013-04-27 05:48:48 +04:00
|
|
|
return $.requestAnimationFrame( function(){
|
|
|
|
updateFunc( viewer );
|
|
|
|
} );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//provides a sequence in the fade animation
|
|
|
|
function scheduleControlsFade( viewer ) {
|
2013-02-26 19:19:48 +04:00
|
|
|
$.requestAnimationFrame( function(){
|
2011-12-08 06:10:13 +04:00
|
|
|
updateControlsFade( viewer );
|
2013-02-26 19:19:48 +04:00
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//initiates an animation to hide the controls
|
|
|
|
function beginControlsAutoHide( viewer ) {
|
2012-03-01 17:38:15 +04:00
|
|
|
if ( !viewer.autoHideControls ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
viewer.controlsShouldFade = true;
|
2013-06-19 21:33:25 +04:00
|
|
|
viewer.controlsFadeBeginTime =
|
|
|
|
+new Date() +
|
2012-03-01 17:38:15 +04:00
|
|
|
viewer.controlsFadeDelay;
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
window.setTimeout( function(){
|
|
|
|
scheduleControlsFade( viewer );
|
2012-03-01 17:38:15 +04:00
|
|
|
}, viewer.controlsFadeDelay );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
//determines if fade animation is done or continues the animation
|
|
|
|
function updateControlsFade( viewer ) {
|
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
|
|
|
opacity,
|
|
|
|
i;
|
|
|
|
if ( viewer.controlsShouldFade ) {
|
|
|
|
currentTime = new Date().getTime();
|
|
|
|
deltaTime = currentTime - viewer.controlsFadeBeginTime;
|
2012-03-01 17:38:15 +04:00
|
|
|
opacity = 1.0 - deltaTime / viewer.controlsFadeLength;
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
opacity = Math.min( 1.0, opacity );
|
|
|
|
opacity = Math.max( 0.0, opacity );
|
|
|
|
|
2011-12-13 02:22:01 +04:00
|
|
|
for ( i = viewer.controls.length - 1; i >= 0; i--) {
|
2013-03-15 18:59:47 +04:00
|
|
|
if (viewer.controls[ i ].autoFade) {
|
|
|
|
viewer.controls[ i ].setOpacity( opacity );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( opacity > 0 ) {
|
|
|
|
// fade again
|
2013-06-19 21:33:25 +04:00
|
|
|
scheduleControlsFade( viewer );
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
//stop the fade animation on the controls and show them
|
|
|
|
function abortControlsAutoHide( viewer ) {
|
|
|
|
var i;
|
|
|
|
viewer.controlsShouldFade = false;
|
|
|
|
for ( i = viewer.controls.length - 1; i >= 0; i-- ) {
|
|
|
|
viewer.controls[ i ].setOpacity( 1.0 );
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Default view event handlers.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-03-16 19:36:28 +04:00
|
|
|
function onFocus(){
|
|
|
|
abortControlsAutoHide( this );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
|
|
|
|
function onBlur(){
|
|
|
|
beginControlsAutoHide( this );
|
2013-06-19 21:33:25 +04:00
|
|
|
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-03-16 19:36:28 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasClick( tracker, position, quick, shift ) {
|
2013-06-19 01:56:13 +04:00
|
|
|
var zoomPerClick,
|
2011-12-08 06:10:13 +04:00
|
|
|
factor;
|
2013-06-19 21:33:25 +04:00
|
|
|
if ( this.viewport && quick ) { // ignore clicks where mouse moved
|
2012-03-01 17:38:15 +04:00
|
|
|
zoomPerClick = this.zoomPerClick;
|
2011-12-08 06:10:13 +04:00
|
|
|
factor = shift ? 1.0 / zoomPerClick : zoomPerClick;
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.zoomBy(
|
2013-06-19 21:33:25 +04:00
|
|
|
factor,
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.pointFromPixel( position, true )
|
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'canvas-click', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
quick: quick,
|
|
|
|
shift: shift
|
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasDrag( tracker, position, delta, shift ) {
|
|
|
|
if ( this.viewport ) {
|
2012-04-03 11:08:27 +04:00
|
|
|
if( !this.panHorizontal ){
|
|
|
|
delta.x = 0;
|
|
|
|
}
|
|
|
|
if( !this.panVertical ){
|
|
|
|
delta.y = 0;
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewport.panBy(
|
|
|
|
this.viewport.deltaPointsFromPixels(
|
|
|
|
delta.negate()
|
|
|
|
)
|
2012-01-24 17:03:50 +04:00
|
|
|
);
|
2013-02-13 07:40:08 +04:00
|
|
|
if( this.constrainDuringPan ){
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'canvas-click', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
delta: delta,
|
|
|
|
shift: shift
|
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onCanvasRelease( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( insideElementPress && this.viewport ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'canvas-release', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
insideElementPress: insideElementPress,
|
|
|
|
insideElementRelease: insideElementRelease
|
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasScroll( tracker, position, scroll, shift ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
var factor;
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2012-03-01 17:38:15 +04:00
|
|
|
factor = Math.pow( this.zoomPerScroll, scroll );
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
factor,
|
|
|
|
this.viewport.pointFromPixel( position, true )
|
2012-01-24 17:03:50 +04:00
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'canvas-scroll', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
scroll: scroll,
|
|
|
|
shift: shift
|
|
|
|
});
|
2012-04-03 11:08:27 +04:00
|
|
|
//cancels event
|
|
|
|
return false;
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onContainerExit( tracker, position, buttonDownElement, buttonDownAny ) {
|
|
|
|
if ( !buttonDownElement ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].mouseInside = false;
|
|
|
|
if ( !THIS[ this.hash ].animating ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
beginControlsAutoHide( this );
|
|
|
|
}
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'container-exit', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
buttonDownElement: buttonDownElement,
|
|
|
|
buttonDownAny: buttonDownAny
|
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onContainerRelease( tracker, position, insideElementPress, insideElementRelease ) {
|
|
|
|
if ( !insideElementRelease ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].mouseInside = false;
|
|
|
|
if ( !THIS[ this.hash ].animating ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
beginControlsAutoHide( this );
|
|
|
|
}
|
|
|
|
}
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'container-release', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
insideElementPress: insideElementPress,
|
|
|
|
insideElementRelease: insideElementRelease
|
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
function onContainerEnter( tracker, position, buttonDownElement, buttonDownAny ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].mouseInside = true;
|
2011-12-08 06:10:13 +04:00
|
|
|
abortControlsAutoHide( this );
|
2013-06-19 21:33:25 +04:00
|
|
|
this.raiseEvent( 'container-enter', {
|
2013-02-14 04:44:23 +04:00
|
|
|
tracker: tracker,
|
|
|
|
position: position,
|
|
|
|
buttonDownElement: buttonDownElement,
|
|
|
|
buttonDownAny: buttonDownAny
|
|
|
|
});
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Page update routines ( aka Views - for future reference )
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2013-04-27 05:48:48 +04:00
|
|
|
function updateMulti( viewer ) {
|
2013-04-29 21:17:37 +04:00
|
|
|
if ( !viewer.source ) {
|
2013-06-18 22:06:43 +04:00
|
|
|
viewer._updateRequestId = null;
|
2013-04-29 21:17:37 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-23 05:47:21 +04:00
|
|
|
updateOnce( viewer );
|
2013-04-27 06:32:51 +04:00
|
|
|
|
2013-06-17 22:30:31 +04:00
|
|
|
// Request the next frame, unless we've been closed during the updateOnce()
|
|
|
|
if ( viewer.source ) {
|
2013-06-19 20:58:09 +04:00
|
|
|
viewer._updateRequestId = scheduleUpdate( viewer, updateMulti );
|
2013-06-17 22:30:31 +04:00
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:47:21 +04:00
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
function updateOnce( viewer ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
var containerSize,
|
|
|
|
animated;
|
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
if ( !viewer.source ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
//viewer.profiler.beginUpdate();
|
2011-12-23 05:36:17 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
containerSize = $.getElementSize( viewer.container );
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( !containerSize.equals( THIS[ viewer.hash ].prevContainerSize ) ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
// maintain image position
|
2013-06-19 21:33:25 +04:00
|
|
|
viewer.viewport.resize( containerSize, true );
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].prevContainerSize = containerSize;
|
2011-12-23 05:36:17 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
animated = viewer.viewport.update();
|
2012-09-05 18:52:57 +04:00
|
|
|
|
|
|
|
if( viewer.referenceStrip ){
|
|
|
|
animated = viewer.referenceStrip.update( viewer.viewport ) || animated;
|
|
|
|
}
|
2012-10-13 07:40:59 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( !THIS[ viewer.hash ].animating && animated ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "animationstart" );
|
|
|
|
abortControlsAutoHide( viewer );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2011-12-23 05:36:17 +04:00
|
|
|
if ( animated ) {
|
|
|
|
viewer.drawer.update();
|
2012-03-07 07:20:00 +04:00
|
|
|
if( viewer.navigator ){
|
|
|
|
viewer.navigator.update( viewer.viewport );
|
|
|
|
}
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "animation" );
|
2012-02-27 15:56:29 +04:00
|
|
|
} else if ( THIS[ viewer.hash ].forceRedraw || viewer.drawer.needsUpdate() ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.drawer.update();
|
2012-03-07 07:20:00 +04:00
|
|
|
if( viewer.navigator ){
|
|
|
|
viewer.navigator.update( viewer.viewport );
|
|
|
|
}
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].forceRedraw = false;
|
2013-06-19 21:33:25 +04:00
|
|
|
}
|
2011-12-23 05:36:17 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ viewer.hash ].animating && !animated ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
viewer.raiseEvent( "animationfinish" );
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( !THIS[ viewer.hash ].mouseInside ) {
|
2011-12-23 05:36:17 +04:00
|
|
|
beginControlsAutoHide( viewer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].animating = animated;
|
2011-12-23 05:36:17 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
//viewer.profiler.endUpdate();
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
function resolveUrl( prefix, url ) {
|
|
|
|
return prefix ? prefix + url : url;
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function beginZoomingIn() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = +new Date();
|
2012-03-01 17:38:15 +04:00
|
|
|
THIS[ this.hash ].zoomFactor = this.zoomPerSecond;
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = true;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function beginZoomingOut() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = +new Date();
|
2012-03-01 17:38:15 +04:00
|
|
|
THIS[ this.hash ].zoomFactor = 1.0 / this.zoomPerSecond;
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = true;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function endZooming() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function scheduleZoom( viewer ) {
|
2013-02-26 19:19:48 +04:00
|
|
|
$.requestAnimationFrame( $.delegate( viewer, doZoom ) );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
|
|
|
|
function doZoom() {
|
2012-01-24 17:03:50 +04:00
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
2013-06-19 01:56:13 +04:00
|
|
|
adjustedFactor;
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ this.hash ].zooming && this.viewport) {
|
2012-01-24 17:03:50 +04:00
|
|
|
currentTime = +new Date();
|
2012-02-27 15:56:29 +04:00
|
|
|
deltaTime = currentTime - THIS[ this.hash ].lastZoomTime;
|
|
|
|
adjustedFactor = Math.pow( THIS[ this.hash ].zoomFactor, deltaTime / 1000 );
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.zoomBy( adjustedFactor );
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.applyConstraints();
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = currentTime;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function doSingleZoomIn() {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2013-06-19 21:33:25 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
this.zoomPerClick / 1.0
|
2011-12-23 05:08:06 +04:00
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function doSingleZoomOut() {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.zoomBy(
|
2012-03-01 17:38:15 +04:00
|
|
|
1.0 / this.zoomPerClick
|
2011-12-23 05:08:06 +04:00
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function lightUp() {
|
2012-01-24 17:03:50 +04:00
|
|
|
this.buttons.emulateEnter();
|
|
|
|
this.buttons.emulateExit();
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function onHome() {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.goHome();
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-23 05:08:06 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
function onFullPage() {
|
|
|
|
this.setFullPage( !this.isFullPage() );
|
2012-01-24 17:03:50 +04:00
|
|
|
// correct for no mouseout event on change
|
2012-04-11 01:02:24 +04:00
|
|
|
if( this.buttons ){
|
|
|
|
this.buttons.emulateExit();
|
|
|
|
}
|
2012-03-20 03:03:58 +04:00
|
|
|
this.fullPageButton.element.focus();
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport ) {
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
function onPrevious(){
|
2012-06-05 15:52:00 +04:00
|
|
|
var previous = THIS[ this.hash ].sequence - 1;
|
2013-05-30 03:10:45 +04:00
|
|
|
if(this.navPrevNextWrap && previous < 0){
|
|
|
|
previous += this.tileSources.length;
|
|
|
|
}
|
2012-06-05 15:52:00 +04:00
|
|
|
this.goToPage( previous );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
|
|
|
function onNext(){
|
2012-06-05 15:52:00 +04:00
|
|
|
var next = THIS[ this.hash ].sequence + 1;
|
2013-05-30 03:10:45 +04:00
|
|
|
if(this.navPrevNextWrap && next >= this.tileSources.length){
|
|
|
|
next = 0;
|
|
|
|
}
|
2012-06-05 15:52:00 +04:00
|
|
|
this.goToPage( next );
|
2013-01-29 21:32:58 +04:00
|
|
|
}
|
2012-04-03 11:08:27 +04:00
|
|
|
|
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|