diff --git a/Projects/ToDo_List/checked.png b/Projects/ToDo_List/checked.png new file mode 100644 index 000000000..d26596a25 Binary files /dev/null and b/Projects/ToDo_List/checked.png differ diff --git a/Projects/ToDo_List/icon.png b/Projects/ToDo_List/icon.png new file mode 100644 index 000000000..5655235c2 Binary files /dev/null and b/Projects/ToDo_List/icon.png differ diff --git a/Projects/ToDo_List/index.html b/Projects/ToDo_List/index.html new file mode 100644 index 000000000..8b9295c90 --- /dev/null +++ b/Projects/ToDo_List/index.html @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + ToDo List + + + +
+
+

ToDo List

+ +
+
+ + +
+ +
+ + + + \ No newline at end of file diff --git a/Projects/ToDo_List/notebook.gif b/Projects/ToDo_List/notebook.gif new file mode 100644 index 000000000..21f56255d Binary files /dev/null and b/Projects/ToDo_List/notebook.gif differ diff --git a/Projects/ToDo_List/script.js b/Projects/ToDo_List/script.js new file mode 100644 index 000000000..e8fce2c0e --- /dev/null +++ b/Projects/ToDo_List/script.js @@ -0,0 +1,96 @@ +const inputBox = document.getElementById("taskInput"); +const listContainer = document.getElementById("taskList"); + +function addTask() { + const taskText = inputBox.value.trim(); + if (taskText === "") { + alert("You must write something!"); + return; + } + + const tasks = listContainer.getElementsByTagName("li"); + console.log(tasks); + for (let i = 0; i < tasks.length; i++) { + if (tasks[i].childNodes[0].nodeValue.trim() === taskText) { + alert("Task already exists!"); + return; + } + } + + let li = document.createElement("li"); + li.textContent = taskText; + + const editBtn = document.createElement("button"); + editBtn.textContent = "✏️"; + editBtn.className = "editBtn"; + editBtn.onclick = function () { + const currentText = li.firstChild.nodeValue.trim(); + const newText = prompt("Edit your task:", currentText); + + if (newText && newText.trim() !== "") { + const trimmedNewText = newText.trim(); + + //existing logic for checking duplicates + for (let i = 0; i < tasks.length; i++) { + const otherText = tasks[i].childNodes[0].nodeValue.trim(); + if (tasks[i] !== li && otherText === trimmedNewText) { + alert("Task already exists!"); + return; + } + } + li.firstChild.nodeValue = trimmedNewText; + saveData(); + } + }; + li.appendChild(editBtn); + const deleteBtn = document.createElement("span"); + deleteBtn.innerHTML = "\u00d7"; + deleteBtn.onclick = function () { + li.remove(); + saveData(); + }; + li.appendChild(deleteBtn); + listContainer.appendChild(li); + inputBox.value = ""; + setAlertMessage("Todo item Created Successfully!"); + saveData(); + + //li.innerHTML = inputBox.value + ' '; + // li.innerHTML = inputBox.value; + // listContainer.appendChild(li); + + // let span = document.createElement("span"); + // span.innerHTML = "\u00d7"; + // li.appendChild(span); + // inputBox.value = ""; // Clear the input box after adding a task + // setAlertMessage("Todo item Created Successfully!"); + // saveData(); // Save the current state of the list to local storage +} + +listContainer.addEventListener( + "click", + function (e) { + if (e.target.tagName === "LI") { + e.target.classList.toggle("checked"); + saveData(); + } + // else if (e.target.tagName === "SPAN") { + // e.target.parentElement.remove(); + // saveData(); + // } + }, + false +); + +function saveData() { + localStorage.setItem("data", listContainer.innerHTML); +} + +function showTask() { + listContainer.innerHTML = localStorage.getItem("data"); +} +showTask(); + +function setAlertMessage(message) { + console.log(message); +} diff --git a/Projects/ToDo_List/styles.css b/Projects/ToDo_List/styles.css new file mode 100644 index 000000000..f74a1d61d --- /dev/null +++ b/Projects/ToDo_List/styles.css @@ -0,0 +1,136 @@ +* { + font-family:'Autour One', cursive; + margin: 0; + padding: 0; + box-sizing: border-box; +} +body{ + background-color: #78c1f3; + display: flex; + justify-content: center; + align-items: center; + min-height: 100vh; +} + +.container{ + background: #ffffff; + padding: 25px; + width: 500px; + border-radius: 15px; +} + +.header h1{ + font-family: 'Bungee Spice', cursive; + text-align: center; + font-size: 40px; +} + +.header{ + display: flex; + justify-content: center; + align-items: center; + margin-bottom: 20px; + padding-left:5px; +} + +.input-container{ + display: flex; + justify-content: center; + align-items: center; + background: #edeef0; + border-radius: 25px; + padding-left: 20px; + margin-bottom: 25px; +} + +.input-container input{ + flex: 1; + background: transparent; + border: none; + outline: none; + padding: 15px 0; + font-size: 20px; +} + +.input-container button{ + background-color:#FF5945; + border: none; + padding: 20px 40px; + border-radius: 25px; + cursor: pointer; + font-size: 18px; + color: #fff; + margin-left: 20px; + outline: none; +} + +ul li{ + list-style: none; + font-size: 20px; + padding: 12px 8px 12px 80px; + user-select: none; + cursor:pointer; + position: relative; +} + +ul li::before{ + content: ''; + position: absolute; + height: 28px; + width: 28px; + border-radius: 50%; + background-image: url('./unchecked.png'); + background-size: cover; + background-position: center; + top: 12px; + left: 8px; +} + +li{ + display:flex; + align-items:center; + border-radius:10px; + margin-bottom:10px; + background:#edeef0; + justify-content:space-between; +} + +ul li.checked{ + color:#555; + text-decoration: line-through; +} + +ul li.checked::before{ + background-image: url('./checked.png'); +} + +ul li span{ + position: absolute; + right: 0; + top: 5px; + width: 40px; + height: 40px; + font-size: 20px; + color: red; + line-height: 40px; + text-align: center; +} + +ul li span:hover{ + background-color: red; + color: white; + border-radius: 50%; + cursor: pointer; + transition: all 0.2s ease-in-out; +} + + +ul li .editBtn { + position: absolute; + right: 40px; + /* top: 5px; */ + background-color: transparent; + border: none; + font-size: 18px; + cursor: pointer; +} diff --git a/Projects/ToDo_List/unchecked.png b/Projects/ToDo_List/unchecked.png new file mode 100644 index 000000000..04a5c5fae Binary files /dev/null and b/Projects/ToDo_List/unchecked.png differ