finished last-scroll remembering implementation across pages in the history stack (regardless of whether they've been removed from the DOM since last appearance).

This commit is contained in:
scottjehl 2011-09-07 08:15:00 -04:00
parent 0d98b8fad6
commit d68d5064bc

View file

@ -379,21 +379,32 @@
}
}
// Save last scroll distance
$( document ).bind( "beforechangepage", function(){
var active = $.mobile.urlHistory.getActive();
if( active ){
var lastScroll = $( window ).scrollTop();
//if the Y location we're scrolling to is less than minScrollBack, let it go for sake of smoothness
if( lastScroll < $.mobile.minScrollBack ){
lastScroll = $.mobile.defaultHomeScroll;
// Save the last scroll distance per page, before it is hidden
var getLastScroll = (function( lastScrollEnabled ){
return function(){
if( !lastScrollEnabled ){
lastScrollEnabled = true;
return;
}
active.lastScroll = lastScroll;
}
});
lastScrollEnabled = false;
var active = $.mobile.urlHistory.getActive();
if( active ){
var lastScroll = $( window ).scrollTop();
// Set active page's lastScroll prop.
// If the Y location we're scrolling to is less than minScrollBack, let it go.
active.lastScroll = lastScroll < $.mobile.minScrollBack ? $.mobile.defaultHomeScroll : lastScroll;
}
};
})( true );
// to get last scroll, we need to get scrolltop before the page change
// using beforechangepage or popstate/hashchange (whichever comes first)
$( document ).bind( "beforechangepage", getLastScroll );
$( window ).bind( $.support.pushState ? "popstate" : "hashchange", getLastScroll );
//function for transitioning between two existing pages
function transitionPages( toPage, fromPage, transition, reverse ) {