Skip to content

Commit

Permalink
Refactor: Fixed duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
revolter committed Jun 11, 2024
1 parent 54002c8 commit 96dcca6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -98,6 +95,11 @@
return deserialize(hash.substring(1));
}

function onValueUpdate(value) {
storeValue(value);
updateTitle(value);
}

function storeValue(value) {
window.location.hash = '#' + serialize(value);
}
Expand Down

0 comments on commit 96dcca6

Please sign in to comment.