-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (57 loc) · 2.16 KB
/
index.js
File metadata and controls
58 lines (57 loc) · 2.16 KB
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
57
58
console.log("JavaScript Loaded");
loadLanguages();
async function loadLanguages(){
var langResponse = await fetch("./Languages/Languages.json");
var languages = await langResponse.json();
var select = document.getElementById("languageSelector");
var option = document.createElement("option");
option.value = "Default";
option.id = "default";
option.innerHTML = "Select a Language";
select.appendChild(option);
for(language in languages){
var option = document.createElement("option");
option.innerHTML = languages[language];
option.value = language;
select.appendChild(option);
};
};
function populateSection(item){
section.innerHTML = "";
section.innerHTML += "<h1 id=\"sectionHeading\">" + item.name + "</h1>";
section.innerHTML += "<p>Syntax</p>"
section.innerHTML += "<code>" + String(item.code) + "</code>";
if(item.examples.length > 1){
section.innerHTML += "<h2>Examples</h2>"
}
else{
section.innerHTML += "<h2>Example</h2>"
}
//section.innerHTML += "<code>" + String(item.examples) + "</code>";
for(example in item.examples){
section.innerHTML += "<p>" + item.examples[example].description + "</p>";
section.innerHTML += "<code>" + item.examples[example].code + "</code>";
}
};
async function changeLanguage(){
var section = document.getElementById("section");
section.innerHTML = "<h1 id=\"sectionHeading\">Select code snippet from the menu</h1>";
document.getElementById("default").disabled = "disabled";
response = await fetch(`./Languages/${document.getElementById("languageSelector").value}.json`);
json = await response.json();
var list = document.getElementById("list");
list.innerHTML = "";
for(item in json){
var li = document.createElement('li');
li.addEventListener("click", function(){
for(item in json){
if(json[item].name == this.innerHTML){
//console.log(json[item].code);
populateSection(json[item]);
};
};
});
li.innerHTML = json[item].name;
list.appendChild(li);
};
};