2023-08-21 00:57:03 +02:00
|
|
|
const fcn_ajaxCommentsSection=_$$$("comments");var fct_commentsObserver,fcn_commentStack=[];function fcn_getCommentSection(e=null,n=null,t=!1){if(!fcn_ajaxCommentsSection)return;const o=_$$$("comments");let c,a="",m=_$$$("comment");if(m&&(a=m.value),fcn_ajaxCommentsSection.classList.contains("ajax-in-progress"))return;if(fcn_ajaxCommentsSection.classList.add("ajax-in-progress"),n||(n=fcn_urlParams.pg??1),!fcn_ajaxCommentsSection)return;const r={action:"fictioneer_ajax_get_comment_section",post_id:e??fcn_ajaxCommentsSection.dataset.postId,page:parseInt(n)};fcn_urlParams.commentcode&&(r.commentcode=fcn_urlParams.commentcode),fcn_ajaxGet(r).then((e=>{if(e.success){n=e.data.page;const c=document.createElement("div");if(c.innerHTML=e.data.html,c.querySelector("#comment_post_ID")){c.querySelector("#comment_post_ID").value=e.data.postId,c.querySelector("#cancel-comment-reply-link").href="#respond";const n=c.querySelector(".logout-link");n&&(n.href=_$$$("comments").dataset.logoutUrl)}o.innerHTML=c.innerHTML,c.remove(),m=_$$$("comment"),m&&(m.value=a,fcn_commentStack.forEach((e=>{m.value+=e}))),fcn_commentStack=[],m&&fcn_textareaAdjust(m),fcn_addModerationEvents(),fcn_addCommentMouseleaveEvents(),fcn_addTextareaEvents(),fcn_addCommentFormEvents(),fcn_addPrivateToggleEvents(),fcn_bindAJAXCommentSubmit(),fcn_addJSTrap(),fcn_revealEditButton(),fcn_revealDeleteButton();const r=location.hash.includes("#comment")?location.hash:".respond",s=document.querySelector(r)??_$$$("respond");t&&s.scrollIntoView({behavior:"smooth"});const i=window.location.protocol+"//"+window.location.host+window.location.pathname;let _="";fcn_urlParams.commentcode&&(_+=`?commentcode=${fcn_urlParams.commentcode}`),n>1&&(_+=_.length>1?`&pg=${n}`:`?pg=${n}`),window.history.pushState({path:i},"",i+_+location.hash)}else c=fcn_buildErrorNotice(e.data.error)})).catch((e=>{c=fcn_buildErrorNotice(e)})).then((()=>{fcn_ajaxCommentsSection.classList.remove("ajax-in-progress"),c&&(o.innerHTML="",o.appendChild(c))}))}function fcn_reloadCommentsPage(e=null){fcn_getCommentSection(null,e,!0)}function fcn_jumpToCommentPage(){const e=parseInt(window.prompt(_x("Enter page number:","Pagination jump prompt.","fictioneer")));e>0&&fcn_reloadCommentsPage(e)}function fcn_setupCommentObserver(){fct_commentsObserver=new IntersectionObserver((([e])=>{e.isIntersecting&&(fcn_getCommentSection(),fct_commentsObserver.disconnect())}),{rootMargin:"400px",threshold:1}),fcn_ajaxCommentsSection&&fct_commentsObserver.observe(fcn_ajaxCommentsSection)}function fcn_loadCommentEarly(){_$$$("comments")&&location.hash.includes("#comment")&&(_$$$("comment")||(fct_commentsObserver.disconnect(),fcn_reloadCommentsPage()))}fcn_theRoot.dataset.ajaxNonce&&!_$$$("fictioneer-ajax-nonce")?fcn_theRoot.addEventListener("nonceReady",(()=>{fcn_setupCommentObserver()})):fcn_setupCommentObserver(),fcn_theRoot.dataset.ajaxNonce&&!_$$$("fictioneer-ajax-nonce")?fcn_theRoot.addEventListener("nonceReady",(()=>{fcn_loadCommentEarly()})):fcn_loadCommentEarly(),_$(".fictioneer-comments")?.addEventListener("click",(e=>{if(e.target.closest("[data-page-jump]"))return void fcn_jumpToCommentPage();const n=e.target.closest("[data-page]");n&&fcn_reloadCommentsPage(n.dataset.page)}));
|