Skip to content
Browse files

BUG Cleaner handling of querystring arguments when selecting locale

  • Loading branch information...
1 parent 709e2fd commit 22c5098f8e27e42d7124e22b2172df1f88c7222e @tractorcow tractorcow committed with chillu Mar 21, 2013
Showing with 14 additions and 5 deletions.
  1. +1 −1 code/controller/TranslatableCMSMainExtension.php
  2. +13 −4 javascript/CMSMain.Translatable.js
View
2 code/controller/TranslatableCMSMainExtension.php
@@ -44,7 +44,7 @@ function init() {
$req->param('Action'),
$req->param('ID'),
$req->param('OtherID'),
- '?' . http_build_query($getVars)
+ ($query = http_build_query($getVars)) ? "?$query" : null
));
}
}
View
17 javascript/CMSMain.Translatable.js
@@ -36,10 +36,19 @@
this._super();
},
onchange: function(e) {
- var url = $.path.addSearchParams(
- document.location.href.replace(/locale=[^&]*/, ''),
- {locale: $(e.target).val()}
- );
+ // Get new locale code
+ locale = {locale: $(e.target).val()};
+
+ // Check existing url
+ search = /locale=[^&]*/;
+ url = document.location.href;
+ if(url.match(search)) {
+ // Replace locale code
+ url = url.replace(search, $.param(locale));
+ } else {
+ // Add locale code
+ url = $.path.addSearchParams(url, locale);
+ }
$('.cms-container').loadPanel(url);
return false;
}

0 comments on commit 22c5098

Please sign in to comment.
Something went wrong with that request. Please try again.