refactor: var und klassenanmen vereinheitlicht

This commit is contained in:
Technoir committed 2026-10-15 14:10:15 +02:00
1 parent a007e62c8e
commit 2c9a205c1e
4 files changed
+28 -28

No files matched your search

@@ -10,33 +10,33 @@ export class ShoppingItem extends HTMLElement {
if (this._rendered) return;
console.log(`rendering element shopping-item`);
const checkboxDone = document.createElement("input");
const spanText = document.createElement("span");
const spanName = document.createElement("span");
const spanAmount = document.createElement("span");
const buttonDelete = document.createElement("button");
const doneCheckbox = document.createElement("input");
const textSpan = document.createElement("span");
const nameSpan = document.createElement("span");
const amountSpan = document.createElement("span");
const deleteButton = document.createElement("button");
checkboxDone.classList.add("item__checkboxDone");
checkboxDone.setAttribute("type", "checkbox");
checkboxDone.setAttribute("autocomplete", "off");
checkboxDone.checked = this.getAttribute("is-checked") === "true";
doneCheckbox.classList.add("item__doneCheckbox");
doneCheckbox.setAttribute("type", "checkbox");
doneCheckbox.setAttribute("autocomplete", "off");
doneCheckbox.checked = this.getAttribute("is-checked") === "true";
spanText.classList.add("item__text");
textSpan.classList.add("item__text");
spanName.classList.add("item__itemName");
spanAmount.classList.add("item__itemAmount");
nameSpan.classList.add("item__name");
amountSpan.classList.add("item__amount");
spanName.textContent = this.getAttribute("item-name");
spanAmount.textContent = this.getAttribute("item-amount");
nameSpan.textContent = this.getAttribute("item-name");
amountSpan.textContent = this.getAttribute("item-amount");
buttonDelete.classList.add("item__buttonDeleteItem");
buttonDelete.setAttribute("type", "button ");
buttonDelete.textContent = "Löschen";
deleteButton.classList.add("item__deleteButton");
deleteButton.setAttribute("type", "button ");
deleteButton.textContent = "Löschen";
spanText.append(spanName, spanAmount);
textSpan.append(nameSpan, amountSpan);
this.append(checkboxDone, spanText, buttonDelete);
this.append(doneCheckbox, textSpan, deleteButton);
this._rendered = true;
}
@@ -46,10 +46,10 @@ export class ShoppingItem extends HTMLElement {
if (newVal == oldVal) return;
switch (name) {
case "item-name":
this.querySelector(".item__itemName").textContent = newVal;
this.querySelector(".item__name").textContent = newVal;
break;
case "item-amount":
this.querySelector(".item__itemAmount").textContent = newVal;
this.querySelector(".item__amount").textContent = newVal;
break;
default:
break;
@@ -72,7 +72,7 @@ function init() {
//event delegation ist schon geil
document.querySelector(".displayedList").addEventListener("click", (event) => {
if (event.target.matches(".item__buttonDeleteItem")) {
if (event.target.matches(".item__deleteButton")) {
deleteItem(event.target.closest("li"));
} else if (event.target.matches(".category__deleteButton")) {
@@ -86,8 +86,8 @@ function init() {
const shoppingItemElement = event.target.closest("shopping-item");
const id = event.target.closest("li").dataset.id;
let itemName = shoppingItemElement.querySelector(".item__itemName").textContent;
let itemAmount = shoppingItemElement.querySelector(".item__itemAmount").textContent;
let itemName = shoppingItemElement.querySelector(".item__name").textContent;
let itemAmount = shoppingItemElement.querySelector(".item__amount").textContent;
/*
* { name: "", value: "", class: "", attr: ""}
*/
@@ -126,7 +126,7 @@ function init() {
});
document.querySelector(".displayedList").addEventListener("change", (e) => {
if (e.target.matches(".item__checkboxDone")) {
if (e.target.matches(".item__doneCheckbox")) {
const item = e.target.closest("li");
e.target.closest("shopping-item").setAttribute("is-checked", e.target.checked);
api.editItem(item.dataset.id, { isDone: e.target.checked });
@@ -20,7 +20,7 @@ export async function editElement({ element, fields, apiCall, id, onSuccess, err
});
formElement.addEventListener("click", (e) => {
if (e.target.matches(".editForm__buttonAbort")) abortEditing(formElement, element);
if (e.target.matches(".editForm__abortButton")) abortEditing(formElement, element);
})
formElement.addEventListener("keydown", (e) => {
@@ -16,11 +16,11 @@ export function createEditForm(fields) {
});
abortButton.setAttribute("type", "button");
abortButton.classList.add("editForm__buttonAbort");
abortButton.classList.add("editForm__abortButton");
abortButton.textContent = "Abbrechen";
saveButton.textContent = "Speichern";
saveButton.classList.add("editForm__buttonSave");
saveButton.classList.add("editForm__saveButton");
saveButton.setAttribute("type", "submit");