forked from rDrama/rDrama
1
0
Fork 0

reset edit box to old value when cancelling

master
Aevann 2024-03-02 14:53:04 +02:00
parent 2ad2a545f5
commit 801c9bea3e
2 changed files with 18 additions and 7 deletions

View File

@ -82,6 +82,7 @@ function toggleReplyBox(t, id) {
t.innerHTML = newHTML t.innerHTML = newHTML
} }
let old_text
function toggleEdit(id){ function toggleEdit(id){
const comment = document.getElementById("comment-text-"+id); const comment = document.getElementById("comment-text-"+id);
const form = document.getElementById("comment-edit-"+id); const form = document.getElementById("comment-edit-"+id);
@ -93,10 +94,14 @@ function toggleEdit(id){
actions.classList.toggle("d-none"); actions.classList.toggle("d-none");
if (comment.classList.contains('d-none')) { if (comment.classList.contains('d-none')) {
old_text = box.value;
autoExpand(box); autoExpand(box);
markdown(box); markdown(box);
charLimit(box.id, 'charcount-edit-' + id) charLimit(box.id, 'charcount-edit-' + id)
} }
else {
box.value = old_text;
}
close_inline_emoji_modal(); close_inline_emoji_modal();
}; };

View File

@ -1,22 +1,28 @@
let old_body_text, old_title_box
function togglePostEdit(id) { function togglePostEdit(id) {
const body = document.getElementById("post-body"); const body = document.getElementById("post-body");
const title = document.getElementById("post-title"); const title = document.getElementById("post-title");
const form = document.getElementById("edit-post-body-"+id); const form = document.getElementById("edit-post-body-"+id);
const body_box = document.getElementById("post-edit-box-"+id);
const title_box = document.getElementById("post-edit-title");
body.classList.toggle("d-none"); body.classList.toggle("d-none");
title.classList.toggle("d-none"); title.classList.toggle("d-none");
form.classList.toggle("d-none"); form.classList.toggle("d-none");
if (body.classList.contains('d-none')) { if (body.classList.contains('d-none')) {
let box = document.getElementById("post-edit-box-"+id); old_body_text = body_box.value;
autoExpand(box); autoExpand(body_box);
markdown(box); markdown(body_box);
charLimit(box.id, 'charcount-post-edit') charLimit(body_box.id, 'charcount-post-edit')
box = document.getElementById("post-edit-title"); old_title_box = title_box.value;
autoExpand(box); autoExpand(title_box);
}
else {
body_box.value = old_body_text;
title_box.value = old_title_box;
} }
close_inline_emoji_modal(); close_inline_emoji_modal();
}; };