-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from salixes/dev-todolist
added L12 - Todo List
- Loading branch information
Showing
8 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" | ||
crossorigin="anonymous"></script> | ||
<title>Applet 6 - Todo List</title> | ||
|
||
<style> | ||
.applet-container { | ||
margin-top: 1rem; | ||
margin-left: 2rem; | ||
} | ||
|
||
.completed { | ||
text-decoration: line-through; | ||
color: gray; | ||
} | ||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
<nav class="navbar navbar-expand-lg bg-body-tertiary"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand" href="../index.html">Home</a> | ||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" | ||
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" | ||
aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"> | ||
<li class="nav-item dropdown"> | ||
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" | ||
aria-expanded="false"> | ||
Applets | ||
</a> | ||
<ul class="dropdown-menu"> | ||
<li><a class="dropdown-item" href="../L06-AppletGallery/L06_Applet1.html">Applet 1</a></li> | ||
<li><a class="dropdown-item" href="../L07-LeafletMap/L07_Applet2.html">Applet 2</a></li> | ||
<li><a class="dropdown-item" href="../L08-EventLogger/L08_Applet3.html">Applet 3</a></li> | ||
<li><a class="dropdown-item" href="../L09-DynamicElements/L09_Applet4.html">Applet 4</a> | ||
</li> | ||
<li><a class="dropdown-item" href="../L11-OpenWeather/L11_Applet5.html">Applet 5</a></li> | ||
<li><a class="dropdown-item" href="../L12-TodoList/L12_Applet6.html">Applet 6</a></li> | ||
|
||
</ul> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link disabled" aria-disabled="true">Disabled</a> | ||
</li> | ||
</ul> | ||
<form class="d-flex" role="search"> | ||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> | ||
<button class="btn btn-outline-success" type="submit">Search</button> | ||
</form> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<div class="container-fluid" style="max-width: 40%;"> | ||
<h2 class="text-center">To-Do List</h2> | ||
<div class="input-group mb-4"> | ||
<textarea class="form-control" id="todoInput" placeholder="Add a new task" rows="3"></textarea> | ||
<div class="input-group-append" style="margin-left: .5rem;"> | ||
<button class="btn btn-primary" id="addButton">Add</button> | ||
</div> | ||
</div> | ||
<ul id="todoList" class="list-group"></ul> | ||
</div> | ||
|
||
<script src="L12_Applet6.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
class TodoList { | ||
|
||
constructor() { | ||
this.editingIndex = -1; | ||
this.addButton = document.getElementById('addButton'); | ||
this.todoInput = document.getElementById('todoInput'); | ||
this.todoList = document.getElementById('todoList'); | ||
|
||
this.addButton.addEventListener('click', () => this.addOrUpdateTask()); | ||
this.todoList.addEventListener('click', (e) => { | ||
const action = e.target.classList.contains('removeButton') ? 'remove' : | ||
e.target.classList.contains('editButton') ? 'edit' : | ||
e.target.classList.contains('doneButton') ? 'done' : null; | ||
if (action) this[action + 'Task'](e); | ||
}); | ||
} | ||
|
||
addOrUpdateTask() { | ||
const taskText = this.todoInput.value.trim(); | ||
if (taskText) { | ||
this.editingIndex === -1 ? this.addTask(taskText) : this.updateTask(taskText); | ||
this.todoInput.value = ''; | ||
} | ||
} | ||
|
||
addTask(taskText) { | ||
const listItem = document.createElement('li'); | ||
listItem.className = 'list-group-item todo-item'; | ||
listItem.innerHTML = ` | ||
<span class="task-text">${taskText}</span> | ||
<span class="timestamp" style="display: block; margin-top: 0.5rem; color: gray;">Date Added: ${new Date().toLocaleString()}</span> | ||
<div style="margin-top: 0.5rem;"> | ||
<button class="btn btn-success btn-sm doneButton">Done</button> | ||
<button class="btn btn-warning btn-sm editButton">Edit</button> | ||
<button class="btn btn-danger btn-sm removeButton">Remove</button> | ||
</div> | ||
`; | ||
this.todoList.appendChild(listItem); | ||
} | ||
|
||
doneTask(event) { | ||
const taskItem = event.target.closest('.todo-item'); | ||
const taskText = taskItem.querySelector('.task-text'); | ||
taskText.classList.toggle('completed'); | ||
|
||
const buttons = taskItem.querySelectorAll('button'); | ||
buttons.forEach(button => button.disabled = true); | ||
} | ||
|
||
updateTask(taskText) { | ||
this.todoList.children[this.editingIndex].querySelector('.task-text').textContent = taskText; | ||
this.resetEditing(); | ||
} | ||
|
||
removeTask(event) { | ||
this.todoList.removeChild(event.target.closest('.todo-item')); | ||
} | ||
|
||
editTask(event) { | ||
const taskItem = event.target.closest('.todo-item'); | ||
this.todoInput.value = taskItem.querySelector('.task-text').textContent; | ||
this.editingIndex = Array.from(this.todoList.children).indexOf(taskItem); | ||
this.addButton.textContent = 'Update'; | ||
} | ||
|
||
resetEditing() { | ||
this.editingIndex = -1; | ||
this.addButton.textContent = 'Add'; | ||
} | ||
} | ||
|
||
class TimestampedTodoList extends TodoList { | ||
addTask(taskText) { | ||
super.addTask(taskText); | ||
const taskItem = this.todoList.lastChild; // Get the newly added task | ||
const timestamp = document.createElement('span'); | ||
timestamp.className = 'timestamp'; | ||
timestamp.textContent = new Date().toLocaleString(); | ||
taskItem.appendChild(timestamp); | ||
} | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => new TodoList()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters