Merge pull request #591 from NyaaPantsu/fix-logged-in-languages
Fix #590
Cette révision appartient à :
révision
d9511b8efb
3 fichiers modifiés avec 33 ajouts et 32 suppressions
31
public/js/languages.js
Fichier normal
31
public/js/languages.js
Fichier normal
|
@ -0,0 +1,31 @@
|
|||
function loadLanguages() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var selector = document.getElementById("bottom_language_selector");
|
||||
selector.hidden = false
|
||||
/* Response format is
|
||||
* { "current": "(user current language)",
|
||||
* "languages": {
|
||||
* "(language_code)": "(language_name"),
|
||||
* }} */
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
for (var language in response.languages) {
|
||||
if (!response.languages.hasOwnProperty(language)) continue;
|
||||
|
||||
var opt = document.createElement("option")
|
||||
opt.value = language
|
||||
opt.innerHTML = response.languages[language]
|
||||
if (language == response.current) {
|
||||
opt.selected = true
|
||||
}
|
||||
|
||||
selector.appendChild(opt)
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.open("GET", "/language?format=json", true)
|
||||
xhr.send()
|
||||
}
|
||||
|
||||
loadLanguages();
|
|
@ -39,35 +39,4 @@ window.onload = function() {
|
|||
var shiftWindow = function() { scrollBy(0, -70) };
|
||||
if (location.hash) shiftWindow();
|
||||
window.addEventListener("hashchange", shiftWindow);
|
||||
};
|
||||
function loadLanguages() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var selector = document.getElementById("bottom_language_selector");
|
||||
selector.hidden = false
|
||||
/* Response format is
|
||||
* { "current": "(user current language)",
|
||||
* "languages": {
|
||||
* "(language_code)": "(language_name"),
|
||||
* }} */
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
for (var language in response.languages) {
|
||||
if (!response.languages.hasOwnProperty(language)) continue;
|
||||
|
||||
var opt = document.createElement("option")
|
||||
opt.value = language
|
||||
opt.innerHTML = response.languages[language]
|
||||
if (language == response.current) {
|
||||
opt.selected = true
|
||||
}
|
||||
|
||||
selector.appendChild(opt)
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.open("GET", "/language?format=json", true)
|
||||
xhr.send()
|
||||
}
|
||||
|
||||
loadLanguages();
|
||||
};
|
|
@ -95,6 +95,7 @@
|
|||
<noscript>
|
||||
<center><a href="{{ .URL.Parse "/language" }}">{{ T "change_language" }}</a></center>
|
||||
</noscript>
|
||||
<script type="text/javascript" charset="utf-8" src="{{.URL.Parse "/js/languages.js"}}"></script>
|
||||
{{end}}
|
||||
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
|
|
Référencer dans un nouveau ticket