-
Notifications
You must be signed in to change notification settings - Fork 4
sauravkr818 - Task 1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sauravkr818
wants to merge
4
commits into
DevCANS:main
Choose a base branch
from
sauravkr818:T1-sauravkr818
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
1. Building a To-Do List Without Framework/submission/index.html
This file contains hidden or 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,128 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Document</title> | ||
| <link | ||
| href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" | ||
| rel="stylesheet" | ||
| integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" | ||
| crossorigin="anonymous" | ||
| /> | ||
| <link | ||
| href="https://unpkg.com/[email protected]/dist/aos.css" | ||
| rel="stylesheet" | ||
| /> | ||
| </head> | ||
| <body> | ||
| <div class="container-fluid"> | ||
| <div class="py-5"></div> | ||
| <div class="row"> | ||
| <div class="col-12 d-flex justify-content-center"> | ||
| <button | ||
| type="button" | ||
| class="btn btn-primary" | ||
| data-bs-toggle="modal" | ||
| data-bs-target="#exampleModal" | ||
| > | ||
| ADD A TODO LIST | ||
| </button> | ||
| <div | ||
| class="modal fade" | ||
| id="exampleModal" | ||
| tabindex="-1" | ||
| aria-labelledby="exampleModalLabel" | ||
| aria-hidden="true" | ||
| > | ||
| <div | ||
| class="modal-dialog modal-dialog-centered modal-dialog-scrollable" | ||
| > | ||
| <div class="modal-content"> | ||
| <div class="modal-header"> | ||
| <h5 | ||
| class="modal-title" | ||
| id="exampleModalLabel" | ||
| > | ||
| ADD A TODO LIST | ||
| </h5> | ||
| <button | ||
| type="button" | ||
| class="btn-close" | ||
| data-bs-dismiss="modal" | ||
| aria-label="Close" | ||
| ></button> | ||
| </div> | ||
| <form id="todo-form"> | ||
| <div class="modal-body"> | ||
| <div class="form-floating mb-3"> | ||
| <input | ||
| type="text" | ||
| class="form-control" | ||
| id="floatingInput" | ||
| placeholder="Maths Homework" | ||
| name="todo-input" | ||
| /> | ||
| <label for="floatingInput" | ||
| >Title</label | ||
| > | ||
| </div> | ||
| </div> | ||
| <div class="modal-footer"> | ||
| <button | ||
| type="button" | ||
| class="btn btn-outline-danger fw-bold" | ||
| data-bs-dismiss="modal" | ||
| > | ||
| Close | ||
| </button> | ||
| <button | ||
| type="submit" | ||
| class="btn btn-outline-success fw-bold" | ||
| > | ||
| Save changes | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div id="confirmation" class="pt-5"></div> | ||
| <div id="todo-list"></div> | ||
|
|
||
| <div class="d-flex justify-content-center py-5"> | ||
| <button | ||
| class="btn btn-outline-success" | ||
| id="save-todo" | ||
| onclick="{saveTodo()}" | ||
| > | ||
| Save | ||
| </button> | ||
| </div> | ||
| <div class="d-flex justify-content-center"> | ||
| <button | ||
| class="btn btn-outline-success" | ||
| id="delete-todo" | ||
| onclick="{deleteTodo()}" | ||
| > | ||
| Clear All | ||
| </button> | ||
| </div> | ||
| <div class="py-5"></div> | ||
| </div> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | ||
| <script | ||
| src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
| integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" | ||
| crossorigin="anonymous" | ||
| ></script> | ||
| <script src="https://unpkg.com/[email protected]/dist/aos.js"></script> | ||
| <script src="./index.js" type="text/javascript"></script> | ||
| <script> | ||
| AOS.init(); | ||
| </script> | ||
| </body> | ||
| </html> | ||
108 changes: 108 additions & 0 deletions
108
1. Building a To-Do List Without Framework/submission/index.js
This file contains hidden or 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,108 @@ | ||
| let todoList = []; | ||
|
|
||
| function generateTodoItem(itemName) { | ||
| const timestamp = Date.now(); | ||
| return { | ||
| id: "todo-item-" + timestamp, | ||
| name: itemName, | ||
| timestamp, | ||
| isDone: false, | ||
| }; | ||
| } | ||
|
|
||
| function todoElement(item, i) { | ||
| const elem = document.createElement("div"); | ||
| elem.id = item.id; | ||
| elem.innerHTML = ` | ||
| <div class="row py-2 pb-2 text-center" data-aos="fade-up"> | ||
| <div class="col-3 text-center">${i + 1}</div> | ||
| <div class="col-3"> <input type="checkbox" onchange="markItem(event)" ${ | ||
| item.isDone ? "checked" : "" | ||
| }/></div> | ||
| <div class="col-3">${item.name}</div> | ||
| <div class="col-3" id=${ | ||
| item.id | ||
| }><button class="btn btn-outline-danger" onclick="deleteItem(event)">Delete Item</button></div> | ||
| </div> | ||
deepakg202 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
deepakg202 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| `; | ||
| return elem; | ||
| } | ||
|
|
||
| function renderList() { | ||
| const listElement = document.getElementById("todo-list"); | ||
|
|
||
| listElement.innerHTML = ""; | ||
|
|
||
| for (let i = 0; i < todoList.length; i++) { | ||
| const todoItem = todoElement(todoList[i], i); | ||
| listElement.appendChild(todoItem); | ||
| } | ||
|
|
||
| let alert = ` | ||
| <div class="text-center alert ${ | ||
deepakg202 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isAdded | ||
| ? "alert-success" | ||
| : "alert-danger" | ||
| } alert-dismissible fade show shadow border-0" role="alert" data-aos="fade-down"> | ||
| <strong>${ | ||
| isAdded | ||
| ? "Congraluations, Your item has been added." | ||
| : "Your item has been deleted." | ||
| } | ||
| <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
| </div>`; | ||
| $("#confirmation").html(alert); | ||
| } | ||
|
|
||
| document | ||
| .getElementById("todo-form") | ||
| .addEventListener("submit", function (event) { | ||
| event.preventDefault(); | ||
| const itemName = event.target["todo-input"].value; | ||
| if (itemName) { | ||
| todoList.push(generateTodoItem(itemName)); | ||
| isAdded = true; | ||
| renderList(); | ||
| event.target.reset(); | ||
| } | ||
| }); | ||
|
|
||
| function markItem(event) { | ||
| const itemId = event.target.parentElement.id; // getting the id of the parent element to search in the array | ||
| todoList.some(function (todoItem) { | ||
| if (todoItem.id === itemId) { | ||
| todoItem.isDone = !todoItem.isDone; | ||
| renderList(); | ||
| return true; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function deleteItem(event) { | ||
| isAdded = false; | ||
| const itemId = event.target.parentElement.id; // getting the id of the parent element to search in the array | ||
| todoList.some(function (todoItem, i) { | ||
| if (todoItem.id === itemId) { | ||
| todoList.splice(i, 1); | ||
| renderList(); | ||
| return true; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function saveTodo(e) { | ||
| localStorage.setItem("todoList", JSON.stringify(todoList)); | ||
| } | ||
| function deleteTodo(e) { | ||
| localStorage.clear(); | ||
deepakg202 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| location.reload(); | ||
| } | ||
deepakg202 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| try { | ||
| if (localStorage.getItem("todoList")) { | ||
| todoList = JSON.parse(localStorage.getItem("todoList")); | ||
| renderList(); | ||
| } | ||
| } catch (e) { | ||
| console.log(e); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.