jimsite/scripts/lists.js
2022-01-29 02:09:47 -05:00

83 lines
3.3 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 &#11148;</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 += `&ldquo;${quote.quote}&rdquo;<br>`;
//Add the text of the quote.
if(quote.hasOwnProperty("card") && !quote.hasOwnProperty("quotee")){
quote.quotee="";
//If a flavor text doesn't have a quotee, then don't write "Unknown".
}
item += `&nbsp;&mdash; ${quote.hasOwnProperty("quotee") ? quote.quotee : "Unknown"}`;
//Add the quotee's name, or "Unknown" if one is not specified.
if(quote.hasOwnProperty("source")){
if(quote.hasOwnProperty("quotee") && quote.quotee!=""){
item += ", "
//Unless there is no quotee, separate the quotee from the source with ", "
}
item += quote.source;
//Add the source if the quote has one.
}
if(quote.hasOwnProperty("card")){
if(quote.quotee!=""||quote.hasOwnProperty("source")){
item += `, `;
//Separate quotee or source from card title with ", "
}
item += `<a target='_blank' href='https://gatherer.wizards.com/pages/card/Details.aspx?multiverseid=${quote.multiverseid}'>${quote.card}</a> (Magic: the Gathering)`
}
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>`;
}
}