WordPress/wp-admin/js/edit-comments.min.js

1 line
14 KiB
JavaScript

var setCommentsList,theList,theExtraList,commentReply;!function(_){var o,s,i=document.title,w=_("#dashboard_right_now").length,r=function(t){t=parseInt(t.html().replace(/[^0-9]+/g,""),10);return isNaN(t)?0:t},l=function(t,e){var n="";if(!isNaN(e)){if(3<(e=e<1?"0":e.toString()).length){for(;3<e.length;)n=thousandsSeparator+e.substr(e.length-3)+n,e=e.substr(0,e.length-3);e+=n}t.html(e)}},x=function(n,t){var e=".post-com-count-"+t,a="comment-count-no-comments",o="comment-count-approved";b("span.approved-count",n),t&&(t=_("span."+o,e),e=_("span."+a,e),t.each(function(){var t=_(this),e=r(t)+n;0===(e=e<1?0:e)?t.removeClass(o).addClass(a):t.addClass(o).removeClass(a),l(t,e)}),e.each(function(){var t=_(this);0<n?t.removeClass(a).addClass(o):t.addClass(a).removeClass(o),l(t,n)}))},b=function(t,n){_(t).each(function(){var t=_(this),e=r(t)+n;l(t,e=e<1?0:e)})},k=function(t){var e;w&&t&&t.i18n_comments_text&&(e=_("#dashboard_right_now"),_(".comment-count a",e).text(t.i18n_comments_text),_(".comment-mod-count a",e).text(t.i18n_moderation_text).parent()[0<t.in_moderation?"removeClass":"addClass"]("hidden"))},m=function(t){var e,n,a;s=s||new RegExp(adminCommentsL10n.docTitleCommentsCount.replace("%s","\\([0-9"+thousandsSeparator+"]+\\)")+"?"),o=o||_("<div />"),e=i,1<=(t=(a=s.exec(document.title))?(a=a[0],o.html(a),r(o)+t):(o.html(0),t))?(l(o,t),(n=s.exec(document.title))&&(e=document.title.replace(n[0],adminCommentsL10n.docTitleCommentsCount.replace("%s",o.text())+" "))):(n=s.exec(e))&&(e=e.replace(n[0],adminCommentsL10n.docTitleComments)),document.title=e},L=function(n,t){var e=".post-com-count-"+t,a="comment-count-no-pending",o="post-com-count-no-pending",s="comment-count-pending";w||m(n),_("span.pending-count").each(function(){var t=_(this),e=r(t)+n;e<1&&(e=0),t.closest(".awaiting-mod")[0===e?"addClass":"removeClass"]("count-0"),l(t,e)}),t&&(t=_("span."+s,e),e=_("span."+a,e),t.each(function(){var t=_(this),e=r(t)+n;0===(e=e<1?0:e)?(t.parent().addClass(o),t.removeClass(s).addClass(a)):(t.parent().removeClass(o),t.addClass(s).removeClass(a)),l(t,e)}),e.each(function(){var t=_(this);0<n?(t.parent().removeClass(o),t.removeClass(a).addClass(s)):(t.parent().addClass(o),t.addClass(a).removeClass(s)),l(t,n)}))};setCommentsList=function(){var i,f=0,g=_('input[name="_total"]',"#comments-form"),l=_('input[name="_per_page"]',"#comments-form"),m=_('input[name="_page"]',"#comments-form"),y=function(t,e,n){e<f||(n&&(f=e),g.val(t.toString()))},t=function(t,e){var n,a,o,s=_("#"+e.element);!0!==e.parsed&&(o=e.parsed.responses[0]),a=_("#replyrow"),n=_("#comment_ID",a).val(),a=_("#replybtn",a),s.is(".unapproved")?(e.data.id==n&&a.text(adminCommentsL10n.replyApprove),s.find(".row-actions span.view").addClass("hidden").end().find("div.comment_status").html("0")):(e.data.id==n&&a.text(adminCommentsL10n.reply),s.find(".row-actions span.view").removeClass("hidden").end().find("div.comment_status").html("1")),i=_("#"+e.element).is("."+e.dimClass)?1:-1,o?(k(o.supplemental),L(i,o.supplemental.postId),x(-1*i,o.supplemental.postId)):(L(i),x(-1*i))},e=function(t,e){var n,a,o,s,i=!1,r=_(t.target).attr("data-wp-lists");return t.data._total=g.val()||0,t.data._per_page=l.val()||0,t.data._page=m.val()||0,t.data._url=document.location.href,t.data.comment_status=_('input[name="comment_status"]',"#comments-form").val(),-1!=r.indexOf(":trash=1")?i="trash":-1!=r.indexOf(":spam=1")&&(i="spam"),i&&(n=r.replace(/.*?comment-([0-9]+).*/,"$1"),a=_("#comment-"+n),o=_("#"+i+"-undo-holder").html(),a.find(".check-column :checkbox").prop("checked",!1),a.siblings("#replyrow").length&&commentReply.cid==n&&commentReply.close(),o=a.is("tr")?(r=a.children(":visible").length,s=_(".author strong",a).text(),_('<tr id="undo-'+n+'" class="undo un'+i+'" style="display:none;"><td colspan="'+r+'">'+o+"</td></tr>")):(s=_(".comment-author",a).text(),_('<div id="undo-'+n+'" style="display:none;" class="undo un'+i+'">'+o+"</div>")),a.before(o),_("strong","#undo-"+n).text(s),(s=_(".undo a","#undo-"+n)).attr("href","comment.php?action=un"+i+"comment&c="+n+"&_wpnonce="+t.data._ajax_nonce),s.attr("data-wp-lists","delete:the-comment-list:comment-"+n+"::un"+i+"=1"),s.attr("class","vim-z vim-destructive"),_(".avatar",a).first().clone().prependTo("#undo-"+n+" ."+i+"-undo-inside"),s.click(function(t){t.preventDefault(),t.stopPropagation(),e.wpList.del(this),_("#undo-"+n).css({backgroundColor:"#ceb"}).fadeOut(350,function(){_(this).remove(),_("#comment-"+n).css("backgroundColor","").fadeIn(300,function(){_(this).show()})})})),t},n=function(t,e){var n,a,o,s,i=!0===e.parsed?{}:e.parsed.responses[0],r=!0===e.parsed?"":i.supplemental.status,l=!0===e.parsed?"":i.supplemental.postId,m=!0===e.parsed?"":i.supplemental,p=_(e.target).parent(),c=_("#"+e.element),d=c.hasClass("approved"),u=c.hasClass("unapproved"),h=c.hasClass("spam"),v=c.hasClass("trash"),c=!1;k(m),p.is("span.undo")?(p.hasClass("unspam")?(n=-1,"trash"===r?a=1:"1"===r?s=1:"0"===r&&(o=1)):p.hasClass("untrash")&&(a=-1,"spam"===r?n=1:"1"===r?s=1:"0"===r&&(o=1)),c=!0):p.is("span.spam")?(d?s=-1:u?o=-1:v&&(a=-1),n=1):p.is("span.unspam")?(d?o=1:u?s=1:(v||h)&&(p.hasClass("approve")?s=1:p.hasClass("unapprove")&&(o=1)),n=-1):p.is("span.trash")?(d?s=-1:u?o=-1:h&&(n=-1),a=1):p.is("span.untrash")?(d?o=1:u?s=1:v&&(p.hasClass("approve")?s=1:p.hasClass("unapprove")&&(o=1)),a=-1):p.is("span.approve:not(.unspam):not(.untrash)")?o=-(s=1):p.is("span.unapprove:not(.unspam):not(.untrash)")?(s=-1,o=1):p.is("span.delete")&&(h?n=-1:v&&(a=-1)),o&&(L(o,l),b("span.all-count",o)),s&&(x(s,l),b("span.all-count",s)),n&&b("span.spam-count",n),a&&b("span.trash-count",a),w||(a=g.val()?parseInt(g.val(),10):0,_(e.target).parent().is("span.undo")?a++:a--,a<0&&(a=0),"object"==typeof t?i.supplemental.total_items_i18n&&f<i.supplemental.time?((e=i.supplemental.total_items_i18n||"")&&(_(".displaying-num").text(e),_(".total-pages").text(i.supplemental.total_pages_i18n),_(".tablenav-pages").find(".next-page, .last-page").toggleClass("disabled",i.supplemental.total_pages==_(".current-page").val())),y(a,i.supplemental.time,!0)):i.supplemental.time&&y(a,i.supplemental.time,!1):y(a,t,!1)),theExtraList&&0!==theExtraList.length&&0!==theExtraList.children().length&&!c&&(theList.get(0).wpList.add(theExtraList.children(":eq(0):not(.no-items)").remove().clone()),C(),t=function(){_("#the-comment-list tr:visible").length||theList.get(0).wpList.add(theExtraList.find(".no-items").clone())},(c=_(":animated","#the-comment-list")).length?c.promise().done(t):t())},C=function(t){var e=_.query.get(),n=_(".total-pages").text(),a=_('input[name="_per_page"]',"#comments-form").val();e.paged||(e.paged=1),e.paged>n||(t?(theExtraList.empty(),e.number=Math.min(8,a)):(e.number=1,e.offset=Math.min(8,a)-1),e.no_placeholder=!0,e.paged++,!0===e.comment_type&&(e.comment_type=""),e=_.extend(e,{action:"fetch-list",list_args:list_args,_ajax_fetch_list_nonce:_("#_ajax_fetch_list_nonce").val()}),_.ajax({url:ajaxurl,global:!1,dataType:"json",data:e,success:function(t){theExtraList.get(0).wpList.add(t.rows)}}))};theExtraList=_("#the-extra-comment-list").wpList({alt:"",delColor:"none",addColor:"none"}),theList=_("#the-comment-list").wpList({alt:"",delBefore:e,dimAfter:t,delAfter:n,addColor:"none"}).bind("wpListDelEnd",function(t,e){var n=_(e.target).attr("data-wp-lists"),e=e.element.replace(/[^0-9]+/g,"");-1==n.indexOf(":trash=1")&&-1==n.indexOf(":spam=1")||_("#undo-"+e).fadeIn(300,function(){_(this).show()})})},commentReply={cid:"",act:"",originalContent:"",init:function(){var t=_("#replyrow");_("a.cancel",t).click(function(){return commentReply.revert()}),_("a.save",t).click(function(){return commentReply.send()}),_("input#author-name, input#author-email, input#author-url",t).keypress(function(t){if(13==t.which)return commentReply.send(),t.preventDefault(),!1}),_("#the-comment-list .column-comment > p").dblclick(function(){commentReply.toggle(_(this).parent())}),_("#doaction, #doaction2, #post-query-submit").click(function(){0<_("#the-comment-list #replyrow").length&&commentReply.close()}),this.comments_listing=_('#comments-form > input[name="comment_status"]').val()||""},addEvents:function(t){t.each(function(){_(this).find(".column-comment > p").dblclick(function(){commentReply.toggle(_(this).parent())})})},toggle:function(t){"none"!==_(t).css("display")&&(_("#replyrow").parent().is("#com-reply")||window.confirm(adminCommentsL10n.warnQuickEdit))&&_(t).find("a.vim-q").click()},revert:function(){return _("#the-comment-list #replyrow").length<1||_("#replyrow").fadeOut("fast",function(){commentReply.close()}),!1},close:function(){var t,e=_("#replyrow");e.parent().is("#com-reply")||(this.cid&&"edit-comment"==this.act&&(t=_("#comment-"+this.cid)).fadeIn(300,function(){t.show()}).css("backgroundColor",""),"undefined"!=typeof QTags&&QTags.closeAllTags("replycontent"),_("#add-new-comment").css("display",""),e.hide(),_("#com-reply").append(e),_("#replycontent").css("height","").val(""),_("#edithead input").val(""),_(".error",e).empty().hide(),_(".spinner",e).removeClass("is-active"),this.cid="",this.originalContent="")},open:function(t,e,n){var a,o,s,i,r=_("#comment-"+t),l=r.height();return this.discardCommentChanges()&&(this.close(),this.cid=t,a=_("#replyrow"),o=_("#inline-"+t),s="edit"==(n=n||"replyto")?"edit":"replyto",s=this.act=s+"-comment",this.originalContent=_("textarea.comment",o).val(),i=_("> th:visible, > td:visible",r).length,a.hasClass("inline-edit-row")&&0!==i&&_("td",a).attr("colspan",i),_("#action",a).val(s),_("#comment_post_ID",a).val(e),_("#comment_ID",a).val(t),"edit"==n?(_("#author-name",a).val(_("div.author",o).text()),_("#author-email",a).val(_("div.author-email",o).text()),_("#author-url",a).val(_("div.author-url",o).text()),_("#status",a).val(_("div.comment_status",o).text()),_("#replycontent",a).val(_("textarea.comment",o).val()),_("#edithead, #editlegend, #savebtn",a).show(),_("#replyhead, #replybtn, #addhead, #addbtn",a).hide(),120<l&&(l=500<l?500:l,_("#replycontent",a).css("height",l+"px")),r.after(a).fadeOut("fast",function(){_("#replyrow").fadeIn(300,function(){_(this).show()})})):"add"==n?(_("#addhead, #addbtn",a).show(),_("#replyhead, #replybtn, #edithead, #editlegend, #savebtn",a).hide(),_("#the-comment-list").prepend(a),_("#replyrow").fadeIn(300)):(n=_("#replybtn",a),_("#edithead, #editlegend, #savebtn, #addhead, #addbtn",a).hide(),_("#replyhead, #replybtn",a).show(),r.after(a),r.hasClass("unapproved")?n.text(adminCommentsL10n.replyApprove):n.text(adminCommentsL10n.reply),_("#replyrow").fadeIn(300,function(){_(this).show()})),setTimeout(function(){var t=_("#replyrow").offset().top,e=t+_("#replyrow").height(),n=window.pageYOffset||document.documentElement.scrollTop,a=document.documentElement.clientHeight||window.innerHeight||0;n+a-20<e?window.scroll(0,e-a+35):t-20<n&&window.scroll(0,t-35),_("#replycontent").focus().keyup(function(t){27==t.which&&commentReply.revert()})},600)),!1},send:function(){var e={};return _("#replysubmit .error").hide(),_("#replysubmit .spinner").addClass("is-active"),_("#replyrow input").not(":button").each(function(){var t=_(this);e[t.attr("name")]=t.val()}),e.content=_("#replycontent").val(),e.id=e.comment_post_ID,e.comments_listing=this.comments_listing,e.p=_('[name="p"]').val(),_("#comment-"+_("#comment_ID").val()).hasClass("unapproved")&&(e.approve_parent=1),_.ajax({type:"POST",url:ajaxurl,data:e,success:function(t){commentReply.show(t)},error:function(t){commentReply.error(t)}}),!1},show:function(t){var e,n,a,o=this;return"string"==typeof t?(o.error({responseText:t}),!1):(e=wpAjax.parseAjaxResponse(t)).errors?(o.error({responseText:wpAjax.broken}),!1):(o.revert(),t="#comment-"+(e=e.responses[0]).id,"edit-comment"==o.act&&_(t).remove(),void(e.supplemental.parent_approved&&(a=_("#comment-"+e.supplemental.parent_approved),L(-1,e.supplemental.parent_post_id),"moderated"==this.comments_listing)?a.animate({backgroundColor:"#CCEEBB"},400,function(){a.fadeOut()}):(e.supplemental.i18n_comments_text&&(w?k(e.supplemental):(x(1,e.supplemental.parent_post_id),b("span.all-count",1))),e=_.trim(e.data),_(e).hide(),_("#replyrow").after(e),t=_(t),o.addEvents(t),n=t.hasClass("unapproved")?"#FFFFE0":t.closest(".widefat, .postbox").css("backgroundColor"),t.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:n},300,function(){a&&a.length&&a.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:n},300).removeClass("unapproved").addClass("approved").find("div.comment_status").html("1")}))))},error:function(t){var e=t.statusText;_("#replysubmit .spinner").removeClass("is-active"),(e=t.responseText?t.responseText.replace(/<.[^<>]*?>/g,""):e)&&_("#replysubmit .error").html(e).show()},addcomment:function(t){var e=this;_("#add-new-comment").fadeOut(200,function(){e.open(0,t,"add"),_("table.comments-box").css("display",""),_("#no-comments").remove()})},discardCommentChanges:function(){var t=_("#replyrow");return this.originalContent===_("#replycontent",t).val()||window.confirm(adminCommentsL10n.warnCommentChanges)}},_(document).ready(function(){var t,e,n,a;setCommentsList(),commentReply.init(),_(document).on("click","span.delete a.delete",function(t){t.preventDefault()}),void 0!==_.table_hotkeys&&(t=function(n){return function(){var t="next"==n?"first":"last",e=_(".tablenav-pages ."+n+"-page:not(.disabled)");e.length&&(window.location=e[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g,"")+"&hotkeys_highlight_"+t+"=1")}},e=function(t,e){window.location=_("span.edit a",e).attr("href")},n=function(){_("#cb-select-all-1").data("wp-toggle",1).trigger("click").removeData("wp-toggle")},a=function(e){return function(){var t=_('select[name="action"]');_('option[value="'+e+'"]',t).prop("selected",!0),_("#doaction").click()}},_.table_hotkeys(_("table.widefat"),["a","u","s","d","r","q","z",["e",e],["shift+x",n],["shift+a",a("approve")],["shift+s",a("spam")],["shift+d",a("delete")],["shift+t",a("trash")],["shift+z",a("untrash")],["shift+u",a("unapprove")]],{highlight_first:adminCommentsL10n.hotkeys_highlight_first,highlight_last:adminCommentsL10n.hotkeys_highlight_last,prev_page_link_cb:t("prev"),next_page_link_cb:t("next"),hotkeys_opts:{disableInInput:!0,type:"keypress",noDisable:'.check-column input[type="checkbox"]'},cycle_expr:"#the-comment-list tr",start_row_index:0})),_("#the-comment-list").on("click",".comment-inline",function(t){t.preventDefault();var e=_(this),t="replyto";void 0!==e.data("action")&&(t=e.data("action")),commentReply.open(e.data("commentId"),e.data("postId"),t)})})}(jQuery);