Skip to content

Commit

Permalink
Set nf_lang cookie after selected a language
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Jul 29, 2018
1 parent 1c41452 commit f7dee9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions themes/navy/layout/partial/after_footer.swig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!-- Scripts -->
<!-- Cookie -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.0/js.cookie.min.js"></script>
<!-- build:js build/js/main.js -->
{{ js('js/lang_select') }}
{{ js('js/toc') }}
Expand Down
9 changes: 6 additions & 3 deletions themes/navy/source/js/lang_select.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
(function() {
'use strict';

var Cookies = window.Cookies.noConflict();

function changeLang() {
var lang = this.value;
var canonical = this.dataset.canonical;
if (lang === 'en') lang = '';
if (lang) lang += '/';
var path = '/';
if (lang !== 'en') path += lang + '/';

location.href = '/' + lang + canonical;
Cookies.set('nf_lang', lang, { expires: 365 });
location.href = path + canonical;
}

document.getElementById('lang-select').addEventListener('change', changeLang);
Expand Down

0 comments on commit f7dee9a

Please sign in to comment.