Permalink
Browse files

Fix for issue 2529 - Transition to the same page

- Added a new allowSamePageTransition option to the changePage() method default settings.

By default, we prevent changePage() requests when the fromPage and toPage are the same element, but folks that generate content manually/dynamically and reuse pages want to be able to transition to the same page. To allow
this, they will need to change the default value of allowSamePageTransition to true, *OR*, pass it in as an option when they manually call changePage().

It should be noted that our default transition animations assume that the formPage and toPage are different elements, so they may behave unexpectedly. It is up to the developer that turns on the allowSamePageTransitiona option
to either turn off transition animations, or make sure that an appropriate animation transition is used.

	// To toggle the default behavior for all changePage() calls,
	// set the default value of allowSamePageTransition to whatever
	// you want it to be. The default is false.

	$.mobile.changePage.defaults.allowSamePageTransition = true;

	// To specify the behavior when manually calling changePage(),
	// pass it as an option. If not specified, the default value
	// specified by $.mobile.changepage.defaults.allowSamePageTransition
	// is used.

	$.mobile.changePage( "#reused-page", { allowSamePageTransition: true } );
  • Loading branch information...
1 parent 86ab894 commit 6cd1e1b1416a810425d343bf14f46fc993ac8668 @jblas jblas committed Sep 26, 2011
Showing with 13 additions and 8 deletions.
  1. +13 −8 js/jquery.mobile.navigation.js
@@ -1023,13 +1023,17 @@
pageTitle = document.title,
isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog";
- // If we are trying to transition to the same page that we are currently on ignore the request.
- // an illegal same page request is defined by the current page being the same as the url, as long as there's history
- // and toPage is not an array or object (those are allowed to be "same")
- //
- // XXX_jblas: We need to remove this at some point when we allow for transitions
- // to the same page.
- if( fromPage && fromPage[0] === toPage[0] ) {
+ // By default, we prevent changePage requests when the fromPage and toPage
+ // are the same element, but folks that generate content manually/dynamically
+ // and reuse pages want to be able to transition to the same page. To allow
+ // this, they will need to change the default value of allowSamePageTransition
+ // to true, *OR*, pass it in as an option when they manually call changePage().
+ // It should be noted that our default transition animations assume that the
+ // formPage and toPage are different elements, so they may behave unexpectedly.
+ // It is up to the developer that turns on the allowSamePageTransitiona option
+ // to either turn off transition animations, or make sure that an appropriate
+ // animation transition is used.
+ if( fromPage && fromPage[0] === toPage[0] && !settings.allowSamePageTransition ) {
isPageTransitioning = false;
mpc.trigger( "pagechange", triggerData );
return;
@@ -1132,7 +1136,8 @@
pageContainer: undefined,
showLoadMsg: true, //loading message shows by default when pages are being fetched during changePage
dataUrl: undefined,
- fromPage: undefined
+ fromPage: undefined,
+ allowSamePageTransition: false
};
/* Event Bindings - hashchange, submit, and click */

0 comments on commit 6cd1e1b

Please sign in to comment.