From 6777a247621995e49fc394657852dfa351b3fa18 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 16 Feb 2023 22:31:31 +0100 Subject: [PATCH] Hide comment form inputs until clicked --- INSTALLATION.md | 1 + functions.php | 5 +++++ includes/functions/comments/_comments_form.php | 9 ++++++--- includes/functions/comments/_comments_threads.php | 1 - js/comments.min.js | 2 +- src/js/comments.js | 13 +++++++++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/INSTALLATION.md b/INSTALLATION.md index c5ea2669..e8fd8d71 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -729,3 +729,4 @@ define( 'CONSTANT_NAME', value ); | FICTIONEER_SHOW_OAUTH_HASHES | boolean | Whether to show OAuth ID hashes in user profiles (admin only). Default `false`. | FICTIONEER_DISALLOWED_KEY_NOTICE | boolean | Whether to show feedback for rejected comment content. Default `true`. | FICTIONEER_FILTER_STORY_CHAPTERS | boolean | Whether to filter selectable chapters by assigned story. Default `true`. +| FICTIONEER_COLLAPSE_COMMENT_FORM | boolean | Whether hide comment form inputs until the textarea is clicked. Default `true`. diff --git a/functions.php b/functions.php index 0804c08a..e172c03c 100644 --- a/functions.php +++ b/functions.php @@ -134,6 +134,11 @@ if ( ! defined( 'FICTIONEER_FILTER_STORY_CHAPTERS' ) ) { define( 'FICTIONEER_FILTER_STORY_CHAPTERS', true ); } +// Boolean: Only show the full comment form after clicking into it +if ( ! defined( 'FICTIONEER_COLLAPSE_COMMENT_FORM' ) ) { + define( 'FICTIONEER_COLLAPSE_COMMENT_FORM', true ); +} + // ============================================================================= // GLOBAL // ============================================================================= diff --git a/includes/functions/comments/_comments_form.php b/includes/functions/comments/_comments_form.php index 537f96b2..d5c3c69b 100644 --- a/includes/functions/comments/_comments_form.php +++ b/includes/functions/comments/_comments_form.php @@ -64,6 +64,7 @@ if ( ! function_exists( 'fictioneer_change_comment_fields' ) ) { $name_placeholder = $required ? __( 'Name *', 'fictioneer' ) : __( 'Name', 'fictioneer' ); $email_placeholder = $required ? __( 'Email (Gravatar) *', 'fictioneer' ) : __( 'Email (optional, Gravatar)', 'fictioneer' ); $privacy_policy_link = get_option( 'wp_page_for_privacy_policy' ) ? esc_url( get_privacy_policy_url() ) : false; + $hidden = FICTIONEER_COLLAPSE_COMMENT_FORM ? 'hidden' : ''; // Rebuild author field $fields['author'] = '
'; @@ -101,7 +102,7 @@ if ( ! function_exists( 'fictioneer_change_comment_fields' ) ) { * around the author and email fields. */ - $fields['author'] = '
' . $fields['author']; + $fields['author'] = '
' . $fields['author']; $fields['email'] = $fields['email'] . '
'; return $fields; @@ -142,6 +143,7 @@ if ( ! function_exists( 'fictioneer_change_submit_field' ) ) { // Setup $close_bottom_container = is_user_logged_in() ? '' : '
'; $is_ajax = get_option( 'fictioneer_enable_ajax_comment_form' ) || get_option( 'fictioneer_enable_ajax_comments' ); + $hidden = FICTIONEER_COLLAPSE_COMMENT_FORM ? 'hidden' : ''; /** * Build the submit button with the comment_form arguments. Markup: @@ -195,7 +197,7 @@ if ( ! function_exists( 'fictioneer_change_submit_field' ) ) { */ return sprintf( - $close_bottom_container . '
' . $private_toggle . $notification_toggle . '%1$s %2$s
%3$s
' . $private_notice . '
', + $close_bottom_container . '
' . $private_toggle . $notification_toggle . '%1$s %2$s
%3$s
' . $private_notice . '
', $submit_button, get_comment_id_fields( get_the_ID() ), preg_replace( '/ 0 ) { $profile_link = get_permalink( $profile_page ); @@ -252,7 +255,7 @@ function fictioneer_comment_form_args( $defaults = [], $post_id = null ) { fictioneer_get_logout_url( get_permalink( $post_id ) ) ) ); - $comment_field = '
'. $toolbar . '
'; + $comment_field = '
'. $toolbar . '
'; // Prepare arguments $args = array( diff --git a/includes/functions/comments/_comments_threads.php b/includes/functions/comments/_comments_threads.php index e2efa30d..58b45f75 100644 --- a/includes/functions/comments/_comments_threads.php +++ b/includes/functions/comments/_comments_threads.php @@ -163,7 +163,6 @@ if ( ! function_exists( 'fictioneer_comments_ajax_form_skeleton' ) ) {
-
{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":o.onclick="",n.style.overflow="hidden",n.style.height="0",n.style.margin="0",n.style.opacity="0"}else o.innerHTML='',o.style.color="var(--warning)",o.style.opacity="1",o.onclick="",e.data.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{o.innerHTML='',o.style.color="var(--warning)",o.style.opacity="1",o.onclick="",e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")})))}function fcn_addModerationMenuEvents(e=document){e.querySelectorAll(".toggle-last-clicked").forEach((e=>{e.addEventListener("click",(e=>{fcn_toggleLastClicked(e.currentTarget),e.stopPropagation()}))}))}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;let t=e.closest(".fictioneer-comment"),n=t.querySelector(".fictioneer-report-comment-button");if(t.classList.contains("ajax-in-progress"))return;t.classList.add("ajax-in-progress");let o={action:"fictioneer_ajax_report_comment",id:t.dataset.id,dubious:n.classList.contains("_dubious")};fcn_ajaxPost(o).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_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={}){let o=n.href?' href="'+n.href+'" target="_blank" rel="nofollow noreferrer noopener"':"",a=n.shortcode?["[","]"]:["<",">"],c=e.selectionStart,i=e.selectionEnd,r=a[0]+t+o+a[1],s=a[0]+"/"+t+a[1],m=r+e.value.substring(c,i)+s;e.value=e.value.substring(0,c)+m+e.value.substring(i,e.value.length),e.setSelectionRange(c+r.length,i+r.length),e.focus()}function fcn_commentMakeBold(){fcn_wrapInTag(_$$$("comment"),"b",{shortcode:!0})}function fcn_commentMakeItalic(){fcn_wrapInTag(_$$$("comment"),"i",{shortcode:!0})}function fcn_commentMakeStrike(){fcn_wrapInTag(_$$$("comment"),"s",{shortcode:!0})}function fcn_commentMakeLink(){fcn_wrapInTag(_$$$("comment"),"link",{shortcode:!0})}function fcn_commentMakeQuote(){fcn_wrapInTag(_$$$("comment"),"quote",{shortcode:!0})}function fcn_commentMakeSpoiler(){fcn_wrapInTag(_$$$("comment"),"spoiler",{shortcode:!0})}function fcn_commentMakeImage(){fcn_wrapInTag(_$$$("comment"),"img",{shortcode:!0})}function fcn_bindAJAXCommentSubmit(){fcn_theRoot.dataset.ajaxSubmit&&"true"==fcn_theRoot.dataset.ajaxSubmit&&_$$$("commentform")?.addEventListener("submit",(e=>{if(e.preventDefault(),Date.now()1,o.classList.toggle("_error",!u),r&&(g=r.checked),r?.classList.toggle("_error",!g),c&&c.value.length>0&&(_=/\S+@\S+\.\S+/.test(c.value)),c?.classList.toggle("_error",!_),!u||!g||!_)return!1;t.classList.add("ajax-in-progress"),n.disabled=!0,n.value=n.dataset.disabled;let $={action:"fictioneer_ajax_submit_comment",post_id:_$$$("comment_post_ID").value,content:o.value,private_comment:d?.checked??0,notification:f?.checked??0,cookie_consent:i?.checked??0,privacy_consent:r?.checked??0,unfiltered_html:_$$$("_wp_unfiltered_html_comment_disabled")?.value??"",depth:l?parseInt(l.dataset.depth)+1:1,fictioneer_comment_validator:s?.value??0};m&&($.parent_id=m),c?.value&&($.email=c?.value),a?.value&&($.author=a?.value),fcn_ajaxPost($).then((e=>{if(_$$$("comment-submit-error-notice")?.remove(),e.success&&e.data?.comment){let t=_$(".commentlist"),n="insertBefore";if(t&&!l&&t.firstElementChild){let e=null;if(t.firstElementChild.classList.contains("_sticky"))for(e=t.firstElementChild,t=e,n="insertAfter";e.nextElementSibling&&e.nextElementSibling.classList.contains("_sticky");)e=t.nextElementSibling,t=e}if(!t){let e=document.createElement("ol");e.classList="fictioneer-comments__list commentlist",_$$$("comments").appendChild(e),n="append",t=e}if(l&&(t=l.querySelector(".children"),n="append",!t)){let e=document.createElement("ol");l.appendChild(e),t=e}let a=document.createElement("div");switch(a.innerHTML=e.data.comment,a=a.firstChild,n){case"append":t.appendChild(a);break;case"insertBefore":t.insertBefore(a,t.firstChild);break;case"insertAfter":t.nextSibling?t.parentNode.insertBefore(a,t.nextSibling):t.parentNode.appendChild(a)}fcn_addModerationMenuEvents(a),fcn_addModerationEvents(),fcn_addCommentMouseleaveEvents(),"0"!=_$$$("comment_parent").value&&_$$$("cancel-comment-reply-link").click(),o.value="",o.style.height="";let c=window.location.protocol+"//"+window.location.host+window.location.pathname,i="";e.data.commentcode&&(i+=`?commentcode=${e.data.commentcode}`),history.pushState({path:c},"",c+i+`#comment-${e.data.comment_id}`),a.scrollIntoView({behavior:"smooth"})}else{let n=e.data?.error??__("Error","fictioneer");t.insertBefore(fcn_buildErrorNotice(n,"comment-submit-error-notice"),t.firstChild)}})).catch((e=>{_$$$("comment-submit-error-notice")?.remove(),t.insertBefore(fcn_buildErrorNotice(`${e.status}: ${e.statusText}`,"comment-submit-error-notice"),t.firstChild)})).then((()=>{t.classList.remove("ajax-in-progress"),n.disabled=!1,n.value=n.dataset.enabled}))}))}fcn_addJSTrap(),fcn_addModerationEvents(),fcn_addCommentMouseleaveEvents(),fcn_addTextareaEvents(),fcn_addPrivateToggleEvents(),fcn_bindAJAXCommentSubmit();var fcn_commentEditUndos={};function fcn_triggerInlineCommentEdit(e){let t=e.closest(".fictioneer-comment");if(t){let e=t.querySelector(".fictioneer-comment__content"),n=t.querySelector(".fictioneer-comment__edit"),o=t.querySelector(".comment-inline-edit-content");fcn_commentEditUndos[t.id]=o.value,t.classList.add("_editing"),e.hidden=!0,n.hidden=!1,o.style.height=o.scrollHeight+"px"}}function fcn_submitInlineCommentEdit(e){let t=e.closest(".fictioneer-comment"),n=t.querySelector(".fictioneer-comment__edit"),o=t.querySelector(".fictioneer-comment__edit-note"),a=t.querySelector(".comment-inline-edit-content").value;if(a!=fcn_commentEditUndos[t.id]){if(t){let c={action:"fictioneer_ajax_edit_comment",comment_id:t.id.replace("comment-",""),content:a};n.classList.add("ajax-in-progress"),e.innerHTML=e.dataset.disabled,e.disabled=!0,fcn_ajaxPost(c).then((e=>{if(e.success){let n=t.querySelector(".fictioneer-comment__content");n.innerHTML=e.data.content,fcn_restoreComment(t,!1,e.data.raw),o||(o=document.createElement("div")),o.classList.add("fictioneer-comment__edit-note"),o.innerHTML=e.data.edited,n.parentNode.appendChild(o)}else fcn_restoreComment(t,!0),e.data?.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{fcn_restoreComment(t,!0),e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),e.innerHTML=e.dataset.enabled,e.disabled=!1}))}}else fcn_restoreComment(t,!0)}function fcn_cancelInlineCommentEdit(e){let t=e.closest(".fictioneer-comment");t&&fcn_restoreComment(t,!0)}function fcn_restoreComment(e,t=!1,n=null){e.querySelector(".fictioneer-comment__content").hidden=!1,e.querySelector(".fictioneer-comment__edit").hidden=!0,e.classList.remove("_editing"),t&&fcn_commentEditUndos[e.id]?e.querySelector(".comment-inline-edit-content").value=fcn_commentEditUndos[e.id]:n&&(e.querySelector(".comment-inline-edit-content").value=n)}function fcn_revealEditButton(){let e=parseInt(fcn_theRoot.dataset.editTime);e&&(e=e>0?6e4*e:e,_$$(".fictioneer-comment[data-fingerprint]").forEach((t=>{if(fcn_matchFingerprint(t.dataset.fingerprint)){if(e>0&&parseInt(t.dataset.timestamp)+e{if(fcn_matchFingerprint(e.dataset.fingerprint)){let t=e.querySelector(".fictioneer-comment__delete");t&&(t.hidden=!1)}}))}function fcn_deleteMyComment(e){if(!fcn_isLoggedIn)return;let t=prompt(e.dataset.dialogMessage);if(!t||t.toLowerCase()!=e.dataset.dialogConfirm.toLowerCase())return;let n=e.closest(".fictioneer-comment");if(n.classList.contains("ajax-in-progress"))return;n.classList.add("ajax-in-progress");let o={action:"fictioneer_ajax_delete_my_comment",comment_id:n.dataset.id};fcn_ajaxPost(o).then((e=>{e.success?(n.classList.add("_deleted"),n.querySelector(".fictioneer-comment__container").innerHTML=e.data.html):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((()=>{n.classList.remove("ajax-in-progress")}))}fcn_isLoggedIn&&fcn_revealEditButton(),fcn_isLoggedIn&&fcn_revealDeleteButton();const fcn_ajaxCommentForm=_$$$("ajax-comment-form-target");function fcn_getCommentForm(){let e,t={action:"fictioneer_ajax_get_comment_form",post_id:_$$$("comments").dataset.postId};fcn_ajaxGet(t).then((t=>{if(t.success){let e=document.createElement("div");e.innerHTML=t.data.html;let n=e.querySelector("#comment_post_ID"),o=e.querySelector("#cancel-comment-reply-link"),a=e.querySelector(".logout-link");n&&(n.value=t.data.postId),o&&(o.href="#respond"),a&&(a.href=_$$$("comments").dataset.logoutUrl),fcn_ajaxCommentForm.innerHTML=e.innerHTML,e.remove(),fcn_addTextareaEvents(),fcn_addPrivateToggleEvents(),fcn_theRoot.dataset.ajaxSubmit&&fcn_bindAJAXCommentSubmit(),fcn_addJSTrap()}else e=fcn_buildErrorNotice(t.data.error)})).catch((t=>{e=fcn_buildErrorNotice(t)})).then((()=>{fcn_ajaxCommentForm.classList.remove("comments-skeleton"),e&&(fcn_ajaxCommentForm.innerHTML="",fcn_ajaxCommentForm.appendChild(e))}))}fcn_ajaxCommentForm&&(fcn_theRoot.dataset.ajaxNonce&&!_$$$("fictioneer-ajax-nonce")?fcn_theRoot.addEventListener("nonceReady",(()=>{fcn_getCommentForm()})):fcn_getCommentForm()); \ No newline at end of file +function fcn_addJSTrap(){let e=document.querySelector(".comment-form");if(e){let t=document.createElement("input");t.setAttribute("type","hidden"),t.id="fictioneer-comment-validator",t.setAttribute("name","fictioneer_comment_validator"),t.setAttribute("value","299792458"),e.appendChild(t)}}function fcn_moderateComment(e,t){let n=_$$$(`comment-${e}`),o=n.querySelector(".fictioneer-mod-menu-toggle");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":o.onclick="",n.style.overflow="hidden",n.style.height="0",n.style.margin="0",n.style.opacity="0"}else o.innerHTML='',o.style.color="var(--warning)",o.style.opacity="1",o.onclick="",e.data.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{o.innerHTML='',o.style.color="var(--warning)",o.style.opacity="1",o.onclick="",e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress")})))}function fcn_addModerationMenuEvents(e=document){e.querySelectorAll(".toggle-last-clicked").forEach((e=>{e.addEventListener("click",(e=>{fcn_toggleLastClicked(e.currentTarget),e.stopPropagation()}))}))}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;let t=e.closest(".fictioneer-comment"),n=t.querySelector(".fictioneer-report-comment-button");if(t.classList.contains("ajax-in-progress"))return;t.classList.add("ajax-in-progress");let o={action:"fictioneer_ajax_report_comment",id:t.dataset.id,dubious:n.classList.contains("_dubious")};fcn_ajaxPost(o).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")})),e.removeAttribute("onclick")}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={}){let o=n.href?' href="'+n.href+'" target="_blank" rel="nofollow noreferrer noopener"':"",a=n.shortcode?["[","]"]:["<",">"],c=e.selectionStart,i=e.selectionEnd,r=a[0]+t+o+a[1],s=a[0]+"/"+t+a[1],m=r+e.value.substring(c,i)+s;e.value=e.value.substring(0,c)+m+e.value.substring(i,e.value.length),e.setSelectionRange(c+r.length,i+r.length),e.focus()}function fcn_commentMakeBold(){fcn_wrapInTag(_$$$("comment"),"b",{shortcode:!0})}function fcn_commentMakeItalic(){fcn_wrapInTag(_$$$("comment"),"i",{shortcode:!0})}function fcn_commentMakeStrike(){fcn_wrapInTag(_$$$("comment"),"s",{shortcode:!0})}function fcn_commentMakeLink(){fcn_wrapInTag(_$$$("comment"),"link",{shortcode:!0})}function fcn_commentMakeQuote(){fcn_wrapInTag(_$$$("comment"),"quote",{shortcode:!0})}function fcn_commentMakeSpoiler(){fcn_wrapInTag(_$$$("comment"),"spoiler",{shortcode:!0})}function fcn_commentMakeImage(){fcn_wrapInTag(_$$$("comment"),"img",{shortcode:!0})}function fcn_bindAJAXCommentSubmit(){fcn_theRoot.dataset.ajaxSubmit&&"true"==fcn_theRoot.dataset.ajaxSubmit&&_$$$("commentform")?.addEventListener("submit",(e=>{if(e.preventDefault(),Date.now()1,o.classList.toggle("_error",!u),r&&(g=r.checked),r?.classList.toggle("_error",!g),c&&c.value.length>0&&(_=/\S+@\S+\.\S+/.test(c.value)),c?.classList.toggle("_error",!_),!u||!g||!_)return!1;t.classList.add("ajax-in-progress"),n.disabled=!0,n.value=n.dataset.disabled;let p={action:"fictioneer_ajax_submit_comment",post_id:_$$$("comment_post_ID").value,content:o.value,private_comment:d?.checked??0,notification:f?.checked??0,cookie_consent:i?.checked??0,privacy_consent:r?.checked??0,unfiltered_html:_$$$("_wp_unfiltered_html_comment_disabled")?.value??"",depth:l?parseInt(l.dataset.depth)+1:1,fictioneer_comment_validator:s?.value??0};m&&(p.parent_id=m),c?.value&&(p.email=c?.value),a?.value&&(p.author=a?.value),fcn_ajaxPost(p).then((e=>{if(_$$$("comment-submit-error-notice")?.remove(),e.success&&e.data?.comment){let t=_$(".commentlist"),n="insertBefore";if(t&&!l&&t.firstElementChild){let e=null;if(t.firstElementChild.classList.contains("_sticky"))for(e=t.firstElementChild,t=e,n="insertAfter";e.nextElementSibling&&e.nextElementSibling.classList.contains("_sticky");)e=t.nextElementSibling,t=e}if(!t){let e=document.createElement("ol");e.classList="fictioneer-comments__list commentlist",_$$$("comments").appendChild(e),n="append",t=e}if(l&&(t=l.querySelector(".children"),n="append",!t)){let e=document.createElement("ol");l.appendChild(e),t=e}let a=document.createElement("div");switch(a.innerHTML=e.data.comment,a=a.firstChild,n){case"append":t.appendChild(a);break;case"insertBefore":t.insertBefore(a,t.firstChild);break;case"insertAfter":t.nextSibling?t.parentNode.insertBefore(a,t.nextSibling):t.parentNode.appendChild(a)}fcn_addModerationMenuEvents(a),fcn_addModerationEvents(),fcn_addCommentMouseleaveEvents(),"0"!=_$$$("comment_parent").value&&_$$$("cancel-comment-reply-link").click(),o.value="",o.style.height="";let c=window.location.protocol+"//"+window.location.host+window.location.pathname,i="";e.data.commentcode&&(i+=`?commentcode=${e.data.commentcode}`),history.pushState({path:c},"",c+i+`#comment-${e.data.comment_id}`),a.scrollIntoView({behavior:"smooth"})}else{let n=e.data?.error??__("Error","fictioneer");t.insertBefore(fcn_buildErrorNotice(n,"comment-submit-error-notice"),t.firstChild)}})).catch((e=>{_$$$("comment-submit-error-notice")?.remove(),t.insertBefore(fcn_buildErrorNotice(`${e.status}: ${e.statusText}`,"comment-submit-error-notice"),t.firstChild)})).then((()=>{t.classList.remove("ajax-in-progress"),n.disabled=!1,n.value=n.dataset.enabled}))}))}fcn_addJSTrap(),fcn_addModerationEvents(),fcn_addCommentMouseleaveEvents(),fcn_addTextareaEvents(),fcn_addPrivateToggleEvents(),fcn_bindAJAXCommentSubmit();var fcn_commentEditUndos={};function fcn_triggerInlineCommentEdit(e){let t=e.closest(".fictioneer-comment");if(t){let e=t.querySelector(".fictioneer-comment__content"),n=t.querySelector(".fictioneer-comment__edit"),o=t.querySelector(".comment-inline-edit-content");fcn_commentEditUndos[t.id]=o.value,t.classList.add("_editing"),e.hidden=!0,n.hidden=!1,o.style.height=o.scrollHeight+"px"}}function fcn_submitInlineCommentEdit(e){let t=e.closest(".fictioneer-comment"),n=t.querySelector(".fictioneer-comment__edit"),o=t.querySelector(".fictioneer-comment__edit-note"),a=t.querySelector(".comment-inline-edit-content").value;if(a!=fcn_commentEditUndos[t.id]){if(t){let c={action:"fictioneer_ajax_edit_comment",comment_id:t.id.replace("comment-",""),content:a};n.classList.add("ajax-in-progress"),e.innerHTML=e.dataset.disabled,e.disabled=!0,fcn_ajaxPost(c).then((e=>{if(e.success){let n=t.querySelector(".fictioneer-comment__content");n.innerHTML=e.data.content,fcn_restoreComment(t,!1,e.data.raw),o||(o=document.createElement("div")),o.classList.add("fictioneer-comment__edit-note"),o.innerHTML=e.data.edited,n.parentNode.appendChild(o)}else fcn_restoreComment(t,!0),e.data?.error&&fcn_showNotification(e.data.error,5,"warning")})).catch((e=>{fcn_restoreComment(t,!0),e.status&&e.statusText&&fcn_showNotification(`${e.status}: ${e.statusText}`,5,"warning")})).then((()=>{n.classList.remove("ajax-in-progress"),e.innerHTML=e.dataset.enabled,e.disabled=!1}))}}else fcn_restoreComment(t,!0)}function fcn_cancelInlineCommentEdit(e){let t=e.closest(".fictioneer-comment");t&&fcn_restoreComment(t,!0)}function fcn_restoreComment(e,t=!1,n=null){e.querySelector(".fictioneer-comment__content").hidden=!1,e.querySelector(".fictioneer-comment__edit").hidden=!0,e.classList.remove("_editing"),t&&fcn_commentEditUndos[e.id]?e.querySelector(".comment-inline-edit-content").value=fcn_commentEditUndos[e.id]:n&&(e.querySelector(".comment-inline-edit-content").value=n)}function fcn_revealEditButton(){let e=parseInt(fcn_theRoot.dataset.editTime);e&&(e=e>0?6e4*e:e,_$$(".fictioneer-comment[data-fingerprint]").forEach((t=>{if(fcn_matchFingerprint(t.dataset.fingerprint)){if(e>0&&parseInt(t.dataset.timestamp)+e{if(fcn_matchFingerprint(e.dataset.fingerprint)){let t=e.querySelector(".fictioneer-comment__delete");t&&(t.hidden=!1)}}))}function fcn_deleteMyComment(e){if(!fcn_isLoggedIn)return;let t=prompt(e.dataset.dialogMessage);if(!t||t.toLowerCase()!=e.dataset.dialogConfirm.toLowerCase())return;let n=e.closest(".fictioneer-comment");if(n.classList.contains("ajax-in-progress"))return;n.classList.add("ajax-in-progress");let o={action:"fictioneer_ajax_delete_my_comment",comment_id:n.dataset.id};fcn_ajaxPost(o).then((e=>{e.success?(n.classList.add("_deleted"),n.querySelector(".fictioneer-comment__container").innerHTML=e.data.html):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((()=>{n.classList.remove("ajax-in-progress")}))}fcn_isLoggedIn&&fcn_revealEditButton(),fcn_isLoggedIn&&fcn_revealDeleteButton();const fcn_ajaxCommentForm=_$$$("ajax-comment-form-target");function fcn_getCommentForm(){let e,t={action:"fictioneer_ajax_get_comment_form",post_id:_$$$("comments").dataset.postId};fcn_ajaxGet(t).then((t=>{if(t.success){let e=document.createElement("div");e.innerHTML=t.data.html;let n=e.querySelector("#comment_post_ID"),o=e.querySelector("#cancel-comment-reply-link"),a=e.querySelector(".logout-link");n&&(n.value=t.data.postId),o&&(o.href="#respond"),a&&(a.href=_$$$("comments").dataset.logoutUrl),fcn_ajaxCommentForm.innerHTML=e.innerHTML,e.remove(),fcn_addTextareaEvents(),fcn_addPrivateToggleEvents(),fcn_theRoot.dataset.ajaxSubmit&&fcn_bindAJAXCommentSubmit(),fcn_addJSTrap()}else e=fcn_buildErrorNotice(t.data.error)})).catch((t=>{e=fcn_buildErrorNotice(t)})).then((()=>{fcn_ajaxCommentForm.classList.remove("comments-skeleton"),e&&(fcn_ajaxCommentForm.innerHTML="",fcn_ajaxCommentForm.appendChild(e))}))}fcn_ajaxCommentForm&&(fcn_theRoot.dataset.ajaxNonce&&!_$$$("fictioneer-ajax-nonce")?fcn_theRoot.addEventListener("nonceReady",(()=>{fcn_getCommentForm()})):fcn_getCommentForm()); \ No newline at end of file diff --git a/src/js/comments.js b/src/js/comments.js index 13059e01..836f7324 100644 --- a/src/js/comments.js +++ b/src/js/comments.js @@ -259,6 +259,19 @@ function fcn_flagComment(source) { // THEME COMMENTS RESPONSE // ============================================================================= +/** + * Reveal comment form inputs. + * + * @since 5.0.21 + */ + +function fcn_revealCommentFormInputs(area) { + area.closest('form').querySelectorAll('.fictioneer-respond__form-actions, .fictioneer-respond__form-bottom').forEach(element => { + element.classList.remove('hidden'); + }); + area.removeAttribute('onclick'); +} + /** * Adjust textarea height to fit the value without vertical scroll bar. *