found some variables leaked globally in viewer.js - continued very minor formatting clean up in preperation of adding docs

This commit is contained in:
thatcher 2012-01-24 08:03:50 -05:00
parent a8730a9f00
commit 0b09cc8859
4 changed files with 384 additions and 310 deletions

View File

@ -6,7 +6,7 @@
PROJECT: openseadragon PROJECT: openseadragon
BUILD_MAJOR: 0 BUILD_MAJOR: 0
BUILD_MINOR: 8 BUILD_MINOR: 8
BUILD_ID: 22 BUILD_ID: 23
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID} VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}

View File

@ -3,7 +3,7 @@
* (c) 2010 OpenSeadragon * (c) 2010 OpenSeadragon
* (c) 2010 CodePlex Foundation * (c) 2010 CodePlex Foundation
* *
* OpenSeadragon 0.8.22 * OpenSeadragon 0.8.23
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* License: New BSD License (BSD) * License: New BSD License (BSD)
@ -1465,6 +1465,12 @@ $.Viewer = function( options ) {
this.container = $.makeNeutralElement( "div" ); this.container = $.makeNeutralElement( "div" );
this.canvas = $.makeNeutralElement( "div" ); this.canvas = $.makeNeutralElement( "div" );
//Used for toggling between fullscreen and default container size
this.bodyWidth = document.body.style.width;
this.bodyHeight = document.body.style.height;
this.bodyOverflow = document.body.style.overflow;
this.docOverflow = document.documentElement.style.overflow;
this._fsBoundsDelta = new $.Point( 1, 1 ); this._fsBoundsDelta = new $.Point( 1, 1 );
this._prevContainerSize = null; this._prevContainerSize = null;
this._lastOpenStartTime = 0; this._lastOpenStartTime = 0;
@ -1552,11 +1558,9 @@ $.Viewer = function( options ) {
beginZoomingOutHandler = $.delegate( this, beginZoomingOut ), beginZoomingOutHandler = $.delegate( this, beginZoomingOut ),
doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ), doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ),
onHomeHandler = $.delegate( this, onHome ), onHomeHandler = $.delegate( this, onHome ),
onFullPageHandler = $.delegate(this, onFullPage); onFullPageHandler = $.delegate( this, onFullPage ),
navImages = this.config.navImages,
var navImages = this.config.navImages; zoomIn = new $.Button({
var zoomIn = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.ZoomIn" ), tooltip: $.getString( "Tooltips.ZoomIn" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomIn.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.zoomIn.REST ),
@ -1568,9 +1572,8 @@ $.Viewer = function( options ) {
onClick: doSingleZoomInHandler, onClick: doSingleZoomInHandler,
onEnter: beginZoomingInHandler, onEnter: beginZoomingInHandler,
onExit: endZoomingHandler onExit: endZoomingHandler
}); }),
zoomOut = new $.Button({
var zoomOut = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.ZoomOut" ), tooltip: $.getString( "Tooltips.ZoomOut" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomOut.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.zoomOut.REST ),
@ -1582,8 +1585,8 @@ $.Viewer = function( options ) {
onClick: doSingleZoomOutHandler, onClick: doSingleZoomOutHandler,
onEnter: beginZoomingOutHandler, onEnter: beginZoomingOutHandler,
onExit: endZoomingHandler onExit: endZoomingHandler
}); }),
var goHome = new $.Button({ goHome = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.Home" ), tooltip: $.getString( "Tooltips.Home" ),
srcRest: resolveUrl( this.urlPrefix, navImages.home.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.home.REST ),
@ -1591,8 +1594,8 @@ $.Viewer = function( options ) {
srcHover: resolveUrl( this.urlPrefix, navImages.home.HOVER ), srcHover: resolveUrl( this.urlPrefix, navImages.home.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.home.DOWN ), srcDown: resolveUrl( this.urlPrefix, navImages.home.DOWN ),
onRelease: onHomeHandler onRelease: onHomeHandler
}); }),
var fullPage = new $.Button({ fullPage = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.FullPage" ), tooltip: $.getString( "Tooltips.FullPage" ),
srcRest: resolveUrl( this.urlPrefix, navImages.fullpage.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.fullpage.REST ),
@ -1602,12 +1605,12 @@ $.Viewer = function( options ) {
onRelease: onFullPageHandler onRelease: onFullPageHandler
}); });
this._group = new $.ButtonGroup({ this.buttons = new $.ButtonGroup({
config: this.config, config: this.config,
buttons: [ zoomIn, zoomOut, goHome, fullPage ] buttons: [ zoomIn, zoomOut, goHome, fullPage ]
}); });
this.navControl = this._group.element; this.navControl = this.buttons.element;
this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade
this.addHandler( 'open', $.delegate( this, lightUp ) ); this.addHandler( 'open', $.delegate( this, lightUp ) );
@ -1703,13 +1706,16 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
}, },
open: function( source ) { open: function( source ) {
var _this = this; var _this = this,
overlay,
i;
if ( this.source ) { if ( this.source ) {
this.close(); this.close();
} }
this._lastOpenStartTime = new Date().getTime(); // to ignore earlier opens // to ignore earlier opens
this._lastOpenStartTime = +new Date();
window.setTimeout( function () { window.setTimeout( function () {
if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) { if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) {
@ -1717,7 +1723,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
} }
}, 2000); }, 2000);
this._lastOpenEndTime = new Date().getTime(); this._lastOpenEndTime = +new Date();
if ( this._lastOpenStartTime < viewer._lastOpenStartTime ) { if ( this._lastOpenStartTime < viewer._lastOpenStartTime ) {
$.Debug.log( "Ignoring out-of-date open." ); $.Debug.log( "Ignoring out-of-date open." );
@ -1747,9 +1753,12 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
this._forceRedraw = true; this._forceRedraw = true;
scheduleUpdate( this, updateMulti ); scheduleUpdate( this, updateMulti );
for ( var i = 0; i < this.overlayControls.length; i++ ) { for ( i = 0; i < this.overlayControls.length; i++ ) {
var overlay = this.overlayControls[ i ];
overlay = this.overlayControls[ i ];
if ( overlay.point != null ) { if ( overlay.point != null ) {
this.drawer.addOverlay( this.drawer.addOverlay(
overlay.id, overlay.id,
new $.Point( new $.Point(
@ -1758,7 +1767,9 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
), ),
$.OverlayPlacement.TOP_LEFT $.OverlayPlacement.TOP_LEFT
); );
} else { } else {
this.drawer.addOverlay( this.drawer.addOverlay(
overlay.id, overlay.id,
new $.Rect( new $.Rect(
@ -1769,34 +1780,40 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
), ),
overlay.placement overlay.placement
); );
} }
} }
this.raiseEvent( "open" ); this.raiseEvent( "open" );
}, },
close: function () {
close: function () {
this.source = null; this.source = null;
this.viewport = null; this.viewport = null;
this.drawer = null; this.drawer = null;
this.profiler = null; this.profiler = null;
this.canvas.innerHTML = ""; this.canvas.innerHTML = "";
}, },
removeControl: function ( elmt ) { removeControl: function ( elmt ) {
var elmt = $.getElement( elmt ), var elmt = $.getElement( elmt ),
i = getControlIndex( this, elmt ); i = getControlIndex( this, elmt );
if ( i >= 0 ) { if ( i >= 0 ) {
this.controls[ i ].destroy(); this.controls[ i ].destroy();
this.controls.splice( i, 1 ); this.controls.splice( i, 1 );
} }
}, },
clearControls: function () { clearControls: function () {
while ( this.controls.length > 0 ) { while ( this.controls.length > 0 ) {
this.controls.pop().destroy(); this.controls.pop().destroy();
} }
}, },
isDashboardEnabled: function () { isDashboardEnabled: function () {
var i; var i;
for ( i = this.controls.length - 1; i >= 0; i-- ) { for ( i = this.controls.length - 1; i >= 0; i-- ) {
if ( this.controls[ i ].isVisible() ) { if ( this.controls[ i ].isVisible() ) {
return true; return true;
@ -1826,9 +1843,6 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
}, },
setFullPage: function( fullPage ) { setFullPage: function( fullPage ) {
if ( fullPage == this.isFullPage() ) {
return;
}
var body = document.body, var body = document.body,
bodyStyle = body.style, bodyStyle = body.style,
@ -1838,15 +1852,19 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
oldBounds, oldBounds,
newBounds; newBounds;
if ( fullPage == this.isFullPage() ) {
return;
}
if ( fullPage ) { if ( fullPage ) {
bodyOverflow = bodyStyle.overflow; this.bodyOverflow = bodyStyle.overflow;
docOverflow = docStyle.overflow; this.docOverflow = docStyle.overflow;
bodyStyle.overflow = "hidden"; bodyStyle.overflow = "hidden";
docStyle.overflow = "hidden"; docStyle.overflow = "hidden";
bodyWidth = bodyStyle.width; this.bodyWidth = bodyStyle.width;
bodyHeight = bodyStyle.height; this.bodyHeight = bodyStyle.height;
bodyStyle.width = "100%"; bodyStyle.width = "100%";
bodyStyle.height = "100%"; bodyStyle.height = "100%";
@ -1864,11 +1882,11 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
} else { } else {
bodyStyle.overflow = bodyOverflow; bodyStyle.overflow = this.bodyOverflow;
docStyle.overflow = docOverflow; docStyle.overflow = this.docOverflow;
bodyStyle.width = bodyWidth; bodyStyle.width = this.bodyWidth;
bodyStyle.height = bodyHeight; bodyStyle.height = this.bodyHeight;
canvasStyle.backgroundColor = ""; canvasStyle.backgroundColor = "";
canvasStyle.color = ""; canvasStyle.color = "";
@ -1939,7 +1957,8 @@ function scheduleUpdate( viewer, updateFunc, prevUpdateTime ){
currentTime = +new Date(); currentTime = +new Date();
prevUpdateTime = prevUpdateTime ? prevUpdateTime : currentTime; prevUpdateTime = prevUpdateTime ? prevUpdateTime : currentTime;
targetTime = prevUpdateTime + 1000 / 60; // 60 fps ideal // 60 frames per second is ideal
targetTime = prevUpdateTime + 1000 / 60;
deltaTime = Math.max( 1, targetTime - currentTime ); deltaTime = Math.max( 1, targetTime - currentTime );
return window.setTimeout( function(){ return window.setTimeout( function(){
@ -1961,7 +1980,7 @@ function beginControlsAutoHide( viewer ) {
} }
viewer.controlsShouldFade = true; viewer.controlsShouldFade = true;
viewer.controlsFadeBeginTime = viewer.controlsFadeBeginTime =
new Date().getTime() + +new Date() +
viewer.controlsFadeDelay; viewer.controlsFadeDelay;
window.setTimeout( function(){ window.setTimeout( function(){
@ -2014,14 +2033,21 @@ function onCanvasClick(tracker, position, quick, shift) {
if ( this.viewport && quick ) { // ignore clicks where mouse moved if ( this.viewport && quick ) { // ignore clicks where mouse moved
zoomPerClick = this.config.zoomPerClick; zoomPerClick = this.config.zoomPerClick;
factor = shift ? 1.0 / zoomPerClick : zoomPerClick; factor = shift ? 1.0 / zoomPerClick : zoomPerClick;
this.viewport.zoomBy(factor, this.viewport.pointFromPixel(position, true)); this.viewport.zoomBy(
factor,
this.viewport.pointFromPixel( position, true )
);
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
}; };
function onCanvasDrag( tracker, position, delta, shift ) { function onCanvasDrag( tracker, position, delta, shift ) {
if ( this.viewport ) { if ( this.viewport ) {
this.viewport.panBy(this.viewport.deltaPointsFromPixels(delta.negate())); this.viewport.panBy(
this.viewport.deltaPointsFromPixels(
delta.negate()
)
);
} }
}; };
@ -2035,7 +2061,10 @@ function onCanvasScroll(tracker, position, scroll, shift) {
var factor; var factor;
if ( this.viewport ) { if ( this.viewport ) {
factor = Math.pow( this.config.zoomPerScroll, scroll ); factor = Math.pow( this.config.zoomPerScroll, scroll );
this.viewport.zoomBy(factor, this.viewport.pointFromPixel(position, true)); this.viewport.zoomBy(
factor,
this.viewport.pointFromPixel( position, true )
);
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
}; };
@ -2081,33 +2110,38 @@ function getControlIndex( viewer, elmt ) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
function updateMulti( viewer ) { function updateMulti( viewer ) {
var beginTime;
if ( !viewer.source ) { if ( !viewer.source ) {
return; return;
} }
var beginTime = new Date().getTime(); beginTime = +new Date();
updateOnce( viewer ); updateOnce( viewer );
scheduleUpdate( viewer, arguments.callee, beginTime ); scheduleUpdate( viewer, arguments.callee, beginTime );
}; };
function updateOnce( viewer ) { function updateOnce( viewer ) {
var containerSize,
animated;
if ( !viewer.source ) { if ( !viewer.source ) {
return; return;
} }
//viewer.profiler.beginUpdate(); //viewer.profiler.beginUpdate();
var containerSize = $.getElementSize( viewer.container ); containerSize = $.getElementSize( viewer.container );
if ( !containerSize.equals( viewer._prevContainerSize ) ) { if ( !containerSize.equals( viewer._prevContainerSize ) ) {
viewer.viewport.resize( containerSize, true ); // maintain image position // maintain image position
viewer.viewport.resize( containerSize, true );
viewer._prevContainerSize = containerSize; viewer._prevContainerSize = containerSize;
viewer.raiseEvent( "resize" ); viewer.raiseEvent( "resize" );
} }
var animated = viewer.viewport.update(); animated = viewer.viewport.update();
if ( !viewer._animating && animated ) { if ( !viewer._animating && animated ) {
viewer.raiseEvent( "animationstart" ); viewer.raiseEvent( "animationstart" );
abortControlsAutoHide( viewer ); abortControlsAutoHide( viewer );
@ -2166,10 +2200,14 @@ function scheduleZoom( viewer ) {
} }
function doZoom() { function doZoom() {
var currentTime,
deltaTime,
adjustFactor;
if ( this._zooming && this.viewport) { if ( this._zooming && this.viewport) {
var currentTime = +new Date(); currentTime = +new Date();
var deltaTime = currentTime - this._lastZoomTime; deltaTime = currentTime - this._lastZoomTime;
var adjustedFactor = Math.pow(this._zoomFactor, deltaTime / 1000); adjustedFactor = Math.pow( this._zoomFactor, deltaTime / 1000 );
this.viewport.zoomBy( adjustedFactor ); this.viewport.zoomBy( adjustedFactor );
this.viewport.applyConstraints(); this.viewport.applyConstraints();
@ -2199,8 +2237,8 @@ function doSingleZoomOut() {
}; };
function lightUp() { function lightUp() {
this._group.emulateEnter(); this.buttons.emulateEnter();
this._group.emulateExit(); this.buttons.emulateExit();
}; };
function onHome() { function onHome() {
@ -2211,8 +2249,8 @@ function onHome() {
function onFullPage() { function onFullPage() {
this.setFullPage( !this.isFullPage() ); this.setFullPage( !this.isFullPage() );
this._group.emulateExit(); // correct for no mouseout event on change // correct for no mouseout event on change
this.buttons.emulateExit();
if ( this.viewport ) { if ( this.viewport ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
@ -3504,8 +3542,8 @@ $.Tile.prototype = {
(function( $ ){ (function( $ ){
var // the max number of images we should keep in memory // the max number of images we should keep in memory
QUOTA = 100, var QUOTA = 100,
// the most shrunk a tile should be // the most shrunk a tile should be
MIN_PIXEL_RATIO = 0.5, MIN_PIXEL_RATIO = 0.5,
//TODO: make TIMEOUT configurable //TODO: make TIMEOUT configurable
@ -3521,8 +3559,7 @@ var // the max number of images we should keep in memory
( BROWSER == $.BROWSERS.CHROME && BROWSER_VERSION >= 2 ) ( BROWSER == $.BROWSERS.CHROME && BROWSER_VERSION >= 2 )
), ),
USE_CANVAS = USE_CANVAS = $.isFunction( document.createElement( "canvas" ).getContext ) &&
$.isFunction( document.createElement("canvas").getContext ) &&
SUBPIXEL_RENDERING; SUBPIXEL_RENDERING;
$.Drawer = function(source, viewport, elmt) { $.Drawer = function(source, viewport, elmt) {

View File

@ -1,8 +1,8 @@
(function( $ ){ (function( $ ){
var // the max number of images we should keep in memory // the max number of images we should keep in memory
QUOTA = 100, var QUOTA = 100,
// the most shrunk a tile should be // the most shrunk a tile should be
MIN_PIXEL_RATIO = 0.5, MIN_PIXEL_RATIO = 0.5,
//TODO: make TIMEOUT configurable //TODO: make TIMEOUT configurable
@ -18,8 +18,7 @@ var // the max number of images we should keep in memory
( BROWSER == $.BROWSERS.CHROME && BROWSER_VERSION >= 2 ) ( BROWSER == $.BROWSERS.CHROME && BROWSER_VERSION >= 2 )
), ),
USE_CANVAS = USE_CANVAS = $.isFunction( document.createElement( "canvas" ).getContext ) &&
$.isFunction( document.createElement("canvas").getContext ) &&
SUBPIXEL_RENDERING; SUBPIXEL_RENDERING;
$.Drawer = function(source, viewport, elmt) { $.Drawer = function(source, viewport, elmt) {

View File

@ -126,6 +126,12 @@ $.Viewer = function( options ) {
this.container = $.makeNeutralElement( "div" ); this.container = $.makeNeutralElement( "div" );
this.canvas = $.makeNeutralElement( "div" ); this.canvas = $.makeNeutralElement( "div" );
//Used for toggling between fullscreen and default container size
this.bodyWidth = document.body.style.width;
this.bodyHeight = document.body.style.height;
this.bodyOverflow = document.body.style.overflow;
this.docOverflow = document.documentElement.style.overflow;
this._fsBoundsDelta = new $.Point( 1, 1 ); this._fsBoundsDelta = new $.Point( 1, 1 );
this._prevContainerSize = null; this._prevContainerSize = null;
this._lastOpenStartTime = 0; this._lastOpenStartTime = 0;
@ -213,11 +219,9 @@ $.Viewer = function( options ) {
beginZoomingOutHandler = $.delegate( this, beginZoomingOut ), beginZoomingOutHandler = $.delegate( this, beginZoomingOut ),
doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ), doSingleZoomOutHandler = $.delegate( this, doSingleZoomOut ),
onHomeHandler = $.delegate( this, onHome ), onHomeHandler = $.delegate( this, onHome ),
onFullPageHandler = $.delegate(this, onFullPage); onFullPageHandler = $.delegate( this, onFullPage ),
navImages = this.config.navImages,
var navImages = this.config.navImages; zoomIn = new $.Button({
var zoomIn = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.ZoomIn" ), tooltip: $.getString( "Tooltips.ZoomIn" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomIn.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.zoomIn.REST ),
@ -229,9 +233,8 @@ $.Viewer = function( options ) {
onClick: doSingleZoomInHandler, onClick: doSingleZoomInHandler,
onEnter: beginZoomingInHandler, onEnter: beginZoomingInHandler,
onExit: endZoomingHandler onExit: endZoomingHandler
}); }),
zoomOut = new $.Button({
var zoomOut = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.ZoomOut" ), tooltip: $.getString( "Tooltips.ZoomOut" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomOut.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.zoomOut.REST ),
@ -243,8 +246,8 @@ $.Viewer = function( options ) {
onClick: doSingleZoomOutHandler, onClick: doSingleZoomOutHandler,
onEnter: beginZoomingOutHandler, onEnter: beginZoomingOutHandler,
onExit: endZoomingHandler onExit: endZoomingHandler
}); }),
var goHome = new $.Button({ goHome = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.Home" ), tooltip: $.getString( "Tooltips.Home" ),
srcRest: resolveUrl( this.urlPrefix, navImages.home.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.home.REST ),
@ -252,8 +255,8 @@ $.Viewer = function( options ) {
srcHover: resolveUrl( this.urlPrefix, navImages.home.HOVER ), srcHover: resolveUrl( this.urlPrefix, navImages.home.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.home.DOWN ), srcDown: resolveUrl( this.urlPrefix, navImages.home.DOWN ),
onRelease: onHomeHandler onRelease: onHomeHandler
}); }),
var fullPage = new $.Button({ fullPage = new $.Button({
config: this.config, config: this.config,
tooltip: $.getString( "Tooltips.FullPage" ), tooltip: $.getString( "Tooltips.FullPage" ),
srcRest: resolveUrl( this.urlPrefix, navImages.fullpage.REST ), srcRest: resolveUrl( this.urlPrefix, navImages.fullpage.REST ),
@ -263,12 +266,12 @@ $.Viewer = function( options ) {
onRelease: onFullPageHandler onRelease: onFullPageHandler
}); });
this._group = new $.ButtonGroup({ this.buttons = new $.ButtonGroup({
config: this.config, config: this.config,
buttons: [ zoomIn, zoomOut, goHome, fullPage ] buttons: [ zoomIn, zoomOut, goHome, fullPage ]
}); });
this.navControl = this._group.element; this.navControl = this.buttons.element;
this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade this.navControl[ $.SIGNAL ] = true; // hack to get our controls to fade
this.addHandler( 'open', $.delegate( this, lightUp ) ); this.addHandler( 'open', $.delegate( this, lightUp ) );
@ -364,13 +367,16 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
}, },
open: function( source ) { open: function( source ) {
var _this = this; var _this = this,
overlay,
i;
if ( this.source ) { if ( this.source ) {
this.close(); this.close();
} }
this._lastOpenStartTime = new Date().getTime(); // to ignore earlier opens // to ignore earlier opens
this._lastOpenStartTime = +new Date();
window.setTimeout( function () { window.setTimeout( function () {
if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) { if ( _this._lastOpenStartTime > _this._lastOpenEndTime ) {
@ -378,7 +384,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
} }
}, 2000); }, 2000);
this._lastOpenEndTime = new Date().getTime(); this._lastOpenEndTime = +new Date();
if ( this._lastOpenStartTime < viewer._lastOpenStartTime ) { if ( this._lastOpenStartTime < viewer._lastOpenStartTime ) {
$.Debug.log( "Ignoring out-of-date open." ); $.Debug.log( "Ignoring out-of-date open." );
@ -408,9 +414,12 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
this._forceRedraw = true; this._forceRedraw = true;
scheduleUpdate( this, updateMulti ); scheduleUpdate( this, updateMulti );
for ( var i = 0; i < this.overlayControls.length; i++ ) { for ( i = 0; i < this.overlayControls.length; i++ ) {
var overlay = this.overlayControls[ i ];
overlay = this.overlayControls[ i ];
if ( overlay.point != null ) { if ( overlay.point != null ) {
this.drawer.addOverlay( this.drawer.addOverlay(
overlay.id, overlay.id,
new $.Point( new $.Point(
@ -419,7 +428,9 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
), ),
$.OverlayPlacement.TOP_LEFT $.OverlayPlacement.TOP_LEFT
); );
} else { } else {
this.drawer.addOverlay( this.drawer.addOverlay(
overlay.id, overlay.id,
new $.Rect( new $.Rect(
@ -430,34 +441,40 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
), ),
overlay.placement overlay.placement
); );
} }
} }
this.raiseEvent( "open" ); this.raiseEvent( "open" );
}, },
close: function () {
close: function () {
this.source = null; this.source = null;
this.viewport = null; this.viewport = null;
this.drawer = null; this.drawer = null;
this.profiler = null; this.profiler = null;
this.canvas.innerHTML = ""; this.canvas.innerHTML = "";
}, },
removeControl: function ( elmt ) { removeControl: function ( elmt ) {
var elmt = $.getElement( elmt ), var elmt = $.getElement( elmt ),
i = getControlIndex( this, elmt ); i = getControlIndex( this, elmt );
if ( i >= 0 ) { if ( i >= 0 ) {
this.controls[ i ].destroy(); this.controls[ i ].destroy();
this.controls.splice( i, 1 ); this.controls.splice( i, 1 );
} }
}, },
clearControls: function () { clearControls: function () {
while ( this.controls.length > 0 ) { while ( this.controls.length > 0 ) {
this.controls.pop().destroy(); this.controls.pop().destroy();
} }
}, },
isDashboardEnabled: function () { isDashboardEnabled: function () {
var i; var i;
for ( i = this.controls.length - 1; i >= 0; i-- ) { for ( i = this.controls.length - 1; i >= 0; i-- ) {
if ( this.controls[ i ].isVisible() ) { if ( this.controls[ i ].isVisible() ) {
return true; return true;
@ -487,9 +504,6 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
}, },
setFullPage: function( fullPage ) { setFullPage: function( fullPage ) {
if ( fullPage == this.isFullPage() ) {
return;
}
var body = document.body, var body = document.body,
bodyStyle = body.style, bodyStyle = body.style,
@ -499,15 +513,19 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
oldBounds, oldBounds,
newBounds; newBounds;
if ( fullPage == this.isFullPage() ) {
return;
}
if ( fullPage ) { if ( fullPage ) {
bodyOverflow = bodyStyle.overflow; this.bodyOverflow = bodyStyle.overflow;
docOverflow = docStyle.overflow; this.docOverflow = docStyle.overflow;
bodyStyle.overflow = "hidden"; bodyStyle.overflow = "hidden";
docStyle.overflow = "hidden"; docStyle.overflow = "hidden";
bodyWidth = bodyStyle.width; this.bodyWidth = bodyStyle.width;
bodyHeight = bodyStyle.height; this.bodyHeight = bodyStyle.height;
bodyStyle.width = "100%"; bodyStyle.width = "100%";
bodyStyle.height = "100%"; bodyStyle.height = "100%";
@ -525,11 +543,11 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
} else { } else {
bodyStyle.overflow = bodyOverflow; bodyStyle.overflow = this.bodyOverflow;
docStyle.overflow = docOverflow; docStyle.overflow = this.docOverflow;
bodyStyle.width = bodyWidth; bodyStyle.width = this.bodyWidth;
bodyStyle.height = bodyHeight; bodyStyle.height = this.bodyHeight;
canvasStyle.backgroundColor = ""; canvasStyle.backgroundColor = "";
canvasStyle.color = ""; canvasStyle.color = "";
@ -600,7 +618,8 @@ function scheduleUpdate( viewer, updateFunc, prevUpdateTime ){
currentTime = +new Date(); currentTime = +new Date();
prevUpdateTime = prevUpdateTime ? prevUpdateTime : currentTime; prevUpdateTime = prevUpdateTime ? prevUpdateTime : currentTime;
targetTime = prevUpdateTime + 1000 / 60; // 60 fps ideal // 60 frames per second is ideal
targetTime = prevUpdateTime + 1000 / 60;
deltaTime = Math.max( 1, targetTime - currentTime ); deltaTime = Math.max( 1, targetTime - currentTime );
return window.setTimeout( function(){ return window.setTimeout( function(){
@ -622,7 +641,7 @@ function beginControlsAutoHide( viewer ) {
} }
viewer.controlsShouldFade = true; viewer.controlsShouldFade = true;
viewer.controlsFadeBeginTime = viewer.controlsFadeBeginTime =
new Date().getTime() + +new Date() +
viewer.controlsFadeDelay; viewer.controlsFadeDelay;
window.setTimeout( function(){ window.setTimeout( function(){
@ -675,14 +694,21 @@ function onCanvasClick(tracker, position, quick, shift) {
if ( this.viewport && quick ) { // ignore clicks where mouse moved if ( this.viewport && quick ) { // ignore clicks where mouse moved
zoomPerClick = this.config.zoomPerClick; zoomPerClick = this.config.zoomPerClick;
factor = shift ? 1.0 / zoomPerClick : zoomPerClick; factor = shift ? 1.0 / zoomPerClick : zoomPerClick;
this.viewport.zoomBy(factor, this.viewport.pointFromPixel(position, true)); this.viewport.zoomBy(
factor,
this.viewport.pointFromPixel( position, true )
);
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
}; };
function onCanvasDrag( tracker, position, delta, shift ) { function onCanvasDrag( tracker, position, delta, shift ) {
if ( this.viewport ) { if ( this.viewport ) {
this.viewport.panBy(this.viewport.deltaPointsFromPixels(delta.negate())); this.viewport.panBy(
this.viewport.deltaPointsFromPixels(
delta.negate()
)
);
} }
}; };
@ -696,7 +722,10 @@ function onCanvasScroll(tracker, position, scroll, shift) {
var factor; var factor;
if ( this.viewport ) { if ( this.viewport ) {
factor = Math.pow( this.config.zoomPerScroll, scroll ); factor = Math.pow( this.config.zoomPerScroll, scroll );
this.viewport.zoomBy(factor, this.viewport.pointFromPixel(position, true)); this.viewport.zoomBy(
factor,
this.viewport.pointFromPixel( position, true )
);
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
}; };
@ -742,33 +771,38 @@ function getControlIndex( viewer, elmt ) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
function updateMulti( viewer ) { function updateMulti( viewer ) {
var beginTime;
if ( !viewer.source ) { if ( !viewer.source ) {
return; return;
} }
var beginTime = new Date().getTime(); beginTime = +new Date();
updateOnce( viewer ); updateOnce( viewer );
scheduleUpdate( viewer, arguments.callee, beginTime ); scheduleUpdate( viewer, arguments.callee, beginTime );
}; };
function updateOnce( viewer ) { function updateOnce( viewer ) {
var containerSize,
animated;
if ( !viewer.source ) { if ( !viewer.source ) {
return; return;
} }
//viewer.profiler.beginUpdate(); //viewer.profiler.beginUpdate();
var containerSize = $.getElementSize( viewer.container ); containerSize = $.getElementSize( viewer.container );
if ( !containerSize.equals( viewer._prevContainerSize ) ) { if ( !containerSize.equals( viewer._prevContainerSize ) ) {
viewer.viewport.resize( containerSize, true ); // maintain image position // maintain image position
viewer.viewport.resize( containerSize, true );
viewer._prevContainerSize = containerSize; viewer._prevContainerSize = containerSize;
viewer.raiseEvent( "resize" ); viewer.raiseEvent( "resize" );
} }
var animated = viewer.viewport.update(); animated = viewer.viewport.update();
if ( !viewer._animating && animated ) { if ( !viewer._animating && animated ) {
viewer.raiseEvent( "animationstart" ); viewer.raiseEvent( "animationstart" );
abortControlsAutoHide( viewer ); abortControlsAutoHide( viewer );
@ -827,10 +861,14 @@ function scheduleZoom( viewer ) {
} }
function doZoom() { function doZoom() {
var currentTime,
deltaTime,
adjustFactor;
if ( this._zooming && this.viewport) { if ( this._zooming && this.viewport) {
var currentTime = +new Date(); currentTime = +new Date();
var deltaTime = currentTime - this._lastZoomTime; deltaTime = currentTime - this._lastZoomTime;
var adjustedFactor = Math.pow(this._zoomFactor, deltaTime / 1000); adjustedFactor = Math.pow( this._zoomFactor, deltaTime / 1000 );
this.viewport.zoomBy( adjustedFactor ); this.viewport.zoomBy( adjustedFactor );
this.viewport.applyConstraints(); this.viewport.applyConstraints();
@ -860,8 +898,8 @@ function doSingleZoomOut() {
}; };
function lightUp() { function lightUp() {
this._group.emulateEnter(); this.buttons.emulateEnter();
this._group.emulateExit(); this.buttons.emulateExit();
}; };
function onHome() { function onHome() {
@ -872,8 +910,8 @@ function onHome() {
function onFullPage() { function onFullPage() {
this.setFullPage( !this.isFullPage() ); this.setFullPage( !this.isFullPage() );
this._group.emulateExit(); // correct for no mouseout event on change // correct for no mouseout event on change
this.buttons.emulateExit();
if ( this.viewport ) { if ( this.viewport ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }