mirror of
https://github.com/danbulant/api_docs
synced 2026-06-16 12:51:08 +00:00
Update language tabs to properly stay in section, and fix history navigation bug
This commit is contained in:
parent
7dead4c392
commit
b363be873b
1 changed files with 14 additions and 5 deletions
|
|
@ -22,17 +22,25 @@ under the License.
|
||||||
function activateLanguage(language) {
|
function activateLanguage(language) {
|
||||||
if (!language) return;
|
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").removeClass('active');
|
||||||
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
|
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
|
||||||
for (var i=0; i < languages.length; i++) {
|
for (var i=0; i < languages.length; i++) {
|
||||||
$(".highlight." + languages[i]).hide();
|
$(".highlight." + languages[i]).hide();
|
||||||
}
|
}
|
||||||
$(".highlight." + language).show();
|
$(".highlight." + language).show();
|
||||||
|
|
||||||
|
// scroll to the new location of the position
|
||||||
|
$(window.location.hash).get(0).scrollIntoView(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if a button is clicked, add the state to the history
|
||||||
|
function pushURL(language) {
|
||||||
|
if (!history) { return; }
|
||||||
|
var hash = window.location.hash;
|
||||||
|
if (hash) {
|
||||||
|
hash = hash.replace(/^#+/, '');
|
||||||
|
}
|
||||||
|
history.pushState({}, '', '?' + language + '#' + hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupLanguages(l) {
|
function setupLanguages(l) {
|
||||||
|
|
@ -60,6 +68,7 @@ under the License.
|
||||||
$(function() {
|
$(function() {
|
||||||
$("#lang-selector a").on("click", function() {
|
$("#lang-selector a").on("click", function() {
|
||||||
var language = $(this).data("language-name");
|
var language = $(this).data("language-name");
|
||||||
|
pushURL(language);
|
||||||
activateLanguage(language);
|
activateLanguage(language);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue