Funktionalität hinzugefügt

This commit is contained in:
Max
2026-07-12 18:27:56 +02:00
parent 0fd38519b5
commit 2dc63aa8ec
2 changed files with 74 additions and 8 deletions
+55 -8
View File
@@ -7,16 +7,63 @@ function neueAufgabe(){
return; return;
} }
let newListItem = document.createElement('li'); saveData({'data' : inputBox.value, 'checked': false, 'index' : todoListContainer.childNodes.length});
newListItem.textContent = inputBox.value; loadData();
todoListContainer.appendChild(newListItem);
saveData();
inputBox.value = ''; inputBox.value = '';
} }
function saveData() function buildListItem(data, checked, index){
{ let listElement = document.createElement('li');
localStorage.setItem('data', todoListContainer.innerHTML); let checkBox = document.createElement('input');
checkBox.setAttribute('type', 'checkbox');
checkBox.setAttribute('id', `list-entry-${index}`);
checkBox.addEventListener('click', () => {saveData(); loadData();});
let listLable = document.createElement('label');
listLable.textContent = data;
listLable.setAttribute('for', `list-entry-${index}`);
listElement.appendChild(checkBox);
listElement.appendChild(listLable);
if (checked) {
checkBox.checked = true;
listLable.classList.add('checked-list-item');
} else {
let removeButton = document.createElement('button');
removeButton.innerHTML = '<i class="material-icons">delete</i>';
removeButton.addEventListener('click', () => {listElement.remove();saveData();loadData();});
listElement.appendChild(removeButton);
}
return listElement;
} }
todoListContainer.innerHTML = localStorage.getItem('data') || ''; function loadData(){
todoListContainer.innerHTML = '';
let data = JSON.parse(localStorage.getItem('data')) || [];
data.forEach((listItem, index) => {
todoListContainer.appendChild(buildListItem(listItem.data, listItem.checked, index));
});
}
function saveData(newItem = null)
{
let todoItems = [];
if (todoListContainer.childNodes.length !== 0) {
todoListContainer.childNodes.forEach((todoItem, index) => {
let data = todoItem.querySelector('label').textContent;
let checked = todoItem.querySelector('input').checked;
todoItems.push({data, checked, index});
});
}
if (newItem) {
todoItems.push(newItem);
}
localStorage.setItem('data', JSON.stringify(todoItems));
}
loadData();
+19
View File
@@ -57,4 +57,23 @@ html {
.schatten-farbverlauf { .schatten-farbverlauf {
background: linear-gradient(45deg, red, orange, yellow, green, blue, violet, pink); background: linear-gradient(45deg, red, orange, yellow, green, blue, violet, pink);
padding: 3px; padding: 3px;
}
.checked-list-item
{
text-decoration: line-through;
color: lightslategrey;
}
ul {
list-style: none;
}
li {
display: flex;
gap: .7em;
}
label {
flex-grow: 1;
} }