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)
@ -1363,7 +1363,7 @@ $.Control.prototype = {
**/ **/
$.Viewer = function( options ) { $.Viewer = function( options ) {
var args = arguments, var args = arguments,
_this = this, _this = this,
i; i;
@ -1462,8 +1462,14 @@ $.Viewer = function( options ) {
}, options ); }, options );
this.element = document.getElementById( options.id ); this.element = document.getElementById( options.id );
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;
@ -1478,10 +1484,10 @@ $.Viewer = function( options ) {
this.config.clickTimeThreshold, this.config.clickTimeThreshold,
this.config.clickDistThreshold this.config.clickDistThreshold
); );
this.innerTracker.clickHandler = $.delegate(this, onCanvasClick); this.innerTracker.clickHandler = $.delegate( this, onCanvasClick );
this.innerTracker.dragHandler = $.delegate(this, onCanvasDrag); this.innerTracker.dragHandler = $.delegate( this, onCanvasDrag );
this.innerTracker.releaseHandler = $.delegate(this, onCanvasRelease); this.innerTracker.releaseHandler = $.delegate( this, onCanvasRelease );
this.innerTracker.scrollHandler = $.delegate(this, onCanvasScroll); this.innerTracker.scrollHandler = $.delegate( this, onCanvasScroll );
this.innerTracker.setTracking( true ); // default state this.innerTracker.setTracking( true ); // default state
this.outerTracker = new $.MouseTracker( this.outerTracker = new $.MouseTracker(
@ -1489,9 +1495,9 @@ $.Viewer = function( options ) {
this.config.clickTimeThreshold, this.config.clickTimeThreshold,
this.config.clickDistThreshold this.config.clickDistThreshold
); );
this.outerTracker.enterHandler = $.delegate(this, onContainerEnter); this.outerTracker.enterHandler = $.delegate( this, onContainerEnter );
this.outerTracker.exitHandler = $.delegate(this, onContainerExit); this.outerTracker.exitHandler = $.delegate( this, onContainerExit );
this.outerTracker.releaseHandler = $.delegate(this, onContainerRelease); this.outerTracker.releaseHandler = $.delegate( this, onContainerRelease );
this.outerTracker.setTracking( true ); // always tracking this.outerTracker.setTracking( true ); // always tracking
(function( canvas ){ (function( canvas ){
@ -1518,7 +1524,7 @@ $.Viewer = function( options ) {
for( i = 0; i < layouts.length; i++ ){ for( i = 0; i < layouts.length; i++ ){
layout = layouts[ i ] layout = layouts[ i ]
this.controls[ layout ] = $.makeNeutralElement("div"); this.controls[ layout ] = $.makeNeutralElement( "div" );
this.controls[ layout ].style.position = 'absolute'; this.controls[ layout ].style.position = 'absolute';
if ( layout.match( 'left' ) ){ if ( layout.match( 'left' ) ){
this.controls[ layout ].style.left = '0px'; this.controls[ layout ].style.left = '0px';
@ -1546,68 +1552,65 @@ $.Viewer = function( options ) {
this.elmt = null; this.elmt = null;
var beginZoomingInHandler = $.delegate(this, beginZoomingIn), var beginZoomingInHandler = $.delegate( this, beginZoomingIn ),
endZoomingHandler = $.delegate(this, endZooming), endZoomingHandler = $.delegate( this, endZooming ),
doSingleZoomInHandler = $.delegate(this, doSingleZoomIn), doSingleZoomInHandler = $.delegate( this, doSingleZoomIn ),
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,
zoomIn = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.ZoomIn" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomIn.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.zoomIn.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.zoomIn.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.zoomIn.DOWN ),
onPress: beginZoomingInHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomInHandler,
onEnter: beginZoomingInHandler,
onExit: endZoomingHandler
}),
zoomOut = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.ZoomOut" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomOut.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.zoomOut.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.zoomOut.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.zoomOut.DOWN ),
onPress: beginZoomingOutHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomOutHandler,
onEnter: beginZoomingOutHandler,
onExit: endZoomingHandler
}),
goHome = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.Home" ),
srcRest: resolveUrl( this.urlPrefix, navImages.home.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.home.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.home.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.home.DOWN ),
onRelease: onHomeHandler
}),
fullPage = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.FullPage" ),
srcRest: resolveUrl( this.urlPrefix, navImages.fullpage.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.fullpage.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.fullpage.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.fullpage.DOWN ),
onRelease: onFullPageHandler
});
var navImages = this.config.navImages; this.buttons = new $.ButtonGroup({
var zoomIn = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.ZoomIn"),
srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.zoomIn.DOWN),
onPress: beginZoomingInHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomInHandler,
onEnter: beginZoomingInHandler,
onExit: endZoomingHandler
});
var zoomOut = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.ZoomOut"),
srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.zoomOut.DOWN),
onPress: beginZoomingOutHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomOutHandler,
onEnter: beginZoomingOutHandler,
onExit: endZoomingHandler
});
var goHome = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.Home"),
srcRest: resolveUrl(this.urlPrefix, navImages.home.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.home.DOWN),
onRelease: onHomeHandler
});
var fullPage = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.FullPage"),
srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.fullpage.DOWN),
onRelease: onFullPageHandler
});
this._group = 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 ) );
@ -1635,12 +1638,12 @@ $.Viewer = function( options ) {
beginControlsAutoHide( _this ); beginControlsAutoHide( _this );
}, 1 ); // initial fade out }, 1 ); // initial fade out
if (this.xmlPath){ if ( this.xmlPath ){
this.openDzi( this.xmlPath ); this.openDzi( this.xmlPath );
} }
}; };
$.extend($.Viewer.prototype, $.EventHandler.prototype, { $.extend( $.Viewer.prototype, $.EventHandler.prototype, {
addControl: function ( elmt, anchor ) { addControl: function ( elmt, anchor ) {
var elmt = $.getElement( elmt ), var elmt = $.getElement( elmt ),
@ -1684,7 +1687,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
return !!this.source; return !!this.source;
}, },
openDzi: function (xmlUrl, xmlString) { openDzi: function ( xmlUrl, xmlString ) {
var _this = this; var _this = this;
$.DziTileSourceHelper.createFromXml( $.DziTileSourceHelper.createFromXml(
xmlUrl, xmlUrl,
@ -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 ];
if (overlay.point != null) { overlay = this.overlayControls[ i ];
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,36 +1780,42 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
), ),
overlay.placement overlay.placement
); );
} }
} }
this.raiseEvent( "open" ); this.raiseEvent( "open" );
}, },
close: function () {
this.source = null;
this.viewport = null;
this.drawer = null;
this.profiler = null;
close: function () {
this.source = null;
this.viewport = null;
this.drawer = 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;
} }
} }
@ -1818,7 +1835,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
return this.container.style.visibility != "hidden"; return this.container.style.visibility != "hidden";
}, },
setDashboardEnabled: function (enabled) { setDashboardEnabled: function( enabled ) {
var i; var i;
for ( i = this.controls.length - 1; i >= 0; i-- ) { for ( i = this.controls.length - 1; i >= 0; i-- ) {
this.controls[ i ].setVisible( enabled ); this.controls[ i ].setVisible( enabled );
@ -1826,27 +1843,28 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
}, },
setFullPage: function( fullPage ) { setFullPage: function( fullPage ) {
var body = document.body,
bodyStyle = body.style,
docStyle = document.documentElement.style,
containerStyle = this.container.style,
canvasStyle = this.canvas.style,
oldBounds,
newBounds;
if ( fullPage == this.isFullPage() ) { if ( fullPage == this.isFullPage() ) {
return; return;
} }
var body = document.body,
bodyStyle = body.style,
docStyle = document.documentElement.style,
containerStyle = this.container.style,
canvasStyle = this.canvas.style,
oldBounds,
newBounds;
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%";
@ -1863,12 +1881,12 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
$.delegate( this, onContainerEnter )(); $.delegate( this, onContainerEnter )();
} else { } else {
bodyStyle.overflow = this.bodyOverflow;
docStyle.overflow = this.docOverflow;
bodyStyle.overflow = bodyOverflow; bodyStyle.width = this.bodyWidth;
docStyle.overflow = docOverflow; bodyStyle.height = this.bodyHeight;
bodyStyle.width = bodyWidth;
bodyStyle.height = bodyHeight;
canvasStyle.backgroundColor = ""; canvasStyle.backgroundColor = "";
canvasStyle.color = ""; canvasStyle.color = "";
@ -1886,7 +1904,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
if ( this.viewport ) { if ( this.viewport ) {
oldBounds = this.viewport.getBounds(); oldBounds = this.viewport.getBounds();
this.viewport.resize(this._prevContainerSize); this.viewport.resize( this._prevContainerSize );
newBounds = this.viewport.getBounds(); newBounds = this.viewport.getBounds();
if ( fullPage ) { if ( fullPage ) {
@ -1931,7 +1949,7 @@ function scheduleUpdate( viewer, updateFunc, prevUpdateTime ){
targetTime, targetTime,
deltaTime; deltaTime;
if (this._animating) { if ( this._animating ) {
return window.setTimeout( function(){ return window.setTimeout( function(){
updateFunc( viewer ); updateFunc( viewer );
}, 1 ); }, 1 );
@ -1939,8 +1957,9 @@ 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
deltaTime = Math.max(1, targetTime - currentTime); targetTime = prevUpdateTime + 1000 / 60;
deltaTime = Math.max( 1, targetTime - currentTime );
return window.setTimeout( function(){ return window.setTimeout( function(){
updateFunc( viewer ); updateFunc( viewer );
@ -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(){
@ -2008,57 +2027,67 @@ function abortControlsAutoHide( viewer ) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Default view event handlers. // Default view event handlers.
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
function onCanvasClick(tracker, position, quick, shift) { function onCanvasClick( tracker, position, quick, shift ) {
var zoomPreClick, var zoomPreClick,
factor; factor;
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()
)
);
} }
}; };
function onCanvasRelease(tracker, position, insideElmtPress, insideElmtRelease) { function onCanvasRelease( tracker, position, insideElmtPress, insideElmtRelease ) {
if (insideElmtPress && this.viewport) { if ( insideElmtPress && this.viewport ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
}; };
function onCanvasScroll(tracker, position, scroll, shift) { 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();
} }
}; };
function onContainerExit(tracker, position, buttonDownElmt, buttonDownAny) { function onContainerExit( tracker, position, buttonDownElmt, buttonDownAny ) {
if (!buttonDownElmt) { if ( !buttonDownElmt ) {
this._mouseInside = false; this._mouseInside = false;
if (!this._animating) { if ( !this._animating ) {
beginControlsAutoHide( this ); beginControlsAutoHide( this );
} }
} }
}; };
function onContainerRelease(tracker, position, insideElmtPress, insideElmtRelease) { function onContainerRelease( tracker, position, insideElmtPress, insideElmtRelease ) {
if (!insideElmtRelease) { if ( !insideElmtRelease ) {
this._mouseInside = false; this._mouseInside = false;
if (!this._animating) { if ( !this._animating ) {
beginControlsAutoHide( this ); beginControlsAutoHide( this );
} }
} }
}; };
function onContainerEnter(tracker, position, buttonDownElmt, buttonDownAny) { function onContainerEnter( tracker, position, buttonDownElmt, buttonDownAny ) {
this._mouseInside = true; this._mouseInside = true;
abortControlsAutoHide( this ); abortControlsAutoHide( this );
}; };
@ -2081,33 +2110,38 @@ function getControlIndex( viewer, elmt ) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
function updateMulti( viewer ) { function updateMulti( viewer ) {
if (!viewer.source) {
var beginTime;
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 );
@ -2162,16 +2196,20 @@ function endZooming() {
} }
function scheduleZoom( viewer ) { function scheduleZoom( viewer ) {
window.setTimeout($.delegate(viewer, doZoom), 10); window.setTimeout( $.delegate( viewer, doZoom ), 10 );
} }
function doZoom() { function doZoom() {
if (this._zooming && this.viewport) { var currentTime,
var currentTime = +new Date(); deltaTime,
var deltaTime = currentTime - this._lastZoomTime; adjustFactor;
var adjustedFactor = Math.pow(this._zoomFactor, deltaTime / 1000);
this.viewport.zoomBy(adjustedFactor); if ( this._zooming && this.viewport) {
currentTime = +new Date();
deltaTime = currentTime - this._lastZoomTime;
adjustedFactor = Math.pow( this._zoomFactor, deltaTime / 1000 );
this.viewport.zoomBy( adjustedFactor );
this.viewport.applyConstraints(); this.viewport.applyConstraints();
this._lastZoomTime = currentTime; this._lastZoomTime = currentTime;
scheduleZoom( this ); scheduleZoom( this );
@ -2179,7 +2217,7 @@ function doZoom() {
}; };
function doSingleZoomIn() { function doSingleZoomIn() {
if (this.viewport) { if ( this.viewport ) {
this._zooming = false; this._zooming = false;
this.viewport.zoomBy( this.viewport.zoomBy(
this.config.zoomPerClick / 1.0 this.config.zoomPerClick / 1.0
@ -2189,7 +2227,7 @@ function doSingleZoomIn() {
}; };
function doSingleZoomOut() { function doSingleZoomOut() {
if (this.viewport) { if ( this.viewport ) {
this._zooming = false; this._zooming = false;
this.viewport.zoomBy( this.viewport.zoomBy(
1.0 / this.config.zoomPerClick 1.0 / this.config.zoomPerClick
@ -2199,21 +2237,21 @@ function doSingleZoomOut() {
}; };
function lightUp() { function lightUp() {
this._group.emulateEnter(); this.buttons.emulateEnter();
this._group.emulateExit(); this.buttons.emulateExit();
}; };
function onHome() { function onHome() {
if (this.viewport) { if ( this.viewport ) {
this.viewport.goHome(); this.viewport.goHome();
} }
}; };
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

@ -24,7 +24,7 @@
**/ **/
$.Viewer = function( options ) { $.Viewer = function( options ) {
var args = arguments, var args = arguments,
_this = this, _this = this,
i; i;
@ -123,8 +123,14 @@ $.Viewer = function( options ) {
}, options ); }, options );
this.element = document.getElementById( options.id ); this.element = document.getElementById( options.id );
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;
@ -139,10 +145,10 @@ $.Viewer = function( options ) {
this.config.clickTimeThreshold, this.config.clickTimeThreshold,
this.config.clickDistThreshold this.config.clickDistThreshold
); );
this.innerTracker.clickHandler = $.delegate(this, onCanvasClick); this.innerTracker.clickHandler = $.delegate( this, onCanvasClick );
this.innerTracker.dragHandler = $.delegate(this, onCanvasDrag); this.innerTracker.dragHandler = $.delegate( this, onCanvasDrag );
this.innerTracker.releaseHandler = $.delegate(this, onCanvasRelease); this.innerTracker.releaseHandler = $.delegate( this, onCanvasRelease );
this.innerTracker.scrollHandler = $.delegate(this, onCanvasScroll); this.innerTracker.scrollHandler = $.delegate( this, onCanvasScroll );
this.innerTracker.setTracking( true ); // default state this.innerTracker.setTracking( true ); // default state
this.outerTracker = new $.MouseTracker( this.outerTracker = new $.MouseTracker(
@ -150,9 +156,9 @@ $.Viewer = function( options ) {
this.config.clickTimeThreshold, this.config.clickTimeThreshold,
this.config.clickDistThreshold this.config.clickDistThreshold
); );
this.outerTracker.enterHandler = $.delegate(this, onContainerEnter); this.outerTracker.enterHandler = $.delegate( this, onContainerEnter );
this.outerTracker.exitHandler = $.delegate(this, onContainerExit); this.outerTracker.exitHandler = $.delegate( this, onContainerExit );
this.outerTracker.releaseHandler = $.delegate(this, onContainerRelease); this.outerTracker.releaseHandler = $.delegate( this, onContainerRelease );
this.outerTracker.setTracking( true ); // always tracking this.outerTracker.setTracking( true ); // always tracking
(function( canvas ){ (function( canvas ){
@ -179,7 +185,7 @@ $.Viewer = function( options ) {
for( i = 0; i < layouts.length; i++ ){ for( i = 0; i < layouts.length; i++ ){
layout = layouts[ i ] layout = layouts[ i ]
this.controls[ layout ] = $.makeNeutralElement("div"); this.controls[ layout ] = $.makeNeutralElement( "div" );
this.controls[ layout ].style.position = 'absolute'; this.controls[ layout ].style.position = 'absolute';
if ( layout.match( 'left' ) ){ if ( layout.match( 'left' ) ){
this.controls[ layout ].style.left = '0px'; this.controls[ layout ].style.left = '0px';
@ -207,68 +213,65 @@ $.Viewer = function( options ) {
this.elmt = null; this.elmt = null;
var beginZoomingInHandler = $.delegate(this, beginZoomingIn), var beginZoomingInHandler = $.delegate( this, beginZoomingIn ),
endZoomingHandler = $.delegate(this, endZooming), endZoomingHandler = $.delegate( this, endZooming ),
doSingleZoomInHandler = $.delegate(this, doSingleZoomIn), doSingleZoomInHandler = $.delegate( this, doSingleZoomIn ),
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,
zoomIn = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.ZoomIn" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomIn.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.zoomIn.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.zoomIn.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.zoomIn.DOWN ),
onPress: beginZoomingInHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomInHandler,
onEnter: beginZoomingInHandler,
onExit: endZoomingHandler
}),
zoomOut = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.ZoomOut" ),
srcRest: resolveUrl( this.urlPrefix, navImages.zoomOut.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.zoomOut.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.zoomOut.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.zoomOut.DOWN ),
onPress: beginZoomingOutHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomOutHandler,
onEnter: beginZoomingOutHandler,
onExit: endZoomingHandler
}),
goHome = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.Home" ),
srcRest: resolveUrl( this.urlPrefix, navImages.home.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.home.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.home.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.home.DOWN ),
onRelease: onHomeHandler
}),
fullPage = new $.Button({
config: this.config,
tooltip: $.getString( "Tooltips.FullPage" ),
srcRest: resolveUrl( this.urlPrefix, navImages.fullpage.REST ),
srcGroup: resolveUrl( this.urlPrefix, navImages.fullpage.GROUP ),
srcHover: resolveUrl( this.urlPrefix, navImages.fullpage.HOVER ),
srcDown: resolveUrl( this.urlPrefix, navImages.fullpage.DOWN ),
onRelease: onFullPageHandler
});
var navImages = this.config.navImages; this.buttons = new $.ButtonGroup({
var zoomIn = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.ZoomIn"),
srcRest: resolveUrl(this.urlPrefix, navImages.zoomIn.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomIn.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.zoomIn.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.zoomIn.DOWN),
onPress: beginZoomingInHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomInHandler,
onEnter: beginZoomingInHandler,
onExit: endZoomingHandler
});
var zoomOut = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.ZoomOut"),
srcRest: resolveUrl(this.urlPrefix, navImages.zoomOut.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.zoomOut.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.zoomOut.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.zoomOut.DOWN),
onPress: beginZoomingOutHandler,
onRelease: endZoomingHandler,
onClick: doSingleZoomOutHandler,
onEnter: beginZoomingOutHandler,
onExit: endZoomingHandler
});
var goHome = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.Home"),
srcRest: resolveUrl(this.urlPrefix, navImages.home.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.home.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.home.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.home.DOWN),
onRelease: onHomeHandler
});
var fullPage = new $.Button({
config: this.config,
tooltip: $.getString("Tooltips.FullPage"),
srcRest: resolveUrl(this.urlPrefix, navImages.fullpage.REST),
srcGroup: resolveUrl(this.urlPrefix, navImages.fullpage.GROUP),
srcHover: resolveUrl(this.urlPrefix, navImages.fullpage.HOVER),
srcDown: resolveUrl(this.urlPrefix, navImages.fullpage.DOWN),
onRelease: onFullPageHandler
});
this._group = 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 ) );
@ -296,12 +299,12 @@ $.Viewer = function( options ) {
beginControlsAutoHide( _this ); beginControlsAutoHide( _this );
}, 1 ); // initial fade out }, 1 ); // initial fade out
if (this.xmlPath){ if ( this.xmlPath ){
this.openDzi( this.xmlPath ); this.openDzi( this.xmlPath );
} }
}; };
$.extend($.Viewer.prototype, $.EventHandler.prototype, { $.extend( $.Viewer.prototype, $.EventHandler.prototype, {
addControl: function ( elmt, anchor ) { addControl: function ( elmt, anchor ) {
var elmt = $.getElement( elmt ), var elmt = $.getElement( elmt ),
@ -345,7 +348,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
return !!this.source; return !!this.source;
}, },
openDzi: function (xmlUrl, xmlString) { openDzi: function ( xmlUrl, xmlString ) {
var _this = this; var _this = this;
$.DziTileSourceHelper.createFromXml( $.DziTileSourceHelper.createFromXml(
xmlUrl, xmlUrl,
@ -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 ];
if (overlay.point != null) { overlay = this.overlayControls[ i ];
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,36 +441,42 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
), ),
overlay.placement overlay.placement
); );
} }
} }
this.raiseEvent( "open" ); this.raiseEvent( "open" );
}, },
close: function () {
this.source = null;
this.viewport = null;
this.drawer = null;
this.profiler = null;
close: function () {
this.source = null;
this.viewport = null;
this.drawer = 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;
} }
} }
@ -479,7 +496,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
return this.container.style.visibility != "hidden"; return this.container.style.visibility != "hidden";
}, },
setDashboardEnabled: function (enabled) { setDashboardEnabled: function( enabled ) {
var i; var i;
for ( i = this.controls.length - 1; i >= 0; i-- ) { for ( i = this.controls.length - 1; i >= 0; i-- ) {
this.controls[ i ].setVisible( enabled ); this.controls[ i ].setVisible( enabled );
@ -487,27 +504,28 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
}, },
setFullPage: function( fullPage ) { setFullPage: function( fullPage ) {
var body = document.body,
bodyStyle = body.style,
docStyle = document.documentElement.style,
containerStyle = this.container.style,
canvasStyle = this.canvas.style,
oldBounds,
newBounds;
if ( fullPage == this.isFullPage() ) { if ( fullPage == this.isFullPage() ) {
return; return;
} }
var body = document.body,
bodyStyle = body.style,
docStyle = document.documentElement.style,
containerStyle = this.container.style,
canvasStyle = this.canvas.style,
oldBounds,
newBounds;
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%";
@ -524,12 +542,12 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
$.delegate( this, onContainerEnter )(); $.delegate( this, onContainerEnter )();
} else { } else {
bodyStyle.overflow = this.bodyOverflow;
docStyle.overflow = this.docOverflow;
bodyStyle.overflow = bodyOverflow; bodyStyle.width = this.bodyWidth;
docStyle.overflow = docOverflow; bodyStyle.height = this.bodyHeight;
bodyStyle.width = bodyWidth;
bodyStyle.height = bodyHeight;
canvasStyle.backgroundColor = ""; canvasStyle.backgroundColor = "";
canvasStyle.color = ""; canvasStyle.color = "";
@ -547,7 +565,7 @@ $.extend($.Viewer.prototype, $.EventHandler.prototype, {
if ( this.viewport ) { if ( this.viewport ) {
oldBounds = this.viewport.getBounds(); oldBounds = this.viewport.getBounds();
this.viewport.resize(this._prevContainerSize); this.viewport.resize( this._prevContainerSize );
newBounds = this.viewport.getBounds(); newBounds = this.viewport.getBounds();
if ( fullPage ) { if ( fullPage ) {
@ -592,7 +610,7 @@ function scheduleUpdate( viewer, updateFunc, prevUpdateTime ){
targetTime, targetTime,
deltaTime; deltaTime;
if (this._animating) { if ( this._animating ) {
return window.setTimeout( function(){ return window.setTimeout( function(){
updateFunc( viewer ); updateFunc( viewer );
}, 1 ); }, 1 );
@ -600,8 +618,9 @@ 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
deltaTime = Math.max(1, targetTime - currentTime); targetTime = prevUpdateTime + 1000 / 60;
deltaTime = Math.max( 1, targetTime - currentTime );
return window.setTimeout( function(){ return window.setTimeout( function(){
updateFunc( viewer ); updateFunc( viewer );
@ -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(){
@ -669,57 +688,67 @@ function abortControlsAutoHide( viewer ) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Default view event handlers. // Default view event handlers.
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
function onCanvasClick(tracker, position, quick, shift) { function onCanvasClick( tracker, position, quick, shift ) {
var zoomPreClick, var zoomPreClick,
factor; factor;
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()
)
);
} }
}; };
function onCanvasRelease(tracker, position, insideElmtPress, insideElmtRelease) { function onCanvasRelease( tracker, position, insideElmtPress, insideElmtRelease ) {
if (insideElmtPress && this.viewport) { if ( insideElmtPress && this.viewport ) {
this.viewport.applyConstraints(); this.viewport.applyConstraints();
} }
}; };
function onCanvasScroll(tracker, position, scroll, shift) { 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();
} }
}; };
function onContainerExit(tracker, position, buttonDownElmt, buttonDownAny) { function onContainerExit( tracker, position, buttonDownElmt, buttonDownAny ) {
if (!buttonDownElmt) { if ( !buttonDownElmt ) {
this._mouseInside = false; this._mouseInside = false;
if (!this._animating) { if ( !this._animating ) {
beginControlsAutoHide( this ); beginControlsAutoHide( this );
} }
} }
}; };
function onContainerRelease(tracker, position, insideElmtPress, insideElmtRelease) { function onContainerRelease( tracker, position, insideElmtPress, insideElmtRelease ) {
if (!insideElmtRelease) { if ( !insideElmtRelease ) {
this._mouseInside = false; this._mouseInside = false;
if (!this._animating) { if ( !this._animating ) {
beginControlsAutoHide( this ); beginControlsAutoHide( this );
} }
} }
}; };
function onContainerEnter(tracker, position, buttonDownElmt, buttonDownAny) { function onContainerEnter( tracker, position, buttonDownElmt, buttonDownAny ) {
this._mouseInside = true; this._mouseInside = true;
abortControlsAutoHide( this ); abortControlsAutoHide( this );
}; };
@ -742,33 +771,38 @@ function getControlIndex( viewer, elmt ) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
function updateMulti( viewer ) { function updateMulti( viewer ) {
if (!viewer.source) {
var beginTime;
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 );
@ -823,16 +857,20 @@ function endZooming() {
} }
function scheduleZoom( viewer ) { function scheduleZoom( viewer ) {
window.setTimeout($.delegate(viewer, doZoom), 10); window.setTimeout( $.delegate( viewer, doZoom ), 10 );
} }
function doZoom() { function doZoom() {
if (this._zooming && this.viewport) { var currentTime,
var currentTime = +new Date(); deltaTime,
var deltaTime = currentTime - this._lastZoomTime; adjustFactor;
var adjustedFactor = Math.pow(this._zoomFactor, deltaTime / 1000);
this.viewport.zoomBy(adjustedFactor); if ( this._zooming && this.viewport) {
currentTime = +new Date();
deltaTime = currentTime - this._lastZoomTime;
adjustedFactor = Math.pow( this._zoomFactor, deltaTime / 1000 );
this.viewport.zoomBy( adjustedFactor );
this.viewport.applyConstraints(); this.viewport.applyConstraints();
this._lastZoomTime = currentTime; this._lastZoomTime = currentTime;
scheduleZoom( this ); scheduleZoom( this );
@ -840,7 +878,7 @@ function doZoom() {
}; };
function doSingleZoomIn() { function doSingleZoomIn() {
if (this.viewport) { if ( this.viewport ) {
this._zooming = false; this._zooming = false;
this.viewport.zoomBy( this.viewport.zoomBy(
this.config.zoomPerClick / 1.0 this.config.zoomPerClick / 1.0
@ -850,7 +888,7 @@ function doSingleZoomIn() {
}; };
function doSingleZoomOut() { function doSingleZoomOut() {
if (this.viewport) { if ( this.viewport ) {
this._zooming = false; this._zooming = false;
this.viewport.zoomBy( this.viewport.zoomBy(
1.0 / this.config.zoomPerClick 1.0 / this.config.zoomPerClick
@ -860,21 +898,21 @@ function doSingleZoomOut() {
}; };
function lightUp() { function lightUp() {
this._group.emulateEnter(); this.buttons.emulateEnter();
this._group.emulateExit(); this.buttons.emulateExit();
}; };
function onHome() { function onHome() {
if (this.viewport) { if ( this.viewport ) {
this.viewport.goHome(); this.viewport.goHome();
} }
}; };
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();
} }
}; };