Skip to content

Commit 7069e21

Browse files
author
Gabriel Schulhof
committed
Navigation: Navigator updates initialHref until initial popstate arrives
Fixes jquery-archivegh-8056 Closes jquery-archivegh-8051
1 parent cc81c15 commit 7069e21

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

js/navigation/navigator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ define(["jquery",
5050
// is not fired.
5151
window.history.replaceState( state, state.title || document.title, href );
5252

53+
// If we haven't yet received the initial popstate, we need to update the reference
54+
// href so that we compare against the correct location
55+
if ( this.ignoreInitialHashChange ) {
56+
initialHref = href;
57+
}
58+
5359
return state;
5460
},
5561

tests/integration/navigation/event/early_popstate_handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define( [ "jquery" ], function( $ ) {
22

33
// TODO: Attaching early to popstate like this becomes unnecessary once the navigate event has been
4-
// properly implemented in that it removes its popstate handler upon teardown and attaches it upon
4+
// properly implemented so that it removes its popstate handler upon teardown and attaches it upon
55
// setup, rather than attaching it upon setup and then simply making sure upon subsequent calls to
66
// setup that the handlers are attached.
77
$( window ).on( "popstate", function( event ) {

tests/integration/navigation/event/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<link rel="stylesheet" href="../../../../external/qunit/qunit.css"/>
1313
<link rel="stylesheet" href="../../../jqm-tests.css"/>
1414
<script>
15-
$.testHelper.asyncLoad( [
15+
$.testHelper.asyncLoad([
1616
[ "early_popstate_handler.js" ],
1717
[ "events/navigate" ],
1818
[ "event_core.js" ]

tests/integration/navigation/sequence/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<script src="../../../../js/jquery.tag.inserter.js"></script>
1010
<script>
1111
$(document).bind('mobileinit',function(){
12+
1213
// Expect content to inherit this theme when not explicitly set
1314
$.mobile.page.prototype.options.contentTheme = "d";
15+
$.testHelper.setPushState();
1416
});
1517
</script>
1618
<script src="../../../jquery.setNameSpace.js"></script>

tests/integration/navigation/sequence/sequence-redirect.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
<script src="../../../../js/jquery.tag.inserter.js"></script>
1010
<script>
1111
$(document).bind('mobileinit',function(){
12+
1213
// Expect content to inherit this theme when not explicitly set
1314
$.mobile.page.prototype.options.contentTheme = "d";
15+
$.testHelper.setPushState();
1416
});
1517
</script>
1618
<script src="../../../jquery.setNameSpace.js"></script>
@@ -21,7 +23,7 @@
2123
$.testHelper.asyncLoad([
2224
[
2325
"widgets/dialog",
24-
"widgets/page",
26+
"widgets/page.dialog",
2527
"widgets/popup"
2628
],
2729
[ "init" ],
@@ -31,25 +33,23 @@
3133
], "../../../../js");
3234
</script>
3335

34-
3536
<link rel="stylesheet" href="../../../../css/themes/default/jquery.mobile.css"/>
3637
<link rel="stylesheet" href="../../../../external/qunit/qunit.css"/>
37-
3838
<script src="../../../swarminject.js"></script>
3939
</head>
4040
<body>
4141

42-
<div id="qunit"></div>
42+
<div id="qunit"></div>
4343

44-
<div data-nstest-role="page" id="sequenceRedirect"></div>
45-
<div id="internal-page" data-nstest-role="page"></div>
44+
<div data-nstest-role="page" id="sequenceRedirect"></div>
45+
<div id="internal-page" data-nstest-role="page"></div>
4646

47-
<!--
48-
This test page is used when testing initial URLs of the form
49-
http://domain/path/to/page1.html#/path/to/page2.html. It really only works if
50-
you load sequence-tests.html via the hash, i.e.,
51-
http://domain/path/to/sequence/index.html#/path/to/sequence-redirect.html
52-
-->
47+
<!--
48+
This test page is used when testing initial URLs of the form
49+
http://domain/path/to/page1.html#/path/to/page2.html. It really only works if
50+
you load sequence-tests.html via the hash, i.e.,
51+
http://domain/path/to/sequence/index.html#/path/to/sequence-redirect.html
52+
-->
5353

5454
</body>
5555
</html>

tests/integration/navigation/sequence/sequence_core.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// The more we click around the test pages and the more combinations of paths
1010
// we try, the better.
1111

12-
$.testHelper.setPushState();
13-
1412
// If the start page is not there, wait for it to appear. Otherwise, leave
1513
// some time before starting the actual run to allow the popstate handler to
1614
// awaken from its slumber
@@ -46,7 +44,8 @@
4644

4745
maybeWaitForStartPage([
4846
function() {
49-
origUrl = location.href.replace( "&ui-state=dialog", "" );
47+
origUrl = $.mobile.path.parseUrl(
48+
location.href.replace( "&ui-state=dialog", "" ) ).hrefNoHash;
5049
$( "#openInternalPage" ).click();
5150
},
5251
{

0 commit comments

Comments
 (0)