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

1 line
9.1 KiB
JavaScript

var theList,theExtraList,toggleWithKeyboard=false;(function(a){setCommentsList=function(){var g,i,h,f=0,c,e,d,b;g=a('.tablenav input[name="_total"]',"#comments-form");i=a('.tablenav input[name="_per_page"]',"#comments-form");h=a('.tablenav input[name="_page"]',"#comments-form");c=function(k,j){var l=a("#"+j.element);if(l.is(".unapproved")){l.find("div.comment_status").html("0")}else{l.find("div.comment_status").html("1")}a("span.pending-count").each(function(){var m=a(this),o;o=m.html().replace(/[ ,.]+/g,"");o=parseInt(o,10);if(isNaN(o)){return}o=o+(a("#"+j.element).is("."+j.dimClass)?1:-1);if(o<0){o=0}m.closest("#awaiting-mod")[0==o?"addClass":"removeClass"]("count-0");o=o.toString();if(o.length>3){o=o.substr(0,o.length-3)+" "+o.substr(-3)}m.html(o)})};e=function(m,q){var s=a(m.target).attr("className"),j,k,l,p,r,o;m.data._total=g.val()||0;m.data._per_page=i.val()||0;m.data._page=h.val()||0;m.data._url=document.location.href;if(s.indexOf(":trash=1")!=-1){j=s.replace(/.*?comment-([0-9]+).*/,"$1");k=a("#comment-"+j);note=a("#undo-holder").html();if(k.is("tr")){l=k.children(":visible").length;o=a(".author strong",k).html();p=a('<tr id="trashundo-'+j+'" style="display:none;"><td class="trash-undo" colspan="'+l+'">'+note+"</td></tr>")}else{o=a(".comment-author",k).html();p=a('<div id="trashundo-'+j+'" style="display:none;" class="trash-undo">'+note+"</div>")}k.before(p);p.fadeIn(400);a("strong","#trashundo-"+j).html(o);r=a("a.undo-trash","#trashundo-"+j);r.attr("href","comment.php?action=untrashcomment&c="+j+"&_ajax_nonce="+m.data._ajax_nonce);r.attr("className","delete:the-comment-list:comment-"+j+"::untrash=1 vim-t vim-destructive");r.click(function(){q.wpList.del(this);a("#trashundo-"+j).fadeOut(250,function(){a(this).remove();a("#comment-"+j).css("backgroundColor","").fadeIn(400)});return false});window.setTimeout(function(){a("#trashundo-"+j).fadeOut("slow",function(){a(this).remove()})},200000)}return m};d=function(j,k,l){if(k<f){return}g.val(j.toString());if(l){f=k}a("span.total-type-count").each(function(){var m=a(this),o;o=g.val().toString();if(o.length>3){o=o.substr(0,o.length-3)+" "+o.substr(-3)}m.html(o)})};b=function(m,k){var l,n,j=a(k.target).parent().is("span.untrash");a("span.pending-count").each(function(){var o=a(this),q,p=a("#"+k.element).is(".unapproved");q=o.html().replace(/[ ,.]+/g,"");q=parseInt(q,10);if(isNaN(q)){return}if(a(k.target).parent().is("span.unapprove")||(j&&p)){q=q+1}else{if(p){q=q-1}}if(q<0){q=0}o.closest("#awaiting-mod")[0==q?"addClass":"removeClass"]("count-0");q=q.toString();if(q.length>3){q=q.substr(0,q.length-3)+" "+q.substr(-3)}o.html(q)});a("span.spam-count").each(function(){var o=a(this),p;p=o.html().replace(/[ ,.]+/g,"");p=parseInt(p,10);if(isNaN(p)){return}if(a(k.target).parent().is("span.spam")){p=p+1}else{if(a("#"+k.element).is(".spam")){p=p-1}}if(p<0){p=0}p=p.toString();if(p.length>3){p=p.substr(0,p.length-3)+" "+p.substr(-3)}o.html(p)});a("span.trash-count").each(function(){var o=a(this),p;p=o.html().replace(/[ ,.]+/g,"");p=parseInt(p,10);if(isNaN(p)){return}if(a(k.target).parent().is("span.trash")){p=p+1}else{if(a("#"+k.element).is(".trash")||j){p=p-1}}if(p<0){p=0}p=p.toString();if(p.length>3){p=p.substr(0,p.length-3)+" "+p.substr(-3)}o.html(p)});if(("object"==typeof m)&&f<k.parsed.responses[0].supplemental.time){l=k.parsed.responses[0].supplemental.total||false;n=k.parsed.responses[0].supplemental.pageLinks||false;if(l&&n){d(l,k.parsed.responses[0].supplemental.time,true);if(a.trim(n)){a(".tablenav-pages").find(".page-numbers").remove().end().append(a(n))}else{a(".tablenav-pages").find(".page-numbers").remove()}}}else{l=g.val()?parseInt(g.val(),10):0;if(l--<0){l=0}d(l,m,false)}if(theExtraList.size()==0||theExtraList.children().size()==0||j){return}theList.get(0).wpList.add(theExtraList.children(":eq(0)").remove().clone());a("#get-extra-comments").submit()};theExtraList=a("#the-extra-comment-list").wpList({alt:"",delColor:"none",addColor:"none"});theList=a("#the-comment-list").wpList({alt:"",delBefore:e,dimAfter:c,delAfter:b,addColor:"none"})};commentReply={init:function(){var b=a("#replyrow");a("a.cancel",b).click(function(){return commentReply.revert()});a("a.save",b).click(function(){return commentReply.send()});a("input#author, input#author-email, input#author-url",b).keypress(function(c){if(c.which==13){commentReply.send();c.preventDefault();return false}});a("#the-comment-list .column-comment > p").dblclick(function(){commentReply.toggle(a(this).parent())});a("#doaction, #doaction2, #post-query-submit").click(function(c){if(a("#the-comment-list #replyrow").length>0){commentReply.close()}});this.comments_listing=a('#comments-form > input[name="comment_status"]').val()||""},addEvents:function(b){b.each(function(){a(this).find(".column-comment > p").dblclick(function(){commentReply.toggle(a(this).parent())})})},toggle:function(b){if(a(b).css("display")!="none"){a(b).find("a.vim-q").click()}},revert:function(){if(a("#the-comment-list #replyrow").length<1){return false}a("#replyrow").fadeOut("fast",function(){commentReply.close()});return false},close:function(){a(this.o).fadeIn("fast").css("backgroundColor","");a("#com-reply").append(a("#replyrow"));a("#replycontent").val("");a("#edithead input").val("");a("#replysubmit .error").html("").hide();a("#replysubmit .waiting").hide();if(a.browser.msie){a("#replycontainer, #replycontent").css("height","120px")}else{a("#replycontainer").resizable("destroy").css("height","120px")}},open:function(i,g,c){var e=this,d,b,f;e.close();e.o="#comment-"+i;a("#replyrow td").attr("colspan",a(".widefat thead th:visible").length);d=a("#replyrow"),rowData=a("#inline-"+i);b=e.act=(c=="edit")?"edit-comment":"replyto-comment";a("#action",d).val(b);a("#comment_post_ID",d).val(g);a("#comment_ID",d).val(i);if(c=="edit"){a("#author",d).val(a("div.author",rowData).text());a("#author-email",d).val(a("div.author-email",rowData).text());a("#author-url",d).val(a("div.author-url",rowData).text());a("#status",d).val(a("div.comment_status",rowData).text());a("#replycontent",d).val(a("textarea.comment",rowData).val());a("#edithead, #savebtn",d).show();a("#replyhead, #replybtn",d).hide();f=a(e.o).height();if(f>220){if(a.browser.msie){a("#replycontainer, #replycontent",d).height(f-105)}else{a("#replycontainer",d).height(f-105)}}a(e.o).after(d.hide()).fadeOut("fast",function(){a("#replyrow").fadeIn("fast")})}else{a("#edithead, #savebtn",d).hide();a("#replyhead, #replybtn",d).show();a(e.o).after(d);a("#replyrow").hide().fadeIn("fast")}if(!a.browser.msie){a("#replycontainer").resizable({handles:"s",axis:"y",minHeight:80,stop:function(){a("#replycontainer").width("auto")}})}setTimeout(function(){var l,j,m,h,k;l=a("#replyrow").offset().top;j=l+a("#replyrow").height();m=window.pageYOffset||document.documentElement.scrollTop;h=document.documentElement.clientHeight||self.innerHeight||0;k=m+h;if(k-20<j){window.scroll(0,j-h+35)}else{if(l-20<m){window.scroll(0,l-35)}}a("#replycontent").focus().keyup(function(n){if(n.which==27){commentReply.revert()}})},600);return false},send:function(){var b={};a("#replysubmit .waiting").show();a("#replyrow input").each(function(){b[a(this).attr("name")]=a(this).val()});b.content=a("#replycontent").val();b.id=b.comment_post_ID;b.comments_listing=this.comments_listing;a.ajax({type:"POST",url:wpListL10n.url,data:b,success:function(c){commentReply.show(c)},error:function(c){commentReply.error(c)}});return false},show:function(b){var e,g,f,d;if(typeof(b)=="string"){this.error({responseText:b});return false}e=wpAjax.parseAjaxResponse(b);if(e.errors){this.error({responseText:wpAjax.broken});return false}if("edit-comment"==this.act){a(this.o).remove()}e=e.responses[0];g=e.data;a(g).hide();a("#replyrow").after(g);this.o=f="#comment-"+e.id;this.revert();this.addEvents(a(f));d=a(f).hasClass("unapproved")?"#ffffe0":"#fff";a(f).animate({backgroundColor:"#CCEEBB"},600).animate({backgroundColor:d},600);a.fn.wpList.process(a(f))},error:function(b){var c=b.statusText;a("#replysubmit .waiting").hide();if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#replysubmit .error").html(c).show()}}};a(document).ready(function(){var e,b,c,d;setCommentsList();commentReply.init();a("span.delete a.delete").click(function(){return false});if(typeof QTags!="undefined"){ed_reply=new QTags("ed_reply","replycontent","replycontainer","more")}if(typeof a.table_hotkeys!="undefined"){e=function(f){return function(){var h,g;h="next"==f?"first":"last";g=a("."+f+".page-numbers");if(g.length){window.location=g[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g,"")+"&hotkeys_highlight_"+h+"=1"}}};b=function(g,f){window.location=a("span.edit a",f).attr("href")};c=function(){toggleWithKeyboard=true;a("#comments-form thead #cb input:checkbox").click().attr("checked","");toggleWithKeyboard=false};d=function(f){return function(h,g){a("option[value="+f+"]").attr("selected","selected");a("form#comments-form")[0].submit()}};a.table_hotkeys(a("table.widefat"),["a","u","s","d","r","q",["e",b],["shift+a",d("approve")],["shift+s",d("markspam")],["shift+d",d("delete")],["shift+x",c],["shift+u",d("unapprove")]],{highlight_first:adminCommentsL10n.hotkeys_highlight_first,highlight_last:adminCommentsL10n.hotkeys_highlight_last,prev_page_link_cb:e("prev"),next_page_link_cb:e("next")})}})})(jQuery);