Skip to content

Commit

Permalink
el
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderG2 authored May 5, 2024
1 parent 1cfb0a1 commit a435bec
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions website/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,36 @@ function openRecipesPrep() {
openRecipes(document.getElementById("select").value);
}

function el(tagName, attributes) {
const element = document.createElement(tagName);
for (const [key, value] of Object.entries(attributes)) {
if (key === "style") {
for (const [key2, value2] of Object.entries(value)) {
element.style[key2] = value2;
}
} else {
element[key] = value;
}
/*if (!("style." in element[key])) {
element[key] = value;
} else {
element.style[key.split("style.")[1]] = value;
}*/
}
return element;
}

async function openRecipes(JSONFile) {
const response = await fetch(`../data/${JSONFile}.json`);
const data = await response.json();
buttonsDiv.innerHTML = "";
for (const [recipe, ingredients] of Object.entries(data)) {
const subdiv = document.createElement("div");
/*const subdiv = document.createElement("div");
subdiv.style.display = "flex";
subdiv.style.flexDirection = "column";*/
const subdiv = el("div", {style: {display: "flex", flexDirection: "column"}})
const subsubdiv = document.createElement("div");
const text = document.createElement("p");
text.textContent = recipe;
text.className = "noMP";
text.id = "text";
const text = el("p", {textContent: recipe, className: "noMP", id: "text"});
const addButton = document.createElement("button");
addButton.textContent = "+";
addButton.onclick = () => {
Expand Down Expand Up @@ -157,8 +176,6 @@ async function openRecipes(JSONFile) {
expandButton.querySelector("img").src = "down.svg";
}
};
subdiv.style.display = "flex";
subdiv.style.flexDirection = "column";
subsubdiv.style.display = "flex";
subsubdiv.style.flexDirection = "row";
subsubdiv.style.width = "100%";
Expand Down

0 comments on commit a435bec

Please sign in to comment.