Commit 1e341563 authored by bootstraponline's avatar bootstraponline

Fix language on load

parent 34c6c69d
......@@ -21,6 +21,12 @@ under the License.
function activateLanguage(language) {
if (!language) return;
var hash = window.location.hash;
if (hash) hash = hash.replace(/^#+/, '');
// do not reload the page every time the language is changed
if (history) history.pushState({}, '', '?' + language + '#' + hash);
$("#lang-selector a").removeClass('active');
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
for (var i=0; i < languages.length; i++) {
......@@ -48,25 +54,13 @@ under the License.
// no language selected, so use the default
activateLanguage(languages[0]);
}
// if we click on a language tab, reload the page with that language in the URL
$("#lang-selector a").bind("click", function() {
window.location.replace("?" + $(this).data("language-name") + window.location.hash);
return false;
});
}
// if we click on a language tab, activate that language
$(function() {
$("#lang-selector a").on("click", function() {
var lang = $(this).data("language-name");
var hash = window.location.hash;
if (hash) hash = hash.replace(/^#+/, '');
// do not reload the page every time the language is changed
if (history) history.pushState({}, '', '?' + lang + '#' + hash);
activateLanguage(lang);
var language = $(this).data("language-name");
activateLanguage(language);
return false;
});
window.onpopstate = function(event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment