2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
(function( $ ){
|
2012-02-27 15:56:29 +04:00
|
|
|
|
|
|
|
// dictionary from hash to private properties
|
|
|
|
var THIS = {};
|
|
|
|
|
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
|
|
|
|
* @param {Object} options
|
|
|
|
* @param {String} options.element Id of Element to attach to,
|
|
|
|
* @param {String} options.xmlPath Xpath ( TODO: not sure! ),
|
|
|
|
* @param {String} options.prefixUrl Url used to prepend to paths, eg button
|
|
|
|
* images, etc.
|
|
|
|
* @param {Seadragon.Controls[]} options.controls Array of Seadragon.Controls,
|
|
|
|
* @param {Seadragon.Overlays[]} options.overlays Array of Seadragon.Overlays,
|
|
|
|
* @param {Seadragon.Controls[]} options.overlayControls An Array of ( TODO:
|
|
|
|
* not sure! )
|
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
|
|
|
$.EventHandler.call( this );
|
|
|
|
|
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,
|
|
|
|
overlayControls: args.length > 5 ? args[ 5 ] : undefined,
|
|
|
|
config: {}
|
|
|
|
};
|
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
//Allow the options object to override global defaults
|
|
|
|
$.extend( true, this, {
|
|
|
|
id: options.id,
|
2011-12-08 06:10:13 +04:00
|
|
|
xmlPath: null,
|
2012-02-28 01:50:22 +04:00
|
|
|
tileSources: null,
|
2011-12-08 06:10:13 +04:00
|
|
|
controls: [],
|
|
|
|
overlays: [],
|
|
|
|
overlayControls: [],
|
2012-02-28 03:29:00 +04:00
|
|
|
config: $.DEFAULT_SETTINGS,
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
//These were referenced but never defined
|
|
|
|
|
|
|
|
//These are originally not part options but declared as members
|
|
|
|
//in initialize. Its still considered idiomatic to put them here
|
|
|
|
source: null,
|
|
|
|
drawer: null,
|
|
|
|
viewport: null,
|
|
|
|
profiler: null,
|
|
|
|
|
|
|
|
//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.
|
|
|
|
customControls: []
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
}, options );
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.element = document.getElementById( options.id );
|
2012-01-24 17:03:50 +04:00
|
|
|
this.container = $.makeNeutralElement( "div" );
|
|
|
|
this.canvas = $.makeNeutralElement( "div" );
|
|
|
|
|
|
|
|
//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-10 07:16:09 +04:00
|
|
|
this.previousBody = [];
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
this.hash = Math.random();
|
|
|
|
|
|
|
|
THIS[ this.hash ] = {
|
|
|
|
"fsBoundsDelta": new $.Point( 1, 1 ),
|
|
|
|
"prevContainerSize": null,
|
|
|
|
"lastOpenStartTime": 0,
|
|
|
|
"lastOpenEndTime": 0,
|
|
|
|
"animating": false,
|
|
|
|
"forceRedraw": false,
|
|
|
|
"mouseInside": false
|
|
|
|
};
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
this.innerTracker = new $.MouseTracker({
|
|
|
|
element: this.canvas,
|
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
|
|
|
clickHandler: $.delegate( this, onCanvasClick ),
|
|
|
|
dragHandler: $.delegate( this, onCanvasDrag ),
|
|
|
|
releaseHandler: $.delegate( this, onCanvasRelease ),
|
|
|
|
scrollHandler: $.delegate( this, onCanvasScroll )
|
|
|
|
}).setTracking( true ); // default state
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2012-02-03 04:12:45 +04:00
|
|
|
this.outerTracker = new $.MouseTracker({
|
|
|
|
element: this.container,
|
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
|
|
|
enterHandler: $.delegate( this, onContainerEnter ),
|
|
|
|
exitHandler: $.delegate( this, onContainerExit ),
|
|
|
|
releaseHandler: $.delegate( this, onContainerRelease )
|
|
|
|
}).setTracking( true ); // always tracking
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
(function( canvas ){
|
|
|
|
canvas.width = "100%";
|
|
|
|
canvas.height = "100%";
|
|
|
|
canvas.overflow = "hidden";
|
|
|
|
canvas.position = "absolute";
|
|
|
|
canvas.top = "0px";
|
|
|
|
canvas.left = "0px";
|
|
|
|
}( this.canvas.style ));
|
|
|
|
|
|
|
|
|
|
|
|
(function( container ){
|
|
|
|
container.width = "100%";
|
|
|
|
container.height = "100%";
|
|
|
|
container.position = "relative";
|
|
|
|
container.left = "0px";
|
|
|
|
container.top = "0px";
|
|
|
|
container.textAlign = "left"; // needed to protect against
|
|
|
|
}( this.container.style ));
|
|
|
|
|
|
|
|
var layouts = [ 'topleft', 'topright', 'bottomright', 'bottomleft'],
|
|
|
|
layout;
|
|
|
|
|
|
|
|
for( i = 0; i < layouts.length; i++ ){
|
|
|
|
layout = layouts[ i ]
|
2012-01-24 17:03:50 +04:00
|
|
|
this.controls[ layout ] = $.makeNeutralElement( "div" );
|
2011-12-08 06:10:13 +04:00
|
|
|
this.controls[ layout ].style.position = 'absolute';
|
|
|
|
if ( layout.match( 'left' ) ){
|
|
|
|
this.controls[ layout ].style.left = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'right' ) ){
|
|
|
|
this.controls[ layout ].style.right = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'top' ) ){
|
|
|
|
this.controls[ layout ].style.top = '0px';
|
|
|
|
}
|
|
|
|
if ( layout.match( 'bottom' ) ){
|
|
|
|
this.controls[ layout ].style.bottom = '0px';
|
|
|
|
}
|
|
|
|
}
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-02-28 19:01:45 +04:00
|
|
|
//private state properties
|
2012-02-27 15:56:29 +04:00
|
|
|
$.extend( THIS[ this.hash ], {
|
|
|
|
"group": null,
|
|
|
|
// whether we should be continuously zooming
|
|
|
|
"zooming": false,
|
|
|
|
// how much we should be continuously zooming by
|
|
|
|
"zoomFactor": null,
|
|
|
|
"lastZoomTime": null
|
|
|
|
});
|
|
|
|
|
2012-02-28 19:01:45 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2012-01-24 17:03:50 +04:00
|
|
|
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 ),
|
|
|
|
navImages = this.config.navImages,
|
|
|
|
zoomIn = new $.Button({
|
2012-02-28 03:29:00 +04:00
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.ZoomIn" ),
|
2012-02-28 03:29:00 +04:00
|
|
|
srcRest: resolveUrl( this.config.prefixUrl, navImages.zoomIn.REST ),
|
|
|
|
srcGroup: resolveUrl( this.config.prefixUrl, navImages.zoomIn.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.config.prefixUrl, navImages.zoomIn.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.config.prefixUrl, navImages.zoomIn.DOWN ),
|
2012-01-24 17:03:50 +04:00
|
|
|
onPress: beginZoomingInHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomInHandler,
|
|
|
|
onEnter: beginZoomingInHandler,
|
|
|
|
onExit: endZoomingHandler
|
|
|
|
}),
|
|
|
|
zoomOut = new $.Button({
|
2012-02-28 03:29:00 +04:00
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.ZoomOut" ),
|
2012-02-28 03:29:00 +04:00
|
|
|
srcRest: resolveUrl( this.config.prefixUrl, navImages.zoomOut.REST ),
|
|
|
|
srcGroup: resolveUrl( this.config.prefixUrl, navImages.zoomOut.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.config.prefixUrl, navImages.zoomOut.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.config.prefixUrl, navImages.zoomOut.DOWN ),
|
2012-01-24 17:03:50 +04:00
|
|
|
onPress: beginZoomingOutHandler,
|
|
|
|
onRelease: endZoomingHandler,
|
|
|
|
onClick: doSingleZoomOutHandler,
|
|
|
|
onEnter: beginZoomingOutHandler,
|
|
|
|
onExit: endZoomingHandler
|
|
|
|
}),
|
|
|
|
goHome = new $.Button({
|
2012-02-28 03:29:00 +04:00
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.Home" ),
|
2012-02-28 03:29:00 +04:00
|
|
|
srcRest: resolveUrl( this.config.prefixUrl, navImages.home.REST ),
|
|
|
|
srcGroup: resolveUrl( this.config.prefixUrl, navImages.home.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.config.prefixUrl, navImages.home.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.config.prefixUrl, navImages.home.DOWN ),
|
2012-01-24 17:03:50 +04:00
|
|
|
onRelease: onHomeHandler
|
|
|
|
}),
|
|
|
|
fullPage = new $.Button({
|
2012-02-28 03:29:00 +04:00
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
2012-01-24 17:03:50 +04:00
|
|
|
tooltip: $.getString( "Tooltips.FullPage" ),
|
2012-02-28 03:29:00 +04:00
|
|
|
srcRest: resolveUrl( this.config.prefixUrl, navImages.fullpage.REST ),
|
|
|
|
srcGroup: resolveUrl( this.config.prefixUrl, navImages.fullpage.GROUP ),
|
|
|
|
srcHover: resolveUrl( this.config.prefixUrl, navImages.fullpage.HOVER ),
|
|
|
|
srcDown: resolveUrl( this.config.prefixUrl, navImages.fullpage.DOWN ),
|
2012-01-24 17:03:50 +04:00
|
|
|
onRelease: onFullPageHandler
|
|
|
|
});
|
|
|
|
|
|
|
|
this.buttons = new $.ButtonGroup({
|
2012-02-28 17:07:56 +04:00
|
|
|
clickTimeThreshold: this.config.clickTimeThreshold,
|
|
|
|
clickDistThreshold: this.config.clickDistThreshold,
|
|
|
|
buttons: [
|
|
|
|
zoomIn,
|
|
|
|
zoomOut,
|
|
|
|
goHome,
|
|
|
|
fullPage
|
|
|
|
]
|
2011-12-23 05:08:06 +04:00
|
|
|
});
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
this.navControl = this.buttons.element;
|
2011-12-23 05:08:06 +04:00
|
|
|
this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade
|
|
|
|
this.addHandler( 'open', $.delegate( this, lightUp ) );
|
|
|
|
|
2011-12-13 02:40:49 +04:00
|
|
|
if ( this.config.showNavigationControl ) {
|
2011-12-13 16:24:34 +04:00
|
|
|
this.navControl.style.marginRight = "4px";
|
|
|
|
this.navControl.style.marginBottom = "4px";
|
2012-02-27 15:56:29 +04:00
|
|
|
this.addControl( this.navControl, $.ControlAnchor.BOTTOM_RIGHT );
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
for ( i = 0; i < this.customControls.length; i++ ) {
|
|
|
|
this.addControl(
|
|
|
|
this.customControls[ i ].id,
|
|
|
|
this.customControls[ i ].anchor
|
|
|
|
);
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.container.appendChild( this.canvas );
|
|
|
|
this.container.appendChild( this.controls.topleft );
|
|
|
|
this.container.appendChild( this.controls.topright );
|
|
|
|
this.container.appendChild( this.controls.bottomright );
|
|
|
|
this.container.appendChild( this.controls.bottomleft );
|
|
|
|
this.element.appendChild( this.container );
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
window.setTimeout( function(){
|
|
|
|
beginControlsAutoHide( _this );
|
|
|
|
}, 1 ); // initial fade out
|
2011-12-07 05:26:06 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
var initialTileSource,
|
|
|
|
customTileSource;
|
|
|
|
|
|
|
|
if ( this.xmlPath ){
|
|
|
|
//Deprecated option. Now it is preferred to use the tileSources option
|
2012-02-28 01:50:22 +04:00
|
|
|
this.tileSources = [ this.xmlPath ];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.tileSources ){
|
2012-02-27 15:56:29 +04:00
|
|
|
//tileSource is a complex option...
|
|
|
|
//It can be a string, object, function, or an array of any of these.
|
|
|
|
//A string implies a DZI
|
|
|
|
//An object implies a simple image
|
|
|
|
//A function implies a custom tile source callback
|
|
|
|
//An array implies a sequence of tile sources which can be any of the
|
|
|
|
//above
|
|
|
|
if( $.isArray( this.tileSources ) ){
|
|
|
|
if( $.isPlainObject( this.tileSources[ 0 ] ) ){
|
|
|
|
//This is a non-sequenced legacy tile source
|
|
|
|
initialTileSource = this.tileSources;
|
|
|
|
} else {
|
|
|
|
//Sequenced tile source
|
|
|
|
initialTileSource = this.tileSources[ 0 ];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
initialTileSource = this.tileSources
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $.type( initialTileSource ) == 'string ') {
|
|
|
|
//Standard DZI format
|
|
|
|
this.openDzi( initialTileSource );
|
|
|
|
} else if ( $.isArray( initialTileSource ) ){
|
|
|
|
//Legacy image pyramid
|
|
|
|
this.open( new $.LegacyTileSource( initialTileSource ) );
|
|
|
|
} else if ( $.isFunction( initialTileSource ) ){
|
|
|
|
//Custom tile source
|
|
|
|
customTileSource = new TileSource();
|
|
|
|
customTileSource.getTileUrl = initialTileSource;
|
|
|
|
this.open( customTileSource );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-07 05:26:06 +04:00
|
|
|
}
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
$.extend( $.Viewer.prototype, $.EventHandler.prototype, {
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.addControl
|
|
|
|
*/
|
2012-02-01 06:01:37 +04:00
|
|
|
addControl: function ( element, anchor ) {
|
|
|
|
var element = $.getElement( element ),
|
2011-12-08 06:10:13 +04:00
|
|
|
div = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
if ( getControlIndex( this, element ) >= 0 ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return; // they're trying to add a duplicate control
|
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
switch ( anchor ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
case $.ControlAnchor.TOP_RIGHT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.topright;
|
2012-02-01 06:01:37 +04:00
|
|
|
element.style.position = "relative";
|
2011-12-06 07:50:25 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_RIGHT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.bottomright;
|
2012-02-01 06:01:37 +04:00
|
|
|
element.style.position = "relative";
|
2011-12-06 07:50:25 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.BOTTOM_LEFT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.bottomleft;
|
2012-02-01 06:01:37 +04:00
|
|
|
element.style.position = "relative";
|
2011-12-06 07:50:25 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.TOP_LEFT:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.controls.topleft;
|
2012-02-01 06:01:37 +04:00
|
|
|
element.style.position = "relative";
|
2011-12-06 07:50:25 +04:00
|
|
|
break;
|
|
|
|
case $.ControlAnchor.NONE:
|
|
|
|
default:
|
2011-12-08 06:10:13 +04:00
|
|
|
div = this.container;
|
2012-02-01 06:01:37 +04:00
|
|
|
element.style.position = "absolute";
|
2011-12-06 07:50:25 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
this.controls.push(
|
2012-02-01 06:01:37 +04:00
|
|
|
new $.Control( element, anchor, div )
|
2011-12-08 06:10:13 +04:00
|
|
|
);
|
2012-02-01 06:01:37 +04:00
|
|
|
element.style.display = "inline-block";
|
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
|
|
|
/**
|
|
|
|
* If the string is xml is simply parsed and opened, otherwise the string
|
|
|
|
* is treated as an URL and an xml document is requested via ajax, parsed
|
|
|
|
* and then opened in the viewer.
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.openDzi
|
|
|
|
* @param {String} dzi and xml string or the url to a DZI xml document.
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
|
|
|
openDzi: function ( dzi ) {
|
2011-12-13 07:40:02 +04:00
|
|
|
var _this = this;
|
2012-02-01 00:59:09 +04:00
|
|
|
$.createFromDZI(
|
|
|
|
dzi,
|
2011-12-13 07:40:02 +04:00
|
|
|
function( source ){
|
|
|
|
_this.open( source );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
);
|
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
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.openTileSource
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-13 07:40:02 +04:00
|
|
|
openTileSource: function ( tileSource ) {
|
|
|
|
var _this = this;
|
|
|
|
window.setTimeout( function () {
|
|
|
|
_this.open( tileSource );
|
2011-12-23 05:47:21 +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
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.open
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-13 07:40:02 +04:00
|
|
|
open: function( source ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
var _this = this,
|
|
|
|
overlay,
|
|
|
|
i;
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
if ( this.source ) {
|
|
|
|
this.close();
|
|
|
|
}
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
// to ignore earlier opens
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastOpenStartTime = +new Date();
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
window.setTimeout( function () {
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ _this.hash ].lastOpenStartTime > THIS[ _this.hash ].lastOpenEndTime ) {
|
|
|
|
THIS[ _this.hash ].setMessage( $.getString( "Messages.Loading" ) );
|
2011-12-13 07:40:02 +04:00
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastOpenEndTime = +new Date();
|
2011-12-13 07:40:02 +04:00
|
|
|
this.canvas.innerHTML = "";
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].prevContainerSize = $.getElementSize( this.container );
|
2011-12-13 07:40:02 +04:00
|
|
|
|
|
|
|
if( source ){
|
|
|
|
this.source = source;
|
|
|
|
}
|
2012-02-28 17:07:56 +04:00
|
|
|
|
2012-02-28 03:29:00 +04:00
|
|
|
this.viewport = new $.Viewport({
|
|
|
|
containerSize: THIS[ this.hash ].prevContainerSize,
|
|
|
|
contentSize: this.source.dimensions,
|
|
|
|
config: this.config
|
|
|
|
});
|
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
this.drawer = new $.Drawer(
|
|
|
|
this.source,
|
|
|
|
this.viewport,
|
|
|
|
this.canvas
|
|
|
|
);
|
2012-01-25 23:14:02 +04:00
|
|
|
|
|
|
|
//this.profiler = new $.Profiler();
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].animating = false;
|
|
|
|
THIS[ this.hash ].forceRedraw = true;
|
2011-12-23 05:47:21 +04:00
|
|
|
scheduleUpdate( this, updateMulti );
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
for ( i = 0; i < this.overlayControls.length; i++ ) {
|
|
|
|
|
|
|
|
overlay = this.overlayControls[ i ];
|
|
|
|
|
|
|
|
if ( overlay.point != null ) {
|
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
this.drawer.addOverlay(
|
|
|
|
overlay.id,
|
|
|
|
new $.Point(
|
|
|
|
overlay.point.X,
|
|
|
|
overlay.point.Y
|
|
|
|
),
|
|
|
|
$.OverlayPlacement.TOP_LEFT
|
|
|
|
);
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
} else {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
this.drawer.addOverlay(
|
|
|
|
overlay.id,
|
|
|
|
new $.Rect(
|
|
|
|
overlay.rect.Point.X,
|
|
|
|
overlay.rect.Point.Y,
|
|
|
|
overlay.rect.Width,
|
|
|
|
overlay.rect.Height
|
|
|
|
),
|
|
|
|
overlay.placement
|
|
|
|
);
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-13 07:40:02 +04:00
|
|
|
}
|
|
|
|
}
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "open" );
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-13 07:40:02 +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-01-24 17:03:50 +04:00
|
|
|
close: function () {
|
|
|
|
this.source = null;
|
|
|
|
this.viewport = null;
|
|
|
|
this.drawer = null;
|
2012-01-25 23:14:02 +04:00
|
|
|
//this.profiler = null;
|
2011-12-13 07:40:02 +04:00
|
|
|
this.canvas.innerHTML = "";
|
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-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.removeControl
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-02-01 06:01:37 +04:00
|
|
|
removeControl: function ( element ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-01 06:01:37 +04:00
|
|
|
var element = $.getElement( element ),
|
|
|
|
i = getControlIndex( this, element );
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
if ( i >= 0 ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
this.controls[ i ].destroy();
|
|
|
|
this.controls.splice( i, 1 );
|
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
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.clearControls
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
clearControls: function () {
|
2011-12-07 05:26:06 +04:00
|
|
|
while ( this.controls.length > 0 ) {
|
|
|
|
this.controls.pop().destroy();
|
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
|
|
|
},
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isDashboardEnabled
|
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
|
|
|
isDashboardEnabled: function () {
|
2011-12-08 06:10:13 +04:00
|
|
|
var i;
|
2012-01-24 17:03:50 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.controls[ i ].isVisible() ) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isFullPage
|
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
|
|
|
isFullPage: function () {
|
2011-12-08 06:10:13 +04:00
|
|
|
return this.container.parentNode == document.body;
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isMouseNavEnabled
|
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
|
|
|
isMouseNavEnabled: function () {
|
2011-12-13 02:40:49 +04:00
|
|
|
return this.innerTracker.isTracking();
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.isVisible
|
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
|
|
|
isVisible: function () {
|
2011-12-08 06:10:13 +04:00
|
|
|
return this.container.style.visibility != "hidden";
|
2011-12-06 07:50:25 +04:00
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @name OpenSeadragon.Viewer.prototype.setDashboardEnabled
|
2012-02-18 22:13:05 +04:00
|
|
|
* @return {OpenSeadragon.Viewer} Chainable.
|
2012-02-01 00:59:09 +04:00
|
|
|
*/
|
2012-01-24 17:03:50 +04:00
|
|
|
setDashboardEnabled: function( enabled ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
var i;
|
|
|
|
for ( i = this.controls.length - 1; i >= 0; i-- ) {
|
2011-12-07 05:26:06 +04:00
|
|
|
this.controls[ i ].setVisible( enabled );
|
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
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
containerStyle = this.container.style,
|
|
|
|
canvasStyle = this.canvas.style,
|
2011-12-08 06:10:13 +04:00
|
|
|
oldBounds,
|
2012-02-10 07:16:09 +04:00
|
|
|
newBounds,
|
|
|
|
nodes,
|
|
|
|
i;
|
2012-01-24 17:03:50 +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
|
|
|
|
|
|
|
if ( fullPage ) {
|
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
|
|
|
|
|
|
|
canvasStyle.backgroundColor = "black";
|
2011-12-08 06:10:13 +04:00
|
|
|
canvasStyle.color = "white";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
containerStyle.position = "fixed";
|
2011-12-08 06:10:13 +04:00
|
|
|
containerStyle.zIndex = "99999999";
|
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
|
|
|
|
//the body intact as only only the top half of the screen would
|
|
|
|
//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 = [];
|
|
|
|
nodes = document.body.childNodes.length;
|
|
|
|
for ( i = 0; i < nodes; i ++ ){
|
|
|
|
this.previousBody.push( document.body.childNodes[ 0 ] );
|
|
|
|
document.body.removeChild( document.body.childNodes[ 0 ] );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
body.appendChild( this.container );
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].prevContainerSize = $.getWindowSize();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
// mouse will be inside container now
|
2011-12-13 02:22:01 +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 {
|
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
|
|
|
|
|
|
|
containerStyle.position = "relative";
|
2011-12-08 06:10:13 +04:00
|
|
|
containerStyle.zIndex = "";
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2012-02-10 07:16:09 +04:00
|
|
|
document.body.removeChild( this.container );
|
|
|
|
nodes = this.previousBody.length;
|
|
|
|
for ( i = 0; i < nodes; i++ ){
|
|
|
|
document.body.appendChild( this.previousBody.shift() );
|
|
|
|
}
|
2011-12-08 06:10:13 +04:00
|
|
|
this.element.appendChild( this.container );
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].prevContainerSize = $.getElementSize( this.element );
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
// mouse will likely be outside now
|
2011-12-13 02:22:01 +04:00
|
|
|
$.delegate( this, onContainerExit )();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
|
|
|
}
|
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(
|
|
|
|
Math.max(
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].fsBoundsDelta.x,
|
|
|
|
THIS[ this.hash ].fsBoundsDelta.y
|
2011-12-08 06:10:13 +04:00
|
|
|
),
|
|
|
|
null,
|
|
|
|
true
|
|
|
|
);
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].forceRedraw = true;
|
2011-12-17 03:29:16 +04:00
|
|
|
this.raiseEvent( "resize", this );
|
2011-12-23 05:36:17 +04:00
|
|
|
updateOnce( this );
|
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
|
|
|
},
|
|
|
|
|
2012-02-01 00:59:09 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @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
|
|
|
*/
|
2011-12-08 06:10:13 +04:00
|
|
|
setMouseNavEnabled: function( enabled ){
|
2011-12-13 02:40:49 +04:00
|
|
|
this.innerTracker.setTracking( enabled );
|
2012-02-18 22:13:05 +04:00
|
|
|
return this;
|
2011-12-06 07:50:25 +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";
|
2012-02-18 22:13:05 +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
|
|
|
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Schedulers provide the general engine for animation
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function scheduleUpdate( viewer, updateFunc, prevUpdateTime ){
|
|
|
|
var currentTime,
|
|
|
|
targetTime,
|
|
|
|
deltaTime;
|
|
|
|
|
2012-02-27 15:56:29 +04:00
|
|
|
if ( THIS[ viewer.hash ].animating ) {
|
2011-12-23 05:47:21 +04:00
|
|
|
return window.setTimeout( function(){
|
|
|
|
updateFunc( viewer );
|
|
|
|
}, 1 );
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
currentTime = +new Date();
|
|
|
|
prevUpdateTime = prevUpdateTime ? prevUpdateTime : currentTime;
|
2012-01-24 17:03:50 +04:00
|
|
|
// 60 frames per second is ideal
|
|
|
|
targetTime = prevUpdateTime + 1000 / 60;
|
|
|
|
deltaTime = Math.max( 1, targetTime - currentTime );
|
2011-12-08 06:10:13 +04:00
|
|
|
|
2011-12-23 05:47:21 +04:00
|
|
|
return window.setTimeout( function(){
|
|
|
|
updateFunc( viewer );
|
|
|
|
}, deltaTime );
|
2011-12-08 06:10:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//provides a sequence in the fade animation
|
|
|
|
function scheduleControlsFade( viewer ) {
|
|
|
|
window.setTimeout( function(){
|
|
|
|
updateControlsFade( viewer );
|
|
|
|
}, 20);
|
|
|
|
};
|
|
|
|
|
|
|
|
//initiates an animation to hide the controls
|
|
|
|
function beginControlsAutoHide( viewer ) {
|
|
|
|
if ( !viewer.config.autoHideControls ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
viewer.controlsShouldFade = true;
|
|
|
|
viewer.controlsFadeBeginTime =
|
2012-01-24 17:03:50 +04:00
|
|
|
+new Date() +
|
2012-02-28 19:01:45 +04:00
|
|
|
viewer.config.controlsFadeDelay;
|
2011-12-08 06:10:13 +04:00
|
|
|
|
|
|
|
window.setTimeout( function(){
|
|
|
|
scheduleControlsFade( viewer );
|
2012-02-28 19:01:45 +04:00
|
|
|
}, viewer.config.controlsFadeDelay );
|
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-02-28 19:01:45 +04:00
|
|
|
opacity = 1.0 - deltaTime / viewer.config.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--) {
|
|
|
|
viewer.controls[ i ].setOpacity( opacity );
|
2011-12-08 06:10:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( opacity > 0 ) {
|
|
|
|
// fade again
|
|
|
|
scheduleControlsFade( viewer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//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 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Default view event handlers.
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasClick( tracker, position, quick, shift ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
var zoomPreClick,
|
|
|
|
factor;
|
2012-01-24 17:03:50 +04:00
|
|
|
if ( this.viewport && quick ) { // ignore clicks where mouse moved
|
2011-12-08 06:10:13 +04:00
|
|
|
zoomPerClick = this.config.zoomPerClick;
|
|
|
|
factor = shift ? 1.0 / zoomPerClick : zoomPerClick;
|
2012-01-24 17:03:50 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
factor,
|
|
|
|
this.viewport.pointFromPixel( position, true )
|
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
function onCanvasDrag( tracker, position, delta, shift ) {
|
|
|
|
if ( this.viewport ) {
|
|
|
|
this.viewport.panBy(
|
|
|
|
this.viewport.deltaPointsFromPixels(
|
|
|
|
delta.negate()
|
|
|
|
)
|
|
|
|
);
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 ) {
|
|
|
|
factor = Math.pow( this.config.zoomPerScroll, scroll );
|
|
|
|
this.viewport.zoomBy(
|
|
|
|
factor,
|
|
|
|
this.viewport.pointFromPixel( position, true )
|
|
|
|
);
|
2011-12-08 06:10:13 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-13 07:40:02 +04:00
|
|
|
// Utility methods
|
2011-12-08 06:10:13 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-02-01 06:01:37 +04:00
|
|
|
function getControlIndex( viewer, element ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
for ( i = viewer.controls.length - 1; i >= 0; i-- ) {
|
2012-02-01 06:01:37 +04:00
|
|
|
if ( viewer.controls[ i ].element == element ) {
|
2011-12-08 06:10:13 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Page update routines ( aka Views - for future reference )
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-12-23 05:47:21 +04:00
|
|
|
|
|
|
|
function updateMulti( viewer ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
|
|
|
|
var beginTime;
|
|
|
|
|
|
|
|
if ( !viewer.source ) {
|
2011-12-23 05:47:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
beginTime = +new Date();
|
2011-12-23 05:47:21 +04:00
|
|
|
updateOnce( viewer );
|
|
|
|
scheduleUpdate( viewer, arguments.callee, beginTime );
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
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
|
|
|
viewer.raiseEvent( "resize" );
|
|
|
|
}
|
|
|
|
|
2012-01-24 17:03:50 +04:00
|
|
|
animated = viewer.viewport.update();
|
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();
|
|
|
|
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-02-27 15:56:29 +04:00
|
|
|
THIS[ viewer.hash ].forceRedraw = false;
|
2011-12-28 03:20:45 +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();
|
2011-12-23 05:36:17 +04:00
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2011-12-23 05:08:06 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation Controls
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function resolveUrl( prefix, url ) {
|
|
|
|
return prefix ? prefix + url : url;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function beginZoomingIn() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = +new Date();
|
|
|
|
THIS[ this.hash ].zoomFactor = this.config.zoomPerSecond;
|
|
|
|
THIS[ this.hash ].zooming = true;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
function beginZoomingOut() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].lastZoomTime = +new Date();
|
|
|
|
THIS[ this.hash ].zoomFactor = 1.0 / this.config.zoomPerSecond;
|
|
|
|
THIS[ this.hash ].zooming = true;
|
2011-12-23 05:08:06 +04:00
|
|
|
scheduleZoom( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
function endZooming() {
|
2012-02-27 15:56:29 +04:00
|
|
|
THIS[ this.hash ].zooming = false;
|
2011-12-23 05:08:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function scheduleZoom( viewer ) {
|
2012-01-24 17:03:50 +04:00
|
|
|
window.setTimeout( $.delegate( viewer, doZoom ), 10 );
|
2011-12-23 05:08:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function doZoom() {
|
2012-01-24 17:03:50 +04:00
|
|
|
var currentTime,
|
|
|
|
deltaTime,
|
|
|
|
adjustFactor;
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.zoomBy(
|
|
|
|
this.config.zoomPerClick / 1.0
|
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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(
|
|
|
|
1.0 / this.config.zoomPerClick
|
|
|
|
);
|
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function lightUp() {
|
2012-01-24 17:03:50 +04:00
|
|
|
this.buttons.emulateEnter();
|
|
|
|
this.buttons.emulateExit();
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onFullPage() {
|
|
|
|
this.setFullPage( !this.isFullPage() );
|
2012-01-24 17:03:50 +04:00
|
|
|
// correct for no mouseout event on change
|
|
|
|
this.buttons.emulateExit();
|
|
|
|
if ( this.viewport ) {
|
2011-12-23 05:08:06 +04:00
|
|
|
this.viewport.applyConstraints();
|
|
|
|
}
|
|
|
|
};
|
2011-12-13 07:40:02 +04:00
|
|
|
|
2011-12-06 07:50:25 +04:00
|
|
|
}( OpenSeadragon ));
|