Skip to content

Commit

Permalink
Merge pull request #68 from bootstraponline/lang_default
Browse files Browse the repository at this point in the history
Lang default
  • Loading branch information
lord committed May 19, 2014
2 parents 34c6c69 + 1e34156 commit cfa9f48
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions source/javascripts/app/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cfa9f48

Please sign in to comment.