aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2018-01-06 11:44:22 +0100
committerhellekin <hellekin@cepheide.org>2018-01-06 11:45:16 +0100
commit9983f77c4af3b08b9f0ffd2041a8809e9652796a (patch)
treeaa4ab3cc68ec09ff4b9e0635c6b6a9515eea2bff
parent66caa9f870dbf7a6c4fb14827761942031b1cf0c (diff)
downloadlesoiseaux.io-9983f77c4af3b08b9f0ffd2041a8809e9652796a.tar.gz
Add cookie for lang
-rw-r--r--assets/js/ps-app.js37
1 files changed, 35 insertions, 2 deletions
diff --git a/assets/js/ps-app.js b/assets/js/ps-app.js
index 33f4f99..4903ab2 100644
--- a/assets/js/ps-app.js
+++ b/assets/js/ps-app.js
@@ -35,20 +35,53 @@
// Use ?lang=XX if available
var URLParams = new URLSearchParams(window.location.search);
if (URLParams.has('lang')) {
+ console.log('Setting lang from param to ' + URLParams.get('lang'))
setLang(URLParams.get('lang'))
+ } else if (C.get('lang')) {
+ console.log('Setting lang to ' + $.cookie('lang'))
+ setLang(C.get('lang'))
}
// Translate to target lang
function setLang(lang) {
if (lang == 'fr') {
- $('html').attr('lang', 'fr')
+ $('html').attr('lang', lang)
$('#lang-switch').html('EN').attr('title', 'Read in English')
} else {
- $('html').attr('lang', 'en')
+ lang = 'en'
+ $('html').attr('lang', lang)
$('#lang-switch').html('FR').attr('title', 'Lire en français')
}
+ C.set('lang', lang)
}
+
});
+ // Basic cookie functions
+ var C = {
+ set: function(name, value) {
+ // Make the cookie expire at the end of session
+ var cookie = name + '=' + encodeURIComponent(value) + ';path=/;domain=.lesoiseaux.io;secure'
+ document.cookie = cookie
+ return cookie
+ },
+ get: function(name) {
+ try {
+ var val = document.cookie.split(';')[0]
+ var key = name + '='
+ return (val.indexOf(key) == 0) ? decodeURIComponent(val.substr(key.length)) : null
+ } catch(e) {
+ return null
+ }
+ },
+ has: function(name) {
+ try {
+ return (document.cookie.split(';')[0].indexOf(name + '=') == 0)
+ } catch(e) {
+ return false
+ }
+ }
+ }
+
})($)