Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
This change sets the "lastScroll" property to each urlHistory item ob…
Browse files Browse the repository at this point in the history
…ject, allowing us to remember previous scroll distances when returning to a page that has since been removed from the DOM. Before this change, this number was stored in data on the page element, so it is lost when the page is removed after pagehide.

Also, this change removes a reference in memory that we were keeping to the $activeClickedLink on each page. We stored this in attempt to refocus a link after returning to a page. Unfortunately, it doesn't seem that this data can be retained after pages are removed from the DOM, outside of somehow remembering a unique selector string to reach that element again (which could be achieved by adding some overhead, ala http://stackoverflow.com/questions/2068272/getting-a-jquery-selector-for-an-element )
  • Loading branch information
scottjehl committed Sep 6, 2011
1 parent df8d6fa commit ac67e92
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions js/jquery.mobile.navigation.js
Expand Up @@ -390,27 +390,19 @@
function transitionPages( toPage, fromPage, transition, reverse ) {

//get current scroll distance
var currScroll = $.support.scrollTop ? $window.scrollTop() : true,
toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll,
var active = $.mobile.urlHistory.getActive(),
toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
screenHeight = getScreenHeight();

//if scrolled down, scroll to top
if( currScroll ){
window.scrollTo( 0, $.mobile.defaultHomeScroll );
}
// Scroll to top
window.scrollTo( 0, $.mobile.defaultHomeScroll );

//if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
if( toScroll < $.mobile.minScrollBack ){
toScroll = 0;
}

if( fromPage ) {
//set as data for returning to that spot
fromPage
.height( screenHeight + currScroll )
.jqmData( "lastScroll", currScroll )
.jqmData( "lastClicked", $activeClickedLink );

//trigger before show/hide events
fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
}
Expand All @@ -430,15 +422,12 @@
promise.done(function() {
//reset toPage height bac
toPage.height( "" );

//jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
if( toScroll ){
$.mobile.silentScroll( toScroll );
$( document ).one( "silentscroll", function() { reFocus( toPage ); } );
}
else{
reFocus( toPage );
}

// Send focus to the newly shown page
reFocus( toPage );

// Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
$.mobile.silentScroll( toScroll );

//trigger show/hide events
if( fromPage ) {
Expand Down Expand Up @@ -904,6 +893,11 @@
isForward: function() { historyDir = 1; }
});
}

// Set active item's lastScroll prop
if( active ){
active.lastScroll = $( window ).scrollTop();
}

// Kill the keyboard.
// XXX_jblas: We need to stop crawling the entire document to kill focus. Instead,
Expand Down

0 comments on commit ac67e92

Please sign in to comment.