Skip to content

Commit 9951e54

Browse files
author
Gabriel Schulhof
committed
Navigation: initialDst no longer needed for resolving funky initial URLs
Closes jquery-archivegh-7630 Fixes jquery-archivegh-7177
1 parent af08283 commit 9951e54

File tree

9 files changed

+62
-57
lines changed

9 files changed

+62
-57
lines changed

js/init.js

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

111-
// Store the initial destination
112-
if ( $.mobile.path.isHashValid( location.hash ) ) {
113-
$.mobile.navigate.history.initialDst = hash.replace( "#", "" );
114-
}
115-
116111
// make sure to set initial popstate state if it exists
117112
// so that navigation back to the initial page works properly
118113
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
@@ -227,18 +227,6 @@ define( [
227227
//
228228
// TODO move check to history object or path object?
229229
to = !$.mobile.path.isPath( to ) ? ( $.mobile.path.makeUrlAbsolute( "#" + to, this._getDocumentBase() ) ) : to;
230-
231-
// If we're about to go to an initial URL that contains a
232-
// reference to a non-existent internal page, go to the first
233-
// page instead. We know that the initial hash refers to a
234-
// non-existent page, because the initial hash did not end
235-
// up in the initial history entry
236-
// TODO move check to history object?
237-
if ( to === $.mobile.path.makeUrlAbsolute( "#" + history.initialDst, this._getDocumentBase() ) &&
238-
history.stack.length &&
239-
history.stack[0].url !== history.initialDst.replace( $.mobile.dialogHashKey, "" ) ) {
240-
to = this._getInitialContent();
241-
}
242230
}
243231
return to || this._getInitialContent();
244232
},
@@ -317,8 +305,7 @@ define( [
317305
// key, and the initial destination isn't equal to the current target
318306
// page, use the special dialog handling
319307
if ( history.activeIndex > 0 &&
320-
to.indexOf( $.mobile.dialogHashKey ) > -1 &&
321-
history.initialDst !== to ) {
308+
to.indexOf( $.mobile.dialogHashKey ) > -1 ) {
322309

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

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

11061087
// 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
@@ -903,11 +903,6 @@ $.widget( "mobile.popup", {
903903
url = $.mobile.path.parseLocation().hash + hashkey;
904904
}
905905

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