From ad791ca5d8d8c67e13448f6a2e9c79b2b637d65e Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 21 Mar 2013 16:01:03 +1300 Subject: [PATCH] BUG Cleaner handling of querystring arguments when selecting locale --- .../controller/TranslatableCMSMainExtension.php | 2 +- javascript/CMSMain.Translatable.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/code/controller/TranslatableCMSMainExtension.php b/code/controller/TranslatableCMSMainExtension.php index ba04454..88ae4bd 100644 --- a/code/controller/TranslatableCMSMainExtension.php +++ b/code/controller/TranslatableCMSMainExtension.php @@ -40,7 +40,7 @@ class TranslatableCMSMainExtension extends Extension { $req->param('Action'), $req->param('ID'), $req->param('OtherID'), - '?' . http_build_query($getVars) + ($query = http_build_query($getVars)) ? "?$query" : null )); } } diff --git a/javascript/CMSMain.Translatable.js b/javascript/CMSMain.Translatable.js index 727f357..196c17d 100755 --- a/javascript/CMSMain.Translatable.js +++ b/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; }