fictioneer/js/comments.min.js

3 lines
13 KiB
JavaScript
Raw Normal View History

2023-07-02 01:04:03 +02:00
function fcn_addJSTrap(){const e=document.querySelector(".comment-form");e&&e.appendChild(fcn_html`
<input type="hidden" id="fictioneer-comment-validator" name="fictioneer_comment_validator" value="299792458">
`)}function fcn_moderateComment(e,t){const n=_$$$(`comment-${e}`),o=n.querySelector(".mod-menu-toggle-icon");n.classList.contains("ajax-in-progress")||(n.classList.add("ajax-in-progress"),"trash"!=t&&"spam"!=t||(n.style.height=n.clientHeight+"px"),fcn_ajaxPost({action:"fictioneer_ajax_moderate_comment",operation:t,id:e}).then((e=>{if(e.success)switch(e.data.operation){case"sticky":n.classList.add("_sticky");break;case"unsticky":n.classList.remove("_sticky");break;case"approve":n.classList.remove("_unapproved");break;case"unapprove":n.classList.add("_unapproved");break;case"open":n.classList.remove("_closed");break;case"close":n.classList.add("_closed");break;case"trash":case"spam":n.style.overflow="hidden",n.style.height="0",n.style.margin="0",n.style.opacity="0"}else o.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",o.style.color="var(--warning)",n.querySelector(".popup-menu-toggle").style.opacity="1",e.data.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{o.classList="fa-solid fa-triangle-exclamation mod-menu-toggle-icon",o.style.color="var(--warning)",n.querySelector(".popup-menu-toggle").style.opacity="1",e.status&&e.statusText?fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning"):e&&fcn_showNotification(e,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),fcn_lastClicked&&fcn_lastClicked.classList.remove("last-clicked"),fcn_lastClicked=null})))}function fcn_addModerationEvents(){_$$(".button-ajax-moderate-comment").forEach((e=>{e.addEventListener("click",(e=>{fcn_moderateComment(e.currentTarget.dataset.id,e.currentTarget.dataset.action)}))}))}function fcn_addCommentMouseleaveEvents(){_$$(".fictioneer-comment__container").forEach((e=>{e.addEventListener("mouseleave",(e=>{fcn_lastClicked&&fcn_lastClicked.classList.remove("last-clicked"),fcn_lastClicked=null,e.stopPropagation()}))}))}function fcn_flagComment(e){if(!fcn_isLoggedIn)return;const t=e.closest(".fictioneer-comment"),n=t.querySelector(".fictioneer-report-comment-button");t.classList.contains("ajax-in-progress")||(t.classList.add("ajax-in-progress"),fcn_ajaxPost({action:"fictioneer_ajax_report_comment",id:t.dataset.id,dubious:n.classList.contains("_dubious")}).then((e=>{e.success?(n.classList.toggle("on",e.data.flagged),n.classList.remove("_dubious"),e.data.resync&&fcn_showNotification(e.data.resync)):e.data?.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")})).then((()=>{t.classList.remove("ajax-in-progress")})))}function fcn_revealCommentFormInputs(e){e.closest("form").querySelectorAll(".fictioneer-respond__form-actions, .fictioneer-respond__form-bottom").forEach((e=>{e.classList.remove("hidden")}))}function fcn_addCommentFormEvents(){_$$$("comment")?.addEventListener("focus",(e=>{fcn_revealCommentFormInputs(e.currentTarget)}),{once:!0})}function fcn_textareaAdjust(e){e.style.height="auto",e.style.height=e.scrollHeight+"px"}function fcn_addTextareaEvents(){_$$(".adaptive-textarea").forEach((e=>{e.addEventListener("input",(e=>{fcn_textareaAdjust(e.currentTarget)}))}))}function fcn_addPrivateToggleEvents(){_$$$("fictioneer-private-comment-toggle")?.addEventListener("change",(e=>{_$$$("respond")?.classList.toggle("_private",e.currentTarget.checked)}))}function fcn_wrapInTag(e,t,n={}){const o=n.href?' href="'+n.href+'" target="_blank" rel="nofollow noreferrer noopener"':"",c=n.shortcode?["[","]"]:["<",">"],a=e.selectionStart,i=e.selectionEnd,r=c[0]+t+o+c[1],s=c[0]+"/"+t+c[1],m=r+e.value.substring(a,i)+s;e.value=e.value.substring(0,a)+m+e.value.substring(i,e.value.length),e.setSelectionRange(a+r.length,i+r.length),e.focus()}function fcn_bindAJAXCommentSubmit(){fcn_theRoot.dataset.ajaxSubmit&&_$$$("commentform")?.addEventListener("submit",(e=>{if(e.preventDefault(),Date.now()<fcn_pageLoadTimestamp+3e3)return;const t=e.currentTarget,n=_$$$("submit"),o=_$$$("comment"),c=_$$$("author"),a=_$$$("email"),i=_$$$("wp-comment-cookies-consent"),r=_$$$("fictioneer-privacy-policy-consent"),s=_$$$("fictio