Changeset 10291 for trunk/wp-admin/js/edit-comments.js
- Timestamp:
- 01/02/2009 03:08:58 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/edit-comments.js
r10258 r10291 1 var theList; var theExtraList; 2 (function($) { 3 4 setCommentsList = function() { 5 var totalInput = $('#comments-form .tablenav :input[name="_total"]'); 6 var perPageInput = $('#comments-form .tablenav :input[name="_per_page"]'); 7 var pageInput = $('#comments-form .tablenav :input[name="_page"]'); 8 var lastConfidentTime = 0; 9 10 var dimAfter = function( r, settings ) { 11 var c = $('#' + settings.element); 12 13 if ( c.is('.unapproved') ) 14 c.find('div.comment_status').html('0') 15 else 16 c.find('div.comment_status').html('1') 17 18 $('span.pending-count').each( function() { 19 var a = $(this); 20 var n = a.html().replace(/[ ,.]+/g, ''); 21 n = parseInt(n,10); 22 if ( isNaN(n) ) return; 23 n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 ); 24 if ( n < 0 ) { n = 0; } 25 $('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); 26 n = n.toString(); 27 if ( n.length > 3 ) 28 n = n.substr(0, n.length-3)+' '+n.substr(-3); 29 a.html(n); 30 }); 31 }; 32 33 // Send current total, page, per_page and url 34 var delBefore = function( settings ) { 35 settings.data._total = totalInput.val(); 36 settings.data._per_page = perPageInput.val(); 37 settings.data._page = pageInput.val(); 38 settings.data._url = document.location.href; 39 return settings; 40 }; 41 42 /* Updates the current total (as displayed visibly) 43 */ 44 var updateTotalCount = function( total, time, setConfidentTime ) { 45 if ( time < lastConfidentTime ) { 46 return; 47 } 48 totalInput.val( total.toString() ); 49 if ( setConfidentTime ) { 50 lastConfidentTime = time; 51 } 52 $('span.total-type-count').each( function() { 53 var a = $(this); 54 var n = totalInput.val().toString(); 55 if ( n.length > 3 ) 56 n = n.substr(0, n.length-3)+' '+n.substr(-3); 57 a.html(n); 58 }); 59 60 }; 61 62 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success 63 var delAfter = function( r, settings ) { 64 $('span.pending-count').each( function() { 65 var a = $(this); 66 var n = a.html().replace(/[ ,.]+/g, ''); 67 n = parseInt(n,10); 68 if ( isNaN(n) ) return; 69 if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment 70 n = n - 1; 71 } else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove" 72 n = n + 1; 73 } 74 if ( n < 0 ) { n = 0; } 75 $('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); 76 n = n.toString(); 77 if ( n.length > 3 ) 78 n = n.substr(0, n.length-3)+' '+n.substr(-3); 79 a.html(n); 80 }); 81 82 $('span.spam-count').each( function() { 83 var a = $(this); 84 var n = a.html().replace(/[ ,.]+/g, ''); 85 n = parseInt(n,10); 86 if ( isNaN(n) ) return; 87 if ( $(settings.target).parents( 'span.spam' ).size() ) { // we marked a comment as spam 88 n = n + 1; 89 } else if ( $('#' + settings.element).is('.spam') ) { // we approved or deleted a comment marked as spam 90 n = n - 1; 91 } 92 if ( n < 0 ) { n = 0; } 93 n = n.toString(); 94 if ( n.length > 3 ) 95 n = n.substr(0, n.length-3)+' '+n.substr(-3); 96 a.html(n); 97 }); 98 99 100 // XML response 101 if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 102 // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links) 103 updateTotalCount( settings.parsed.responses[0].supplemental.total, settings.parsed.responses[0].supplemental.time, true ); 104 if ( $.trim( settings.parsed.responses[0].supplemental.pageLinks ) ) { 105 $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( settings.parsed.responses[0].supplemental.pageLinks ) ); 106 } else if ( 'undefined' != typeof settings.parsed.responses[0].supplemental.pageLinks ) { 107 $('.tablenav-pages').find( '.page-numbers' ).remove(); 108 } 109 } else { 110 // Decrement the total 111 var total = parseInt( totalInput.val(), 10 ); 112 if ( total-- < 0 ) 113 total = 0; 114 updateTotalCount( total, r, false ); 115 } 116 117 if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) { 118 return; 119 } 120 121 theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); 122 $('#get-extra-comments').submit(); 123 }; 124 125 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); 126 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ); 127 128 }; 129 130 $(document).ready(function(){ 131 setCommentsList(); 132 }); 133 134 commentReply = { 135 136 init : function() { 137 var row = $('#replyrow'); 138 139 $('a.cancel', row).click(function() { return commentReply.revert(); }); 140 $('a.save', row).click(function() { return commentReply.send(this); }); 141 142 // add events 143 $('#the-comment-list .column-comment > p').dblclick(function(){ 144 commentReply.toggle($(this).parent()); 145 }); 146 147 $('#doaction, #doaction2, #post-query-submit').click(function(e){ 148 if ( $('#the-comment-list #replyrow').length > 0 ) 149 t.close(); 150 }); 151 152 }, 153 154 addEvents : function(r) { 155 r.each(function() { 156 $(this).find('.column-comment > p').dblclick(function(){ 157 commentReply.toggle($(this).parent()); 158 }); 159 }); 160 }, 161 162 toggle : function(el) { 163 if ( $(el).css('display') != 'none' ) 164 $(el).find('a.vim-q').click(); 165 }, 166 167 revert : function() { 168 169 if ( $('#the-comment-list #replyrow').length < 1 ) 170 return false; 171 172 $('#replyrow').fadeOut('fast', function(){ 173 commentReply.close(); 174 }); 175 176 return false; 177 }, 178 179 close : function() { 180 $(this.o).fadeIn('fast').css('backgroundColor', ''); 181 $('#com-reply').append( $('#replyrow') ); 182 $('#replycontent').val(''); 183 $('#edithead input').val(''); 184 $('#replysubmit .error').html('').hide(); 185 $('#replysubmit .waiting').hide(); 186 if ( $.browser.msie ) 187 $('#replycontainer, #replycontent').css('height', '120px'); 188 else 189 $('#replycontainer').resizable('destroy').css('height', '120px'); 190 }, 191 192 open : function(id, p, a) { 193 var t = this; 194 t.close(); 195 t.o = '#comment-'+id; 196 197 $('#replyrow td').attr('colspan', $('.widefat thead th:visible').length); 198 var editRow = $('#replyrow'), rowData = $('#inline-'+id); 199 var act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment'; 200 201 $('#action', editRow).val(act); 202 $('#comment_post_ID', editRow).val(p); 203 $('#comment_ID', editRow).val(id); 204 205 if ( a == 'edit' ) { 206 $('#author', editRow).val( $('div.author', rowData).text() ); 207 $('#author-email', editRow).val( $('div.author-email', rowData).text() ); 208 $('#author-url', editRow).val( $('div.author-url', rowData).text() ); 209 $('#status', editRow).val( $('div.comment_status', rowData).text() ); 210 $('#replycontent', editRow).val( $('textarea.comment', rowData).val() ); 211 $('#edithead, #savebtn', editRow).show(); 212 $('#replyhead, #replybtn', editRow).hide(); 213 214 var h = $(t.o).height(); 215 if ( h > 220 ) 216 if ( $.browser.msie ) 217 $('#replycontainer, #replycontent', editRow).height(h-105); 218 else 219 $('#replycontainer', editRow).height(h-105); 220 221 $(t.o).after(editRow.hide()).fadeOut('fast', function(){ 222 $('#replyrow').fadeIn('fast'); 223 }); 224 } else { 225 $('#edithead, #savebtn', editRow).hide(); 226 $('#replyhead, #replybtn', editRow).show(); 227 $(t.o).after(editRow); 228 $('#replyrow').hide().fadeIn('fast'); 229 } 230 231 if ( ! $.browser.msie ) 232 $('#replycontainer').resizable({ 233 handles : 's', 234 axis : 'y', 235 minHeight : 80, 236 stop : function() { 237 $('#replycontainer').width('auto'); 238 } 239 }); 240 241 setTimeout(function() { 242 var rtop = $('#replyrow').offset().top; 243 var rbottom = rtop + $('#replyrow').height(); 244 var scrollTop = window.pageYOffset || document.documentElement.scrollTop; 245 var vp = document.documentElement.clientHeight || self.innerHeight || 0; 246 var scrollBottom = scrollTop + vp; 247 248 if ( scrollBottom - 20 < rbottom ) 249 window.scroll(0, rbottom - vp + 35); 250 else if ( rtop - 20 < scrollTop ) 251 window.scroll(0, rtop - 35); 252 253 $('#replycontent').focus().keyup(function(e){ 254 if (e.which == 27) commentReply.revert(); // close on Escape 255 }); 256 }, 600); 257 258 return false; 259 }, 260 261 send : function() { 262 var post = {}; 263 264 $('#replysubmit .waiting').show(); 265 266 $('#replyrow input').each(function() { 267 post[ $(this).attr('name') ] = $(this).val(); 268 }); 269 270 post.content = $('#replycontent').val(); 271 post.id = post.comment_post_ID; 272 273 $.ajax({ 274 type : 'POST', 275 url : wpListL10n.url, 276 data : post, 277 success : function(x) { commentReply.show(x); }, 278 error : function(r) { commentReply.error(r); } 279 }); 280 281 return false; 282 }, 283 284 show : function(xml) { 285 286 if ( typeof(xml) == 'string' ) { 287 this.error({'responseText': xml}); 288 return false; 289 } 290 291 var r = wpAjax.parseAjaxResponse(xml); 292 if ( r.errors ) { 293 this.error({'responseText': wpAjax.broken}); 294 return false; 295 } 296 297 if ( 'edit-comment' == this.act ) 298 $(this.o).remove(); 299 300 r = r.responses[0]; 301 var c = r.data; 302 303 $(c).hide() 304 $('#replyrow').after(c); 305 this.o = id = '#comment-'+r.id; 306 this.revert(); 307 this.addEvents($(id)); 308 var bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff'; 309 310 $(id) 311 .animate( { 'backgroundColor':'#CCEEBB' }, 600 ) 312 .animate( { 'backgroundColor': bg }, 600 ); 313 314 $.fn.wpList.process($(id)) 315 }, 316 317 error : function(r) { 318 var er = r.statusText; 319 320 $('#replysubmit .waiting').hide(); 321 322 if ( r.responseText ) 323 er = r.responseText.replace( /<.[^<>]*?>/g, '' ); 324 325 if ( er ) 326 $('#replysubmit .error').html(er).show(); 327 328 } 329 }; 330 toggleWithKeyboard = false; 331 $(document).ready(function(){ 332 columns.init('edit-comments'); 333 commentReply.init(); 334 335 if ( typeof QTags != 'undefined' ) 336 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more'); 337 338 if ( typeof $.table_hotkeys != 'undefined' ) { 339 var make_hotkeys_redirect = function(which) { 340 return function() { 341 var first_last = 'next' == which? 'first' : 'last'; 342 var l=$('.'+which+'.page-numbers'); 343 if (l.length) 344 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; 345 } 346 }; 347 var edit_comment = function(event, current_row) { 348 window.location = $('span.edit a', current_row).attr('href'); 349 }; 350 var toggle_all = function() { 351 toggleWithKeyboard = true; 352 var master_checkbox = $('form#comments-form .check-column :checkbox:first'); 353 master_checkbox.click().attr('checked', ''); 354 toggleWithKeyboard = false; 355 } 356 var make_bulk = function(value) { 357 return function(event, _) { 358 $('option[value='+value+']').attr('selected', 'selected'); 359 $('form#comments-form')[0].submit(); 360 } 361 }; 362 $.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment], 363 ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')], 364 ['shift+d', make_bulk('delete')], ['shift+x', toggle_all], 365 ['shift+u', make_bulk('unapprove')]], 366 {highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, 367 prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next')} 368 ); 369 } 370 }); 371 372 })(jQuery); 1 var theList,theExtraList;(function(a){setCommentsList=function(){var g,i,h,f=0,c,e,d,b;g=a('#comments-form .tablenav :input[name="_total"]');i=a('#comments-form .tablenav :input[name="_per_page"]');h=a('#comments-form .tablenav :input[name="_page"]');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}a("#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(j){j.data._total=g.val();j.data._per_page=i.val();j.data._page=h.val();j.data._url=document.location.href;return j};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(l,j){a("span.pending-count").each(function(){var m=a(this),o;o=m.html().replace(/[ ,.]+/g,"");o=parseInt(o,10);if(isNaN(o)){return}if(a("#"+j.element).is(".unapproved")){o=o-1}else{if(a(j.target).parents("span.unapprove").size()){o=o+1}}if(o<0){o=0}a("#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)});a("span.spam-count").each(function(){var m=a(this),o;o=m.html().replace(/[ ,.]+/g,"");o=parseInt(o,10);if(isNaN(o)){return}if(a(j.target).parents("span.spam").size()){o=o+1}else{if(a("#"+j.element).is(".spam")){o=o-1}}if(o<0){o=0}o=o.toString();if(o.length>3){o=o.substr(0,o.length-3)+" "+o.substr(-3)}m.html(o)});if(("object"==typeof l)&&f<j.parsed.responses[0].supplemental.time){d(j.parsed.responses[0].supplemental.total,j.parsed.responses[0].supplemental.time,true);if(a.trim(j.parsed.responses[0].supplemental.pageLinks)){a(".tablenav-pages").find(".page-numbers").remove().end().append(a(j.parsed.responses[0].supplemental.pageLinks))}else{if("undefined"!=typeof j.parsed.responses[0].supplemental.pageLinks){a(".tablenav-pages").find(".page-numbers").remove()}}}else{var k=parseInt(g.val(),10);if(k--<0){k=0}d(k,l,false)}if(theExtraList.size()==0||theExtraList.children().size()==0){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"})};a(document).ready(function(){setCommentsList()});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(this)});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()}})},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;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()}}};toggleWithKeyboard=false;a(document).ready(function(){var e,b,c,d;columns.init("edit-comments");commentReply.init();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;var f=a("form#comments-form .check-column :checkbox:first");f.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);
Note: See TracChangeset
for help on using the changeset viewer.