Skip to content

Commit cfa9f48

Browse files
committed
Merge pull request #68 from bootstraponline/lang_default
Lang default
2 parents 34c6c69 + 1e34156 commit cfa9f48

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

source/javascripts/app/lang.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ under the License.
2121

2222
function activateLanguage(language) {
2323
if (!language) return;
24+
25+
var hash = window.location.hash;
26+
if (hash) hash = hash.replace(/^#+/, '');
27+
// do not reload the page every time the language is changed
28+
if (history) history.pushState({}, '', '?' + language + '#' + hash);
29+
2430
$("#lang-selector a").removeClass('active');
2531
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
2632
for (var i=0; i < languages.length; i++) {
@@ -48,25 +54,13 @@ under the License.
4854
// no language selected, so use the default
4955
activateLanguage(languages[0]);
5056
}
51-
52-
// if we click on a language tab, reload the page with that language in the URL
53-
$("#lang-selector a").bind("click", function() {
54-
window.location.replace("?" + $(this).data("language-name") + window.location.hash);
55-
return false;
56-
});
57-
5857
}
5958

6059
// if we click on a language tab, activate that language
6160
$(function() {
6261
$("#lang-selector a").on("click", function() {
63-
var lang = $(this).data("language-name");
64-
var hash = window.location.hash;
65-
if (hash) hash = hash.replace(/^#+/, '');
66-
// do not reload the page every time the language is changed
67-
if (history) history.pushState({}, '', '?' + lang + '#' + hash);
68-
69-
activateLanguage(lang);
62+
var language = $(this).data("language-name");
63+
activateLanguage(language);
7064
return false;
7165
});
7266
window.onpopstate = function(event) {

0 commit comments

Comments
 (0)