@@ -287,14 +287,25 @@ define([
},

squash: function( url, resolutionUrl ) {
var href, cleanedUrl, search, stateIndex,
var href, cleanedUrl, search, stateIndex, docUrl,
isPath = this.isPath( url ),
uri = this.parseUrl( url ),
preservedHash = uri.hash,
uiState = "";

// produce a url against which we can resole the provided path
resolutionUrl = resolutionUrl || (path.isPath(url) ? path.getLocation() : path.getDocumentUrl());
// produce a url against which we can resolve the provided path
if ( !resolutionUrl ) {
if ( path.isPath( url ) ) {
resolutionUrl = path.getLocation();
} else {
docUrl = path.getDocumentUrl( true );
if ( path.isPath( docUrl.hash ) ) {
resolutionUrl = path.squash( docUrl.href );
} else {
resolutionUrl = docUrl.href;
}
}
}

// If the url is anything but a simple string, remove any preceding hash
// eg #foo/bar -> foo/bar
@@ -41,5 +41,12 @@ <h3>Navigation</h3>
<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>
</div>
</div>

<div data-role="page" id="page2">
<div data-role="header">
<h2>Internal page on another page</h2>
</div>
</div>

</body>
</html>
@@ -53,8 +53,10 @@
<a id="openBasicDialog" href="basic-dialog.html" data-nstest-rel="dialog">Dialog</a>
<a id="openAnotherDialog" href="basic-dialog1.html" data-nstest-rel="dialog">Dialog 1</a>
<a id="openAnotherPage" href="another-page.html">Another page</a>
<a id="openInternalPage" href="#internal-page">Internal page</a>
</div>
</div>

<div id="internal-page" data-nstest-role="page"></div>
</body>
</html>
@@ -39,13 +39,10 @@
</head>
<body>

<h1 id="qunit-header">jQuery Mobile Sequence Test Suite</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<div id="qunit"></div>

<div data-nstest-role="page" id="sequenceRedirect"></div>
<div id="internal-page" data-nstest-role="page"></div>

<!--
This test page is used when testing initial URLs of the form
@@ -38,6 +38,34 @@
}
}

asyncTest( "Navigating to an internal page", function() {
var origUrl,
eventNs = ".navigatingToAnInternalPage";

expect( 1 );

maybeWaitForStartPage([
function() {
origUrl = location.href.replace( "&ui-state=dialog", "" );
$( "#openInternalPage" ).click();
},
{
pagecontainerchange: { src: $.mobile.pageContainer, event: "pagecontainerchange" + eventNs + "1" }
},
function() {
deepEqual( location.href, origUrl.indexOf( "#" ) >= 0 ?
origUrl + "internal-page" :
origUrl + "#internal-page",
"URL after popup opens differs only by an appended dialog hash key" );
$.mobile.back();
},
{
pagecontainerchange: { src: $.mobile.pageContainer, event: "pagecontainerchange" + eventNs + "2" }
},
start
]);
});

asyncTest( "Returning from a dialog results in the page from which it opened", function() {
var eventNs = ".returningFromADialog";
expect( 2 );
@@ -64,19 +92,25 @@
});

asyncTest( "Returning from a popup results in the page from which it opened", function() {
var origActive, eventNs = ".returningFromAPopup";
var origActive, origUrl,
eventNs = ".returningFromAPopup";

expect( 3 );
expect( 4 );

maybeWaitForStartPage([
function() {
origActive = $.mobile.activePage;
origUrl = location.href;
$( "#openPopup" ).click();
},
{
popupafteropen: { src: function() { return $( "#thePopup" ); }, event: "popupafteropen" + eventNs + "1" }
},
function( result ) {
deepEqual( location.href, origUrl.indexOf( "#" ) >= 0 ?
origUrl + $.mobile.dialogHashKey :
origUrl + "#" + $.mobile.dialogHashKey,
"URL after popup opens differs only by an appended dialog hash key" );
ok( !result.popupafteropen.timedOut, "Popup emitted 'popupafteropen'" );
$( "#thePopup" ).parent().prev().click();
},