mirror of
https://github.com/danbulant/api_docs
synced 2026-05-24 12:27:29 +00:00
Prevent reload page on language change, fixes #36
- Uses onpopstate to handle users pressing back buttons - Switches the query string and changes the language without reloading. - Thanks to @bootstraponline for some of the code in this commit.
This commit is contained in:
parent
215d773fcf
commit
75869a561f
1 changed files with 17 additions and 0 deletions
|
|
@ -55,4 +55,21 @@ under the License.
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
window.onpopstate = function(event) {
|
||||||
|
activateLanguage(window.location.search.substr(1));
|
||||||
|
};
|
||||||
|
});
|
||||||
})(window);
|
})(window);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue