From cf97d2c4edb3be6a914987e044510479cd63edac Mon Sep 17 00:00:00 2001 From: Naeltard Date: Thu, 2 Apr 2015 04:16:23 +0200 Subject: [PATCH] lang switcher ability --- lib/system | 2 +- slingit/page/default_page/default_page.php | 5 ++-- slingit/page/default_page/js/lang_switcher.js | 30 +++++++++++++++++++ .../page/default_page/tpl/default_page.tpl | 7 +++-- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 slingit/page/default_page/js/lang_switcher.js diff --git a/lib/system b/lib/system index fe3b624..49e18f1 160000 --- a/lib/system +++ b/lib/system @@ -1 +1 @@ -Subproject commit fe3b6242a618bee42ade7ad08338d8dd7d1f16a6 +Subproject commit 49e18f1c3cf61c62952a3be957f1093a88cb1782 diff --git a/slingit/page/default_page/default_page.php b/slingit/page/default_page/default_page.php index d003cef..2da6b9b 100644 --- a/slingit/page/default_page/default_page.php +++ b/slingit/page/default_page/default_page.php @@ -8,7 +8,8 @@ class default_page extends \SYSTEM\PAGE\Page { //''. //''. ''. - ''; + ''. + ''; } @@ -23,8 +24,8 @@ class default_page extends \SYSTEM\PAGE\Page { $vars = array(); $vars['js'] = $this->js(); $vars['css'] = $this->css(); + $vars['PATH_LOCAL_IMG'] = \SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'page/img/'); - //$vars['content'] = $this->generate_elementlist(); return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/tpl/default_page.tpl'), $vars); } } \ No newline at end of file diff --git a/slingit/page/default_page/js/lang_switcher.js b/slingit/page/default_page/js/lang_switcher.js new file mode 100644 index 0000000..e7ce427 --- /dev/null +++ b/slingit/page/default_page/js/lang_switcher.js @@ -0,0 +1,30 @@ +function switchLocale(locale){ + reloadWithQueryStringVars({"_lang": locale}); +} + +function reloadWithQueryStringVars (queryStringVars) { + var existingQueryVars = location.search ? location.search.substring(1).split("&") : [], + currentUrl = location.search ? location.href.replace(location.search,"") : location.href, + newQueryVars = {}, + newUrl = currentUrl.replace(/#/g, "#") + "?"; + if(existingQueryVars.length > 0) { + for (var i = 0; i < existingQueryVars.length; i++) { + var pair = existingQueryVars[i].split("="); + newQueryVars[pair[0]] = pair[1]; + } + } + if(queryStringVars) { + for (var queryStringVar in queryStringVars) { + newQueryVars[queryStringVar] = queryStringVars[queryStringVar]; + } + } + if(newQueryVars) { + for (var newQueryVar in newQueryVars) { + newUrl += newQueryVar + "=" + newQueryVars[newQueryVar] + "&"; + } + newUrl = newUrl.substring(0, newUrl.length-1); + window.location.href = newUrl; + } else { + window.location.href = location.href; + } +} diff --git a/slingit/page/default_page/tpl/default_page.tpl b/slingit/page/default_page/tpl/default_page.tpl index e89e246..00936d7 100644 --- a/slingit/page/default_page/tpl/default_page.tpl +++ b/slingit/page/default_page/tpl/default_page.tpl @@ -22,9 +22,10 @@
\ No newline at end of file