Skip to content

Commit

Permalink
Commenting and minor fix for the new JSON games menu implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Jul 17, 2024
1 parent b530231 commit 5a6a857
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions views/assets/js/common-16451543478.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,13 @@ addEventListener("DOMContentLoaded", () => {
Object.freeze(goProx);
});

(async () => {
// Load in relevant JSON files used to organize large sets of data.
// This first one is for links, whereas the rest are for navigation menus.
(async () => {
const huLinks = await fetch("/assets/json/links.json", {mode: "same-origin"}).then(response => response.json());

for (let item of Object.entries(huLinks))
// Replace all placeholder links with the corresponding entry in huLinks.
(document.getElementById(item[0]) || {}).href = item[1];

const navLists = {
Expand All @@ -421,9 +422,11 @@ addEventListener("DOMContentLoaded", () => {
let navList = document.getElementById(listId);

if(navList) {

// List items stored in JSON format will be returned as a JS object.
const data = await fetch(`/assets/json/${filename}.json`, {mode: "same-origin"}).then(response => response.json());

// Load the JSON lists into specific HTML parent elements as groups of
// child elements, if the parent element is found.
switch (filename) {
case "emu-nav":
case "emulib-nav":
Expand All @@ -433,15 +436,20 @@ addEventListener("DOMContentLoaded", () => {
"emulib-nav": "emulib",
"h5-nav": "h5g"
},

dir = dirnames[filename],
clickHandler = parser => e => {

// Add a little functionality for each list item when clicked on.
clickHandler = (parser, a) => e => {
if (e.target == a || e.target.tagName != "A") {
e.preventDefault();
parser();
}
};

for (let item of data) {
// Load each item as an anchor tag with an image, heading,
// description, and click event listener.
let a = document.createElement("a");
a.href = "#";

Expand All @@ -461,13 +469,15 @@ addEventListener("DOMContentLoaded", () => {
a.appendChild(title);
a.appendChild(desc);

// Which function is used for the click event is determined by
// the corresponding location/index in the dirnames object.
let functionsList = [
() => goFrame(item.path),
() => goFrame("/?eg&core=" + item.core + "&rom=" + item.rom),
() => item.custom ? goProx[item.custom](true) : goFrame("/archive/g/" + item.path, item.nolag)
];

a.addEventListener("click", clickHandler(functionsList[Object.values(dirnames).indexOf(dir)]));
a.addEventListener("click", clickHandler(functionsList[Object.values(dirnames).indexOf(dir)], a));

navList.appendChild(a);
}
Expand All @@ -476,6 +486,8 @@ addEventListener("DOMContentLoaded", () => {

case "flash-nav":
for (let item of data) {
// Load each item as an anchor tag with a short title and click
// event listener.
let a = document.createElement("a");
a.href = "#";
a.textContent = item.slice(0, -4);
Expand Down

0 comments on commit 5a6a857

Please sign in to comment.