Add counter to avoid trying to set scroll indefinitly

Style and spelling fixes
Set scrolls tests setup inside own function
This commit is contained in:
Antoine Vandecreme 2013-11-08 13:56:13 -05:00
parent fafc985ada
commit 6aca0c0886
2 changed files with 23 additions and 22 deletions

View File

@ -759,7 +759,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
THIS[ this.hash ].prevElementParent.insertBefore( THIS[ this.hash ].prevElementParent.insertBefore(
this.element, this.element,
THIS[ this.hash ].prevNextSibling THIS[ this.hash ].prevNextSibling
); );
//If we've got a toolbar, we need to enable the user to use css to //If we've got a toolbar, we need to enable the user to use css to
//reset it to its original state //reset it to its original state
@ -773,7 +773,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this.toolbar.parentNode.insertBefore( this.toolbar.parentNode.insertBefore(
this.toolbar.element, this.toolbar.element,
this.toolbar.nextSibling this.toolbar.nextSibling
); );
delete this.toolbar.parentNode; delete this.toolbar.parentNode;
delete this.toolbar.nextSibling; delete this.toolbar.nextSibling;
} }
@ -783,10 +783,13 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
// After exiting fullPage or fullScreen, it can take some time // After exiting fullPage or fullScreen, it can take some time
// before the browser can actually set the scroll. // before the browser can actually set the scroll.
var restoreScrollCounter = 0;
var restoreScroll = function() { var restoreScroll = function() {
$.setPageScroll( _this.pageScroll ); $.setPageScroll( _this.pageScroll );
var pageScroll = $.getPageScroll(); var pageScroll = $.getPageScroll();
if ( pageScroll.x !== _this.pageScroll.x || restoreScrollCounter++;
if ( restoreScrollCounter < 10 &&
pageScroll.x !== _this.pageScroll.x ||
pageScroll.y !== _this.pageScroll.y ) { pageScroll.y !== _this.pageScroll.y ) {
$.requestAnimationFrame( restoreScroll ); $.requestAnimationFrame( restoreScroll );
} }
@ -975,7 +978,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
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, onFullScreen ), onFullScreenHandler = $.delegate( this, onFullScreen ),
onFocusHandler = $.delegate( this, onFocus ), onFocusHandler = $.delegate( this, onFocus ),
onBlurHandler = $.delegate( this, onBlur ), onBlurHandler = $.delegate( this, onBlur ),
navImages = this.navImages, navImages = this.navImages,
@ -1050,7 +1053,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
srcGroup: resolveUrl( this.prefixUrl, navImages.fullpage.GROUP ), srcGroup: resolveUrl( this.prefixUrl, navImages.fullpage.GROUP ),
srcHover: resolveUrl( this.prefixUrl, navImages.fullpage.HOVER ), srcHover: resolveUrl( this.prefixUrl, navImages.fullpage.HOVER ),
srcDown: resolveUrl( this.prefixUrl, navImages.fullpage.DOWN ), srcDown: resolveUrl( this.prefixUrl, navImages.fullpage.DOWN ),
onRelease: onFullPageHandler, onRelease: onFullScreenHandler,
onFocus: onFocusHandler, onFocus: onFocusHandler,
onBlur: onBlurHandler onBlur: onBlurHandler
})); }));
@ -1665,7 +1668,7 @@ function updateOnce( viewer ) {
//viewer.profiler.endUpdate(); //viewer.profiler.endUpdate();
} }
// This function resize the viewport and recenter the image // This function resizes the viewport and recenters the image
// as it was before resizing. // as it was before resizing.
// TODO: better adjust width and height. The new width and height // TODO: better adjust width and height. The new width and height
// should depend on the image dimensions and on the dimensions // should depend on the image dimensions and on the dimensions

View File

@ -2,30 +2,22 @@
( function() { ( function() {
var origWidth, origHeight;
module( 'Polyfills', { module( 'Polyfills', {
setup: function() { setup: function() {
origWidth = $( "body" ).width();
origHeight = $( "body" ).height();
$( "body" ).width( origWidth + 10000 );
$( "body" ).height( origHeight + 10000 );
$( document ).scrollLeft( 0 );
$( document ).scrollTop( 0 );
testLog.reset(); testLog.reset();
},
teardown: function() {
$( "body" ).width( origWidth );
$( "body" ).height( origHeight );
$( document ).scrollLeft( 0 );
$( document ).scrollTop( 0 );
} }
} ); } );
// ---------- // ----------
test( 'pageScroll', function() { test( 'pageScroll', function() {
// Setup
var origWidth = $( "body" ).width(),
origHeight = $( "body" ).height();
$( "body" ).width( origWidth + 10000 );
$( "body" ).height( origHeight + 10000 );
$( document ).scrollLeft( 0 );
$( document ).scrollTop( 0 );
// End setup
// Test get // Test get
var originalGetPageScroll = OpenSeadragon.getPageScroll; var originalGetPageScroll = OpenSeadragon.getPageScroll;
@ -125,6 +117,12 @@
equal( currentSetPageScroll, OpenSeadragon.setPageScroll, equal( currentSetPageScroll, OpenSeadragon.setPageScroll,
"OpenSeadragon.setPageScroll must not be reassigned after first call." ); "OpenSeadragon.setPageScroll must not be reassigned after first call." );
// Teardown
$( "body" ).width( origWidth );
$( "body" ).height( origHeight );
$( document ).scrollLeft( 0 );
$( document ).scrollTop( 0 );
} ); } );
} )(); } )();