Skip to content

Commit 75869a5

Browse files
committed
Prevent reload page on language change, fixes ringcentral#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.
1 parent 215d773 commit 75869a5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

source/javascripts/app/lang.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,21 @@ under the License.
5555
});
5656

5757
}
58+
59+
// if we click on a language tab, activate that language
60+
$(function() {
61+
$("#lang-selector a").on("click", function() {
62+
var lang = $(this).data("language-name");
63+
var hash = window.location.hash;
64+
if (hash) hash = hash.replace(/^#+/, '');
65+
// do not reload the page every time the language is changed
66+
if (history) history.pushState({}, '', '?' + lang + '#' + hash);
67+
68+
activateLanguage(lang);
69+
return false;
70+
});
71+
window.onpopstate = function(event) {
72+
activateLanguage(window.location.search.substr(1));
73+
};
74+
});
5875
})(window);

0 commit comments

Comments
 (0)