From 4f2cba6af737829e660126afaa44e1559184e324 Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 8 Aug 2023 13:52:07 +0300 Subject: [PATCH] make oldfiles contain DataTransfer objects instead of lists --- files/assets/js/chat.js | 2 +- files/assets/js/comments_v.js | 6 +++--- files/assets/js/core.js | 19 +++++++------------ files/assets/js/userpage_v.js | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index 951754d1e..494e30830 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -172,7 +172,7 @@ function send() { autoExpand(ta); document.getElementById("quotes").classList.add("d-none") document.getElementById('quotes_id').value = null; - oldfiles[ta.id] = []; + oldfiles[ta.id] = new DataTransfer(); input.value = null; input.previousElementSibling.innerHTML = '' diff --git a/files/assets/js/comments_v.js b/files/assets/js/comments_v.js index bfa1f36ec..a86f5b31c 100644 --- a/files/assets/js/comments_v.js +++ b/files/assets/js/comments_v.js @@ -169,7 +169,7 @@ function post_reply(id) { const input = ta.parentElement.querySelector('input[type="file"]') input.previousElementSibling.innerHTML = ''; input.value = null; - oldfiles[ta.id] = [] + oldfiles[ta.id] = new DataTransfer(); remove_dialog(); restore_reply_buttons(`c_${id}`) @@ -221,7 +221,7 @@ function comment_edit(id){ const input = ta.parentElement.querySelector('input[type="file"]') input.previousElementSibling.innerHTML = ''; input.value = null; - oldfiles[ta.id] = [] + oldfiles[ta.id] = new DataTransfer(); remove_dialog(); } @@ -294,7 +294,7 @@ function post_comment(fullname, hide){ const input = ta.parentElement.querySelector('input[type="file"]') input.previousElementSibling.innerHTML = ''; input.value = null; - oldfiles[ta.id] = [] + oldfiles[ta.id] = new DataTransfer(); const ghost_town_box = document.getElementById('ghost-town-box') if (ghost_town_box) ghost_town_box.remove() diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 178563b8d..c243e61bf 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -483,33 +483,28 @@ function handle_files(input, newfiles) { const ta = input.parentElement.parentElement.parentElement.parentElement.querySelector('textarea.file-ta'); if (oldfiles[ta.id]) { - let list = new DataTransfer(); - for (const file of oldfiles[ta.id]) { - list.items.add(file); - } for (const file of newfiles) { - list.items.add(file); + oldfiles[ta.id].items.add(file); } - input.files = list.files; + input.files = oldfiles[ta.id].files; } else { - input.files = newfiles; - oldfiles[ta.id] = [] + oldfiles[ta.id] = new DataTransfer(); } if (input.files.length > 20) { alert("You can't upload more than 20 files at one time!") input.value = null - oldfiles[ta.id] = [] + oldfiles[ta.id] = new DataTransfer(); return } - for (const file of newfiles) { - oldfiles[ta.id].push(file) - if (location.pathname != '/chat' && location.pathname != '/old_chat') + if (location.pathname != '/chat' && location.pathname != '/old_chat') { + for (const file of newfiles) { insertText(ta, `[${file.name}]`); } + } autoExpand(ta) diff --git a/files/assets/js/userpage_v.js b/files/assets/js/userpage_v.js index 5ec436eeb..b2b522e9c 100644 --- a/files/assets/js/userpage_v.js +++ b/files/assets/js/userpage_v.js @@ -80,7 +80,7 @@ function sendMessage(form) { const input = ta.parentElement.querySelector('input[type="file"]'); input.previousElementSibling.innerHTML = ''; input.value = null; - oldfiles[ta.id] = []; + oldfiles[ta.id] = new DataTransfer(); } } )