66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
var lists = JSON.parse(loadFile("data/lists.json"));
|
|
//Load list data from lists.json file using vendor loadfile.js.
|
|
var list_id = $("#query-list")[0].innerText;
|
|
//Get list id from <var> tag created in query-handler.php.
|
|
var list = null;
|
|
if(lists.hasOwnProperty(list_id)){
|
|
list = lists[list_id];
|
|
} else {
|
|
list = lists["master"];
|
|
//If the list id in the query is invalid, go back to the main list.
|
|
}
|
|
|
|
$("#list-title")[0].innerText = list.title;
|
|
if(list.hasOwnProperty("description")){
|
|
$("#list-description")[0].innerText = list.description;
|
|
}
|
|
|
|
if(list.hasOwnProperty("ordered") && list.ordered){
|
|
$("#list-container")[0].innerHTML += "<ol id='list'></ol>";
|
|
//Create an ordered list of the list has attribute "ordered":true.
|
|
} else {
|
|
$("#list-container")[0].innerHTML += "<ul id='list'></ul>";
|
|
//By default, lists are unordered.
|
|
}
|
|
|
|
$("#lists")[0].innerHTML += "<br /><a id='list-return-link' href='index.php?page=lists&list=master'>Return to Master List ⮌</a>";
|
|
//Add a return link to the bottom of the article.
|
|
|
|
|
|
switch(list_id){
|
|
case "master":
|
|
for(id in lists){
|
|
var item = `<li><a href='index.php?page=lists&list=${id}'>${lists[id].title}</a></li>`;
|
|
$("#list")[0].innerHTML += item;
|
|
//The Master List contains a link to every other list in the JSON file.
|
|
}
|
|
$("#list-return-link")[0].style.display="none";
|
|
//"Return to Master List" link is not needed on Master List itself.
|
|
break;
|
|
case "quotes":
|
|
for(quote of list.list){
|
|
var item = "<p>";
|
|
if(quote.hasOwnProperty("title")){
|
|
item += `<b>${quote.title}</b><br />`;
|
|
//Add a title if the quote has one (e.g. "The Litany Against Fear").
|
|
}
|
|
item += `"${quote.quote}"<br>`;
|
|
//Add the text of the quote.
|
|
item += ` — ${quote.hasOwnProperty("quotee") ? quote.quotee : "Unknown"}`;
|
|
//Add the quotee's name, or "Unknown" if one is not specified.
|
|
if(quote.hasOwnProperty("source")){
|
|
item += `, ${quote.source}`;
|
|
//Add the source if the quote has one.
|
|
}
|
|
item += "</p><hr />";
|
|
//Delimit the quotes with a horizontal rule.
|
|
$("#list")[0].innerHTML += item;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
for(item of list.list){
|
|
$("#list")[0].innerHTML += `<li>${item}</li>`;
|
|
}
|
|
}
|