Permalink
Browse files

Navigation: Do not wait for load() if document.readyState is "complete"

(cherry picked from commit 9310e8d)

Closes gh-7389
Fixes gh-7386
  • Loading branch information...
gabrielschulhof committed May 9, 2014
1 parent 5445bc4 commit d37576f42e18fb8d63c4c02d39a8eadd5443fa46
@@ -25,6 +25,15 @@ define( [
// resolved and nulled on window.load()
loadDeferred = $.Deferred(),
// function that resolves the above deferred
pageIsFullyLoaded = function() {
// Resolve and null the deferred
loadDeferred.resolve();
loadDeferred = null;
},
documentUrl = $.mobile.path.documentUrl,
// used to track last vclicked element to make sure its value is added to form data
@@ -442,12 +451,12 @@ define( [
$( function() { domreadyDeferred.resolve(); } );
$.mobile.window.load( function() {
// Resolve and null the deferred
loadDeferred.resolve();
loadDeferred = null;
});
// Account for the possibility that the load event has already fired
if ( document.readyState === "complete" ) {
pageIsFullyLoaded();
} else {
$.mobile.window.load( pageIsFullyLoaded );
}
$.when( domreadyDeferred, $.mobile.navreadyDeferred ).done( function() { $.mobile._registerInternalEvents(); } );
})( jQuery );
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>jQuery Mobile Init Test Suite</title>
<script src="../../../external/requirejs/require.js"></script>
<script src="../../../js/requirejs.config.js"></script>
<script src="../../requirejs.config.js"></script>
<script src="../../../js/jquery.tag.inserter.js"></script>
<script src="../../jquery.setNameSpace.js"></script>
<script src="../../jquery.testHelper.js"></script>
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
<link rel="stylesheet" href="../../jqm-tests.css"/>
<script src="../../../external/qunit/qunit.js"></script>
<script>
$.testHelper.asyncLoad([
[ "tests/unit/init/no_autoinit_page_core" ]
]);
</script>
<script src="../../swarminject.js"></script>
</head>
<body>
<div id="qunit"></div>
<div data-nstest-role="page" id="foo">
</div>
<div data-nstest-role="page" id="bar" data-nstest-url="bak">
</div>
</body>
</html>
@@ -0,0 +1,25 @@
asyncTest( "resetActivePageHeight() will be called when page is initialized late", function() {
var resetActivePageHeightCallCount = 0;
$( document ).on( "mobileinit", function() {
$.mobile.autoInitializePage = false;
$.mobile.resetActivePageHeight = ( function( original ) {
return function resetActivePageHeight() {
resetActivePageHeightCallCount++;
return original.apply( this, arguments );
};
})( $.mobile.resetActivePageHeight );
});
require([ "jquery", "./init" ], function() {
setTimeout( function() {
$.mobile.initializePage();
deepEqual( resetActivePageHeightCallCount, 1,
"$.mobile.resetActivePageHeight() was called from delayed initializePage()" );
start();
}, 5000 );
});
});

0 comments on commit d37576f

Please sign in to comment.