Skip to content

Commit 522b48e

Browse files
author
scottjehl
committed
started on the change to allow default prevention on beforechangepage
1 parent df8d6fa commit 522b48e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

js/jquery.mobile.navigation.js

100644100755
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,19 @@
837837
// Make sure we have a pageContainer to work with.
838838
settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
839839

840+
var mpc = settings.pageContainer,
841+
bcpEvent = new $.Event( "beforechangepage" ),
842+
url = toPage;
843+
844+
// Let listeners know we're about to change the current page.
845+
mpc.trigger( bcpEvent, url, settings );
846+
847+
// If the default behavior is prevented, stop here!
848+
if( bcpEvent.isDefaultPrevented() ){
849+
return;
850+
}
851+
852+
840853
// If the caller passed us a url, call loadPage()
841854
// to make sure it is loaded into the DOM. We'll listen
842855
// to the promise object it returns so we know when
@@ -864,8 +877,7 @@
864877

865878
// The caller passed us a real page DOM element. Update our
866879
// internal state and then trigger a transition to the page.
867-
var mpc = settings.pageContainer,
868-
fromPage = $.mobile.activePage,
880+
var fromPage = $.mobile.activePage,
869881
url = toPage.jqmData( "url" ),
870882
// The pageUrl var is usually the same as url, except when url is obscured as a dialog url. pageUrl always contains the file path
871883
pageUrl = url,
@@ -876,9 +888,6 @@
876888
pageTitle = document.title,
877889
isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog";
878890

879-
// Let listeners know we're about to change the current page.
880-
mpc.trigger( "beforechangepage" );
881-
882891
// If we are trying to transition to the same page that we are currently on ignore the request.
883892
// an illegal same page request is defined by the current page being the same as the url, as long as there's history
884893
// and toPage is not an array or object (those are allowed to be "same")

0 commit comments

Comments
 (0)