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

Commit

Permalink
- Added "fromPage" option to changePage(). This used to be in there b…
Browse files Browse the repository at this point in the history
…efore the navigation re-work, I just added it back in.

- Added "dataUrl" option to changePage(). This allows a caller to specify a page element to change to, but specify an alternate URL for location display purposes. This is useful for dynamic applications that re-use and over-write existing page content to avoid overwhelming the DOM.

- Renamed the "beforechangepage" and "changepage" events to "pagebeforechange" and "pagechange" respectively. This was done to match the page widget naming of its notifications. Left the triggers for the old events in place but with DEPRECATED comments.

- Renamed the properties of the data object passed to the page events.
  • Loading branch information
jblas committed Sep 8, 2011
1 parent 701b381 commit 6aa8c8f
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions js/jquery.mobile.navigation.js
Expand Up @@ -831,18 +831,28 @@
// 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;

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

// Let listeners know we're about to change the current page.
mpc.trigger( bcpEvent, { url: url, settings: settings } );
mpc.trigger( pbcEvent, triggerData );

mpc.trigger( "beforechangepage", triggerData ); // XXX: DEPRECATED for 1.0

// If the default behavior is prevented, stop here!
if( bcpEvent.isDefaultPrevented() ){
if( pbcEvent.isDefaultPrevented() ){
return;
}


// We allow "pagebeforechange" observers to modify the toPage in the trigger
// data to allow for redirects. Make sure our toPage is updated.

toPage = triggerData.toPage;

// Set the isPageTransitioning flag to prevent any requests from
// entering this method while we are in the midst of loading a page
// or transitioning.
Expand All @@ -869,15 +879,16 @@

//release transition lock so navigation is free again
releasePageTransitionLock();
settings.pageContainer.trigger("changepagefailed");
settings.pageContainer.trigger( "pagechangefailed", triggerData );
settings.pageContainer.trigger( "changepagefailed", triggerData ); // XXX: DEPRECATED for 1.0
});
return;
}

// The caller passed us a real page DOM element. Update our
// internal state and then trigger a transition to the page.
var fromPage = $.mobile.activePage,
url = toPage.jqmData( "url" ),
var fromPage = settings.fromPage,
url = ( settings.dataUrl && path.convertUrlToDataUrl( settings.dataUrl ) ) || toPage.jqmData( "url" ),
// The pageUrl var is usually the same as url, except when url is obscured as a dialog url. pageUrl always contains the file path
pageUrl = url,
fileUrl = path.getFilePath( url ),
Expand All @@ -895,7 +906,8 @@
// to the same page.
if( fromPage && fromPage[0] === toPage[0] ) {
isPageTransitioning = false;
mpc.trigger( "changepage" );
mpc.trigger( "pagechange", triggerData );
mpc.trigger( "changepage", triggerData ); // XXX: DEPRECATED for 1.0
return;
}

Expand Down Expand Up @@ -982,7 +994,9 @@
releasePageTransitionLock();

// Let listeners know we're all done changing the current page.
mpc.trigger( "changepage" );
mpc.trigger( "pagechange", triggerData );

mpc.trigger( "changepage", triggerData ); // XXX: DEPRECATED for 1.0
});
};

Expand All @@ -994,7 +1008,9 @@
role: undefined, // By default we rely on the role defined by the @data-role attribute.
duplicateCachedPage: undefined,
pageContainer: undefined,
showLoadMsg: true //loading message shows by default when pages are being fetched during changePage
showLoadMsg: true, //loading message shows by default when pages are being fetched during changePage
dataUrl: undefined,
fromPage: undefined
};

/* Event Bindings - hashchange, submit, and click */
Expand Down

0 comments on commit 6aa8c8f

Please sign in to comment.