diff --git a/files/assets/js/comments_v.js b/files/assets/js/comments_v.js index a61c7c005..8be02cd30 100644 --- a/files/assets/js/comments_v.js +++ b/files/assets/js/comments_v.js @@ -126,7 +126,13 @@ function post_reply(id){ catch(e) {} const xhr = createXhrWithFormKey("/reply", "POST", form); + + const upload_prog = document.getElementById(`upload-prog-c_${id}`); + xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; + xhr[0].onload=function(){ + upload_prog.classList.add("d-none") + let data try {data = JSON.parse(xhr[0].response)} catch(e) {console.log(e)} @@ -178,7 +184,13 @@ function comment_edit(id){ } catch(e) {} const xhr = createXhrWithFormKey("/edit_comment/"+id, "POST", form); + + const upload_prog = document.getElementById(`upload-prog-edit-c_${id}`); + xhr[0].upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; + xhr[0].onload=function(){ + upload_prog.classList.add("d-none") + let data try {data = JSON.parse(xhr[0].response)} catch(e) {console.log(e)} @@ -230,8 +242,14 @@ function post_comment(fullname, hide){ const xhr = new XMLHttpRequest(); url = '/comment'; xhr.open("POST", url); + + const upload_prog = document.getElementById(`upload-prog-${fullname}`); + xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; + xhr.setRequestHeader('xhr', 'xhr'); xhr.onload=function(){ + upload_prog.classList.add("d-none") + let data try {data = JSON.parse(xhr.response)} catch(e) {console.log(e)} diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 278dc24a5..cee0819e1 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -574,3 +574,15 @@ function cancel_files(element) { if (typeof checkForRequired === "function") checkForRequired(); } + +function handleUploadProgress(e, upload_prog) { + const bar = upload_prog.firstElementChild; + const percentIndicator = upload_prog.lastElementChild; + + upload_prog.classList.remove("d-none") + if (e.lengthComputable) { + const progressPercent = Math.floor((e.loaded / e.total) * 100); + bar.value = progressPercent; + percentIndicator.textContent = progressPercent + '%'; + } +} diff --git a/files/assets/js/submit.js b/files/assets/js/submit.js index d0203ea01..1f6d5af5a 100644 --- a/files/assets/js/submit.js +++ b/files/assets/js/submit.js @@ -173,19 +173,6 @@ document.addEventListener('keydown', (e) => { checkRepost(); -const uploadfilelist = document.getElementById('upload-filelist'); -const bar = document.getElementById('file-progress'); -const percentIndicator = document.getElementById('progress-percent'); - -function handleUploadProgress(evt) { - uploadfilelist.classList.remove("d-none") - if (evt.lengthComputable) { - const progressPercent = Math.floor((evt.loaded / evt.total) * 100); - bar.value = progressPercent; - percentIndicator.textContent = progressPercent + '%'; - } -} - function submit(form) { submitButton.disabled = true; @@ -198,11 +185,15 @@ function submit(form) { actionPath = form.getAttribute("action"); xhr.open("POST", actionPath); - xhr.upload.onprogress = handleUploadProgress; + + const upload_prog = document.getElementById('upload-prog'); + xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; + xhr.setRequestHeader('xhr', 'xhr'); xhr.onload = function() { - uploadfilelist.classList.add("d-none") + upload_prog.classList.add("d-none") + if (xhr.status >= 200 && xhr.status < 300) { const post_id = JSON.parse(xhr.response)['post_id']; diff --git a/files/templates/comments.html b/files/templates/comments.html index de03797a3..96cb3b0fd 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -259,21 +259,29 @@ {% if v and v.id==c.author_id %} {% endif %} @@ -536,8 +544,16 @@ {{macros.file_input('file-upload-reply-' ~ c.fullname, True)}} - - +
+ + + + + + + + +
diff --git a/files/templates/submit.html b/files/templates/submit.html index 526f91152..30fb7025f 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -31,7 +31,7 @@ - +
@@ -97,9 +97,9 @@ Cancel
- - - + + +
diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index 6a8c0da4e..42167896f 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -141,9 +141,16 @@ {% endif %} + {% if enable_cancel_button %} {% endif %} + + + + + +
Formatting help