Clean up handling of "view more comments" button

This commit is contained in:
iro84657 2022-09-07 07:47:25 -04:00 committed by Ben Rog-Wilhelm
parent 4b935addb8
commit 2767d556ca
2 changed files with 17 additions and 13 deletions

View file

@ -38,9 +38,9 @@
</div>
</div>
</div>
{% endif %}
{% include 'usernote.html' %}
{% endif %}
{% macro single_comment(c, level=1) %}
@ -741,6 +741,16 @@
{% endfor %}
{% if offset %}
{% if p %}
{% set pid = p.id %}
{% endif %}
<div id="viewmore-{{offset}}">
<br>
<button id="viewbtn" class="btn btn-primary" onclick="viewmore({{pid}},'{{sort}}',{{offset}},{{ids}})">VIEW MORE COMMENTS</button>
</div>
{% endif %}
{% if not ajax %}
{% if v %}
{% include "gif_modal.html" %}
@ -889,12 +899,4 @@
</script>
{% endif %}
{% if offset %}
{% if p %}
{% set pid = p.id %}
{% endif %}
<br>
<div id="viewmore-{{offset}}"><button id="viewbtn" class="btn btn-primary" onclick="viewmore({{pid}},'{{sort}}',{{offset}},{{ids}})">VIEW MORE COMMENTS</a></div>
{% endif %}
</body>

View file

@ -539,9 +539,11 @@
xhr.setRequestHeader('xhr', 'xhr');
xhr.onload=function(){
if (xhr.status==200) {
let e = document.getElementById(`viewmore-${offset}`);
e.innerHTML = xhr.response.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '');
bs_trigger(e)
const e = document.getElementById(`viewmore-${offset}`);
const html = xhr.response.replace(/data-src/g, "src").replace(/data-cfsrc/g, "src").replace(/style="display:none;visibility:hidden;"/g, "");
const fragment = document.createRange().createContextualFragment(html);
bs_trigger(fragment);
e.replaceWith(fragment);
comments = JSON.parse(localStorage.getItem("old-comment-counts")) || {}
lastCount = comments['{{p.id}}']