mirror of
https://github.com/danbulant/api_docs
synced 2026-06-19 22:31:47 +00:00
Fixes some leakage in the language selector
Signed-off-by: Christopher Rogers <chrissrogers@gmail.com>
This commit is contained in:
parent
53db9d4a64
commit
68807cd485
1 changed files with 38 additions and 32 deletions
|
|
@ -13,40 +13,46 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
License for the specific language governing permissions and limitations
|
License for the specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
languages = []
|
(function (global) {
|
||||||
function activateLanguage(language) {
|
var languages = [];
|
||||||
$("#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();
|
|
||||||
|
|
||||||
}
|
global.setupLanguages = setupLanguages;
|
||||||
|
global.activateLanguage = activateLanguage;
|
||||||
|
|
||||||
function setupLanguages(l) {
|
function activateLanguage(language) {
|
||||||
languages = l;
|
$("#lang-selector a").removeClass('active');
|
||||||
currentLanguage = languages[0];
|
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
|
||||||
defaultLanguage = localStorage.getItem("language");
|
for (var i=0; i < languages.length; i++) {
|
||||||
|
$(".highlight." + languages[i]).hide();
|
||||||
if ((location.search.substr(1) != "") && (jQuery.inArray(location.search.substr(1), languages)) != -1) {
|
}
|
||||||
// the language is in the URL, so use that language!
|
$(".highlight." + language).show();
|
||||||
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
|
function setupLanguages(l) {
|
||||||
$("#lang-selector a").bind("click", function() {
|
var currentLanguage = l[0];
|
||||||
window.location.replace("?" + $(this).data("language-name") + window.location.hash);
|
var defaultLanguage = localStorage.getItem("language");
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
languages = l;
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
})(window);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue