allow ppl to make multiple comments to the same parents without reloading the page

remotes/1693045480750635534/spooky-22
Aevann1 2022-07-23 10:53:17 +02:00
parent 008f12a1f3
commit 46786e117b
3 changed files with 2200 additions and 2176 deletions

View File

@ -201,7 +201,7 @@ function comment_edit(id){
xhr.send(form)
}
function post_comment(fullname){
function post_comment(fullname, hide){
const btn = document.getElementById('save-reply-to-'+fullname)
btn.disabled = true
btn.classList.add('disabled');
@ -227,20 +227,42 @@ function post_comment(fullname){
try {data = JSON.parse(xhr.response)}
catch(e) {console.log(e)}
if (data && data["comment"]) {
commentForm=document.getElementById('comment-form-space-'+fullname);
commentForm.innerHTML = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '');
console.log(hide)
document.getElementById(hide).classList.add('d-none');
let id = fullname.split('_')[1];
let name = 'comment-form-space-' + fullname;
commentForm = document.getElementById(name);
let comments = document.getElementById('replies-of-' + id);
let comment = data["comment"].replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '');
comments.innerHTML = comment + comments.innerHTML;
bs_trigger(commentForm);
let placeholder = document.getElementById("placeholder-comment");
if(placeholder){
comments.classList.remove('text-center');
comments.classList.remove('py-7');
placeholder.parentNode.removeChild(placeholder);
}
btn.disabled = false;
btn.classList.remove('disabled');
document.getElementById('reply-form-body-'+fullname).value = ''
}
else {
if (data && data["error"]) document.getElementById('toast-post-error-text').innerText = data["error"];
else document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')).show();
}
setTimeout(() => {
btn.disabled = false;
btn.classList.remove('disabled');
}, 2000);
}
}
xhr.send(form)
}

View File

@ -583,7 +583,7 @@
<input autocomplete="off" id="file-upload-reply-{{c.fullname}}" accept="image/*, video/*, audio/*" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{c.fullname}}','file-upload-reply-{{c.fullname}}')" hidden>
</label>
</div>
<a id="save-reply-to-{{c.fullname}}" class="btn btn-primary ml-2 fl-r commentmob" onclick="post_comment('{{c.fullname}}', '{{c.post.id}}');remove_dialog()"role="button">Comment</a>
<a id="save-reply-to-{{c.fullname}}" class="btn btn-primary ml-2 fl-r commentmob" onclick="post_comment('{{c.fullname}}', 'reply-to-{{c.id}}');remove_dialog()"role="button">Comment</a>
<a role="button" onclick="document.getElementById('reply-to-{{c.id}}').classList.add('d-none');remove_dialog()" class="btn btn-link text-muted ml-auto cancel-form fl-r commentmob">Cancel</a>
</form>
<div id="reply-edit-{{c.id}}" class="preview mb-3 mt-5"></div>
@ -635,6 +635,8 @@
</div>
</div>
{% endif %}
{% else %}
<div id="replies-of-{{c.id}}"></div>
{% endif %}
</div>
@ -862,7 +864,7 @@
{% if v %}
<script src="{{asset('js/marked.js')}}"></script>
<script src="/assets/js/comments_v.js?v=283"></script>
<script src="/assets/js/comments_v.js?v=284"></script>
{% endif %}
<script src="/assets/js/clipboard.js?v=250"></script>

View File

@ -982,7 +982,7 @@
<input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="parent_fullname" value="t2_{{p.id}}">
<input autocomplete="off" id="reply-form-submission-{{p.fullname}}" type="hidden" name="submission" value="{{p.id}}">
<textarea required autocomplete="off" {% if not (p and p.id in ADMIGGERS) %}{% if v.longpost %}minlength="280"{% elif v.bird %}maxlength="140"{% endif %}{% endif %} minlength="1" maxlength="10000" oninput="markdown('reply-form-body-{{p.fullname}}', 'form-preview-{{p.id}}');charLimit('reply-form-body-{{p.fullname}}','charcount-reply')" id="reply-form-body-{{p.fullname}}" data-fullname="{{p.fullname}}" class="comment-box form-control rounded" id="comment-form" name="body" form="reply-to-{{p.fullname}}" aria-label="With textarea" placeholder="Add your comment..." rows="3"></textarea>
<textarea required autocomplete="off" {% if not (p and p.id in ADMIGGERS) %}{% if v.longpost %}minlength="280"{% elif v.bird %}maxlength="140"{% endif %}{% endif %} minlength="1" maxlength="10000" oninput="markdown('reply-form-body-{{p.fullname}}', 'form-preview-{{p.id}}');charLimit('reply-form-body-{{p.fullname}}','charcount-reply')" id="reply-form-body-{{p.fullname}}" data-fullname="{{p.fullname}}" class="comment-box form-control rounded" name="body" form="reply-to-{{p.fullname}}" aria-label="With textarea" placeholder="Add your comment..." rows="3"></textarea>
<div class="text-small font-weight-bold mt-1" id="charcount-reply" style="right: 1rem; bottom: 0.5rem; z-index: 3;"></div>
@ -1004,7 +1004,7 @@
<input autocomplete="off" id="file-upload-reply-{{p.fullname}}" accept="image/*, video/*, audio/*" type="file" multiple="multiple" name="file" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-show-reply-{{p.fullname}}','file-upload-reply-{{p.fullname}}')" hidden>
</label>
</div>
<a id="save-reply-to-{{p.fullname}}" role="button" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto fl-r" onclick="post_comment('{{p.fullname}}', '{{p.id}}');remove_dialog()">Comment</a>
<a id="save-reply-to-{{p.fullname}}" role="button" form="reply-to-{{p.fullname}}" class="btn btn-primary text-whitebtn ml-auto fl-r" onclick="post_comment('{{p.fullname}}', 'reply-to-{{p.fullname}}');remove_dialog()">Comment</a>
</form>
<div id="form-preview-{{p.id}}" class="mb-3 mt-5"></div>
<div class="form-text text-small p-0 m-0"><a href="/formatting" {% if v and v.newtab and not g.webview %}target="_blank"{% endif %}>Formatting help</a></div>
@ -1027,7 +1027,7 @@
{% endif %}
{% if p.replies %}
<div class="comment-section">
<div class="comment-section" id="replies-of-{{p.id}}">
{% with comments=p.replies %}
{% include "comments.html" %}
{% endwith %}
@ -1070,7 +1070,7 @@
{% endif %}
{% elif not p.replies and p.deleted_utc == 0 %}
<div class="comment-section text-center py-7">
<div class="comment-section text-center py-7" id="replies-of-{{p.id}}">
<span class="fa-stack fa-2x text-muted mb-4">
<i class="fas fa-square text-gray-500 opacity-25 fa-stack-2x"></i>
<i class="fas text-gray-500 fa-ghost fa-stack-1x text-lg"></i>