mirror of
https://github.com/placeholder-soft/prodigyapi.git
synced 2026-03-29 22:36:53 +08:00
Now, Slate will use localStorage to track the last selected language, so if the user visits again with no language in the URL, they will be redirected to the last language they used. This update also fixes a bug with how the layout inserts the language names into the javascript. Previously, they would be, (for some inane reason) arrays within arrays. It is now just an array. Whoever wrote that previous code was clearly a fool.
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
/*
|
|
Copyright 2008-2013 Concur Technologies, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
not use this file except in compliance with the License. You may obtain
|
|
a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
License for the specific language governing permissions and limitations
|
|
under the License.
|
|
*/
|
|
languages = []
|
|
function activateLanguage(language) {
|
|
$("#lang-selector a").removeClass('active');
|
|
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
|
|
for (var i=0; i < languages.length; i++) {
|
|
$(".highlight." + languages[i]).hide();
|
|
}
|
|
$(".highlight." + language).show();
|
|
|
|
}
|
|
|
|
function setupLanguages(l) {
|
|
languages = l;
|
|
currentLanguage = languages[0];
|
|
defaultLanguage = localStorage.getItem("language");
|
|
|
|
if ((location.search.substr(1) != "") && (jQuery.inArray(location.search.substr(1), languages)) != -1) {
|
|
// the language is in the URL, so use that language!
|
|
activateLanguage(location.search.substr(1));
|
|
|
|
// set this language as the default for next time, if the URL has no language
|
|
localStorage.setItem("language", location.search.substr(1));
|
|
} else if ((defaultLanguage !== null) && (jQuery.inArray(defaultLanguage, languages) != -1)) {
|
|
// the language was the last selected one saved in localstorage, so use that language!
|
|
activateLanguage(defaultLanguage);
|
|
} else {
|
|
// 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;
|
|
});
|
|
|
|
}
|