From 8198b8a2b58ceabcaf5649daf9b21792181d56df Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 16:13:22 +0800
Subject: [PATCH 01/17] editable to do list
---
js/app.js | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 139 insertions(+), 1 deletion(-)
diff --git a/js/app.js b/js/app.js
index 74cbc288..2723c57a 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1 +1,139 @@
-// CODE EXPLAINED channel
\ No newline at end of file
+const dateElement = document.getElementById('date');
+const clear = document.querySelector('.clear');
+const list = document.getElementById('list');
+const input = document.querySelector('input');
+const addButton = document.querySelector('.fa-plus-circle');
+
+const CHECK = "fa-check-circle";
+const UNCHECK = "fa-circle-thin";
+const LINE_THROUGH = "lineThrough";
+const CHANGE = "editable";
+
+var timer = null, delay = 260, click = 0, canFocus = true;//double click
+
+clear.addEventListener("click", function () {
+ localStorage.clear();
+ location.reload();
+});
+/* show time */
+const options = { weekday: 'long', month: 'short', day: 'numeric' };
+const today = new Date();
+dateElement.innerHTML = today.toLocaleDateString("en-US", options);
+
+let LIST, id;
+let data = localStorage.getItem("TODO");
+//get historical data from localstorage
+if (data) {
+ LIST = JSON.parse(data);
+ id = LIST.length;
+ loadList(LIST);
+}
+else {
+ LIST = []
+ id = 0;
+}
+
+function loadList(array) {
+ array.forEach(element => {
+ add_to_do(element.name, element.id, element.done, element.trash);
+ });
+}
+
+function add_to_do(toDo, id, done, trash) {
+ if (trash)
+ return;
+ const DONE = done ? CHECK : UNCHECK;
+ const LINE = done ? LINE_THROUGH : "";
+
+ const item = `
+
+
+
+
+ `;
+ const position = "beforeend";
+ list.insertAdjacentHTML(position, item);//可以使用appendchild直接插入dom,效率会更高
+}
+
+input.addEventListener("keypress", function (even) {
+ if (event.keyCode === 13) {
+ const toDo = input.value;
+ if (toDo) {
+ add_to_do(toDo, id, false, false);
+
+ LIST.push({ name: toDo, id: id, done: false, trash: false });
+
+ localStorage.setItem("TODO", JSON.stringify(LIST));
+ id++;
+ input.value = "";
+ }
+ }
+});
+
+addButton.addEventListener('click', function () {
+ const toDo = input.value;
+ if (toDo) {
+ add_to_do(toDo, id, false, false);
+
+ LIST.push({ name: toDo, id: id, done: false, trash: false });
+
+ localStorage.setItem("TODO", JSON.stringify(LIST));
+ id++;
+ input.value = "";
+ }
+});
+
+list.addEventListener("click", function (event) {
+ const element = event.target;
+ const elementJob = element.attributes.job.value;
+
+ if (elementJob === 'complete') {
+ completeToDo(element);
+ } else if (elementJob === 'delete') {
+ removeToDo(element);
+ }
+ else if(elementJob === 'edit'){
+ editTodo(element);
+ }
+
+ localStorage.setItem("TODO", JSON.stringify(LIST));
+
+}, false);
+
+function completeToDo(element) {
+ element.classList.toggle(UNCHECK);
+ element.classList.toggle(CHECK);
+ element.parentNode.querySelector(".text").classList.toggle(LINE_THROUGH);
+
+ LIST[element.id].done = LIST[element.id].done ? false : true;
+}
+
+function removeToDo(element) {
+ element.parentNode.parentNode.removeChild(element.parentNode);
+ LIST[element.id].trash = true;
+}
+
+function editTodo(element){
+ var newTodo, content = element.parentNode.querySelector(".text");
+ if(canFocus)
+ content.blur();
+ click++;
+ if(click === 1){
+ timer = setTimeout(function(){
+ click = 0;
+ }, (delay));
+ } else{
+ click = 0;
+ canFocus = false;
+ clearTimeout(timer);
+ content.focus();
+ content.onblur = ()=>{
+ newTodo = content.value;
+ LIST[element.id].name = newTodo;
+ localStorage.setItem("TODO",JSON.stringify(LIST));
+ canFocus = true;
+ };
+ }
+
+}
+
From 2e15b0aff1e26ac1084621446fa783630b063576 Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 16:17:32 +0800
Subject: [PATCH 02/17] Update README.md
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index e7670232..81b4831c 100644
--- a/README.md
+++ b/README.md
@@ -33,3 +33,6 @@ https://youtu.be/9TcU2C1AACw
Flappy Bird Game Using JavaScript
https://youtu.be/L07i4g-zhDA
+
+### 2019.12.21
+added a function when double click the item you can edit the content of to-do-list and the changes will auto save then the content lose the focus.
From 8d98c897b2e286ecac924470cc2f07ff6efc8522 Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 16:43:57 +0800
Subject: [PATCH 03/17] Add files via upload
the content of the to-do-lists are editable!
---
js/app.js | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/js/app.js b/js/app.js
index 2723c57a..997242e6 100644
--- a/js/app.js
+++ b/js/app.js
@@ -9,7 +9,7 @@ const UNCHECK = "fa-circle-thin";
const LINE_THROUGH = "lineThrough";
const CHANGE = "editable";
-var timer = null, delay = 260, click = 0, canFocus = true;//double click
+var timer = null, delay = 260, click = 0;//double click
clear.addEventListener("click", function () {
localStorage.clear();
@@ -47,7 +47,7 @@ function add_to_do(toDo, id, done, trash) {
const item = `
-
+
`;
@@ -114,9 +114,7 @@ function removeToDo(element) {
}
function editTodo(element){
- var newTodo, content = element.parentNode.querySelector(".text");
- if(canFocus)
- content.blur();
+ var newTodo, content = element.parentNode.querySelector(".text"),preText;
click++;
if(click === 1){
timer = setTimeout(function(){
@@ -124,14 +122,17 @@ function editTodo(element){
}, (delay));
} else{
click = 0;
- canFocus = false;
clearTimeout(timer);
+ preText = content.value;
+ content.disabled = false;
content.focus();
content.onblur = ()=>{
newTodo = content.value;
- LIST[element.id].name = newTodo;
- localStorage.setItem("TODO",JSON.stringify(LIST));
- canFocus = true;
+ if(preText !== newTodo){
+ LIST[element.id].name = newTodo;
+ localStorage.setItem("TODO",JSON.stringify(LIST));
+ content.disabled = true;
+ }
};
}
From 7f699802d673565bcec0509fb1f0c2f8cd2daf11 Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 16:47:22 +0800
Subject: [PATCH 04/17] Add files via upload
the page of the to-do-list
---
homepage.html | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 homepage.html
diff --git a/homepage.html b/homepage.html
new file mode 100644
index 00000000..44c99909
--- /dev/null
+++ b/homepage.html
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+ Too many lists to do
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From 38c800503fc80b8a05edae6a58a242e0c7a4b00a Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 16:57:39 +0800
Subject: [PATCH 05/17] Set theme jekyll-theme-time-machine
---
_config.yml | 1 +
1 file changed, 1 insertion(+)
create mode 100644 _config.yml
diff --git a/_config.yml b/_config.yml
new file mode 100644
index 00000000..ddeb671b
--- /dev/null
+++ b/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-time-machine
\ No newline at end of file
From 58a1f849b04cc226a32d20b450523d6b460fa1a4 Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 17:01:00 +0800
Subject: [PATCH 06/17] Rename index.html to ind22ex.html
---
index.html => ind22ex.html | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename index.html => ind22ex.html (100%)
diff --git a/index.html b/ind22ex.html
similarity index 100%
rename from index.html
rename to ind22ex.html
From 66f948aeb34f08fa68124601f0d945245cbb78b5 Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 17:01:29 +0800
Subject: [PATCH 07/17] Delete ind22ex.html
---
ind22ex.html | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 ind22ex.html
diff --git a/ind22ex.html b/ind22ex.html
deleted file mode 100644
index 3bf3ada8..00000000
--- a/ind22ex.html
+++ /dev/null
@@ -1 +0,0 @@
-
From 834e761f4dbcd3668c0356bb17be8dcdf4b8084f Mon Sep 17 00:00:00 2001
From: KKKinlibrary <48236175+KKKinlibrary@users.noreply.github.com>
Date: Sat, 21 Dec 2019 17:01:58 +0800
Subject: [PATCH 08/17] Rename homepage.html to index.html
---
homepage.html => index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
rename homepage.html => index.html (96%)
diff --git a/homepage.html b/index.html
similarity index 96%
rename from homepage.html
rename to index.html
index 44c99909..985ec8a5 100644
--- a/homepage.html
+++ b/index.html
@@ -36,4 +36,4 @@