diff --git a/js/jquery.mobile.core.js b/js/jquery.mobile.core.js index 26a8744f7cd..cb059a10760 100644 --- a/js/jquery.mobile.core.js +++ b/js/jquery.mobile.core.js @@ -56,9 +56,6 @@ return $.support.mediaquery; }, - //automatically initialize first pages or not. - autoInitialize: true, - //TODO might be useful upstream in jquery itself ? keyCode: { ALT: 18, @@ -144,7 +141,7 @@ var activeBtn =$( "." + $.mobile.activeBtnClass ).first(); $loader - .appendTo( $.mobile.pageContainer ) + .appendTo( 'body' ) //position at y center (if scrollTop supported), above the activeBtn (if defined), or just 100px from top .css( { top: $.support.scrollTop && $(window).scrollTop() + $(window).height() / 2 || @@ -174,40 +171,43 @@ // find and enhance the pages in the dom and transition to the first page. initializePage: function(){ - //find present pages - var $pages = $( "[data-role='page']" ); - - //add dialogs, set data-url attrs - $pages.add( "[data-role='dialog']" ).each(function(){ - $(this).attr( "data-url", $(this).attr( "id" )); - }); + // when dom-ready + $(function(){ + //find present pages + var $pages = $( "[data-role='page']" ); - //define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback) - $.mobile.firstPage = $pages.first(); + //add dialogs, set data-url attrs + $pages.add( "[data-role='dialog']" ).each(function(){ + $(this).attr( "data-url", $(this).attr( "id" )); + }); - //define page container - $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" ); + //define first page in dom case one backs out to the directory root (not always the first page visited, but defined as fallback) + $.mobile.firstPage = $pages.first(); - //cue page loading message - $.mobile.pageLoading(); + //define page container + $.mobile.pageContainer = $pages.first().parent().addClass( "ui-mobile-viewport" ); - // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM - if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){ - $.mobile.changePage( $.mobile.firstPage, false, true, false, true ); - } - // otherwise, trigger a hashchange to load a deeplink - else { - $window.trigger( "hashchange", [ true ] ); - } + // if hashchange listening is disabled or there's no hash deeplink, change to the first page in the DOM + if( !$.mobile.hashListeningEnabled || !$.mobile.path.stripHash( location.hash ) ){ + $.mobile.changePage( $.mobile.firstPage, false, true, false, true ); + } + // otherwise, trigger a hashchange to load a deeplink + else { + $window.trigger( "hashchange", [ true ] ); + } + }); } }); //dom-ready inits - if($.mobile.autoInitialize){ - $($.mobile.initializePage); + // make sure pageLoading is called with false (not done) + $(function(){ + $.mobile.pageLoading( false ); + }); + if( $.mobile.autoInitialize ){ + $.mobile.initializePage(); } - //window load event //hide iOS browser chrome on load $window.load( $.mobile.silentScroll ); diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index 32a6a324ef3..0d0f4087ee3 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -154,8 +154,11 @@ $.testHelper.reloadLib(libName); ok($("html").hasClass("ui-mobile-rendering"), "Still in rendering state after library load."); + ok($("html").hasClass("ui-loading"), "pageLoading executed successfully"); + ok($(".ui-loader").length, "loader is present"); $.mobile.initializePage(); ok(!$("html").hasClass("ui-mobile-rendering"), "Rendered ok after call to initializePage"); + ok(!$("html").hasClass("ui-loading"), "pageLoading removed loading class"); }); }); })(jQuery); \ No newline at end of file