Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 0095c40

Browse files
author
Gabriel Schulhof
committed
Navigation: initialDst no longer needed for resolving funky initial URLs
(cherry picked from commit 9951e54) Closes gh-7630 Fixes gh-7177
1 parent 4813c33 commit 0095c40

File tree

9 files changed

+62
-57
lines changed

9 files changed

+62
-57
lines changed

js/jquery.mobile.init.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ define([
109109
$.mobile.path.isPath( hash ) ||
110110
hash === $.mobile.dialogHashKey ) ) ) {
111111

112-
// Store the initial destination
113-
if ( $.mobile.path.isHashValid( location.hash ) ) {
114-
$.mobile.navigate.history.initialDst = hash.replace( "#", "" );
115-
}
116-
117112
// make sure to set initial popstate state if it exists
118113
// so that navigation back to the initial page works properly
119114
if ( $.event.special.navigate.isPushStateEnabled() ) {

js/navigation/path.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,25 @@ define([
287287
},
288288

289289
squash: function( url, resolutionUrl ) {
290-
var href, cleanedUrl, search, stateIndex,
290+
var href, cleanedUrl, search, stateIndex, docUrl,
291291
isPath = this.isPath( url ),
292292
uri = this.parseUrl( url ),
293293
preservedHash = uri.hash,
294294
uiState = "";
295295

296-
// produce a url against which we can resole the provided path
297-
resolutionUrl = resolutionUrl || (path.isPath(url) ? path.getLocation() : path.getDocumentUrl());
296+
// produce a url against which we can resolve the provided path
297+
if ( !resolutionUrl ) {
298+
if ( isPath ) {
299+
resolutionUrl = path.getLocation();
300+
} else {
301+
docUrl = path.getDocumentUrl( true );
302+
if ( path.isPath( docUrl.hash ) ) {
303+
resolutionUrl = path.squash( docUrl.href );
304+
} else {
305+
resolutionUrl = docUrl.href;
306+
}
307+
}
308+
}
298309

299310
// If the url is anything but a simple string, remove any preceding hash
300311
// eg #foo/bar -> foo/bar

js/widgets/pagecontainer.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,6 @@ define( [
228228
//
229229
// TODO move check to history object or path object?
230230
to = !$.mobile.path.isPath( to ) ? ( $.mobile.path.makeUrlAbsolute( "#" + to, this._getDocumentBase() ) ) : to;
231-
232-
// If we're about to go to an initial URL that contains a
233-
// reference to a non-existent internal page, go to the first
234-
// page instead. We know that the initial hash refers to a
235-
// non-existent page, because the initial hash did not end
236-
// up in the initial history entry
237-
// TODO move check to history object?
238-
if ( to === $.mobile.path.makeUrlAbsolute( "#" + history.initialDst, this._getDocumentBase() ) &&
239-
history.stack.length &&
240-
history.stack[0].url !== history.initialDst.replace( $.mobile.dialogHashKey, "" ) ) {
241-
to = this._getInitialContent();
242-
}
243231
}
244232
return to || this._getInitialContent();
245233
},
@@ -318,8 +306,7 @@ define( [
318306
// key, and the initial destination isn't equal to the current target
319307
// page, use the special dialog handling
320308
if ( history.activeIndex > 0 &&
321-
to.indexOf( $.mobile.dialogHashKey ) > -1 &&
322-
history.initialDst !== to ) {
309+
to.indexOf( $.mobile.dialogHashKey ) > -1 ) {
323310

324311
to = this._handleDialog( changePageOptions, data );
325312

@@ -1096,12 +1083,6 @@ define( [
10961083
} else {
10971084
url += "#" + $.mobile.dialogHashKey;
10981085
}
1099-
1100-
// tack on another dialogHashKey if this is the same as the initial hash
1101-
// this makes sure that a history entry is created for this dialog
1102-
if ( $.mobile.navigate.history.activeIndex === 0 && url === $.mobile.navigate.history.initialDst ) {
1103-
url += $.mobile.dialogHashKey;
1104-
}
11051086
}
11061087

11071088
// if title element wasn't found, try the page div data attr too

js/widgets/popup.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,6 @@ $.widget( "mobile.popup", {
904904
url = $.mobile.path.parseLocation().hash + hashkey;
905905
}
906906

907-
// Tack on an extra hashkey if this is the first page and we've just reconstructed the initial hash
908-
if ( urlHistory.activeIndex === 0 && url === urlHistory.initialDst ) {
909-
url += hashkey;
910-
}
911-
912907
// swallow the the initial navigation event, and bind for the next
913908
this.window.one( "beforenavigate", function( theEvent ) {
914909
theEvent.preventDefault();

tests/functional/hashchange/hashchange1.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ <h3>Navigation</h3>
4141
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
4242
</div>
4343
</div>
44+
45+
<div data-role="page" id="page2">
46+
<div data-role="header">
47+
<h2>Internal page on another page</h2>
48+
</div>
49+
</div>
50+
4451
</body>
4552
</html>

tests/integration/navigation/sequence/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@
5353
<a id="openBasicDialog" href="basic-dialog.html" data-nstest-rel="dialog">Dialog</a>
5454
<a id="openAnotherDialog" href="basic-dialog1.html" data-nstest-rel="dialog">Dialog 1</a>
5555
<a id="openAnotherPage" href="another-page.html">Another page</a>
56+
<a id="openInternalPage" href="#internal-page">Internal page</a>
5657
</div>
5758
</div>
5859

60+
<div id="internal-page" data-nstest-role="page"></div>
5961
</body>
6062
</html>

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@
3939
</head>
4040
<body>
4141

42-
<h1 id="qunit-header">jQuery Mobile Sequence Test Suite</h1>
43-
<h2 id="qunit-banner"></h2>
44-
<h2 id="qunit-userAgent"></h2>
45-
<ol id="qunit-tests">
46-
</ol>
42+
<div id="qunit"></div>
4743

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

5047
<!--
5148
This test page is used when testing initial URLs of the form

tests/integration/navigation/sequence/sequence_core.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@
3838
}
3939
}
4040

41+
asyncTest( "Navigating to an internal page", function() {
42+
var origUrl,
43+
eventNs = ".navigatingToAnInternalPage";
44+
45+
expect( 1 );
46+
47+
maybeWaitForStartPage([
48+
function() {
49+
origUrl = location.href.replace( "&ui-state=dialog", "" );
50+
$( "#openInternalPage" ).click();
51+
},
52+
{
53+
pagecontainerchange: { src: $.mobile.pageContainer, event: "pagecontainerchange" + eventNs + "1" }
54+
},
55+
function() {
56+
deepEqual( location.href, origUrl.indexOf( "#" ) >= 0 ?
57+
origUrl + "internal-page" :
58+
origUrl + "#internal-page",
59+
"URL after popup opens differs only by an appended dialog hash key" );
60+
$.mobile.back();
61+
},
62+
{
63+
pagecontainerchange: { src: $.mobile.pageContainer, event: "pagecontainerchange" + eventNs + "2" }
64+
},
65+
start
66+
]);
67+
});
68+
4169
asyncTest( "Returning from a dialog results in the page from which it opened", function() {
4270
var eventNs = ".returningFromADialog";
4371
expect( 2 );
@@ -64,19 +92,25 @@
6492
});
6593

6694
asyncTest( "Returning from a popup results in the page from which it opened", function() {
67-
var origActive, eventNs = ".returningFromAPopup";
95+
var origActive, origUrl,
96+
eventNs = ".returningFromAPopup";
6897

69-
expect( 3 );
98+
expect( 4 );
7099

71100
maybeWaitForStartPage([
72101
function() {
73102
origActive = $.mobile.activePage;
103+
origUrl = location.href;
74104
$( "#openPopup" ).click();
75105
},
76106
{
77107
popupafteropen: { src: function() { return $( "#thePopup" ); }, event: "popupafteropen" + eventNs + "1" }
78108
},
79109
function( result ) {
110+
deepEqual( location.href, origUrl.indexOf( "#" ) >= 0 ?
111+
origUrl + $.mobile.dialogHashKey :
112+
origUrl + "#" + $.mobile.dialogHashKey,
113+
"URL after popup opens differs only by an appended dialog hash key" );
80114
ok( !result.popupafteropen.timedOut, "Popup emitted 'popupafteropen'" );
81115
$( "#thePopup" ).parent().prev().click();
82116
},

tests/unit/content/content_core.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,6 @@
198198
equal( "foo/bar", proto._handleDestination( "#foo/bar" ) );
199199
});
200200

201-
test( "returns initial content when the url is base plus initial destination", function() {
202-
var initialContent = $( "<div>" );
203-
204-
proto._getHistory = function() {
205-
return {
206-
initialDst: "foo",
207-
stack: [ {url: "will not be equal to initial destination"} ]
208-
};
209-
};
210-
211-
proto._getInitialContent = function() {
212-
return initialContent;
213-
};
214-
215-
equal( initialContent, proto._handleDestination(base + "#" + proto._getHistory().initialDst) );
216-
});
217-
218201
module( "Content Widget _recordScroll" );
219202

220203
test( "does not record scroll position when disabled", function() {

0 commit comments

Comments
 (0)