Skip to content
This repository
Browse code

Call init when both mobileinit and domready have happened instead of …

…just domready.

Fixes #4136
  • Loading branch information...
commit 8b938e2e357c696b09ed7b4690e185e7951c1d25 1 parent 8f4f809
Ghislain Seguin authored May 16, 2012

Showing 1 changed file with 13 additions and 2 deletions. Show diff stats Hide diff stats

  1. 15  js/jquery.mobile.navigation.pushstate.js
15  js/jquery.mobile.navigation.pushstate.js
@@ -12,7 +12,17 @@ define( [ "jquery", "./jquery.mobile.navigation", "../external/requirejs/depend!
12 12
 	var	pushStateHandler = {},
13 13
 		self = pushStateHandler,
14 14
 		$win = $( window ),
15  
-		url = $.mobile.path.parseUrl( location.href );
  15
+		url = $.mobile.path.parseUrl( location.href ),
  16
+		mobileinitDeferred = $.Deferred(),
  17
+		domreadyDeferred = $.Deferred();
  18
+
  19
+	$( document ).ready( function() {
  20
+		domreadyDeferred.resolve();
  21
+	});
  22
+
  23
+	$( document ).one( "mobileinit", function() {
  24
+		mobileinitDeferred.resolve();
  25
+	});
16 26
 
17 27
 	$.extend( pushStateHandler, {
18 28
 		// TODO move to a path helper, this is rather common functionality
@@ -138,7 +148,8 @@ define( [ "jquery", "./jquery.mobile.navigation", "../external/requirejs/depend!
138 148
 		}
139 149
 	});
140 150
 
141  
-	$( function() {
  151
+	// We need to init when both "mobileinit" and "domready" have happened
  152
+	$.when( domreadyDeferred, mobileinitDeferred ).done( function() {
142 153
 		if( $.mobile.pushStateEnabled && $.support.pushState ){
143 154
 			pushStateHandler.init();
144 155
 		}

3 notes on commit 8b938e2

John Bender

This commit makes me happy. It's super nice.

Sven Franck

@johnbender: this saved half my day working with requireJS. I'm still stuck with controlgroups not being initialized on the first page though. I guess this is because the controlgroup widget is triggered from initializePage(), is it?. Any idea for a workaround?

Sven Franck

@johnbender: never mind - ctrl.controlgroup({ excludeInvisible: false })

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