2013-07-02 02:17:45 +04:00
/* global QUnit, module, Util, $, console, test, asyncTest, start, ok, equal */
2013-03-21 21:55:36 +04:00
QUnit . config . autostart = false ;
2013-03-24 05:06:38 +04:00
( function ( ) {
2014-01-17 00:11:35 +04:00
var debug = false ,
viewer ,
2013-04-03 05:07:10 +04:00
displayRegion ,
navigator ,
2014-01-17 00:11:35 +04:00
navigatorScaleFactor ,
2013-04-03 19:51:24 +04:00
contentStartFromLeft ,
contentStartFromTop ,
displayRegionWidth ,
2013-06-12 23:06:17 +04:00
displayRegionHeight ,
topNavigatorClickAdjustment ;
2013-03-25 20:18:55 +04:00
module ( "navigator" , {
2013-07-02 02:17:45 +04:00
setup : function ( ) {
Util . initializeTestDOM ( ) ;
2013-03-25 20:18:55 +04:00
resetTestVariables ( ) ;
2013-06-07 18:25:26 +04:00
$ ( document ) . scrollTop ( 0 ) ;
$ ( document ) . scrollLeft ( 0 ) ;
2013-06-02 00:08:23 +04:00
} ,
2013-07-02 02:17:45 +04:00
teardown : function ( ) {
// jQuery UI creates its controls outside the normal DOM hierarchy which QUnit cleans up:
if ( $ ( '#exampleNavigator' ) . is ( ':ui-dialog' ) ) {
$ ( '#exampleNavigator' ) . dialog ( 'destroy' ) ;
}
2013-06-02 00:08:23 +04:00
resetTestVariables ( ) ;
2013-03-25 20:18:55 +04:00
}
} ) ;
2013-03-21 21:55:36 +04:00
2013-03-24 05:06:38 +04:00
$ ( document ) . ready ( function ( ) {
2013-03-21 21:55:36 +04:00
start ( ) ;
} ) ;
2013-04-02 22:09:49 +04:00
var resetTestVariables = function ( ) {
2013-07-02 02:17:45 +04:00
if ( viewer ) {
2013-04-02 22:09:49 +04:00
viewer . close ( ) ;
}
displayRegion = null ;
navigator = null ;
2014-01-17 00:11:35 +04:00
navigatorScaleFactor = null ;
2013-04-03 19:51:24 +04:00
contentStartFromLeft = null ;
contentStartFromTop = null ;
displayRegionWidth = null ;
displayRegionHeight = null ;
2013-06-12 23:06:17 +04:00
topNavigatorClickAdjustment = 0 ;
2013-03-21 21:55:36 +04:00
} ;
2013-03-24 05:06:38 +04:00
var assessNavigatorLocation = function ( expectedX , expectedY ) {
var navigator = $ ( ".navigator" ) ;
2013-03-21 21:55:36 +04:00
2014-01-19 06:19:22 +04:00
Util . assessNumericValue ( expectedX , navigator . offset ( ) . left , 10 , ' Navigator x Position' ) ;
Util . assessNumericValue ( expectedY , navigator . offset ( ) . top , 10 , ' Navigator y Position' ) ;
2013-03-21 21:55:36 +04:00
} ;
2014-01-19 06:19:22 +04:00
var assessNavigatorSize = function ( expectedWidth , expectedHeight , msg ) {
2014-01-17 00:11:35 +04:00
var navigator = $ ( ".navigator" ) ;
2014-01-19 06:19:22 +04:00
Util . assessNumericValue ( expectedWidth , navigator . width ( ) , 2 , ' Navigator Width ' + ( msg ? msg : '' ) ) ;
Util . assessNumericValue ( expectedHeight , navigator . height ( ) , 2 , ' Navigator Height ' + ( msg ? msg : '' ) ) ;
2014-01-17 00:11:35 +04:00
} ;
2014-01-19 06:19:22 +04:00
var assessNavigatorAspectRatio = function ( expectedAspectRatio , variance , msg ) {
2014-01-17 00:11:35 +04:00
var navigator = $ ( ".navigator" ) ;
2014-01-19 06:19:22 +04:00
Util . assessNumericValue ( expectedAspectRatio , navigator . width ( ) / navigator . height ( ) , variance , ' Navigator Aspect Ratio ' + ( msg ? msg : '' ) ) ;
} ;
var assessNavigatorArea = function ( expectedArea , msg ) {
var navigator = $ ( ".navigator" ) ;
Util . assessNumericValue ( expectedArea , navigator . width ( ) * navigator . height ( ) , Math . max ( navigator . width ( ) , navigator . height ( ) ) , ' Navigator Area ' + ( msg ? msg : '' ) ) ;
2014-01-17 00:11:35 +04:00
} ;
2014-01-21 20:44:04 +04:00
var navigatorRegionBoundsInPoints = function ( ) {
2013-04-03 05:07:10 +04:00
var regionBoundsInPoints ,
expectedDisplayRegionWidth ,
expectedDisplayRegionHeight ,
expectedDisplayRegionXLocation ,
expectedDisplayRegionYLocation ;
2014-01-17 00:11:35 +04:00
2014-01-21 20:44:04 +04:00
if ( navigator === null ) {
2013-03-25 20:18:55 +04:00
navigator = $ ( ".navigator" ) ;
2014-01-17 00:11:35 +04:00
navigatorScaleFactor = Math . min ( navigator . width ( ) / viewer . viewport . contentSize . x , navigator . height ( ) / viewer . viewport . contentSize . y ) ;
displayRegionWidth = viewer . viewport . contentSize . x * navigatorScaleFactor ;
displayRegionHeight = viewer . viewport . contentSize . y * navigatorScaleFactor ;
contentStartFromLeft = ( navigator . width ( ) - displayRegionWidth ) / 2 ;
contentStartFromTop = ( navigator . height ( ) - displayRegionHeight ) / 2 ;
2013-03-25 19:01:31 +04:00
}
2014-01-17 00:11:35 +04:00
expectedDisplayRegionWidth = viewer . viewport . getBounds ( ) . width * displayRegionWidth ;
expectedDisplayRegionHeight = viewer . viewport . getBounds ( ) . height * displayRegionHeight * viewer . source . aspectRatio ;
expectedDisplayRegionXLocation = viewer . viewport . getBounds ( ) . x * displayRegionWidth + contentStartFromLeft ;
expectedDisplayRegionYLocation = viewer . viewport . getBounds ( ) . y * displayRegionHeight * viewer . source . aspectRatio + contentStartFromTop ;
2013-04-02 22:09:49 +04:00
regionBoundsInPoints = new OpenSeadragon . Rect ( expectedDisplayRegionXLocation , expectedDisplayRegionYLocation , expectedDisplayRegionWidth , expectedDisplayRegionHeight ) ;
2013-03-31 05:53:22 +04:00
2014-01-17 00:11:35 +04:00
if ( debug ) {
console . log ( 'Image width: ' + viewer . viewport . contentSize . x + '\n' +
'Image height: ' + viewer . viewport . contentSize . y + '\n' +
'navigator.width(): ' + navigator . width ( ) + '\n' +
'navigator.height(): ' + navigator . height ( ) + '\n' +
'navigatorScaleFactor: ' + navigatorScaleFactor + '\n' +
'contentStartFromLeft: ' + contentStartFromLeft + '\n' +
'contentStartFromTop: ' + contentStartFromTop + '\n' +
'displayRegionWidth: ' + displayRegionWidth + '\n' +
'displayRegionHeight: ' + displayRegionHeight + '\n' +
'expectedDisplayRegionXLocation: ' + expectedDisplayRegionXLocation + '\n' +
'expectedDisplayRegionYLocation: ' + expectedDisplayRegionYLocation + '\n' +
'expectedDisplayRegionWidth: ' + expectedDisplayRegionWidth + '\n' +
'expectedDisplayRegionHeight: ' + expectedDisplayRegionHeight + '\n'
) ;
}
2013-03-31 05:53:22 +04:00
return regionBoundsInPoints ;
} ;
2014-01-21 20:44:04 +04:00
var assessDisplayRegion = function ( status ) {
2013-03-25 19:01:31 +04:00
2014-01-17 00:11:35 +04:00
if ( debug ) {
console . log ( status ) ;
}
2014-01-21 20:44:04 +04:00
var expectedBounds = navigatorRegionBoundsInPoints ( ) ;
2013-04-05 06:30:59 +04:00
Util . assessNumericValue ( expectedBounds . width , displayRegion . width ( ) + viewer . navigator . totalBorderWidths . x , 2 , status + ' Width synchronization' ) ;
Util . assessNumericValue ( expectedBounds . height , displayRegion . height ( ) + viewer . navigator . totalBorderWidths . y , 2 , status + ' Height synchronization' ) ;
Util . assessNumericValue ( expectedBounds . x , displayRegion . position ( ) . left , 2 , status + ' Left synchronization' ) ;
Util . assessNumericValue ( expectedBounds . y , displayRegion . position ( ) . top , 2 , status + ' Top synchronization' ) ;
2013-03-21 21:55:36 +04:00
} ;
2013-03-24 05:06:38 +04:00
var waitForViewer = function ( ) {
2013-04-02 21:49:15 +04:00
return function ( handler , count , lastDisplayRegionLeft , lastDisplayWidth ) {
2013-04-03 05:07:10 +04:00
var viewerAndNavigatorDisplayReady = false ,
currentDisplayRegionLeft ,
currentDisplayWidth ;
2013-04-02 22:09:49 +04:00
if ( displayRegion === null ) {
displayRegion = $ ( ".displayregion" ) ;
}
if ( typeof count !== "number" ) {
count = 0 ;
lastDisplayRegionLeft = null ;
lastDisplayWidth = null ;
}
try {
currentDisplayRegionLeft = displayRegion . position ( ) . left ;
currentDisplayWidth = displayRegion . width ( ) ;
viewerAndNavigatorDisplayReady = viewer . drawer !== null &&
! viewer . drawer . needsUpdate ( ) &&
currentDisplayWidth > 0 &&
2013-07-02 02:17:45 +04:00
Util . equalsWithVariance ( lastDisplayRegionLeft , currentDisplayRegionLeft , 0.0001 ) &&
Util . equalsWithVariance ( lastDisplayWidth , currentDisplayWidth , 0.0001 ) &&
Util . equalsWithVariance ( viewer . viewport . getBounds ( true ) . x , viewer . viewport . getBounds ( ) . x , 0.0001 ) &&
Util . equalsWithVariance ( viewer . viewport . getBounds ( true ) . y , viewer . viewport . getBounds ( ) . y , 0.0001 ) &&
Util . equalsWithVariance ( viewer . viewport . getBounds ( true ) . width , viewer . viewport . getBounds ( ) . width , 0.0001 ) ;
2013-04-02 22:09:49 +04:00
}
catch ( err ) {
//Ignore. Subsequent code will try again shortly
}
if ( ( ! viewerAndNavigatorDisplayReady ) && count < 50 ) {
count ++ ;
setTimeout ( function ( ) {
waitForViewer ( handler , count , currentDisplayRegionLeft , currentDisplayWidth ) ;
2013-07-02 02:17:45 +04:00
} , 100 ) ;
2013-04-02 22:09:49 +04:00
}
else {
if ( count === 40 ) {
console . log ( "waitForViewer:" +
viewer . drawer + ":" + viewer . drawer . needsUpdate ( ) + ":" +
viewerAndNavigatorDisplayReady + ":" +
lastDisplayRegionLeft + ":" + currentDisplayRegionLeft + ":" +
lastDisplayWidth + ":" + currentDisplayWidth + ":" +
viewer . viewport . getBounds ( true ) . x + ":" + viewer . viewport . getBounds ( ) . x + ":" +
viewer . viewport . getBounds ( true ) . y + ":" + viewer . viewport . getBounds ( ) . y + ":" +
viewer . viewport . getBounds ( true ) . width + ":" + viewer . viewport . getBounds ( ) . width + ":" +
count ) ;
2013-03-21 21:55:36 +04:00
}
2013-04-02 22:09:49 +04:00
handler ( ) ;
}
} ;
2013-03-21 21:55:36 +04:00
} ( ) ;
2013-04-02 22:09:49 +04:00
var simulateNavigatorClick = function ( viewer , locationX , locationY ) {
2013-06-07 18:25:26 +04:00
//Assumes that the page has not been scrolled from the top or left
2013-04-03 05:07:10 +04:00
var $canvas = $ ( viewer . element ) . find ( '.openseadragon-canvas' ) ,
offset = $canvas . offset ( ) ,
event = {
clientX : offset . left + locationX ,
clientY : offset . top + locationY
} ;
2013-03-31 19:00:45 +04:00
$canvas
. simulate ( 'mouseover' , event )
. simulate ( 'mousedown' , event )
. simulate ( 'mouseup' , event ) ;
2013-03-31 19:10:31 +04:00
} ;
2013-03-31 19:00:45 +04:00
2013-04-02 22:09:49 +04:00
var simulateNavigatorDrag = function ( viewer , distanceX , distanceY ) {
2013-04-03 05:07:10 +04:00
var $canvas = $ ( viewer . element ) . find ( '.displayregion' ) ,
event = {
dx : Math . floor ( distanceX ) ,
dy : Math . floor ( distanceY )
} ;
2013-03-31 19:00:45 +04:00
$canvas
. simulate ( 'drag' , event ) ;
2013-03-31 19:10:31 +04:00
} ;
2013-03-31 19:00:45 +04:00
2013-04-02 22:09:49 +04:00
var assessViewerInCorner = function ( theContentCorner ) {
return function ( ) {
var expectedXCoordinate , expecteYCoordinate ;
if ( theContentCorner === "TOPLEFT" ) {
expectedXCoordinate = 0 ;
expecteYCoordinate = 0 ;
}
else if ( theContentCorner === "TOPRIGHT" ) {
expectedXCoordinate = 1 - viewer . viewport . getBounds ( ) . width ;
expecteYCoordinate = 0 ;
}
else if ( theContentCorner === "BOTTOMRIGHT" ) {
expectedXCoordinate = 1 - viewer . viewport . getBounds ( ) . width ;
expecteYCoordinate = 1 / viewer . source . aspectRatio - viewer . viewport . getBounds ( ) . height ;
}
else if ( theContentCorner === "BOTTOMLEFT" ) {
expectedXCoordinate = 0 ;
expecteYCoordinate = 1 / viewer . source . aspectRatio - viewer . viewport . getBounds ( ) . height ;
}
if ( viewer . viewport . getBounds ( ) . width < 1 ) {
2013-07-02 02:17:45 +04:00
Util . assessNumericValue ( expectedXCoordinate , viewer . viewport . getBounds ( ) . x , 0.04 , ' Viewer at ' + theContentCorner + ', x coord' ) ;
2013-04-02 22:09:49 +04:00
}
if ( viewer . viewport . getBounds ( ) . height < 1 / viewer . source . aspectRatio ) {
2013-07-02 02:17:45 +04:00
Util . assessNumericValue ( expecteYCoordinate , viewer . viewport . getBounds ( ) . y , 0.04 , ' Viewer at ' + theContentCorner + ', y coord' ) ;
2013-04-02 22:09:49 +04:00
}
2013-07-02 02:17:45 +04:00
} ;
2013-04-02 06:33:58 +04:00
} ;
2013-04-02 22:09:49 +04:00
var assessViewerInCenter = function ( ) {
2013-07-02 02:17:45 +04:00
var yPositionVariance = 0.04 ;
2013-04-02 22:09:49 +04:00
if ( viewer . source . aspectRatio < 1 ) {
2013-04-02 06:33:58 +04:00
yPositionVariance = yPositionVariance / viewer . source . aspectRatio ;
}
2013-04-05 06:30:59 +04:00
Util . assessNumericValue ( 1 / viewer . source . aspectRatio / 2 , viewer . viewport . getCenter ( ) . y , yPositionVariance , ' Viewer at center, y coord' ) ;
2013-07-02 02:17:45 +04:00
Util . assessNumericValue ( 0.5 , viewer . viewport . getCenter ( ) . x , 0.4 , ' Viewer at center, x coord' ) ;
2013-04-02 06:33:58 +04:00
} ;
2013-04-02 22:09:49 +04:00
var clickOnNavigator = function ( theContentCorner ) {
return function ( ) {
2013-04-03 05:07:10 +04:00
var xPos ,
yPos ;
2013-04-02 22:09:49 +04:00
if ( theContentCorner === "TOPLEFT" ) {
2013-04-03 19:51:24 +04:00
xPos = contentStartFromLeft ;
2013-06-12 23:06:17 +04:00
yPos = contentStartFromTop + topNavigatorClickAdjustment ;
2013-04-02 22:09:49 +04:00
}
else if ( theContentCorner === "TOPRIGHT" ) {
2013-04-03 19:51:24 +04:00
xPos = contentStartFromLeft + displayRegionWidth ;
2013-06-12 23:06:17 +04:00
yPos = contentStartFromTop + topNavigatorClickAdjustment ;
2013-04-02 22:09:49 +04:00
}
else if ( theContentCorner === "BOTTOMRIGHT" ) {
2013-04-03 19:51:24 +04:00
xPos = contentStartFromLeft + displayRegionWidth ;
yPos = contentStartFromTop + displayRegionHeight ;
2013-04-02 22:09:49 +04:00
}
else if ( theContentCorner === "BOTTOMLEFT" ) {
2013-04-03 19:51:24 +04:00
xPos = contentStartFromLeft ;
yPos = contentStartFromTop + displayRegionHeight ;
2013-04-02 22:09:49 +04:00
}
2013-04-02 21:49:15 +04:00
simulateNavigatorClick ( viewer . navigator , xPos , yPos ) ;
2013-07-02 02:17:45 +04:00
} ;
2013-03-31 05:53:22 +04:00
} ;
2013-04-02 22:09:49 +04:00
var dragNavigatorBackToCenter = function ( ) {
2013-04-03 05:07:10 +04:00
var start = viewer . viewport . getBounds ( ) . getTopLeft ( ) ,
target = new OpenSeadragon . Point ( 0.5 - viewer . viewport . getBounds ( ) . width / 2 ,
1 / viewer . source . aspectRatio / 2 - viewer . viewport . getBounds ( ) . height / 2 ) ,
delta = target . minus ( start ) ;
2013-04-02 22:09:49 +04:00
if ( viewer . source . aspectRatio < 1 ) {
delta . y = delta . y * viewer . source . aspectRatio ;
2013-04-02 06:33:58 +04:00
}
2013-04-03 19:51:24 +04:00
simulateNavigatorDrag ( viewer . navigator , delta . x * displayRegionWidth , delta . y * displayRegionHeight ) ;
2013-03-31 05:53:22 +04:00
} ;
2014-01-19 06:19:22 +04:00
var resizeElement = function ( $element , width , height ) {
$element . width ( width ) ;
$element . height ( height ) ;
} ;
2013-03-24 05:06:38 +04:00
var assessNavigatorViewerPlacement = function ( seadragonProperties , testProperties ) {
2013-04-02 22:09:49 +04:00
var navigatorOperationScenarios = [
2014-01-19 06:19:22 +04:00
{ interactionOperation : clickOnNavigator ( "TOPRIGHT" ) ,
assessmentOperation : assessViewerInCorner ( "TOPRIGHT" ) ,
assessmentMessage : "After click on navigator on top right" } ,
{ interactionOperation : dragNavigatorBackToCenter ,
assessmentOperation : assessViewerInCenter ,
assessmentMessage : "After drag on navigator from top right" } ,
{ interactionOperation : clickOnNavigator ( "BOTTOMLEFT" ) ,
assessmentOperation : assessViewerInCorner ( "BOTTOMLEFT" ) ,
assessmentMessage : "After click on navigator on bottom left" } ,
{ interactionOperation : dragNavigatorBackToCenter ,
assessmentOperation : assessViewerInCenter ,
assessmentMessage : "After drag on navigator from bottom left" } ,
{ interactionOperation : clickOnNavigator ( "BOTTOMRIGHT" ) ,
assessmentOperation : assessViewerInCorner ( "BOTTOMRIGHT" ) ,
assessmentMessage : "After click on navigator on bottom right" } ,
{ interactionOperation : dragNavigatorBackToCenter ,
assessmentOperation : assessViewerInCenter ,
assessmentMessage : "After drag on navigator from bottom right" } ,
{ interactionOperation : clickOnNavigator ( "TOPLEFT" ) ,
assessmentOperation : assessViewerInCorner ( "TOPLEFT" ) ,
assessmentMessage : "After click on navigator on top left" } ,
{ interactionOperation : dragNavigatorBackToCenter ,
assessmentOperation : assessViewerInCenter ,
assessmentMessage : "After drag on navigator from top left" }
] ,
viewerResizeScenarios = [
{ resizeFactorX : 0.5 , resizeFactorY : 1.0 , assessmentMessage : "After Viewer Resize (50%, 100%)" } ,
{ resizeFactorX : 1.0 , resizeFactorY : 0.5 , assessmentMessage : "After Viewer Resize (100%, 50%)" } ,
{ resizeFactorX : 1.0 , resizeFactorY : 1.0 , assessmentMessage : "After Viewer Resize (100%, 100%)" }
] ,
2014-01-21 20:44:04 +04:00
navigatorResizeScenarios = [
{ resizeFactorX : 0.75 , resizeFactorY : 1.0 , assessmentMessage : "After Navigator Resize (75%, 100%)" } ,
{ resizeFactorX : 1.0 , resizeFactorY : 0.75 , assessmentMessage : "After Navigator Resize (100%, 75%)" } ,
{ resizeFactorX : 1.0 , resizeFactorY : 1.0 , assessmentMessage : "After Navigator Resize (100%, 100%)" }
] ,
2014-01-19 06:19:22 +04:00
autoFadeWaitTime = 100 ,
navigatorElement = null ,
viewerElement = null ,
viewerOriginalSize = null ,
navigatorOriginalSize = null ;
2013-04-02 22:09:49 +04:00
2013-04-03 05:07:10 +04:00
seadragonProperties . visibilityRatio = 1 ;
viewer = OpenSeadragon ( seadragonProperties ) ;
2013-06-12 23:06:17 +04:00
if ( $ . isNumeric ( testProperties . topNavigatorClickAdjustment ) )
{
topNavigatorClickAdjustment = testProperties . topNavigatorClickAdjustment ;
}
2013-04-02 22:09:49 +04:00
var assessNavigatorOperationAndTakeNextStep = function ( step ) {
return function ( ) {
var nextStep = step + 1 ;
2013-04-03 19:51:24 +04:00
assessDisplayRegion ( navigatorOperationScenarios [ step ] . assessmentMessage ) ;
2013-04-02 22:09:49 +04:00
navigatorOperationScenarios [ step ] . assessmentOperation ( ) ;
if ( step === navigatorOperationScenarios . length - 1 ) {
2013-04-02 21:49:15 +04:00
start ( ) ;
}
2013-04-02 22:09:49 +04:00
else {
navigatorOperationScenarios [ nextStep ] . interactionOperation ( ) ;
2013-04-02 21:49:15 +04:00
waitForViewer ( assessNavigatorOperationAndTakeNextStep ( nextStep ) ) ;
}
} ;
2013-03-31 05:53:22 +04:00
} ;
2013-06-12 23:06:17 +04:00
var assessAfterSnapback = function ( ) {
assessDisplayRegion ( "After snapback" ) ;
2013-04-02 22:09:49 +04:00
navigatorOperationScenarios [ 0 ] . interactionOperation ( ) ;
2013-04-02 21:49:15 +04:00
waitForViewer ( assessNavigatorOperationAndTakeNextStep ( 0 ) ) ;
2013-03-21 21:55:36 +04:00
} ;
2013-06-12 23:06:17 +04:00
var assessAfterDragOnViewer = function ( ) {
assessDisplayRegion ( "After pan" ) ;
viewer . viewport . applyConstraints ( ) ;
waitForViewer ( assessAfterSnapback ) ;
} ;
2013-03-31 05:53:22 +04:00
var assessAfterZoomOnViewer = function ( ) {
2013-03-24 05:06:38 +04:00
var target = new OpenSeadragon . Point ( 0.4 , 0.4 ) ;
2013-04-03 19:51:24 +04:00
assessDisplayRegion ( "After image zoom" ) ;
2013-03-24 05:06:38 +04:00
viewer . viewport . panTo ( target ) ;
2013-03-31 07:27:33 +04:00
waitForViewer ( assessAfterDragOnViewer ) ;
2013-03-21 21:55:36 +04:00
} ;
2014-01-21 20:44:04 +04:00
var assessAfterResizeNavigator = function ( ) {
2014-01-19 06:19:22 +04:00
viewer . viewport . zoomTo ( viewer . viewport . getZoom ( ) * 2 ) ;
waitForViewer ( assessAfterZoomOnViewer ) ;
} ;
2014-01-21 20:44:04 +04:00
var assessNavigatorResizeAndTakeNextStep = function ( step ) {
return function ( ) {
var nextStep = step + 1 ;
assessNavigatorSize ( navigatorOriginalSize . x * navigatorResizeScenarios [ step ] . resizeFactorX , navigatorOriginalSize . y * navigatorResizeScenarios [ step ] . resizeFactorY , navigatorResizeScenarios [ step ] . assessmentMessage ) ;
assessDisplayRegion ( navigatorResizeScenarios [ step ] . assessmentMessage ) ;
if ( step === viewerResizeScenarios . length - 1 ) {
assessAfterResizeNavigator ( ) ;
}
else {
resizeElement ( navigatorElement , navigatorOriginalSize . x * navigatorResizeScenarios [ nextStep ] . resizeFactorX , navigatorOriginalSize . y * navigatorResizeScenarios [ nextStep ] . resizeFactorY ) ;
waitForViewer ( assessNavigatorResizeAndTakeNextStep ( nextStep ) ) ;
}
} ;
} ;
2014-01-19 06:19:22 +04:00
var assessViewerResizeAndTakeNextStep = function ( step ) {
return function ( ) {
var nextStep = step + 1 ;
if ( seadragonProperties . navigatorId ) {
// Navigator hosted in outside element...size shouldn't change
assessNavigatorSize ( navigatorOriginalSize . x , navigatorOriginalSize . y , viewerResizeScenarios [ step ] . assessmentMessage ) ;
}
else {
// Navigator hosted in viewer
if ( seadragonProperties . navigatorPosition && seadragonProperties . navigatorPosition == 'ABSOLUTE' ) {
// Navigator positioned 'ABSOLUTE'...size shouldn't change
assessNavigatorSize ( navigatorOriginalSize . x , navigatorOriginalSize . y , viewerResizeScenarios [ step ] . assessmentMessage ) ;
}
else {
// Navigator positioned 'TOP_LEFT', 'TOP_RIGHT', 'BOTTOM_LEFT', or 'BOTTOM_RIGHT'
if ( seadragonProperties . navigatorMaintainSizeRatio ) {
// Navigator should maintain aspect ratio and size proportioned to viewer size
assessNavigatorAspectRatio ( viewerElement . width ( ) / viewerElement . height ( ) , 0.0001 , viewerResizeScenarios [ step ] . assessmentMessage ) ;
assessNavigatorSize ( viewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , viewerElement . height ( ) * seadragonProperties . navigatorSizeRatio , viewerResizeScenarios [ step ] . assessmentMessage ) ;
}
else {
// Navigator should maintain aspect ratio and area
// Variances are loosened up here, since 1 pixel rounding difference in resizing to maintain area
// can cause a relatively large difference in area and aspect ratio.
assessNavigatorAspectRatio ( viewerElement . width ( ) / viewerElement . height ( ) , 0.1 , viewerResizeScenarios [ step ] . assessmentMessage ) ;
assessNavigatorArea ( navigatorOriginalSize . x * navigatorOriginalSize . y , viewerResizeScenarios [ step ] . assessmentMessage ) ;
}
}
}
if ( step === viewerResizeScenarios . length - 1 ) {
2014-01-21 20:44:04 +04:00
if ( seadragonProperties . navigatorId ) {
// Navigator hosted in outside element...run navigator resize tests
resizeElement ( navigatorElement , navigatorOriginalSize . x * navigatorResizeScenarios [ 0 ] . resizeFactorX , navigatorOriginalSize . y * navigatorResizeScenarios [ 0 ] . resizeFactorY ) ;
waitForViewer ( assessNavigatorResizeAndTakeNextStep ( 0 ) ) ;
}
else {
// Navigator hosted in viewer...skip navigator resize tests
assessAfterResizeNavigator ( ) ;
}
2014-01-19 06:19:22 +04:00
}
else {
resizeElement ( viewerElement , viewerOriginalSize . x * viewerResizeScenarios [ nextStep ] . resizeFactorX , viewerOriginalSize . y * viewerResizeScenarios [ nextStep ] . resizeFactorY ) ;
waitForViewer ( assessViewerResizeAndTakeNextStep ( nextStep ) ) ;
}
} ;
} ;
2013-04-03 19:51:24 +04:00
var captureInitialStateThenAct = function ( ) {
assessDisplayRegion ( "After image load" ) ;
2013-03-21 21:55:36 +04:00
2013-03-24 05:06:38 +04:00
testProperties . determineExpectationsAndAssessNavigatorLocation ( seadragonProperties , testProperties ) ;
2013-03-21 21:55:36 +04:00
2014-01-19 06:19:22 +04:00
viewerOriginalSize = new OpenSeadragon . Point ( viewerElement . width ( ) , viewerElement . height ( ) ) ;
navigatorOriginalSize = new OpenSeadragon . Point ( navigatorElement . width ( ) , navigatorElement . height ( ) ) ;
resizeElement ( viewerElement , viewerOriginalSize . x * viewerResizeScenarios [ 0 ] . resizeFactorX , viewerOriginalSize . y * viewerResizeScenarios [ 0 ] . resizeFactorY ) ;
waitForViewer ( assessViewerResizeAndTakeNextStep ( 0 ) ) ;
2013-03-21 21:55:36 +04:00
} ;
2013-06-07 18:25:26 +04:00
var assessAutoFadeTriggered = function ( ) {
2014-01-19 06:19:22 +04:00
ok ( navigatorElement . parent ( ) . css ( "opacity" ) < 1 , "Expecting navigator to be autofade when in the default location" ) ;
2013-04-03 19:51:24 +04:00
waitForViewer ( captureInitialStateThenAct ) ;
2013-03-21 21:55:36 +04:00
} ;
2013-06-07 18:25:26 +04:00
var assessAutoFadeDisabled = function ( ) {
2014-01-19 06:19:22 +04:00
ok ( navigatorElement . parent ( ) . css ( "opacity" ) > 0 , "Expecting navigator to be always visible when in a custom location" ) ;
2013-04-03 19:51:24 +04:00
waitForViewer ( captureInitialStateThenAct ) ;
2013-04-03 00:40:52 +04:00
} ;
2013-03-21 21:55:36 +04:00
2013-04-03 00:40:52 +04:00
var openHandler = function ( ) {
viewer . removeHandler ( 'open' , openHandler ) ;
2014-01-19 06:19:22 +04:00
navigatorElement = $ ( testProperties . navigatorLocator ) ;
viewerElement = $ ( "#" + seadragonProperties . id ) ;
//TODO This should be testProperties.testAutoFade, but test hangs. Fix this!
2013-04-03 05:07:10 +04:00
if ( ! testProperties . testAutohide ) {
2013-04-03 19:51:24 +04:00
waitForViewer ( captureInitialStateThenAct ) ;
2013-04-03 00:40:52 +04:00
}
2013-04-03 05:07:10 +04:00
else {
2014-01-19 06:19:22 +04:00
ok ( navigatorElement . parent ( ) . css ( "opacity" ) > 0 , "Expecting navigator to be visible initially" ) ;
2013-04-03 00:40:52 +04:00
var event = {
clientX : 1 ,
clientY : 1
} ;
2013-07-02 02:17:45 +04:00
2014-01-21 20:44:04 +04:00
viewerElement . simulate ( 'blur' , event ) ;
2013-07-02 02:17:45 +04:00
2013-06-07 18:25:26 +04:00
if ( testProperties . expectedAutoFade ) {
setTimeout ( assessAutoFadeTriggered , autoFadeWaitTime ) ;
2013-07-02 02:17:45 +04:00
} else {
2013-06-07 18:25:26 +04:00
setTimeout ( assessAutoFadeDisabled , autoFadeWaitTime ) ;
2013-03-24 05:06:38 +04:00
}
2013-04-03 00:40:52 +04:00
}
} ;
viewer . addHandler ( 'open' , openHandler ) ;
} ;
2013-03-21 21:55:36 +04:00
2013-03-24 05:06:38 +04:00
asyncTest ( 'DefaultNavigatorLocationWithWideImageTallViewer' , function ( ) {
assessNavigatorViewerPlacement ( {
id : 'tallexample' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/wide.dzi' ,
2013-06-02 00:08:23 +04:00
showNavigator : true ,
2014-01-17 00:11:35 +04:00
navigatorSizeRatio : 0.2 ,
2014-01-19 06:19:22 +04:00
navigatorMaintainSizeRatio : false ,
2013-06-07 18:25:26 +04:00
animationTime : 0
2013-03-24 05:06:38 +04:00
} ,
{
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
2013-06-07 18:25:26 +04:00
testAutoFade : false ,
2013-03-24 05:06:38 +04:00
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
2013-04-03 05:07:10 +04:00
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorElement = $ ( testProperties . navigatorLocator ) ;
2013-03-24 05:06:38 +04:00
assessNavigatorLocation ( mainViewerElement . offset ( ) . left + mainViewerElement . width ( ) - navigatorElement . width ( ) ,
mainViewerElement . offset ( ) . top ) ;
2014-01-17 00:11:35 +04:00
assessNavigatorSize ( mainViewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , mainViewerElement . height ( ) * seadragonProperties . navigatorSizeRatio ) ;
2014-01-19 06:19:22 +04:00
assessNavigatorAspectRatio ( mainViewerElement . width ( ) / mainViewerElement . height ( ) , 0.0001 ) ;
2013-03-24 05:06:38 +04:00
}
} ) ;
} ) ;
2013-03-21 21:55:36 +04:00
2014-01-17 00:11:35 +04:00
asyncTest ( 'DefaultNavigatorLocationWithTallImageWideViewer' , function ( ) {
2013-03-24 05:06:38 +04:00
assessNavigatorViewerPlacement ( {
id : 'wideexample' ,
prefixUrl : '/build/openseadragon/images/' ,
2014-01-17 00:11:35 +04:00
tileSources : '/test/data/tall.dzi' ,
2013-06-02 00:08:23 +04:00
showNavigator : true ,
2014-01-17 00:11:35 +04:00
navigatorSizeRatio : 0.2 ,
2014-01-19 06:19:22 +04:00
navigatorMaintainSizeRatio : false ,
2014-01-17 00:11:35 +04:00
animationTime : 0 ,
controlsFadeDelay : 0 ,
controlsFadeLength : 1
2013-03-24 05:06:38 +04:00
} ,
{
2014-01-17 00:11:35 +04:00
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
testAutoFade : true ,
expectedAutoFade : true ,
2013-03-24 05:06:38 +04:00
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
2013-04-03 05:07:10 +04:00
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
2014-01-17 00:11:35 +04:00
navigatorElement = $ ( testProperties . navigatorLocator ) ;
assessNavigatorLocation ( mainViewerElement . offset ( ) . left + mainViewerElement . width ( ) - navigatorElement . width ( ) ,
mainViewerElement . offset ( ) . top ) ;
assessNavigatorSize ( mainViewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , mainViewerElement . height ( ) * seadragonProperties . navigatorSizeRatio ) ;
2014-01-19 06:19:22 +04:00
assessNavigatorAspectRatio ( mainViewerElement . width ( ) / mainViewerElement . height ( ) , 0.0001 ) ;
2013-03-24 05:06:38 +04:00
}
} ) ;
} ) ;
2013-03-21 21:55:36 +04:00
2014-01-17 00:11:35 +04:00
asyncTest ( 'TopLeftNavigatorLocation' , function ( ) {
2013-03-24 05:06:38 +04:00
assessNavigatorViewerPlacement ( {
2014-01-17 00:11:35 +04:00
id : 'example' ,
2013-03-24 05:06:38 +04:00
prefixUrl : '/build/openseadragon/images/' ,
2014-01-17 00:11:35 +04:00
tileSources : '/test/data/testpattern.dzi' ,
showNavigationControl : false ,
2013-06-02 00:08:23 +04:00
showNavigator : true ,
2014-01-17 00:11:35 +04:00
navigatorSizeRatio : 0.2 ,
2014-01-19 06:19:22 +04:00
navigatorMaintainSizeRatio : false ,
2014-01-17 00:11:35 +04:00
navigatorPosition : 'TOP_LEFT' ,
2013-06-02 00:08:23 +04:00
animationTime : 0 ,
2013-06-07 18:25:26 +04:00
controlsFadeDelay : 0 ,
controlsFadeLength : 1
2013-03-24 05:06:38 +04:00
} ,
{
2014-01-17 00:11:35 +04:00
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
2013-06-07 18:25:26 +04:00
testAutoFade : true ,
2014-01-17 00:11:35 +04:00
expectedAutoFade : true ,
2013-03-24 05:06:38 +04:00
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
2014-01-17 00:11:35 +04:00
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorElement = $ ( testProperties . navigatorLocator ) ;
assessNavigatorLocation ( mainViewerElement . offset ( ) . left ,
mainViewerElement . offset ( ) . top ) ;
assessNavigatorSize ( mainViewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , mainViewerElement . height ( ) * seadragonProperties . navigatorSizeRatio ) ;
2014-01-19 06:19:22 +04:00
assessNavigatorAspectRatio ( mainViewerElement . width ( ) / mainViewerElement . height ( ) , 0.0001 ) ;
2013-03-24 05:06:38 +04:00
}
} ) ;
} ) ;
2013-03-21 21:55:36 +04:00
2014-01-17 00:11:35 +04:00
asyncTest ( 'TopRightNavigatorLocation' , function ( ) {
2013-03-24 05:06:38 +04:00
assessNavigatorViewerPlacement ( {
2014-01-17 00:11:35 +04:00
id : 'example' ,
2013-03-24 05:06:38 +04:00
prefixUrl : '/build/openseadragon/images/' ,
2014-01-17 00:11:35 +04:00
tileSources : '/test/data/testpattern.dzi' ,
showNavigationControl : false ,
2013-06-02 00:08:23 +04:00
showNavigator : true ,
2014-01-17 00:11:35 +04:00
navigatorSizeRatio : 0.2 ,
2014-01-19 06:19:22 +04:00
navigatorMaintainSizeRatio : true ,
2014-01-17 00:11:35 +04:00
navigatorPosition : 'TOP_RIGHT' ,
2013-06-02 00:08:23 +04:00
animationTime : 0 ,
2013-06-07 18:25:26 +04:00
controlsFadeDelay : 0 ,
controlsFadeLength : 1
2013-03-24 05:06:38 +04:00
} ,
{
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
2013-06-07 18:25:26 +04:00
testAutoFade : true ,
expectedAutoFade : true ,
2013-03-24 05:06:38 +04:00
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
2013-04-03 05:07:10 +04:00
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorElement = $ ( testProperties . navigatorLocator ) ;
2013-03-24 05:06:38 +04:00
assessNavigatorLocation ( mainViewerElement . offset ( ) . left + mainViewerElement . width ( ) - navigatorElement . width ( ) ,
mainViewerElement . offset ( ) . top ) ;
2014-01-17 00:11:35 +04:00
assessNavigatorSize ( mainViewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , mainViewerElement . height ( ) * seadragonProperties . navigatorSizeRatio ) ;
2014-01-19 06:19:22 +04:00
assessNavigatorAspectRatio ( mainViewerElement . width ( ) / mainViewerElement . height ( ) , 0.0001 ) ;
2014-01-17 00:11:35 +04:00
}
} ) ;
} ) ;
asyncTest ( 'BottomLeftNavigatorLocation' , function ( ) {
assessNavigatorViewerPlacement ( {
id : 'example' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/testpattern.dzi' ,
showNavigationControl : false ,
showNavigator : true ,
navigatorSizeRatio : 0.2 ,
2014-01-19 06:19:22 +04:00
navigatorMaintainSizeRatio : false ,
2014-01-17 00:11:35 +04:00
navigatorPosition : 'BOTTOM_LEFT' ,
animationTime : 0 ,
controlsFadeDelay : 0 ,
controlsFadeLength : 1
} ,
{
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
testAutoFade : true ,
expectedAutoFade : true ,
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorElement = $ ( testProperties . navigatorLocator ) ;
assessNavigatorLocation ( mainViewerElement . offset ( ) . left ,
mainViewerElement . offset ( ) . top + mainViewerElement . height ( ) - navigatorElement . height ( ) ) ;
assessNavigatorSize ( mainViewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , mainViewerElement . height ( ) * seadragonProperties . navigatorSizeRatio ) ;
2014-01-19 06:19:22 +04:00
assessNavigatorAspectRatio ( mainViewerElement . width ( ) / mainViewerElement . height ( ) , 0.0001 ) ;
2014-01-17 00:11:35 +04:00
}
} ) ;
} ) ;
asyncTest ( 'BottomRightNavigatorLocation' , function ( ) {
assessNavigatorViewerPlacement ( {
id : 'example' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/testpattern.dzi' ,
showNavigationControl : false ,
showNavigator : true ,
navigatorSizeRatio : 0.2 ,
2014-01-19 06:19:22 +04:00
navigatorMaintainSizeRatio : false ,
2014-01-17 00:11:35 +04:00
navigatorPosition : 'BOTTOM_RIGHT' ,
animationTime : 0 ,
controlsFadeDelay : 0 ,
controlsFadeLength : 1
} ,
{
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
testAutoFade : true ,
expectedAutoFade : true ,
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorElement = $ ( testProperties . navigatorLocator ) ;
assessNavigatorLocation ( mainViewerElement . offset ( ) . left + mainViewerElement . width ( ) - navigatorElement . width ( ) ,
mainViewerElement . offset ( ) . top + mainViewerElement . height ( ) - navigatorElement . height ( ) ) ;
assessNavigatorSize ( mainViewerElement . width ( ) * seadragonProperties . navigatorSizeRatio , mainViewerElement . height ( ) * seadragonProperties . navigatorSizeRatio ) ;
2014-01-19 06:19:22 +04:00
assessNavigatorAspectRatio ( mainViewerElement . width ( ) / mainViewerElement . height ( ) , 0.0001 ) ;
2014-01-17 00:11:35 +04:00
}
} ) ;
} ) ;
asyncTest ( 'AbsoluteNavigatorLocation' , function ( ) {
assessNavigatorViewerPlacement ( {
id : 'example' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/testpattern.dzi' ,
showNavigationControl : false ,
showNavigator : true ,
navigatorPosition : 'ABSOLUTE' ,
navigatorTop : 10 ,
navigatorLeft : 10 ,
navigatorHeight : 150 ,
navigatorWidth : 175 ,
animationTime : 0 ,
controlsFadeDelay : 0 ,
controlsFadeLength : 1
} ,
{
displayRegionLocator : '.navigator .displayregion' ,
navigatorLocator : '.navigator' ,
testAutoFade : true ,
expectedAutoFade : true ,
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorElement = $ ( testProperties . navigatorLocator ) ;
assessNavigatorLocation ( mainViewerElement . offset ( ) . left + seadragonProperties . navigatorLeft ,
mainViewerElement . offset ( ) . top + seadragonProperties . navigatorTop ) ;
assessNavigatorSize ( seadragonProperties . navigatorWidth , seadragonProperties . navigatorHeight ) ;
}
} ) ;
} ) ;
asyncTest ( 'CustomNavigatorElementWithWideImageWideViewer' , function ( ) {
assessNavigatorViewerPlacement ( {
id : 'wideexample' ,
navigatorId : 'exampleNavigator' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/wide.dzi' ,
showNavigator : true ,
animationTime : 0
} ,
{
displayRegionLocator : '#exampleNavigator .displayregion' ,
navigatorLocator : '#exampleNavigator' ,
testAutoFade : false ,
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
var mainViewerElement = $ ( "#" + seadragonProperties . id ) ,
navigatorViewerElement = $ ( "#" + seadragonProperties . navigatorId ) ;
assessNavigatorLocation ( mainViewerElement . offset ( ) . left ,
mainViewerElement . offset ( ) . top - navigatorViewerElement . parent ( ) . height ( ) ) ;
}
} ) ;
} ) ;
asyncTest ( 'CustomDialogNavigatorElementWithTallImageTallViewer' , function ( ) {
2014-01-19 06:19:22 +04:00
$ ( '#exampleNavigator' ) . dialog ( { width : 150 ,
height : 100 ,
2014-01-17 00:11:35 +04:00
open : function ( event , ui ) {
2014-01-19 06:19:22 +04:00
$ ( '#exampleNavigator' ) . width ( 150 ) ;
$ ( '#exampleNavigator' ) . height ( 100 ) ;
2014-01-17 00:11:35 +04:00
}
2014-01-19 06:19:22 +04:00
//TODO Use this in testing resizable navigator
//resize: function (event, ui) {
// //ui.size.width
// //ui.size.height
// //$('#exampleNavigator').dialog("option", "width", 200);
// //$('#exampleNavigator').dialog("option", "width", 200);
//}
2014-01-17 00:11:35 +04:00
} ) ;
assessNavigatorViewerPlacement ( {
id : 'tallexample' ,
navigatorId : 'exampleNavigator' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/tall.dzi' ,
showNavigator : true ,
animationTime : 0 ,
controlsFadeDelay : 0 ,
controlsFadeLength : 1
} ,
{
displayRegionLocator : '#exampleNavigator .displayregion' ,
navigatorLocator : '#exampleNavigator' ,
testAutoFade : true ,
expectedAutoFade : false ,
//On Firefox at some screen size/resolution/magnification combinations, there is an issue with the
//simulated click. This property is a work around for that problem
topNavigatorClickAdjustment : 15 ,
determineExpectationsAndAssessNavigatorLocation : function ( seadragonProperties , testProperties ) {
var jqueryDialog = $ ( testProperties . navigatorLocator ) ;
assessNavigatorLocation ( jqueryDialog . offset ( ) . left ,
jqueryDialog . offset ( ) . top ) ;
assessNavigatorSize ( jqueryDialog . width ( ) , jqueryDialog . height ( ) ) ;
2013-03-24 05:06:38 +04:00
}
} ) ;
2013-03-21 21:55:36 +04:00
} ) ;
2013-06-18 22:09:05 +04:00
asyncTest ( 'Viewer closing one image and opening another' , function ( ) {
var timeWatcher = Util . timeWatcher ( ) ;
viewer = OpenSeadragon ( {
id : 'example' ,
prefixUrl : '/build/openseadragon/images/' ,
tileSources : '/test/data/testpattern.dzi' ,
springStiffness : 100 , // Faster animation = faster tests
showNavigator : true
} ) ;
2013-10-11 04:00:15 +04:00
var openHandler1 = function ( event ) {
2013-06-18 22:09:05 +04:00
viewer . removeHandler ( 'open' , openHandler1 ) ;
ok ( viewer . navigator , 'navigator exists' ) ;
viewer . navigator . addHandler ( 'open' , navOpenHandler1 ) ;
} ;
2013-10-11 04:00:15 +04:00
var navOpenHandler1 = function ( event ) {
2013-06-18 22:09:05 +04:00
viewer . navigator . removeHandler ( 'open' , navOpenHandler1 ) ;
equal ( viewer . navigator . source , viewer . source , 'viewer and navigator have the same source' ) ;
ok ( viewer . navigator . _updateRequestId , 'navigator timer is on' ) ;
viewer . addHandler ( 'close' , closeHandler1 ) ;
viewer . addHandler ( 'open' , openHandler2 ) ;
viewer . open ( '/test/data/tall.dzi' ) ;
} ;
2013-10-11 04:00:15 +04:00
var closeHandler1 = function ( event ) {
2013-06-18 22:09:05 +04:00
viewer . removeHandler ( 'close' , closeHandler1 ) ;
ok ( true , 'calling open closes the old one' ) ;
equal ( viewer . navigator . source , null , 'navigator source has been cleared' ) ;
} ;
2013-10-11 04:00:15 +04:00
var openHandler2 = function ( event ) {
2013-06-18 22:09:05 +04:00
viewer . removeHandler ( 'open' , openHandler2 ) ;
viewer . navigator . addHandler ( 'open' , navOpenHandler2 ) ;
} ;
2013-10-11 04:00:15 +04:00
var navOpenHandler2 = function ( event ) {
2013-06-18 22:09:05 +04:00
viewer . navigator . removeHandler ( 'open' , navOpenHandler2 ) ;
equal ( viewer . navigator . source , viewer . source , 'viewer and navigator have the same source' ) ;
viewer . addHandler ( 'close' , closeHandler2 ) ;
viewer . close ( ) ;
} ;
2013-10-11 04:00:15 +04:00
var closeHandler2 = function ( event ) {
2013-06-18 22:09:05 +04:00
viewer . removeHandler ( 'close' , closeHandler2 ) ;
ok ( ! viewer . navigator . _updateRequestId , 'navigator timer is off' ) ;
setTimeout ( function ( ) {
ok ( ! viewer . navigator . _updateRequestId , 'navigator timer is still off' ) ;
timeWatcher . done ( ) ;
} , 100 ) ;
} ;
viewer . addHandler ( 'open' , openHandler1 ) ;
} ) ;
2013-03-21 21:55:36 +04:00
} ) ( ) ;