mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge query strings in $.path rather than duplicating
Fixes common duplications like ?locale=en_US&locale=en_US, triggered e.g. by gridfield's showDetailView(). See https://github.com/silverstripe/silverstripe-translatable/issues/154
This commit is contained in:
parent
8ad172cff5
commit
41031900f9
@ -160,11 +160,32 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
//Add search (aka query) params to the specified url.
|
//Add search (aka query) params to the specified url.
|
||||||
|
// 2013-12-06 ischommer: Customized to merge with existing keys
|
||||||
addSearchParams: function( url, params ) {
|
addSearchParams: function( url, params ) {
|
||||||
var u = path.parseUrl( url ),
|
var u = path.parseUrl( url ),
|
||||||
p = ( typeof params === "object" ) ? $.param( params ) : params,
|
params = ( typeof params === "string" ) ? path.convertSearchToArray( params ) : params,
|
||||||
s = u.search || "?";
|
newParams = $.extend( path.convertSearchToArray( u.search ), params );
|
||||||
return u.hrefNoSearch + s + ( s.charAt( s.length - 1 ) !== "?" ? "&" : "" ) + p + ( u.hash || "" );
|
return u.hrefNoSearch + '?' + $.param( newParams ) + ( u.hash || "" );
|
||||||
|
},
|
||||||
|
|
||||||
|
// 2013-12-06 ischommer: Added to allow merge with existing keys
|
||||||
|
getSearchParams: function(url) {
|
||||||
|
var u = path.parseUrl( url );
|
||||||
|
return path.convertSearchToArray( u.search );
|
||||||
|
},
|
||||||
|
|
||||||
|
// Converts query strings (foo=bar&baz=bla) to a hash.
|
||||||
|
// TODO Handle repeating elements (e.g. arr[]=one&arr[]=two)
|
||||||
|
// 2013-12-06 ischommer: Added to allow merge with existing keys
|
||||||
|
convertSearchToArray: function(search) {
|
||||||
|
var params = {},
|
||||||
|
search = search.replace( /^\?/, '' ),
|
||||||
|
parts = search ? search.split( '&' ) : [], i, tmp;
|
||||||
|
for(i=0; i < parts.length; i++) {
|
||||||
|
tmp = parts[i].split( '=' );
|
||||||
|
params[tmp[0]] = tmp[1];
|
||||||
|
}
|
||||||
|
return params;
|
||||||
},
|
},
|
||||||
|
|
||||||
convertUrlToDataUrl: function( absUrl ) {
|
convertUrlToDataUrl: function( absUrl ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user