Skip to content

Commit

Permalink
refactor: move common functionality into separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
lavafroth committed Aug 12, 2023
1 parent 30fc09b commit 41eedec
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ function reload_listing() {
})
}

function create_file() {
title.readOnly = true
doApi({"action": "create", "filename": title.value})
}

title_button.addEventListener('click', create_file);
title.addEventListener('keypress', (e) => {
if (e.keyCode==13) {
title.readOnly = true
doApi({"action": "create", "filename": title.value})
create_file()
}
})

title_button.addEventListener('click', () => {
title.readOnly = true
doApi({"action": "create", "filename": title.value})
});

add_icon.addEventListener('click', () => {
editor.value = ''
title.value = ''
Expand All @@ -88,14 +88,8 @@ add_icon.addEventListener('click', () => {
})

documents_icon.addEventListener('click', () => {
const classList = files.classList
if (classList.contains("show")) {
files.classList.replace('show', 'hide')
} else if (classList.contains("hide")) {
files.classList.replace('hide', 'show')
} else {
files.classList.add('hide')
}
files.classList.toggle("show");
files.classList.toggle("hide");
});

run_icon.addEventListener('click', () => {
Expand Down

0 comments on commit 41eedec

Please sign in to comment.