|
837 | 837 | // Make sure we have a pageContainer to work with. |
838 | 838 | settings.pageContainer = settings.pageContainer || $.mobile.pageContainer; |
839 | 839 |
|
| 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 | + |
840 | 853 | // If the caller passed us a url, call loadPage() |
841 | 854 | // to make sure it is loaded into the DOM. We'll listen |
842 | 855 | // to the promise object it returns so we know when |
|
864 | 877 |
|
865 | 878 | // The caller passed us a real page DOM element. Update our |
866 | 879 | // internal state and then trigger a transition to the page. |
867 | | - var mpc = settings.pageContainer, |
868 | | - fromPage = $.mobile.activePage, |
| 880 | + var fromPage = $.mobile.activePage, |
869 | 881 | url = toPage.jqmData( "url" ), |
870 | 882 | // The pageUrl var is usually the same as url, except when url is obscured as a dialog url. pageUrl always contains the file path |
871 | 883 | pageUrl = url, |
|
876 | 888 | pageTitle = document.title, |
877 | 889 | isDialog = settings.role === "dialog" || toPage.jqmData( "role" ) === "dialog"; |
878 | 890 |
|
879 | | - // Let listeners know we're about to change the current page. |
880 | | - mpc.trigger( "beforechangepage" ); |
881 | | - |
882 | 891 | // If we are trying to transition to the same page that we are currently on ignore the request. |
883 | 892 | // an illegal same page request is defined by the current page being the same as the url, as long as there's history |
884 | 893 | // and toPage is not an array or object (those are allowed to be "same") |
|
0 commit comments