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

Commit 0ba0452

Browse files
committed
create, store, and pass the absolute url in all page lifecycle events on the trigger data object
1 parent 824261b commit 0ba0452

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

js/jquery.mobile.navigation.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,12 @@ define( [
601601
$page.page();
602602
}
603603

604+
// determine the current base url
605+
function findBaseWithDefault() {
606+
var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
607+
return closestBase || documentBase.hrefNoHash;
608+
}
609+
604610
/* exposed $.mobile methods */
605611

606612
//animation complete callback
@@ -626,8 +632,6 @@ define( [
626632

627633
$.mobile.dialogHashKey = dialogHashKey;
628634

629-
630-
631635
//enable cross-domain page support
632636
$.mobile.allowCrossDomainPages = false;
633637

@@ -680,12 +684,6 @@ define( [
680684
// page is loaded off the network.
681685
dupCachedPage = null,
682686

683-
// determine the current base url
684-
findBaseWithDefault = function() {
685-
var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
686-
return closestBase || documentBase.hrefNoHash;
687-
},
688-
689687
// The absolute version of the URL passed into the function. This
690688
// version of the URL may contain dialog/subpage params in it.
691689
absUrl = path.makeUrlAbsolute( url, findBaseWithDefault() );
@@ -975,18 +973,33 @@ define( [
975973
return;
976974
}
977975

978-
var settings = $.extend( {}, $.mobile.changePage.defaults, options );
976+
var settings = $.extend( {}, $.mobile.changePage.defaults, options ), isString;
979977

980978
// Make sure we have a pageContainer to work with.
981979
settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
982980

983981
// Make sure we have a fromPage.
984982
settings.fromPage = settings.fromPage || $.mobile.activePage;
985983

984+
isString = (typeof toPage === "string");
985+
986986
var mpc = settings.pageContainer,
987987
pbcEvent = new $.Event( "pagebeforechange" ),
988988
triggerData = { toPage: toPage, options: settings };
989989

990+
// NOTE: preserve the original target as the dataUrl value will be simplified
991+
// eg, removing ui-state, and removing query params from the hash
992+
// this is so that users who want to use query params have access to them
993+
// in the event bindings for the page life cycle See issue #5085
994+
if ( isString ) {
995+
// if the toPage is a string simply convert it
996+
triggerData.url = path.makeUrlAbsolute( toPage, findBaseWithDefault() );
997+
} else {
998+
// if the toPage is a jQuery object grab the absolute url stored
999+
// in the loadPage callback where it exists
1000+
triggerData.url = toPage.data( 'absoluteUrl' );
1001+
}
1002+
9901003
// Let listeners know we're about to change the current page.
9911004
mpc.trigger( pbcEvent, triggerData );
9921005

@@ -1010,17 +1023,15 @@ define( [
10101023
// to make sure it is loaded into the DOM. We'll listen
10111024
// to the promise object it returns so we know when
10121025
// it is done loading or if an error ocurred.
1013-
if ( typeof toPage === "string" ) {
1014-
// preserve the original target as the dataUrl value will be simplified
1015-
// eg, removing ui-state, and removing query params from the hash
1016-
// this is so that users who want to use query params have access to them
1017-
// in the event bindings for the page life cycle See issue #5085
1018-
settings.target = toPage;
1019-
1026+
if ( isString ) {
10201027
$.mobile.loadPage( toPage, settings )
10211028
.done(function( url, options, newPage, dupCachedPage ) {
10221029
isPageTransitioning = false;
10231030
options.duplicateCachedPage = dupCachedPage;
1031+
1032+
// store the original absolute url so that it can be provided
1033+
// to events in the triggerData
1034+
newPage.data( 'absoluteUrl', triggerData.url );
10241035
$.mobile.changePage( newPage, options );
10251036
})
10261037
.fail(function( url, options ) {

0 commit comments

Comments
 (0)