From a6a8953834039a3c391bf033c53bf137effe1185 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 28 May 2024 18:47:46 +0200 Subject: [PATCH 1/7] add debounce to save --- index.html | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 8573790..4d6dad7 100644 --- a/index.html +++ b/index.html @@ -53,13 +53,25 @@ } } - function addValueListener(textarea) { - textarea.addEventListener('input', (event) => { - const value = event.target.value; - storeValue(value); - updateTitle(value); - }, false); - } + const debounce = (func, delay) => { + let debounceTimer; + return function () { + const context = this; + const args = arguments; + clearTimeout(debounceTimer); + debounceTimer = setTimeout(() => func.apply(context, args), delay); + }; + }; + + function addValueListener(textarea) { + textarea.addEventListener('input', debounce((event) => { + const value = event.target.value; + storeValue(value) + updateTitle(value); + }, 300), + false + ); + } function addHashListener(textarea) { window.addEventListener('hashchange', () => { From 34e9bb38e4743024921f0954a0a5079d303eb83d Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 28 May 2024 18:50:38 +0200 Subject: [PATCH 2/7] fix formatting --- index.html | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index 4d6dad7..bb8c8c8 100644 --- a/index.html +++ b/index.html @@ -53,25 +53,25 @@ } } - const debounce = (func, delay) => { - let debounceTimer; - return function () { - const context = this; - const args = arguments; - clearTimeout(debounceTimer); - debounceTimer = setTimeout(() => func.apply(context, args), delay); - }; - }; - - function addValueListener(textarea) { - textarea.addEventListener('input', debounce((event) => { + const debounce = (func, delay) => { + let debounceTimer; + return function () { + const context = this; + const args = arguments; + clearTimeout(debounceTimer); + debounceTimer = setTimeout(() => func.apply(context, args), delay); + }; + }; + + function addValueListener(textarea) { + textarea.addEventListener('input', debounce((event) => { const value = event.target.value; storeValue(value) updateTitle(value); }, 300), - false - ); - } + false + ); + } function addHashListener(textarea) { window.addEventListener('hashchange', () => { From 93bb032ee929f9273100ccb7b55b68633a46ea39 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <5748627+revolter@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:23:43 +0300 Subject: [PATCH 3/7] Refactor: Added missing semicolon --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index bb8c8c8..a77b79e 100644 --- a/index.html +++ b/index.html @@ -66,7 +66,7 @@ function addValueListener(textarea) { textarea.addEventListener('input', debounce((event) => { const value = event.target.value; - storeValue(value) + storeValue(value); updateTitle(value); }, 300), false From b14a24a1cede2bc5a041ed24ab7f234dd1d4e02a Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <5748627+revolter@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:25:09 +0300 Subject: [PATCH 4/7] Refactor: Fixed inconsistent indentation --- index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index a77b79e..ccb5649 100644 --- a/index.html +++ b/index.html @@ -64,12 +64,17 @@ }; function addValueListener(textarea) { - textarea.addEventListener('input', debounce((event) => { - const value = event.target.value; - storeValue(value); - updateTitle(value); - }, 300), - false + textarea.addEventListener( + 'input', + debounce( + (event) => { + const value = event.target.value; + storeValue(value); + updateTitle(value); + }, + 300 + ), + false ); } From fc631a08278bb3f2216d5dfa7d38c8c3b8d04ce5 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <5748627+revolter@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:39:14 +0300 Subject: [PATCH 5/7] Refactor: Fixed inconsistent indentation --- index.html | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index ccb5649..ed7f584 100644 --- a/index.html +++ b/index.html @@ -64,18 +64,11 @@ }; function addValueListener(textarea) { - textarea.addEventListener( - 'input', - debounce( - (event) => { - const value = event.target.value; - storeValue(value); - updateTitle(value); - }, - 300 - ), - false - ); + textarea.addEventListener('input', debounce((event) => { + const value = event.target.value; + storeValue(value); + updateTitle(value); + }, 300), false); } function addHashListener(textarea) { From 54002c8b41b4e7f2a40aa3d838b3d37b5303a5ef Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <5748627+revolter@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:41:18 +0300 Subject: [PATCH 6/7] Added value storing on textarea or tab blur --- index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/index.html b/index.html index ed7f584..9563411 100644 --- a/index.html +++ b/index.html @@ -40,6 +40,7 @@ const textarea = document.getElementById('{{ textarea_id }}'); loadValue(textarea); addValueListener(textarea); + addFocusListener(textarea); addHashListener(textarea); } @@ -71,6 +72,20 @@ }, 300), false); } + function addFocusListener(textarea) { + textarea.addEventListener('blur', () => { + const value = textarea.value; + storeValue(value); + updateTitle(value); + }, false); + + window.addEventListener('blur', () => { + const value = textarea.value; + storeValue(value); + updateTitle(value); + }, false); + } + function addHashListener(textarea) { window.addEventListener('hashchange', () => { loadValue(textarea); From 96dcca6fc3244fc1de012f7e1d3282bf5a5f2620 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <5748627+revolter@users.noreply.github.com> Date: Tue, 11 Jun 2024 21:43:28 +0300 Subject: [PATCH 7/7] Refactor: Fixed duplicated code --- index.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 9563411..aa66033 100644 --- a/index.html +++ b/index.html @@ -67,22 +67,19 @@ function addValueListener(textarea) { textarea.addEventListener('input', debounce((event) => { const value = event.target.value; - storeValue(value); - updateTitle(value); + onValueUpdate(value); }, 300), false); } function addFocusListener(textarea) { textarea.addEventListener('blur', () => { const value = textarea.value; - storeValue(value); - updateTitle(value); + onValueUpdate(value); }, false); window.addEventListener('blur', () => { const value = textarea.value; - storeValue(value); - updateTitle(value); + onValueUpdate(value); }, false); } @@ -98,6 +95,11 @@ return deserialize(hash.substring(1)); } + function onValueUpdate(value) { + storeValue(value); + updateTitle(value); + } + function storeValue(value) { window.location.hash = '#' + serialize(value); }