Skip to content
This repository
Browse code

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
authored August 07, 2011

Showing 1 changed file with 15 additions and 21 deletions. Show diff stats Hide diff stats

  1. 36  js/jquery.mobile.navigation.js
36  js/jquery.mobile.navigation.js
@@ -390,14 +390,12 @@
390 390
 	function transitionPages( toPage, fromPage, transition, reverse ) {
391 391
 
392 392
 		//get current scroll distance
393  
-		var currScroll = $.support.scrollTop ? $window.scrollTop() : true,
394  
-			toScroll	= toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll,
  393
+		var active	= $.mobile.urlHistory.getActive(),
  394
+			toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
395 395
 			screenHeight = getScreenHeight();
396 396
 
397  
-		//if scrolled down, scroll to top
398  
-		if( currScroll ){
399  
-			window.scrollTo( 0, $.mobile.defaultHomeScroll );
400  
-		}
  397
+		// Scroll to top
  398
+		window.scrollTo( 0, $.mobile.defaultHomeScroll );
401 399
 
402 400
 		//if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
403 401
 		if( toScroll < $.mobile.minScrollBack ){
@@ -405,12 +403,6 @@
405 403
 		}
406 404
 
407 405
 		if( fromPage ) {
408  
-			//set as data for returning to that spot
409  
-			fromPage
410  
-				.height( screenHeight + currScroll )
411  
-				.jqmData( "lastScroll", currScroll )
412  
-				.jqmData( "lastClicked", $activeClickedLink );
413  
-
414 406
 			//trigger before show/hide events
415 407
 			fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
416 408
 		}
@@ -430,15 +422,12 @@
430 422
 		promise.done(function() {
431 423
 			//reset toPage height bac
432 424
 			toPage.height( "" );
433  
-
434  
-			//jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
435  
-			if( toScroll ){
436  
-				$.mobile.silentScroll( toScroll );
437  
-				$( document ).one( "silentscroll", function() { reFocus( toPage ); } );
438  
-			}
439  
-			else{
440  
-				reFocus( toPage );
441  
-			}
  425
+			
  426
+			// Send focus to the newly shown page
  427
+			reFocus( toPage );
  428
+			
  429
+			// Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
  430
+			$.mobile.silentScroll( toScroll );
442 431
 
443 432
 			//trigger show/hide events
444 433
 			if( fromPage ) {
@@ -904,6 +893,11 @@
904 893
 				isForward:	function() { historyDir = 1; }
905 894
 			});
906 895
 		}
  896
+		
  897
+		// Set active item's lastScroll prop
  898
+		if( active ){
  899
+			active.lastScroll = $( window ).scrollTop();
  900
+		}
907 901
 
908 902
 		// Kill the keyboard.
909 903
 		// XXX_jblas: We need to stop crawling the entire document to kill focus. Instead,

0 notes on commit ac67e92

Please sign in to comment.
Something went wrong with that request. Please try again.