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

Commit

Permalink
create, store, and pass the absolute url in all page lifecycle events…
Browse files Browse the repository at this point in the history
… on the trigger data object
  • Loading branch information
johnbender committed Oct 12, 2012
1 parent 824261b commit 0ba0452
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions js/jquery.mobile.navigation.js
Expand Up @@ -601,6 +601,12 @@ define( [
$page.page();
}

// determine the current base url
function findBaseWithDefault() {
var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
return closestBase || documentBase.hrefNoHash;
}

/* exposed $.mobile methods */

//animation complete callback
Expand All @@ -626,8 +632,6 @@ define( [

$.mobile.dialogHashKey = dialogHashKey;



//enable cross-domain page support
$.mobile.allowCrossDomainPages = false;

Expand Down Expand Up @@ -680,12 +684,6 @@ define( [
// page is loaded off the network.
dupCachedPage = null,

// determine the current base url
findBaseWithDefault = function() {
var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
return closestBase || documentBase.hrefNoHash;
},

// The absolute version of the URL passed into the function. This
// version of the URL may contain dialog/subpage params in it.
absUrl = path.makeUrlAbsolute( url, findBaseWithDefault() );
Expand Down Expand Up @@ -975,18 +973,33 @@ define( [
return;
}

var settings = $.extend( {}, $.mobile.changePage.defaults, options );
var settings = $.extend( {}, $.mobile.changePage.defaults, options ), isString;

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

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

isString = (typeof toPage === "string");

var mpc = settings.pageContainer,
pbcEvent = new $.Event( "pagebeforechange" ),
triggerData = { toPage: toPage, options: settings };

// NOTE: preserve the original target as the dataUrl value will be simplified
// eg, removing ui-state, and removing query params from the hash
// this is so that users who want to use query params have access to them
// in the event bindings for the page life cycle See issue #5085
if ( isString ) {
// if the toPage is a string simply convert it
triggerData.url = path.makeUrlAbsolute( toPage, findBaseWithDefault() );
} else {
// if the toPage is a jQuery object grab the absolute url stored
// in the loadPage callback where it exists
triggerData.url = toPage.data( 'absoluteUrl' );
}

// Let listeners know we're about to change the current page.
mpc.trigger( pbcEvent, triggerData );

Expand All @@ -1010,17 +1023,15 @@ define( [
// to make sure it is loaded into the DOM. We'll listen
// to the promise object it returns so we know when
// it is done loading or if an error ocurred.
if ( typeof toPage === "string" ) {
// preserve the original target as the dataUrl value will be simplified
// eg, removing ui-state, and removing query params from the hash
// this is so that users who want to use query params have access to them
// in the event bindings for the page life cycle See issue #5085
settings.target = toPage;

if ( isString ) {
$.mobile.loadPage( toPage, settings )
.done(function( url, options, newPage, dupCachedPage ) {
isPageTransitioning = false;
options.duplicateCachedPage = dupCachedPage;

// store the original absolute url so that it can be provided
// to events in the triggerData
newPage.data( 'absoluteUrl', triggerData.url );
$.mobile.changePage( newPage, options );
})
.fail(function( url, options ) {
Expand Down

0 comments on commit 0ba0452

Please sign in to comment.