Permalink
Browse files

Fix for #77.

Some code cleanup in the url processing function.
  • Loading branch information...
1 parent a82c64e commit 443d352a443b63e1e15c035ee0ac4845818acb3d @azicchetti committed Jun 1, 2013
Showing with 69 additions and 47 deletions.
  1. +3 −2 README.md
  2. +12 −8 examples/test-bC.html
  3. +3 −3 examples/testSamePage.html
  4. +49 −32 js/jquery.mobile.router.js
  5. +2 −2 js/jquery.mobile.router.min.js
View
@@ -540,8 +540,9 @@ ability to use jQuery Mobile (not the router) in "ajax mode" on certain Android
http://code.google.com/p/android/issues/detail?id=17535
-If you experience something like this, there's a simple patch you can apply using the router and
-the pagebeforeload event.
+Cordova 2.x includes a workaround for this, but if you need to use an older version for whatever reason,
+you may experience the dreaded "chromium error: -6".
+However, there's a simple patch you can apply using the router and the pagebeforeload event.
I won't put it here in the documentation since it's not a general use-case, but if you really need it,
just open an issue on github or send me a private email.
View
@@ -7,20 +7,24 @@
<script type="text/javascript" src="../js/jquery.mobile.router.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript">
- var router=new $.mobile.Router({
- "#localpage2": {handler: "localpage", events: "bC", argsre: true},
- "#localpage4": {handler: "localpage4", events: "bC", argsre: true},
- "#index": { handler: function(type){
+ var router=new $.mobile.Router([
+ { "#localpage2": {handler: "localpage", events: "bC", argsre: true} },
+ { "#localpage2": {handler: "localpageShow", events: "bs", argsre: true} },
+ { "#localpage4": {handler: "localpage4", events: "bC", argsre: true} },
+ { "#index": { handler: function(type){
console.log("Index has been "+(type=="pagehide"?"hidden":"shown"));
- }, events: "h,s" }
- },{
+ }, events: "h,s" } }
+ ],{
+ localpageShow: function(type,match,ui,page,e){
+ console.log(match[0]);
+ },
localpage: function(type,match,ui,page,e){
e.preventDefault();
console.log("pagebeforechange evt:");
console.log(match);
console.log(page);
// if you want to re-route the transition to #localpage4, uncomment the following 2 lines
- //ui.toPage="#localpage4";
+ //ui.toPage="#localpage4?pippo=pluto";
//ui.options.dataUrl="localpage4";
console.log("Waiting 6 seconds before resolving the deferred...");
setTimeout(function(){
@@ -30,7 +34,7 @@
},
localpage4: function(type,match,ui,page,e){
- console.log("bC - localpage4");
+ console.log("bC - localpage4 "+match[0]);
}
});
</script>
@@ -2,10 +2,10 @@
<html>
<head>
<title>Page Title</title>
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
+ <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
+ <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../js/jquery.mobile.router.js"></script>
- <script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
+ <script type="text/javascript" src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript">
var router=new $.mobile.Router({
"#localpage2(?:[?/](.*))?": "localpage2",
View
@@ -1,5 +1,5 @@
/*!
- * jQueryMobile-router v20130525
+ * jQueryMobile-router v20130527
* http://github.com/azicchetti/jquerymobile-router
*
* Copyright 2011-2013 (c) Andrea Zicchetti
@@ -37,10 +37,18 @@ $(document).on("mobileinit", function(){
var previousUrl = null, nextUrl = null, ignoreNext = false;
$(document).on("pagebeforechange", function(e, data) {
- var toPage=( typeof data.toPage === "string" ) ? data.toPage : data.toPage.jqmData("url")||"";
-
if ( data.options.hasOwnProperty("_jqmrouter_handled") ){ return; }
+
+ var toPage;
+ if ( typeof data.toPage === "string" ){
+ toPage = data.toPage;
+ } else {
+ toPage = data.toPage.jqmData("url") || "";
+ if (data.toPage.attr("id") == toPage){ toPage = "#" + toPage; }
+ }
+
data.options._jqmrouter_handled = true;
+
// handle form submissions
if ( data.options.data && (data.options.type+"").toLowerCase() == "get" ){
toPage += "?" + data.options.data;
@@ -215,7 +223,7 @@ $(document).on("mobileinit", function(){
},
_processRoutes: function(e,ui,page) {
- var _self=this, refUrl, url, $page, retry = 0, bCData = null;
+ var _self=this, refUrl, url, retry = 0, bCData = null;
if (e.type == "pagebeforechange"){
if (ui.options._jqmrouter_bC){
// we must return when _jqmrouter_bC is set to avoid loops
@@ -234,32 +242,30 @@ $(document).on("mobileinit", function(){
} else {
refUrl = nextUrl;
}
- do {
- if ( !refUrl ){
- if ( page ){
- $page = $(page);
- refUrl = $page.jqmData("url");
- if ( refUrl ){
- if ( $page.attr("id") == refUrl ) { refUrl = "#" + refUrl; }
- refUrl = $.mobile.path.parseUrl(refUrl);
- }
- }
- } else if ( !this.documentEvts[e.type] && page && !$(page).jqmData("url") ){
- return;
+
+ url = !this.conf.ajaxApp ?
+ refUrl.hash : (refUrl.pathname + refUrl.search + refUrl.hash)
+ ;
+ if (url.length == 0){
+ // if ajaxApp is false, url may be "" when the user clicks the back button
+ // and returns to the first page of the application (which is usually
+ // loaded without the hash part of the url). Let's handle this...
+ refUrl = null;
+ if (!this.documentEvts[e.type] && page){
+ refUrl = $(page).jqmData("url");
+ } else {
+ // mhm, we should be visiting the first page of the app
+ refUrl = $.mobile.firstPage.jqmData("url");
+ //refUrl = $(":jqmData(role=page):first").jqmData("url");
}
- if ( !refUrl ) { return; }
- url = ( !this.conf.ajaxApp ?
- refUrl.hash
- :refUrl.pathname + refUrl.search + refUrl.hash
- );
- if ( url.length == 0 ){
- // if ajaxApp is false, url may be "" when the user clicks the back button
- // and returns to the first page of the application (which is usually
- // loaded without the hash part of the url). Let's handle this...
- refUrl = "";
+ if (refUrl){
+ refUrl = $.mobile.path.parseUrl("#" + refUrl);
+ url = !this.conf.ajaxApp ?
+ refUrl.hash : (refUrl.pathname + refUrl.search + refUrl.hash)
+ ;
}
- retry ++;
- } while( url.length == 0 && retry <= 1 );
+ }
+ if (url.length == 0){ return; }
var bHandled = false;
$.each(this.routes[e.type], function(route,routeConf){
@@ -309,13 +315,24 @@ $(document).on("mobileinit", function(){
bCData.deferred.done(function(){
// if the user re-routed the bC, we shouldn't set _jqmrouter_handled or _jqmrouter_bC
var extraOpt = (bCData.toPage === ui.toPage ?
- { _jqmrouter_handled: true, _jqmrouter_bC: true } : null);
+ { _jqmrouter_handled: true, _jqmrouter_bC: true } : null
+ );
// destination page is refUrl.href, ui.toPage or page.
// I'm using ui.toPage so that really crazy users may try to re-route the transition to
// another location by modifying this property from the handler.
- $.mobile.changePage(ui.toPage, $.extend({
- dataUrl: ui.options.dataUrl
- }, extraOpt ));
+ $.mobile.changePage(ui.toPage, $.extend({
+ allowSamePageTransition: ui.options.allowSamePageTransition,
+ changeHash: ui.options.changeHash,
+ data: ui.options.data,
+ dataUrl: ui.options.dataUrl,
+ pageContainer: ui.options.pageContainer,
+ reloadPage: ui.options.reloadPage,
+ reverse: ui.options.reverse,
+ role: ui.options.role,
+ showLoadMsg: ui.options.showLoadMsg,
+ transition: ui.options.transition,
+ type: ui.options.type
+ }, extraOpt));
});
}
},
Oops, something went wrong.

0 comments on commit 443d352

Please sign in to comment.