1 var theList,theExtraList,toggleWithKeyboard=false;(function(d){var b,a,e,c;setCommentsList=function(){var g,i,k,n=0,j,l,h,m,f;g=d('input[name="_total"]',"#comments-form");i=d('input[name="_per_page"]',"#comments-form");k=d('input[name="_page"]',"#comments-form");j=function(s,p){var v=d("#"+p.element),o,u,q;o=d("#replyrow");u=d("#comment_ID",o).val();q=d("#replybtn",o);if(v.is(".unapproved")){if(p.data.id==u){q.text(adminCommentsL10n.replyApprove)}v.find("div.comment_status").html("0")}else{if(p.data.id==u){q.text(adminCommentsL10n.reply)}v.find("div.comment_status").html("1")}var t=d("#"+p.element).is("."+p.dimClass)?1:-1;e(t)};l=function(r,v){var x=d(r.target).attr("class"),o,p,q,u,w,t,s=false;r.data._total=g.val()||0;r.data._per_page=i.val()||0;r.data._page=k.val()||0;r.data._url=document.location.href;r.data.comment_status=d('input[name="comment_status"]',"#comments-form").val();if(x.indexOf(":trash=1")!=-1){s="trash"}else{if(x.indexOf(":spam=1")!=-1){s="spam"}}if(s){o=x.replace(/.*?comment-([0-9]+).*/,"$1");p=d("#comment-"+o);note=d("#"+s+"-undo-holder").html();p.find(".check-column :checkbox").prop("checked",false);if(p.siblings("#replyrow").length&&commentReply.cid==o){commentReply.close()}if(p.is("tr")){q=p.children(":visible").length;t=d(".author strong",p).text();u=d('<tr id="undo-'+o+'" class="undo un'+s+'" style="display:none;"><td colspan="'+q+'">'+note+"</td></tr>")}else{t=d(".comment-author",p).text();u=d('<div id="undo-'+o+'" style="display:none;" class="undo un'+s+'">'+note+"</div>")}p.before(u);d("strong","#undo-"+o).text(t);w=d(".undo a","#undo-"+o);w.attr("href","comment.php?action=un"+s+"comment&c="+o+"&_wpnonce="+r.data._ajax_nonce);w.attr("class","delete:the-comment-list:comment-"+o+"::un"+s+"=1 vim-z vim-destructive");d(".avatar",p).clone().prependTo("#undo-"+o+" ."+s+"-undo-inside");w.click(function(){v.wpList.del(this);d("#undo-"+o).css({backgroundColor:"#ceb"}).fadeOut(350,function(){d(this).remove();d("#comment-"+o).css("backgroundColor","").fadeIn(300,function(){d(this).show()})});return false})}return r};h=function(o,p,q){if(p<n){return}if(q){n=p}g.val(o.toString())};c=function(t){var s=d("#dashboard_right_now"),p,r,q,o;t=t||0;if(isNaN(t)||!s.length){return}p=d("span.total-count",s);r=d("span.approved-count",s);q=b(p);q=q+t;o=q-b(d("span.pending-count",s))-b(d("span.spam-count",s));a(p,q);a(r,o)};b=function(o){var p=parseInt(o.html().replace(/[^0-9]+/g,""),10);if(isNaN(p)){return 0}return p};a=function(p,q){var o="";if(isNaN(q)){return}q=q<1?"0":q.toString();if(q.length>3){while(q.length>3){o=thousandsSeparator+q.substr(q.length-3)+o;q=q.substr(0,q.length-3)}q=q+o}p.html(q)};e=function(o){d("span.pending-count").each(function(){var p=d(this),q=b(p)+o;if(q<1){q=0}p.closest(".awaiting-mod")[0==q?"addClass":"removeClass"]("count-0");a(p,q)});c()};m=function(o,s){var v,t,x,w,p,y=d(s.target).parent().is("span.untrash"),q=d(s.target).parent().is("span.unspam"),u=d("#"+s.element).is(".unapproved");function z(r){if(d(s.target).parent().is("span."+r)){return 1}else{if(d("#"+s.element).is("."+r)){return -1}}return 0}if(y){w=-1}else{w=z("trash")}if(q){x=-1}else{x=z("spam")}if(d(s.target).parent().is("span.unapprove")||((y||q)&&u)){p=1}else{if(u){p=-1}}if(p){e(p)}d("span.spam-count").each(function(){var r=d(this),A=b(r)+x;a(r,A)});d("span.trash-count").each(function(){var r=d(this),A=b(r)+w;a(r,A)});if(d("#dashboard_right_now").length){t=w?-1*w:0;c(t)}else{v=g.val()?parseInt(g.val(),10):0;if(d(s.target).parent().is("span.undo")){v++}else{v--}if(v<0){v=0}if(("object"==typeof o)&&n<s.parsed.responses[0].supplemental.time){total_items_i18n=s.parsed.responses[0].supplemental.total_items_i18n||"";if(total_items_i18n){d(".displaying-num").text(total_items_i18n);d(".total-pages").text(s.parsed.responses[0].supplemental.total_pages_i18n);d(".tablenav-pages").find(".next-page, .last-page").toggleClass("disabled",s.parsed.responses[0].supplemental.total_pages==d(".current-page").val())}h(v,s.parsed.responses[0].supplemental.time,true)}else{h(v,o,false)}}if(!theExtraList||theExtraList.size()==0||theExtraList.children().size()==0||y||q){return}theList.get(0).wpList.add(theExtraList.children(":eq(0)").remove().clone());f()};f=function(r){var p=d.query.get(),o=d(".total-pages").text(),q=d('input[name="_per_page"]',"#comments-form").val();if(!p.paged){p.paged=1}if(p.paged>o){return}if(r){theExtraList.empty();p.number=Math.min(8,q)}else{p.number=1;p.offset=Math.min(8,q)-1}p.no_placeholder=true;p.paged++;if(true===p.comment_type){p.comment_type=""}p=d.extend(p,{action:"fetch-list",list_args:list_args,_ajax_fetch_list_nonce:d("#_ajax_fetch_list_nonce").val()});d.ajax({url:ajaxurl,global:false,dataType:"json",data:p,success:function(s){theExtraList.get(0).wpList.add(s.rows)}})};theExtraList=d("#the-extra-comment-list").wpList({alt:"",delColor:"none",addColor:"none"});theList=d("#the-comment-list").wpList({alt:"",delBefore:l,dimAfter:j,delAfter:m,addColor:"none"}).bind("wpListDelEnd",function(p,o){var q=o.element.replace(/[^0-9]+/g,"");if(o.target.className.indexOf(":trash=1")!=-1||o.target.className.indexOf(":spam=1")!=-1){d("#undo-"+q).fadeIn(300,function(){d(this).show()})}})};commentReply={cid:"",act:"",init:function(){var f=d("#replyrow");d("a.cancel",f).click(function(){return commentReply.revert()});d("a.save",f).click(function(){return commentReply.send()});d("input#author, input#author-email, input#author-url",f).keypress(function(g){if(g.which==13){commentReply.send();g.preventDefault();return false}});d("#the-comment-list .column-comment > p").dblclick(function(){commentReply.toggle(d(this).parent())});d("#doaction, #doaction2, #post-query-submit").click(function(g){if(d("#the-comment-list #replyrow").length>0){commentReply.close()}});this.comments_listing=d('#comments-form > input[name="comment_status"]').val()||""},addEvents:function(f){f.each(function(){d(this).find(".column-comment > p").dblclick(function(){commentReply.toggle(d(this).parent())})})},toggle:function(f){if(d(f).css("display")!="none"){d(f).find("a.vim-q").click()}},revert:function(){if(d("#the-comment-list #replyrow").length<1){return false}d("#replyrow").fadeOut("fast",function(){commentReply.close()});return false},close:function(){var g,f=d("#replyrow");if(f.parent().is("#com-reply")){return}if(this.cid&&this.act=="edit-comment"){g=d("#comment-"+this.cid);g.fadeIn(300,function(){g.show()}).css("backgroundColor","")}if(typeof QTags!="undefined"){QTags.closeAllTags("replycontent")}d("#add-new-comment").css("display","");f.hide();d("#com-reply").append(f);d("#replycontent").css("height","").val("");d("#edithead input").val("");d(".error",f).html("").hide();d(".waiting",f).hide();this.cid=""},open:function(f,i,k){var p=this,g,j,m,n=d("#comment-"+f),l=n.height(),o;p.close();p.cid=f;g=d("#replyrow");j=d("#inline-"+f);k=k||"replyto";m="edit"==k?"edit":"replyto";m=p.act=m+"-comment";d("#action",g).val(m);d("#comment_post_ID",g).val(i);d("#comment_ID",g).val(f);if(l>120){d("#replycontent",g).css("height",(35+l)+"px")}if(k=="edit"){d("#author",g).val(d("div.author",j).text());d("#author-email",g).val(d("div.author-email",j).text());d("#author-url",g).val(d("div.author-url",j).text());d("#status",g).val(d("div.comment_status",j).text());d("#replycontent",g).val(d("textarea.comment",j).val());d("#edithead, #savebtn",g).show();d("#replyhead, #replybtn, #addhead, #addbtn",g).hide();n.after(g).fadeOut("fast",function(){d("#replyrow").fadeIn(300,function(){d(this).show()})})}else{if(k=="add"){d("#addhead, #addbtn",g).show();d("#replyhead, #replybtn, #edithead, #editbtn",g).hide();d("#the-comment-list").prepend(g);d("#replyrow").fadeIn(300)}else{o=d("#replybtn",g);d("#edithead, #savebtn, #addhead, #addbtn",g).hide();d("#replyhead, #replybtn",g).show();n.after(g);if(n.hasClass("unapproved")){o.text(adminCommentsL10n.replyApprove)}else{o.text(adminCommentsL10n.reply)}d("#replyrow").fadeIn(300,function(){d(this).show()})}}setTimeout(function(){var s,q,t,h,r;s=d("#replyrow").offset().top;q=s+d("#replyrow").height();t=window.pageYOffset||document.documentElement.scrollTop;h=document.documentElement.clientHeight||self.innerHeight||0;r=t+h;if(r-20<q){window.scroll(0,q-h+35)}else{if(s-20<t){window.scroll(0,s-35)}}d("#replycontent").focus().keyup(function(u){if(u.which==27){commentReply.revert()}})},600);return false},send:function(){var f={};d("#replysubmit .error").hide();d("#replysubmit .waiting").show();d("#replyrow input").not(":button").each(function(){var g=d(this);f[g.attr("name")]=g.val()});f.content=d("#replycontent").val();f.id=f.comment_post_ID;f.comments_listing=this.comments_listing;f.p=d('[name="p"]').val();if(d("#comment-"+d("#comment_ID").val()).hasClass("unapproved")){f.approve_parent=1}d.ajax({type:"POST",url:ajaxurl,data:f,success:function(g){commentReply.show(g)},error:function(g){commentReply.error(g)}});return false},show:function(g){var i=this,j,l,k,h,f;if(typeof(g)=="string"){i.error({responseText:g});return false}j=wpAjax.parseAjaxResponse(g);if(j.errors){i.error({responseText:wpAjax.broken});return false}i.revert();j=j.responses[0];l=j.data;k="#comment-"+j.id;if("edit-comment"==i.act){d(k).remove()}if(j.supplemental.parent_approved){f=d("#comment-"+j.supplemental.parent_approved);e(-1);if(this.comments_listing=="moderated"){f.animate({backgroundColor:"#CCEEBB"},400,function(){f.fadeOut()});return}}d(l).hide();d("#replyrow").after(l);k=d(k);i.addEvents(k);h=k.hasClass("unapproved")?"#FFFFE0":k.closest(".widefat, .postbox").css("backgroundColor");k.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:h},300,function(){if(f&&f.length){f.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:h},300).removeClass("unapproved").addClass("approved").find("div.comment_status").html("1")}})},error:function(f){var g=f.statusText;d("#replysubmit .waiting").hide();if(f.responseText){g=f.responseText.replace(/<.[^<>]*?>/g,"")}if(g){d("#replysubmit .error").html(g).show()}},addcomment:function(f){var g=this;d("#add-new-comment").fadeOut(200,function(){g.open(0,f,"add");d("table.comments-box").css("display","");d("#no-comments").remove()})}};d(document).ready(function(){var i,f,g,h;setCommentsList();commentReply.init();d(document).delegate("span.delete a.delete","click",function(){return false});if(typeof d.table_hotkeys!="undefined"){i=function(j){return function(){var m,k;m="next"==j?"first":"last";k=d(".tablenav-pages ."+j+"-page:not(.disabled)");if(k.length){window.location=k[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g,"")+"&hotkeys_highlight_"+m+"=1"}}};f=function(k,j){window.location=d("span.edit a",j).attr("href")};g=function(){toggleWithKeyboard=true;d("input:checkbox","#cb").click().prop("checked",false);toggleWithKeyboard=false};h=function(j){return function(){var k=d('select[name="action"]');d('option[value="'+j+'"]',k).prop("selected",true);d("#doaction").click()}};d.table_hotkeys(d("table.widefat"),["a","u","s","d","r","q","z",["e",f],["shift+x",g],["shift+a",h("approve")],["shift+s",h("spam")],["shift+d",h("delete")],["shift+t",h("trash")],["shift+z",h("untrash")],["shift+u",h("unapprove")]],{highlight_first:adminCommentsL10n.hotkeys_highlight_first,highlight_last:adminCommentsL10n.hotkeys_highlight_last,prev_page_link_cb:i("prev"),next_page_link_cb:i("next")})}})})(jQuery); |
1 var theList, theExtraList, toggleWithKeyboard = false; |
|
2 |
|
3 (function($) { |
|
4 var getCount, updateCount, updatePending, dashboardTotals; |
|
5 |
|
6 setCommentsList = function() { |
|
7 var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList; |
|
8 |
|
9 totalInput = $('input[name="_total"]', '#comments-form'); |
|
10 perPageInput = $('input[name="_per_page"]', '#comments-form'); |
|
11 pageInput = $('input[name="_page"]', '#comments-form'); |
|
12 |
|
13 dimAfter = function( r, settings ) { |
|
14 var c = $('#' + settings.element), editRow, replyID, replyButton; |
|
15 |
|
16 editRow = $('#replyrow'); |
|
17 replyID = $('#comment_ID', editRow).val(); |
|
18 replyButton = $('#replybtn', editRow); |
|
19 |
|
20 if ( c.is('.unapproved') ) { |
|
21 if ( settings.data.id == replyID ) |
|
22 replyButton.text(adminCommentsL10n.replyApprove); |
|
23 |
|
24 c.find('div.comment_status').html('0'); |
|
25 } else { |
|
26 if ( settings.data.id == replyID ) |
|
27 replyButton.text(adminCommentsL10n.reply); |
|
28 |
|
29 c.find('div.comment_status').html('1'); |
|
30 } |
|
31 |
|
32 var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; |
|
33 updatePending( diff ); |
|
34 }; |
|
35 |
|
36 // Send current total, page, per_page and url |
|
37 delBefore = function( settings, list ) { |
|
38 var wpListsData = $(settings.target).attr('data-wp-lists'), id, el, n, h, a, author, action = false; |
|
39 |
|
40 settings.data._total = totalInput.val() || 0; |
|
41 settings.data._per_page = perPageInput.val() || 0; |
|
42 settings.data._page = pageInput.val() || 0; |
|
43 settings.data._url = document.location.href; |
|
44 settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val(); |
|
45 |
|
46 if ( wpListsData.indexOf(':trash=1') != -1 ) |
|
47 action = 'trash'; |
|
48 else if ( wpListsData.indexOf(':spam=1') != -1 ) |
|
49 action = 'spam'; |
|
50 |
|
51 if ( action ) { |
|
52 id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1'); |
|
53 el = $('#comment-' + id); |
|
54 note = $('#' + action + '-undo-holder').html(); |
|
55 |
|
56 el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits. |
|
57 |
|
58 if ( el.siblings('#replyrow').length && commentReply.cid == id ) |
|
59 commentReply.close(); |
|
60 |
|
61 if ( el.is('tr') ) { |
|
62 n = el.children(':visible').length; |
|
63 author = $('.author strong', el).text(); |
|
64 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>'); |
|
65 } else { |
|
66 author = $('.comment-author', el).text(); |
|
67 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>'); |
|
68 } |
|
69 |
|
70 el.before(h); |
|
71 |
|
72 $('strong', '#undo-' + id).text(author); |
|
73 a = $('.undo a', '#undo-' + id); |
|
74 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); |
|
75 a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1'); |
|
76 a.attr('class', 'vim-z vim-destructive'); |
|
77 $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); |
|
78 |
|
79 a.click(function(){ |
|
80 list.wpList.del(this); |
|
81 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ |
|
82 $(this).remove(); |
|
83 $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() }); |
|
84 }); |
|
85 return false; |
|
86 }); |
|
87 } |
|
88 |
|
89 return settings; |
|
90 }; |
|
91 |
|
92 // Updates the current total (stored in the _total input) |
|
93 updateTotalCount = function( total, time, setConfidentTime ) { |
|
94 if ( time < lastConfidentTime ) |
|
95 return; |
|
96 |
|
97 if ( setConfidentTime ) |
|
98 lastConfidentTime = time; |
|
99 |
|
100 totalInput.val( total.toString() ); |
|
101 }; |
|
102 |
|
103 dashboardTotals = function(n) { |
|
104 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN; |
|
105 |
|
106 n = n || 0; |
|
107 if ( isNaN(n) || !dash.length ) |
|
108 return; |
|
109 |
|
110 total = $('span.total-count', dash); |
|
111 appr = $('span.approved-count', dash); |
|
112 totalN = getCount(total); |
|
113 |
|
114 totalN = totalN + n; |
|
115 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) ); |
|
116 updateCount(total, totalN); |
|
117 updateCount(appr, apprN); |
|
118 }; |
|
119 |
|
120 getCount = function(el) { |
|
121 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); |
|
122 if ( isNaN(n) ) |
|
123 return 0; |
|
124 return n; |
|
125 }; |
|
126 |
|
127 updateCount = function(el, n) { |
|
128 var n1 = ''; |
|
129 if ( isNaN(n) ) |
|
130 return; |
|
131 n = n < 1 ? '0' : n.toString(); |
|
132 if ( n.length > 3 ) { |
|
133 while ( n.length > 3 ) { |
|
134 n1 = thousandsSeparator + n.substr(n.length - 3) + n1; |
|
135 n = n.substr(0, n.length - 3); |
|
136 } |
|
137 n = n + n1; |
|
138 } |
|
139 el.html(n); |
|
140 }; |
|
141 |
|
142 updatePending = function( diff ) { |
|
143 $('span.pending-count').each(function() { |
|
144 var a = $(this), n = getCount(a) + diff; |
|
145 if ( n < 1 ) |
|
146 n = 0; |
|
147 a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); |
|
148 updateCount( a, n ); |
|
149 }); |
|
150 |
|
151 dashboardTotals(); |
|
152 }; |
|
153 |
|
154 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success |
|
155 delAfter = function( r, settings ) { |
|
156 var total, N, spam, trash, pending, |
|
157 untrash = $(settings.target).parent().is('span.untrash'), |
|
158 unspam = $(settings.target).parent().is('span.unspam'), |
|
159 unapproved = $('#' + settings.element).is('.unapproved'); |
|
160 |
|
161 function getUpdate(s) { |
|
162 if ( $(settings.target).parent().is('span.' + s) ) |
|
163 return 1; |
|
164 else if ( $('#' + settings.element).is('.' + s) ) |
|
165 return -1; |
|
166 |
|
167 return 0; |
|
168 } |
|
169 |
|
170 if ( untrash ) |
|
171 trash = -1; |
|
172 else |
|
173 trash = getUpdate('trash'); |
|
174 |
|
175 if ( unspam ) |
|
176 spam = -1; |
|
177 else |
|
178 spam = getUpdate('spam'); |
|
179 |
|
180 if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { |
|
181 // a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending, |
|
182 // or a trash/spam of a pending comment was undone |
|
183 pending = 1; |
|
184 } else if ( unapproved ) { |
|
185 // a pending comment was trashed/spammed/approved |
|
186 pending = -1; |
|
187 } |
|
188 |
|
189 if ( pending ) |
|
190 updatePending(pending); |
|
191 |
|
192 $('span.spam-count').each( function() { |
|
193 var a = $(this), n = getCount(a) + spam; |
|
194 updateCount(a, n); |
|
195 }); |
|
196 |
|
197 $('span.trash-count').each( function() { |
|
198 var a = $(this), n = getCount(a) + trash; |
|
199 updateCount(a, n); |
|
200 }); |
|
201 |
|
202 if ( $('#dashboard_right_now').length ) { |
|
203 N = trash ? -1 * trash : 0; |
|
204 dashboardTotals(N); |
|
205 } else { |
|
206 total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; |
|
207 if ( $(settings.target).parent().is('span.undo') ) |
|
208 total++; |
|
209 else |
|
210 total--; |
|
211 |
|
212 if ( total < 0 ) |
|
213 total = 0; |
|
214 |
|
215 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { |
|
216 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || ''; |
|
217 if ( total_items_i18n ) { |
|
218 $('.displaying-num').text( total_items_i18n ); |
|
219 $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n ); |
|
220 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val()); |
|
221 } |
|
222 updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true ); |
|
223 } else { |
|
224 updateTotalCount( total, r, false ); |
|
225 } |
|
226 } |
|
227 |
|
228 if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) { |
|
229 return; |
|
230 } |
|
231 |
|
232 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); |
|
233 |
|
234 refillTheExtraList(); |
|
235 }; |
|
236 |
|
237 refillTheExtraList = function(ev) { |
|
238 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val(); |
|
239 |
|
240 if (! args.paged) |
|
241 args.paged = 1; |
|
242 |
|
243 if (args.paged > total_pages) { |
|
244 return; |
|
245 } |
|
246 |
|
247 if (ev) { |
|
248 theExtraList.empty(); |
|
249 args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php |
|
250 } else { |
|
251 args.number = 1; |
|
252 args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list |
|
253 } |
|
254 |
|
255 args.no_placeholder = true; |
|
256 |
|
257 args.paged ++; |
|
258 |
|
259 // $.query.get() needs some correction to be sent into an ajax request |
|
260 if ( true === args.comment_type ) |
|
261 args.comment_type = ''; |
|
262 |
|
263 args = $.extend(args, { |
|
264 'action': 'fetch-list', |
|
265 'list_args': list_args, |
|
266 '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val() |
|
267 }); |
|
268 |
|
269 $.ajax({ |
|
270 url: ajaxurl, |
|
271 global: false, |
|
272 dataType: 'json', |
|
273 data: args, |
|
274 success: function(response) { |
|
275 theExtraList.get(0).wpList.add( response.rows ); |
|
276 } |
|
277 }); |
|
278 }; |
|
279 |
|
280 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); |
|
281 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) |
|
282 .bind('wpListDelEnd', function(e, s){ |
|
283 var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, ''); |
|
284 |
|
285 if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 ) |
|
286 $('#undo-' + id).fadeIn(300, function(){ $(this).show() }); |
|
287 }); |
|
288 }; |
|
289 |
|
290 commentReply = { |
|
291 cid : '', |
|
292 act : '', |
|
293 |
|
294 init : function() { |
|
295 var row = $('#replyrow'); |
|
296 |
|
297 $('a.cancel', row).click(function() { return commentReply.revert(); }); |
|
298 $('a.save', row).click(function() { return commentReply.send(); }); |
|
299 $('input#author, input#author-email, input#author-url', row).keypress(function(e){ |
|
300 if ( e.which == 13 ) { |
|
301 commentReply.send(); |
|
302 e.preventDefault(); |
|
303 return false; |
|
304 } |
|
305 }); |
|
306 |
|
307 // add events |
|
308 $('#the-comment-list .column-comment > p').dblclick(function(){ |
|
309 commentReply.toggle($(this).parent()); |
|
310 }); |
|
311 |
|
312 $('#doaction, #doaction2, #post-query-submit').click(function(e){ |
|
313 if ( $('#the-comment-list #replyrow').length > 0 ) |
|
314 commentReply.close(); |
|
315 }); |
|
316 |
|
317 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; |
|
318 |
|
319 /* $(listTable).bind('beforeChangePage', function(){ |
|
320 commentReply.close(); |
|
321 }); */ |
|
322 }, |
|
323 |
|
324 addEvents : function(r) { |
|
325 r.each(function() { |
|
326 $(this).find('.column-comment > p').dblclick(function(){ |
|
327 commentReply.toggle($(this).parent()); |
|
328 }); |
|
329 }); |
|
330 }, |
|
331 |
|
332 toggle : function(el) { |
|
333 if ( $(el).css('display') != 'none' ) |
|
334 $(el).find('a.vim-q').click(); |
|
335 }, |
|
336 |
|
337 revert : function() { |
|
338 |
|
339 if ( $('#the-comment-list #replyrow').length < 1 ) |
|
340 return false; |
|
341 |
|
342 $('#replyrow').fadeOut('fast', function(){ |
|
343 commentReply.close(); |
|
344 }); |
|
345 |
|
346 return false; |
|
347 }, |
|
348 |
|
349 close : function() { |
|
350 var c, replyrow = $('#replyrow'); |
|
351 |
|
352 // replyrow is not showing? |
|
353 if ( replyrow.parent().is('#com-reply') ) |
|
354 return; |
|
355 |
|
356 if ( this.cid && this.act == 'edit-comment' ) { |
|
357 c = $('#comment-' + this.cid); |
|
358 c.fadeIn(300, function(){ c.show() }).css('backgroundColor', ''); |
|
359 } |
|
360 |
|
361 // reset the Quicktags buttons |
|
362 if ( typeof QTags != 'undefined' ) |
|
363 QTags.closeAllTags('replycontent'); |
|
364 |
|
365 $('#add-new-comment').css('display', ''); |
|
366 |
|
367 replyrow.hide(); |
|
368 $('#com-reply').append( replyrow ); |
|
369 $('#replycontent').css('height', '').val(''); |
|
370 $('#edithead input').val(''); |
|
371 $('.error', replyrow).html('').hide(); |
|
372 $('.spinner', replyrow).hide(); |
|
373 |
|
374 this.cid = ''; |
|
375 }, |
|
376 |
|
377 open : function(comment_id, post_id, action) { |
|
378 var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton; |
|
379 |
|
380 t.close(); |
|
381 t.cid = comment_id; |
|
382 |
|
383 editRow = $('#replyrow'); |
|
384 rowData = $('#inline-'+comment_id); |
|
385 action = action || 'replyto'; |
|
386 act = 'edit' == action ? 'edit' : 'replyto'; |
|
387 act = t.act = act + '-comment'; |
|
388 |
|
389 $('#action', editRow).val(act); |
|
390 $('#comment_post_ID', editRow).val(post_id); |
|
391 $('#comment_ID', editRow).val(comment_id); |
|
392 |
|
393 if ( h > 120 ) |
|
394 $('#replycontent', editRow).css('height', (35+h) + 'px'); |
|
395 |
|
396 if ( action == 'edit' ) { |
|
397 $('#author', editRow).val( $('div.author', rowData).text() ); |
|
398 $('#author-email', editRow).val( $('div.author-email', rowData).text() ); |
|
399 $('#author-url', editRow).val( $('div.author-url', rowData).text() ); |
|
400 $('#status', editRow).val( $('div.comment_status', rowData).text() ); |
|
401 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() ); |
|
402 $('#edithead, #savebtn', editRow).show(); |
|
403 $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide(); |
|
404 |
|
405 c.after( editRow ).fadeOut('fast', function(){ |
|
406 $('#replyrow').fadeIn(300, function(){ $(this).show() }); |
|
407 }); |
|
408 } else if ( action == 'add' ) { |
|
409 $('#addhead, #addbtn', editRow).show(); |
|
410 $('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide(); |
|
411 $('#the-comment-list').prepend(editRow); |
|
412 $('#replyrow').fadeIn(300); |
|
413 } else { |
|
414 replyButton = $('#replybtn', editRow); |
|
415 $('#edithead, #savebtn, #addhead, #addbtn', editRow).hide(); |
|
416 $('#replyhead, #replybtn', editRow).show(); |
|
417 c.after(editRow); |
|
418 |
|
419 if ( c.hasClass('unapproved') ) { |
|
420 replyButton.text(adminCommentsL10n.replyApprove); |
|
421 } else { |
|
422 replyButton.text(adminCommentsL10n.reply); |
|
423 } |
|
424 |
|
425 $('#replyrow').fadeIn(300, function(){ $(this).show() }); |
|
426 } |
|
427 |
|
428 setTimeout(function() { |
|
429 var rtop, rbottom, scrollTop, vp, scrollBottom; |
|
430 |
|
431 rtop = $('#replyrow').offset().top; |
|
432 rbottom = rtop + $('#replyrow').height(); |
|
433 scrollTop = window.pageYOffset || document.documentElement.scrollTop; |
|
434 vp = document.documentElement.clientHeight || self.innerHeight || 0; |
|
435 scrollBottom = scrollTop + vp; |
|
436 |
|
437 if ( scrollBottom - 20 < rbottom ) |
|
438 window.scroll(0, rbottom - vp + 35); |
|
439 else if ( rtop - 20 < scrollTop ) |
|
440 window.scroll(0, rtop - 35); |
|
441 |
|
442 $('#replycontent').focus().keyup(function(e){ |
|
443 if ( e.which == 27 ) |
|
444 commentReply.revert(); // close on Escape |
|
445 }); |
|
446 }, 600); |
|
447 |
|
448 return false; |
|
449 }, |
|
450 |
|
451 send : function() { |
|
452 var post = {}; |
|
453 |
|
454 $('#replysubmit .error').hide(); |
|
455 $('#replysubmit .spinner').show(); |
|
456 |
|
457 $('#replyrow input').not(':button').each(function() { |
|
458 var t = $(this); |
|
459 post[ t.attr('name') ] = t.val(); |
|
460 }); |
|
461 |
|
462 post.content = $('#replycontent').val(); |
|
463 post.id = post.comment_post_ID; |
|
464 post.comments_listing = this.comments_listing; |
|
465 post.p = $('[name="p"]').val(); |
|
466 |
|
467 if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') ) |
|
468 post.approve_parent = 1; |
|
469 |
|
470 $.ajax({ |
|
471 type : 'POST', |
|
472 url : ajaxurl, |
|
473 data : post, |
|
474 success : function(x) { commentReply.show(x); }, |
|
475 error : function(r) { commentReply.error(r); } |
|
476 }); |
|
477 |
|
478 return false; |
|
479 }, |
|
480 |
|
481 show : function(xml) { |
|
482 var t = this, r, c, id, bg, pid; |
|
483 |
|
484 if ( typeof(xml) == 'string' ) { |
|
485 t.error({'responseText': xml}); |
|
486 return false; |
|
487 } |
|
488 |
|
489 r = wpAjax.parseAjaxResponse(xml); |
|
490 if ( r.errors ) { |
|
491 t.error({'responseText': wpAjax.broken}); |
|
492 return false; |
|
493 } |
|
494 |
|
495 t.revert(); |
|
496 |
|
497 r = r.responses[0]; |
|
498 c = r.data; |
|
499 id = '#comment-' + r.id; |
|
500 |
|
501 if ( 'edit-comment' == t.act ) |
|
502 $(id).remove(); |
|
503 |
|
504 if ( r.supplemental.parent_approved ) { |
|
505 pid = $('#comment-' + r.supplemental.parent_approved); |
|
506 updatePending( -1 ); |
|
507 |
|
508 if ( this.comments_listing == 'moderated' ) { |
|
509 pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){ |
|
510 pid.fadeOut(); |
|
511 }); |
|
512 return; |
|
513 } |
|
514 } |
|
515 |
|
516 $(c).hide() |
|
517 $('#replyrow').after(c); |
|
518 id = $(id); |
|
519 t.addEvents(id); |
|
520 bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor'); |
|
521 |
|
522 id.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) |
|
523 .animate( { 'backgroundColor': bg }, 300, function() { |
|
524 if ( pid && pid.length ) { |
|
525 pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) |
|
526 .animate( { 'backgroundColor': bg }, 300 ) |
|
527 .removeClass('unapproved').addClass('approved') |
|
528 .find('div.comment_status').html('1'); |
|
529 } |
|
530 }); |
|
531 |
|
532 }, |
|
533 |
|
534 error : function(r) { |
|
535 var er = r.statusText; |
|
536 |
|
537 $('#replysubmit .spinner').hide(); |
|
538 |
|
539 if ( r.responseText ) |
|
540 er = r.responseText.replace( /<.[^<>]*?>/g, '' ); |
|
541 |
|
542 if ( er ) |
|
543 $('#replysubmit .error').html(er).show(); |
|
544 |
|
545 }, |
|
546 |
|
547 addcomment: function(post_id) { |
|
548 var t = this; |
|
549 |
|
550 $('#add-new-comment').fadeOut(200, function(){ |
|
551 t.open(0, post_id, 'add'); |
|
552 $('table.comments-box').css('display', ''); |
|
553 $('#no-comments').remove(); |
|
554 }); |
|
555 } |
|
556 }; |
|
557 |
|
558 $(document).ready(function(){ |
|
559 var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk; |
|
560 |
|
561 setCommentsList(); |
|
562 commentReply.init(); |
|
563 $(document).delegate('span.delete a.delete', 'click', function(){return false;}); |
|
564 |
|
565 if ( typeof $.table_hotkeys != 'undefined' ) { |
|
566 make_hotkeys_redirect = function(which) { |
|
567 return function() { |
|
568 var first_last, l; |
|
569 |
|
570 first_last = 'next' == which? 'first' : 'last'; |
|
571 l = $('.tablenav-pages .'+which+'-page:not(.disabled)'); |
|
572 if (l.length) |
|
573 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; |
|
574 } |
|
575 }; |
|
576 |
|
577 edit_comment = function(event, current_row) { |
|
578 window.location = $('span.edit a', current_row).attr('href'); |
|
579 }; |
|
580 |
|
581 toggle_all = function() { |
|
582 toggleWithKeyboard = true; |
|
583 $('input:checkbox', '#cb').click().prop('checked', false); |
|
584 toggleWithKeyboard = false; |
|
585 }; |
|
586 |
|
587 make_bulk = function(value) { |
|
588 return function() { |
|
589 var scope = $('select[name="action"]'); |
|
590 $('option[value="' + value + '"]', scope).prop('selected', true); |
|
591 $('#doaction').click(); |
|
592 } |
|
593 }; |
|
594 |
|
595 $.table_hotkeys( |
|
596 $('table.widefat'), |
|
597 ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], |
|
598 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')], |
|
599 ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')], |
|
600 ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]], |
|
601 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, |
|
602 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') } |
|
603 ); |
|
604 } |
|
605 }); |
|
606 |
|
607 })(jQuery); |