Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This change sets the "lastScroll" property to each urlHistory item ob…

…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...
commit ac67e92cbbd510c31c2e1369a881f132b13bdf56 1 parent df8d6fa
scottjehl authored
Showing with 15 additions and 21 deletions.
  1. +15 −21 js/jquery.mobile.navigation.js
View
36 js/jquery.mobile.navigation.js
@@ -390,14 +390,12 @@
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 ){
@@ -405,12 +403,6 @@
}
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 } );
}
@@ -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 ) {
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.