Files
wordpress-theme-aksrt/assets/js/runtime/comment.min.js
T
2026-08-29 16:15:06 +08:00

2 lines
7.8 KiB
JavaScript

jQuery.fn.FixedInput=function(action){var _this=jQuery(this);switch(_this.attr("on-start")||_this.on("click",".fixed-body",function(){_this.FixedInput("hide")}).attr("on-start",!0),action){case"show":return _this.addClass("show"),setTimeout(()=>{jQuery(_this.find("textarea,input")[0]).focus()},100);case"hide":return _this.find("#cancel-comment-reply-link").click(),_this.find("input,textarea").blur(),_this.find(".dropup").removeClass("open"),_this.removeClass("show");default:}},_win.bd.on("click","[fixed-input]",function(){var _this=jQuery(this),_fixed=jQuery(_this.attr("fixed-input"));scrollTopTo("#comments"),_fixed.FixedInput("show")});var $comments=jQuery("#comments-title"),$cancel=jQuery("#cancel-comment-reply-link"),$author=jQuery("#comment-user-info"),$submit=jQuery("#commentform #submit"),$com_ajax_url=_win.ajax_url,$com_list=jQuery("#postcomments .commentlist");_win.bd.on("click",".commentlist .pagenav a,.comment-orderby",function(){var _this=jQuery(this);if(jQuery("#cancel-comment-reply-link").click(),_this.hasClass("pag-jump")){_this.addClass("ajax-next");return}var ajax_replace=!_this.attr("no-replace");return post_ajax(jQuery(this),".commentlist",".commentlist",".comment","",".pagenav","","",ajax_replace)}),_win.bd.on("click",".comment-edit-link,.comment-reply-link",function(){var _this=jQuery(this),commentid=_this.attr("data-commentid"),is_edit=_this.hasClass("comment-edit-link");return addComment.moveForm(_this,"div-comment-"+commentid,commentid,"respond",_this.attr("data-postid"),is_edit),scrollTopTo(jQuery("#div-comment-"+commentid),-10),!1}),_win.bd.on("keydown","#comment",function(e){var keycode=e.which||e.keyCode;(e.metaKey||e.ctrlKey)&&keycode==13&&jQuery(this).closest("#commentform").find("#submit").click()}),_win.bd.on("click",".comment-trash-link",function(){var _this=jQuery(this),commentid=_this.attr("data-commentid"),trash_data={action:"trash_comment",comment_id:commentid,_wpnonce:_this.attr("data-nonce")};confirm(aksrt__("comment_confirm_delete"))==1&&aksrt_ajax(_this,trash_data,function(n){n.error||jQuery("#comment-"+commentid).slideUp().delay(1e3,function(){jQuery(this).remove()})},aksrt__("processing"))}),_win.bd.on("click",".comment-approve-link",function(){var _this=jQuery(this),commentid=_this.attr("data-commentid"),trash_data={action:"approve_comment",comment_id:commentid,_wpnonce:_this.attr("data-nonce")},reply=jQuery("#div-comment-"+commentid).find(".reply-link");aksrt_ajax(_this,trash_data,function(n){if(!n.error){var _text=n.status=="hold"?aksrt__("comment_approve"):aksrt__("comment_reject"),_class=n.status=="hold"?"approve":"unapprove",_badg=n.status=="hold"?'<span class="badg c-red badg-sm">'+aksrt__("comment_pending_review")+"</span>":"";n.status=="hold"?reply.remove():reply.length||_this.parents(".dropdown").before('<span class="reply-link"><a class="comment-reply-link" data-commentid="'+commentid+'" href="javascript:;">'+aksrt__("comment_reply")+"</a></span>"),jQuery("#div-comment-"+commentid).find(".badge-approve").html(_badg),_this.removeClass("approve unapprove").addClass(_class).find("text").html(_text)}})});function htmlEscapes(val){var htmlEscapes2={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"},a=val.replace(/[&<>"']/g,function(match){return htmlEscapes2[match]});return a}function htmlUnescapes(val){var htmlUnescapes2={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#039;":"'"},a=val.replace(/&(amp|lt|gt|quot|#039);/g,function(match){return htmlUnescapes2[match]});return a}_win.bd.on("click","#commentform #submit",function(){var _this=jQuery(this),_form=_this.parents("#commentform"),inputs=_form.serializeObject();if($author.length&&$author.attr("require_name_email")){if(inputs.author.length<2||inputs.email.length<4)return notyf(aksrt__("comment_enter_name_email"),"warning"),$author.addClass("open").find('[name="author"]').focus(),!1;if(!is_mail(inputs.email))return notyf(aksrt__("comment_email_invalid"),"warning"),$author.addClass("open").find('[name="email"]').focus(),!1}return inputs.comment.length<4?(notyf(aksrt__("comment_too_short"),"warning"),jQuery("#comment").focus(),!1):(inputs.comment=htmlEscapes(inputs.comment),inputs.action="submit_comment",aksrt_ajax(_this,inputs,function(n){var data=n.html;if(!n.error&&data){if(inputs.edit_comment_ID)$cancel.click(),jQuery("#comment-content-"+inputs.edit_comment_ID).html(data);else{var data=data.replace(/class="comment/,'style="display:none;" class="comment ajax-comment'),respond=jQuery("#respond"),$com_list2=jQuery("#postcomments .commentlist"),is_comment_parent=respond.parent().parent(".comment");if(is_comment_parent.length){var _children=is_comment_parent.find(">.children");_children.length?_children.prepend(data):is_comment_parent.append('<ul class="children">'+data+"</ul>")}else if(!$com_list2.length)respond.after('<div id="postcomments"><ol class="commentlist list-unstyled">'+data+"</ol></div>");else{var $order=jQuery("#postcomments .commentlist>.comment-filter");$order.length?$order.after(data):$com_list2.prepend(data)}if(jQuery("[reply-show]").length&&n.comment)if(~~n.comment.comment_approved>0){var hash=jQuery(jQuery("[reply-show]")[0]).attr("reload-hash");hash&&(window.location.hash=hash),window.location.reload()}else setTimeout(function(){notyf(aksrt__("comment_hidden_after_review"),"warning")},200);$cancel.click(),jQuery("#postcomments .ajax-comment").slideDown(200).removeClass("ajax-comment"),jQuery("#postcomments .comment-null").slideUp(200)}auto_fun(),wait_for(n.wait_time),jQuery("#comment").val(""),jQuery("#respond").FixedInput("hide")}}),!1)});var addComment={moveForm:function(_this,commId,parentId,respondId,postId,num){var t=this,div,comm=t.I(commId),respond=t.I(respondId),cancel=t.I("cancel-comment-reply-link"),parent=t.I("comment_parent"),post=t.I("comment_post_ID"),action_text_r=jQuery("#"+respondId+" .action-text");if(jQuery(".comment-footer").show(),num){var $submit_html=$submit.html();action_text_r.html(aksrt__("comment_edit_content")),t.I("comment").value="",jQuery("#comment_parent").attr("name","edit_comment_ID"),$submit.attr("disabled",!0).html('<i class="loading mr6"></i><span>'+aksrt__("loading")+"</span>"),jQuery("#comment").attr("disabled",!0).val(aksrt__("comment_fetching_content")),jQuery("#"+commId).find(".comment-footer").hide();var data={action:"get_comment",comment_id:parentId};aksrt_ajax(_this,data,function(n){n.error&&$cancel.click(),$submit.html($submit_html).attr("disabled",!1),jQuery("#comment").attr("disabled",!1).val(htmlUnescapes(n.comment_content)).focus()},"stop")}action_text_r.html(_this.attr("data-replyto")),t.respondId=respondId,postId=postId||!1,t.I("wp-temp-form-div")||(div=document.createElement("div"),div.id="wp-temp-form-div",div.style.display="none",respond.parentNode.insertBefore(div,respond)),comm?comm.parentNode.insertBefore(respond,comm.nextSibling):(temp=t.I("wp-temp-form-div"),t.I("comment_parent").value="0",temp.parentNode.insertBefore(respond,temp),temp.parentNode.removeChild(temp)),post&&postId&&(post.value=postId),parent.value=parentId,cancel.style.display="",cancel.onclick=function(){var t2=addComment,temp2=t2.I("wp-temp-form-div"),respond2=t2.I(t2.respondId);return jQuery("#comment_parent").attr("name","comment_parent"),t2.I("comment_parent").value="0",jQuery(".comment-footer").show(),jQuery("#comment").val("").trigger("input"),setTimeout(function(){jQuery("#"+respondId).removeClass("show")},10),action_text_r.html(""),temp2&&respond2&&(temp2.parentNode.insertBefore(respond2,temp2),temp2.parentNode.removeChild(temp2)),this.style.display="none",this.onclick=null,!1};try{setTimeout(function(){jQuery("#"+respondId).FixedInput("show")},10)}catch{}return!1},I:function(e){return document.getElementById(e)}};function wait_for($time){var wait=$time||15,$submit_html=$submit.html();function wait_ing(){wait>0?($submit.html('<div style="width:55px;"><i class="loading mr10"></i>'+wait+"</div>").attr("disabled",!0),wait--,setTimeout(wait_ing,1e3)):($submit.html($submit_html).attr("disabled",!1),wait=15)}wait_ing()}