* refactors `get_route_str`. The result is the addition of two new functions - `get_raw_route_str` and `_decode_str` * delays decoding of route parts
This commit is contained in:
parent
e232abdafd
commit
c98b97a21c
1 changed files with 21 additions and 14 deletions
|
|
@ -67,9 +67,10 @@ frappe.route = function() {
|
|||
|
||||
frappe.get_route = function(route) {
|
||||
// for app
|
||||
var route = frappe.get_route_str(route).split('/')
|
||||
var route = frappe.get_raw_route_str(route).split('/');
|
||||
route = $.map(route, frappe._decode_str);
|
||||
var parts = route[route.length - 1].split("?");
|
||||
route[route.length - 1] = parts[0];
|
||||
route[route.length - 1] = frappe._decode_str(parts[0]);
|
||||
if (parts.length > 1) {
|
||||
var query_params = get_query_params(parts[1]);
|
||||
frappe.route_options = $.extend(frappe.route_options || {}, query_params);
|
||||
|
|
@ -92,25 +93,31 @@ frappe.get_prev_route = function() {
|
|||
}
|
||||
}
|
||||
|
||||
frappe.get_route_str = function(route) {
|
||||
frappe._decode_str = function(r) {
|
||||
try {
|
||||
return decodeURIComponent(r);
|
||||
} catch(e) {
|
||||
if (e instanceof URIError) {
|
||||
return r;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frappe.get_raw_route_str = function(route) {
|
||||
if(!route)
|
||||
route = window.location.hash;
|
||||
|
||||
if(route.substr(0,1)=='#') route = route.substr(1);
|
||||
if(route.substr(0,1)=='!') route = route.substr(1);
|
||||
|
||||
route = $.map(route.split('/'), function(r) {
|
||||
try {
|
||||
return decodeURIComponent(r);
|
||||
} catch(e) {
|
||||
if (e instanceof URIError) {
|
||||
return r;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return route;
|
||||
}
|
||||
|
||||
}).join('/');
|
||||
frappe.get_route_str = function(route) {
|
||||
var rawRoute = frappe.get_raw_route_str()
|
||||
route = $.map(rawRoute.split('/'), frappe._decode_str).join('/');
|
||||
|
||||
return route;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue