Skip to content
This repository
Browse code

Added a configurable timeout to $.mobile.loadPage to give pages that …

…are being fetched from cache a little time to load before a loading message appears. We'll need to tweak this timer based on device testing to determine how long it takes on average to fetch a cached page. If the delay ends up needing to be longer than 300ms or so to suit some devices, it's probably not worth having this feature at all.
  • Loading branch information...
commit be74405b49342f247a9e867ea700e31a84ba5ee8 1 parent bdba60e
authored July 30, 2011

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

  1. 25  js/jquery.mobile.navigation.js
25  js/jquery.mobile.navigation.js
@@ -615,7 +615,21 @@
615 615
 		}
616 616
 
617 617
 		if ( settings.showLoadMsg ) {
618  
-			$.mobile.showPageLoadingMsg();
  618
+			
  619
+			// This configurable timeout allows cached pages a brief delay to load without showing a message
  620
+			var loadMsgDelay = setTimeout(function(){
  621
+					$.mobile.showPageLoadingMsg();
  622
+				}, settings.loadMsgDelay ),
  623
+				
  624
+				// Shared logic for clearing timeout and removing message.
  625
+				hideMsg = function(){
  626
+					
  627
+					// Stop message show timer
  628
+					clearTimeout( loadMsgDelay );
  629
+					
  630
+					// Hide loading message
  631
+					$.mobile.hidePageLoadingMsg();
  632
+				};
619 633
 		}
620 634
 
621 635
 		if ( !( $.mobile.allowCrossDomainPages || path.isSameDomain( documentUrl, absUrl ) ) ) {
@@ -717,7 +731,7 @@
717 731
 
718 732
 					// Remove loading message.
719 733
 					if ( settings.showLoadMsg ) {
720  
-						$.mobile.hidePageLoadingMsg();
  734
+						hideMsg();
721 735
 					}
722 736
 
723 737
 					deferred.resolve( absUrl, options, page, dupCachedPage );
@@ -730,7 +744,9 @@
730 744
 
731 745
 					// Remove loading message.
732 746
 					if ( settings.showLoadMsg ) {
733  
-						$.mobile.hidePageLoadingMsg();
  747
+						
  748
+						// Remove loading message.
  749
+						hideMsg();
734 750
 
735 751
 						//show error message
736 752
 						$( "<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>" )
@@ -756,7 +772,8 @@
756 772
 		reloadPage: false,
757 773
 		role: undefined, // By default we rely on the role defined by the @data-role attribute.
758 774
 		showLoadMsg: false,
759  
-		pageContainer: undefined
  775
+		pageContainer: undefined,
  776
+		loadMsgDelay: 50 // This delay allows loads that pull from browser cache to occur without showing the loading message.
760 777
 	};
761 778
 
762 779
 	// Show a specific page in the page container.

0 notes on commit be74405

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