diff options
author | Matěj Cepl <mcepl@redhat.com> | 2012-10-23 22:10:27 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2012-10-24 00:20:03 +0200 |
commit | 36e29fcc0b26dc0364ec962ff718810a7cb6a80f (patch) | |
tree | fcc366359b683fec07fe2b251fb4a8ac17b9684c /hesla.js | |
parent | f50d0336db9052cb0afa465ab3a5f84662970f8a (diff) | |
download | hesla-36e29fcc0b26dc0364ec962ff718810a7cb6a80f.tar.gz |
Switching language version.
Fix #76
Diffstat (limited to 'hesla.js')
-rw-r--r-- | hesla.js | 37 |
1 files changed, 35 insertions, 2 deletions
@@ -1,7 +1,6 @@ if (!Date.prototype.toISODateString) { (function() { - function pad(number) { var r = String(number); if ( r.length === 1 ) { @@ -17,9 +16,43 @@ if (!Date.prototype.toISODateString) { }; }()); +} + +const today_id = new Date().toISODateString(); + +// Switch langauge +function lang_reload() { + var new_basename = "index.html"; + var new_url = "NOURL"; + if (localStorage.language && (localStorage.language === "de")) { + new_basename = "index_de.html"; + } + + var old_basename = window.location.pathname.split("/").slice(-1); + if ((old_basename !== new_basename) || (window.location.pathname.length === 0)) { + new_url = window.location.href.replace(/(index[a-zA-Z-_]*\.html)?$/, + new_basename); + } + + if (window.location.href !== new_url) { + window.location.assign(new_url); + } } -var today_id = new Date().toISODateString(); +document.getElementById("czech_nav").addEventListener("click", + function(evt) { + localStorage.language = "cs"; + lang_reload(); + }, false); + +document.getElementById("german_nav").addEventListener("click", + function(evt) { + localStorage.language = "de"; + lang_reload(); + }, false); + +lang_reload(); + var today_losungen = document.getElementById(today_id); today_losungen.style.display = "block"; |