From b995df4533890bd66e2b377d1d4168c057faed73 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sun, 7 Aug 2022 00:51:29 +0300 Subject: [PATCH] Added cancel button for snippet edit --- public/js/snippetedit.js | 18 ++++++++++++++++-- src/templates/src/include/snippet_edit.html | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/public/js/snippetedit.js b/public/js/snippetedit.js index 10950327..3e0fc0b1 100644 --- a/public/js/snippetedit.js +++ b/public/js/snippetedit.js @@ -55,6 +55,21 @@ function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmen } updateProjectSelector(); + if (originalSnippetEl) { + snippetEdit.cancelLink.addEventListener("click", function() { + cancel(); + }); + } else { + snippetEdit.cancelLink.remove(); + } + + function cancel() { + if (originalSnippetEl) { + snippetEdit.root.parentElement.insertBefore(originalSnippetEl, snippetEdit.root); + } + snippetEdit.root.remove(); + } + function addProject(proj) { let projEl = snippetEditProjectTemplate(); projEl.projectId.value = proj.id; @@ -328,8 +343,7 @@ function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmen if (originalSnippetEl && (!attachmentChanged && originalText == snippetEdit.text.value.trim() && !projectsChanged)) { // NOTE(asaf): We're in edit mode and nothing changed, so no need to submit to the server. ev.preventDefault(); - snippetEdit.root.parentElement.insertBefore(originalSnippetEl, snippetEdit.root); - snippetEdit.root.remove(); + cancel(); } }); diff --git a/src/templates/src/include/snippet_edit.html b/src/templates/src/include/snippet_edit.html index d4688b56..78822b54 100644 --- a/src/templates/src/include/snippet_edit.html +++ b/src/templates/src/include/snippet_edit.html @@ -10,6 +10,7 @@
Date +