forked from scratchdesignstudio/info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (50 loc) · 1.92 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// used tutorial here: http://www.w3schools.com/howto/howto_js_dropdown.asp
// when the user clicks the button for the dropdown menu to appear/disappear
function dropit(){
document.getElementById("dropOptions").classList.toggle("show");
}
// read hash and adjust accordingly on page load
window.onload = function(){
if(location.hash){
langSelect(location.hash.substring(1));
}
};
// close the dropdown menu if the user clicks outside it
window.onclick = function(e){
if(!e.target.matches('.dropdownButton')){
var items = document.getElementsByClassName("dropdown-content");
for(i=0;i<items.length;i++){
var openDropdown = items[i];
if(openDropdown.classList.contains('show')){
openDropdown.classList.remove('show');
}
}
}
};
// creates link objects for the dropdown
function prep(){
var dropdown = document.getElementById('dropOptions');
var option;
for (var i in l10n){
option = document.createElement('a');
option.dataset.locale = i;
option.onclick = function(){
var lang = this.getAttribute('data-locale');
location.hash = lang;
langSelect(lang);
};
option.innerHTML = l10n[i].language;
dropdown.appendChild(option);
}
}
// switch language according to its two-letter code
function langSelect(hash){
if(l10n[hash]){
var locale = l10n[hash];
document.getElementById('dropButton').innerHTML = l10n[hash].language + " ▾"; // set the button text to the selected option
document.getElementById('translatorCredit').innerHTML = locale.translator ? locale.translator : l10n['en'].translator;
document.getElementById('standardDescription').innerHTML = locale.standard ? locale.standard : l10n['en'].standard;
document.getElementById('uniqueDescription').innerHTML = locale.unique ? locale.unique : l10n['en'].unique;
document.getElementById('curatorString').innerHTML = locale.curators ? locale.curators : l10n['en'].curators;
}
}