Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

964 rindas
27 KiB

  1. /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
  2. var setCommentsList, theList, theExtraList, commentReply;
  3. (function($) {
  4. var getCount, updateCount, updateCountText, updatePending, updateApproved,
  5. updateHtmlTitle, updateDashboardText, adminTitle = document.title,
  6. isDashboard = $('#dashboard_right_now').length,
  7. titleDiv, titleRegEx;
  8. getCount = function(el) {
  9. var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
  10. if ( isNaN(n) ) {
  11. return 0;
  12. }
  13. return n;
  14. };
  15. updateCount = function(el, n) {
  16. var n1 = '';
  17. if ( isNaN(n) ) {
  18. return;
  19. }
  20. n = n < 1 ? '0' : n.toString();
  21. if ( n.length > 3 ) {
  22. while ( n.length > 3 ) {
  23. n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
  24. n = n.substr(0, n.length - 3);
  25. }
  26. n = n + n1;
  27. }
  28. el.html(n);
  29. };
  30. updateApproved = function( diff, commentPostId ) {
  31. var postSelector = '.post-com-count-' + commentPostId,
  32. noClass = 'comment-count-no-comments',
  33. approvedClass = 'comment-count-approved',
  34. approved,
  35. noComments;
  36. updateCountText( 'span.approved-count', diff );
  37. if ( ! commentPostId ) {
  38. return;
  39. }
  40. // cache selectors to not get dupes
  41. approved = $( 'span.' + approvedClass, postSelector );
  42. noComments = $( 'span.' + noClass, postSelector );
  43. approved.each(function() {
  44. var a = $(this), n = getCount(a) + diff;
  45. if ( n < 1 )
  46. n = 0;
  47. if ( 0 === n ) {
  48. a.removeClass( approvedClass ).addClass( noClass );
  49. } else {
  50. a.addClass( approvedClass ).removeClass( noClass );
  51. }
  52. updateCount( a, n );
  53. });
  54. noComments.each(function() {
  55. var a = $(this);
  56. if ( diff > 0 ) {
  57. a.removeClass( noClass ).addClass( approvedClass );
  58. } else {
  59. a.addClass( noClass ).removeClass( approvedClass );
  60. }
  61. updateCount( a, diff );
  62. });
  63. };
  64. updateCountText = function( selector, diff ) {
  65. $( selector ).each(function() {
  66. var a = $(this), n = getCount(a) + diff;
  67. if ( n < 1 ) {
  68. n = 0;
  69. }
  70. updateCount( a, n );
  71. });
  72. };
  73. updateDashboardText = function ( response ) {
  74. if ( ! isDashboard || ! response || ! response.i18n_comments_text ) {
  75. return;
  76. }
  77. var rightNow = $( '#dashboard_right_now' );
  78. $( '.comment-count a', rightNow ).text( response.i18n_comments_text );
  79. $( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text )
  80. .parent()
  81. [ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' );
  82. };
  83. updateHtmlTitle = function ( diff ) {
  84. var newTitle, regExMatch, titleCount, commentFrag;
  85. titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
  86. // count funcs operate on a $'d element
  87. titleDiv = titleDiv || $( '<div />' );
  88. newTitle = adminTitle;
  89. commentFrag = titleRegEx.exec( document.title );
  90. if ( commentFrag ) {
  91. commentFrag = commentFrag[0];
  92. titleDiv.html( commentFrag );
  93. titleCount = getCount( titleDiv ) + diff;
  94. } else {
  95. titleDiv.html( 0 );
  96. titleCount = diff;
  97. }
  98. if ( titleCount >= 1 ) {
  99. updateCount( titleDiv, titleCount );
  100. regExMatch = titleRegEx.exec( document.title );
  101. if ( regExMatch ) {
  102. newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
  103. }
  104. } else {
  105. regExMatch = titleRegEx.exec( newTitle );
  106. if ( regExMatch ) {
  107. newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
  108. }
  109. }
  110. document.title = newTitle;
  111. };
  112. updatePending = function( diff, commentPostId ) {
  113. var postSelector = '.post-com-count-' + commentPostId,
  114. noClass = 'comment-count-no-pending',
  115. noParentClass = 'post-com-count-no-pending',
  116. pendingClass = 'comment-count-pending',
  117. pending,
  118. noPending;
  119. if ( ! isDashboard ) {
  120. updateHtmlTitle( diff );
  121. }
  122. $( 'span.pending-count' ).each(function() {
  123. var a = $(this), n = getCount(a) + diff;
  124. if ( n < 1 )
  125. n = 0;
  126. a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
  127. updateCount( a, n );
  128. });
  129. if ( ! commentPostId ) {
  130. return;
  131. }
  132. // cache selectors to not get dupes
  133. pending = $( 'span.' + pendingClass, postSelector );
  134. noPending = $( 'span.' + noClass, postSelector );
  135. pending.each(function() {
  136. var a = $(this), n = getCount(a) + diff;
  137. if ( n < 1 )
  138. n = 0;
  139. if ( 0 === n ) {
  140. a.parent().addClass( noParentClass );
  141. a.removeClass( pendingClass ).addClass( noClass );
  142. } else {
  143. a.parent().removeClass( noParentClass );
  144. a.addClass( pendingClass ).removeClass( noClass );
  145. }
  146. updateCount( a, n );
  147. });
  148. noPending.each(function() {
  149. var a = $(this);
  150. if ( diff > 0 ) {
  151. a.parent().removeClass( noParentClass );
  152. a.removeClass( noClass ).addClass( pendingClass );
  153. } else {
  154. a.parent().addClass( noParentClass );
  155. a.addClass( noClass ).removeClass( pendingClass );
  156. }
  157. updateCount( a, diff );
  158. });
  159. };
  160. setCommentsList = function() {
  161. var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
  162. lastConfidentTime = 0;
  163. totalInput = $('input[name="_total"]', '#comments-form');
  164. perPageInput = $('input[name="_per_page"]', '#comments-form');
  165. pageInput = $('input[name="_page"]', '#comments-form');
  166. // Updates the current total (stored in the _total input)
  167. updateTotalCount = function( total, time, setConfidentTime ) {
  168. if ( time < lastConfidentTime )
  169. return;
  170. if ( setConfidentTime )
  171. lastConfidentTime = time;
  172. totalInput.val( total.toString() );
  173. };
  174. // this fires when viewing "All"
  175. dimAfter = function( r, settings ) {
  176. var editRow, replyID, replyButton, response,
  177. c = $( '#' + settings.element );
  178. if ( true !== settings.parsed ) {
  179. response = settings.parsed.responses[0];
  180. }
  181. editRow = $('#replyrow');
  182. replyID = $('#comment_ID', editRow).val();
  183. replyButton = $('#replybtn', editRow);
  184. if ( c.is('.unapproved') ) {
  185. if ( settings.data.id == replyID )
  186. replyButton.text(adminCommentsL10n.replyApprove);
  187. c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
  188. .find( 'div.comment_status' ).html( '0' );
  189. } else {
  190. if ( settings.data.id == replyID )
  191. replyButton.text(adminCommentsL10n.reply);
  192. c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
  193. .find( 'div.comment_status' ).html( '1' );
  194. }
  195. diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
  196. if ( response ) {
  197. updateDashboardText( response.supplemental );
  198. updatePending( diff, response.supplemental.postId );
  199. updateApproved( -1 * diff, response.supplemental.postId );
  200. } else {
  201. updatePending( diff );
  202. updateApproved( -1 * diff );
  203. }
  204. };
  205. // Send current total, page, per_page and url
  206. delBefore = function( settings, list ) {
  207. var note, id, el, n, h, a, author,
  208. action = false,
  209. wpListsData = $( settings.target ).attr( 'data-wp-lists' );
  210. settings.data._total = totalInput.val() || 0;
  211. settings.data._per_page = perPageInput.val() || 0;
  212. settings.data._page = pageInput.val() || 0;
  213. settings.data._url = document.location.href;
  214. settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
  215. if ( wpListsData.indexOf(':trash=1') != -1 )
  216. action = 'trash';
  217. else if ( wpListsData.indexOf(':spam=1') != -1 )
  218. action = 'spam';
  219. if ( action ) {
  220. id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1');
  221. el = $('#comment-' + id);
  222. note = $('#' + action + '-undo-holder').html();
  223. el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
  224. if ( el.siblings('#replyrow').length && commentReply.cid == id )
  225. commentReply.close();
  226. if ( el.is('tr') ) {
  227. n = el.children(':visible').length;
  228. author = $('.author strong', el).text();
  229. h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
  230. } else {
  231. author = $('.comment-author', el).text();
  232. h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
  233. }
  234. el.before(h);
  235. $('strong', '#undo-' + id).text(author);
  236. a = $('.undo a', '#undo-' + id);
  237. a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
  238. a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
  239. a.attr('class', 'vim-z vim-destructive');
  240. $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
  241. a.click(function( e ){
  242. e.preventDefault();
  243. e.stopPropagation(); // ticket #35904
  244. list.wpList.del(this);
  245. $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
  246. $(this).remove();
  247. $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
  248. });
  249. });
  250. }
  251. return settings;
  252. };
  253. // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
  254. delAfter = function( r, settings ) {
  255. var total_items_i18n, total, animated, animatedCallback,
  256. response = true === settings.parsed ? {} : settings.parsed.responses[0],
  257. commentStatus = true === settings.parsed ? '' : response.supplemental.status,
  258. commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
  259. newTotal = true === settings.parsed ? '' : response.supplemental,
  260. targetParent = $( settings.target ).parent(),
  261. commentRow = $('#' + settings.element),
  262. spamDiff, trashDiff, pendingDiff, approvedDiff,
  263. approved = commentRow.hasClass( 'approved' ),
  264. unapproved = commentRow.hasClass( 'unapproved' ),
  265. spammed = commentRow.hasClass( 'spam' ),
  266. trashed = commentRow.hasClass( 'trash' ),
  267. undoing = false; // ticket #35904
  268. updateDashboardText( newTotal );
  269. // the order of these checks is important
  270. // .unspam can also have .approve or .unapprove
  271. // .untrash can also have .approve or .unapprove
  272. if ( targetParent.is( 'span.undo' ) ) {
  273. // the comment was spammed
  274. if ( targetParent.hasClass( 'unspam' ) ) {
  275. spamDiff = -1;
  276. if ( 'trash' === commentStatus ) {
  277. trashDiff = 1;
  278. } else if ( '1' === commentStatus ) {
  279. approvedDiff = 1;
  280. } else if ( '0' === commentStatus ) {
  281. pendingDiff = 1;
  282. }
  283. // the comment was trashed
  284. } else if ( targetParent.hasClass( 'untrash' ) ) {
  285. trashDiff = -1;
  286. if ( 'spam' === commentStatus ) {
  287. spamDiff = 1;
  288. } else if ( '1' === commentStatus ) {
  289. approvedDiff = 1;
  290. } else if ( '0' === commentStatus ) {
  291. pendingDiff = 1;
  292. }
  293. }
  294. undoing = true;
  295. // user clicked "Spam"
  296. } else if ( targetParent.is( 'span.spam' ) ) {
  297. // the comment is currently approved
  298. if ( approved ) {
  299. approvedDiff = -1;
  300. // the comment is currently pending
  301. } else if ( unapproved ) {
  302. pendingDiff = -1;
  303. // the comment was in the trash
  304. } else if ( trashed ) {
  305. trashDiff = -1;
  306. }
  307. // you can't spam an item on the spam screen
  308. spamDiff = 1;
  309. // user clicked "Unspam"
  310. } else if ( targetParent.is( 'span.unspam' ) ) {
  311. if ( approved ) {
  312. pendingDiff = 1;
  313. } else if ( unapproved ) {
  314. approvedDiff = 1;
  315. } else if ( trashed ) {
  316. // the comment was previously approved
  317. if ( targetParent.hasClass( 'approve' ) ) {
  318. approvedDiff = 1;
  319. // the comment was previously pending
  320. } else if ( targetParent.hasClass( 'unapprove' ) ) {
  321. pendingDiff = 1;
  322. }
  323. } else if ( spammed ) {
  324. if ( targetParent.hasClass( 'approve' ) ) {
  325. approvedDiff = 1;
  326. } else if ( targetParent.hasClass( 'unapprove' ) ) {
  327. pendingDiff = 1;
  328. }
  329. }
  330. // you can Unspam an item on the spam screen
  331. spamDiff = -1;
  332. // user clicked "Trash"
  333. } else if ( targetParent.is( 'span.trash' ) ) {
  334. if ( approved ) {
  335. approvedDiff = -1;
  336. } else if ( unapproved ) {
  337. pendingDiff = -1;
  338. // the comment was in the spam queue
  339. } else if ( spammed ) {
  340. spamDiff = -1;
  341. }
  342. // you can't trash an item on the trash screen
  343. trashDiff = 1;
  344. // user clicked "Restore"
  345. } else if ( targetParent.is( 'span.untrash' ) ) {
  346. if ( approved ) {
  347. pendingDiff = 1;
  348. } else if ( unapproved ) {
  349. approvedDiff = 1;
  350. } else if ( trashed ) {
  351. if ( targetParent.hasClass( 'approve' ) ) {
  352. approvedDiff = 1;
  353. } else if ( targetParent.hasClass( 'unapprove' ) ) {
  354. pendingDiff = 1;
  355. }
  356. }
  357. // you can't go from trash to spam
  358. // you can untrash on the trash screen
  359. trashDiff = -1;
  360. // User clicked "Approve"
  361. } else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
  362. approvedDiff = 1;
  363. pendingDiff = -1;
  364. // User clicked "Unapprove"
  365. } else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
  366. approvedDiff = -1;
  367. pendingDiff = 1;
  368. // User clicked "Delete Permanently"
  369. } else if ( targetParent.is( 'span.delete' ) ) {
  370. if ( spammed ) {
  371. spamDiff = -1;
  372. } else if ( trashed ) {
  373. trashDiff = -1;
  374. }
  375. }
  376. if ( pendingDiff ) {
  377. updatePending( pendingDiff, commentPostId );
  378. updateCountText( 'span.all-count', pendingDiff );
  379. }
  380. if ( approvedDiff ) {
  381. updateApproved( approvedDiff, commentPostId );
  382. updateCountText( 'span.all-count', approvedDiff );
  383. }
  384. if ( spamDiff ) {
  385. updateCountText( 'span.spam-count', spamDiff );
  386. }
  387. if ( trashDiff ) {
  388. updateCountText( 'span.trash-count', trashDiff );
  389. }
  390. if ( ! isDashboard ) {
  391. total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
  392. if ( $(settings.target).parent().is('span.undo') )
  393. total++;
  394. else
  395. total--;
  396. if ( total < 0 )
  397. total = 0;
  398. if ( 'object' === typeof r ) {
  399. if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
  400. total_items_i18n = response.supplemental.total_items_i18n || '';
  401. if ( total_items_i18n ) {
  402. $('.displaying-num').text( total_items_i18n );
  403. $('.total-pages').text( response.supplemental.total_pages_i18n );
  404. $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
  405. }
  406. updateTotalCount( total, response.supplemental.time, true );
  407. } else if ( response.supplemental.time ) {
  408. updateTotalCount( total, response.supplemental.time, false );
  409. }
  410. } else {
  411. updateTotalCount( total, r, false );
  412. }
  413. }
  414. if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
  415. return;
  416. }
  417. theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
  418. refillTheExtraList();
  419. animated = $( ':animated', '#the-comment-list' );
  420. animatedCallback = function () {
  421. if ( ! $( '#the-comment-list tr:visible' ).length ) {
  422. theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
  423. }
  424. };
  425. if ( animated.length ) {
  426. animated.promise().done( animatedCallback );
  427. } else {
  428. animatedCallback();
  429. }
  430. };
  431. refillTheExtraList = function(ev) {
  432. var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
  433. if (! args.paged)
  434. args.paged = 1;
  435. if (args.paged > total_pages) {
  436. return;
  437. }
  438. if (ev) {
  439. theExtraList.empty();
  440. args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
  441. } else {
  442. args.number = 1;
  443. args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
  444. }
  445. args.no_placeholder = true;
  446. args.paged ++;
  447. // $.query.get() needs some correction to be sent into an ajax request
  448. if ( true === args.comment_type )
  449. args.comment_type = '';
  450. args = $.extend(args, {
  451. 'action': 'fetch-list',
  452. 'list_args': list_args,
  453. '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
  454. });
  455. $.ajax({
  456. url: ajaxurl,
  457. global: false,
  458. dataType: 'json',
  459. data: args,
  460. success: function(response) {
  461. theExtraList.get(0).wpList.add( response.rows );
  462. }
  463. });
  464. };
  465. theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
  466. theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
  467. .bind('wpListDelEnd', function(e, s){
  468. var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, '');
  469. if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 )
  470. $('#undo-' + id).fadeIn(300, function(){ $(this).show(); });
  471. });
  472. };
  473. commentReply = {
  474. cid : '',
  475. act : '',
  476. originalContent : '',
  477. init : function() {
  478. var row = $('#replyrow');
  479. $('a.cancel', row).click(function() { return commentReply.revert(); });
  480. $('a.save', row).click(function() { return commentReply.send(); });
  481. $( 'input#author-name, input#author-email, input#author-url', row ).keypress( function( e ) {
  482. if ( e.which == 13 ) {
  483. commentReply.send();
  484. e.preventDefault();
  485. return false;
  486. }
  487. });
  488. // add events
  489. $('#the-comment-list .column-comment > p').dblclick(function(){
  490. commentReply.toggle($(this).parent());
  491. });
  492. $('#doaction, #doaction2, #post-query-submit').click(function(){
  493. if ( $('#the-comment-list #replyrow').length > 0 )
  494. commentReply.close();
  495. });
  496. this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
  497. /* $(listTable).bind('beforeChangePage', function(){
  498. commentReply.close();
  499. }); */
  500. },
  501. addEvents : function(r) {
  502. r.each(function() {
  503. $(this).find('.column-comment > p').dblclick(function(){
  504. commentReply.toggle($(this).parent());
  505. });
  506. });
  507. },
  508. toggle : function(el) {
  509. if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) {
  510. $( el ).find( 'a.vim-q' ).click();
  511. }
  512. },
  513. revert : function() {
  514. if ( $('#the-comment-list #replyrow').length < 1 )
  515. return false;
  516. $('#replyrow').fadeOut('fast', function(){
  517. commentReply.close();
  518. });
  519. return false;
  520. },
  521. close : function() {
  522. var c, replyrow = $('#replyrow');
  523. // replyrow is not showing?
  524. if ( replyrow.parent().is('#com-reply') )
  525. return;
  526. if ( this.cid && this.act == 'edit-comment' ) {
  527. c = $('#comment-' + this.cid);
  528. c.fadeIn(300, function(){ c.show(); }).css('backgroundColor', '');
  529. }
  530. // reset the Quicktags buttons
  531. if ( typeof QTags != 'undefined' )
  532. QTags.closeAllTags('replycontent');
  533. $('#add-new-comment').css('display', '');
  534. replyrow.hide();
  535. $('#com-reply').append( replyrow );
  536. $('#replycontent').css('height', '').val('');
  537. $('#edithead input').val('');
  538. $('.error', replyrow).empty().hide();
  539. $( '.spinner', replyrow ).removeClass( 'is-active' );
  540. this.cid = '';
  541. this.originalContent = '';
  542. },
  543. open : function(comment_id, post_id, action) {
  544. var editRow, rowData, act, replyButton, editHeight,
  545. t = this,
  546. c = $('#comment-' + comment_id),
  547. h = c.height(),
  548. colspanVal = 0;
  549. if ( ! this.discardCommentChanges() ) {
  550. return false;
  551. }
  552. t.close();
  553. t.cid = comment_id;
  554. editRow = $('#replyrow');
  555. rowData = $('#inline-'+comment_id);
  556. action = action || 'replyto';
  557. act = 'edit' == action ? 'edit' : 'replyto';
  558. act = t.act = act + '-comment';
  559. t.originalContent = $('textarea.comment', rowData).val();
  560. colspanVal = $( '> th:visible, > td:visible', c ).length;
  561. // Make sure it's actually a table and there's a `colspan` value to apply.
  562. if ( editRow.hasClass( 'inline-edit-row' ) && 0 !== colspanVal ) {
  563. $( 'td', editRow ).attr( 'colspan', colspanVal );
  564. }
  565. $('#action', editRow).val(act);
  566. $('#comment_post_ID', editRow).val(post_id);
  567. $('#comment_ID', editRow).val(comment_id);
  568. if ( action == 'edit' ) {
  569. $( '#author-name', editRow ).val( $( 'div.author', rowData ).text() );
  570. $('#author-email', editRow).val( $('div.author-email', rowData).text() );
  571. $('#author-url', editRow).val( $('div.author-url', rowData).text() );
  572. $('#status', editRow).val( $('div.comment_status', rowData).text() );
  573. $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
  574. $( '#edithead, #editlegend, #savebtn', editRow ).show();
  575. $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
  576. if ( h > 120 ) {
  577. // Limit the maximum height when editing very long comments to make it more manageable.
  578. // The textarea is resizable in most browsers, so the user can adjust it if needed.
  579. editHeight = h > 500 ? 500 : h;
  580. $('#replycontent', editRow).css('height', editHeight + 'px');
  581. }
  582. c.after( editRow ).fadeOut('fast', function(){
  583. $('#replyrow').fadeIn(300, function(){ $(this).show(); });
  584. });
  585. } else if ( action == 'add' ) {
  586. $('#addhead, #addbtn', editRow).show();
  587. $( '#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow ) .hide();
  588. $('#the-comment-list').prepend(editRow);
  589. $('#replyrow').fadeIn(300);
  590. } else {
  591. replyButton = $('#replybtn', editRow);
  592. $( '#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow ).hide();
  593. $('#replyhead, #replybtn', editRow).show();
  594. c.after(editRow);
  595. if ( c.hasClass('unapproved') ) {
  596. replyButton.text(adminCommentsL10n.replyApprove);
  597. } else {
  598. replyButton.text(adminCommentsL10n.reply);
  599. }
  600. $('#replyrow').fadeIn(300, function(){ $(this).show(); });
  601. }
  602. setTimeout(function() {
  603. var rtop, rbottom, scrollTop, vp, scrollBottom;
  604. rtop = $('#replyrow').offset().top;
  605. rbottom = rtop + $('#replyrow').height();
  606. scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  607. vp = document.documentElement.clientHeight || window.innerHeight || 0;
  608. scrollBottom = scrollTop + vp;
  609. if ( scrollBottom - 20 < rbottom )
  610. window.scroll(0, rbottom - vp + 35);
  611. else if ( rtop - 20 < scrollTop )
  612. window.scroll(0, rtop - 35);
  613. $('#replycontent').focus().keyup(function(e){
  614. if ( e.which == 27 )
  615. commentReply.revert(); // close on Escape
  616. });
  617. }, 600);
  618. return false;
  619. },
  620. send : function() {
  621. var post = {};
  622. $('#replysubmit .error').hide();
  623. $( '#replysubmit .spinner' ).addClass( 'is-active' );
  624. $('#replyrow input').not(':button').each(function() {
  625. var t = $(this);
  626. post[ t.attr('name') ] = t.val();
  627. });
  628. post.content = $('#replycontent').val();
  629. post.id = post.comment_post_ID;
  630. post.comments_listing = this.comments_listing;
  631. post.p = $('[name="p"]').val();
  632. if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
  633. post.approve_parent = 1;
  634. $.ajax({
  635. type : 'POST',
  636. url : ajaxurl,
  637. data : post,
  638. success : function(x) { commentReply.show(x); },
  639. error : function(r) { commentReply.error(r); }
  640. });
  641. return false;
  642. },
  643. show : function(xml) {
  644. var t = this, r, c, id, bg, pid;
  645. if ( typeof(xml) == 'string' ) {
  646. t.error({'responseText': xml});
  647. return false;
  648. }
  649. r = wpAjax.parseAjaxResponse(xml);
  650. if ( r.errors ) {
  651. t.error({'responseText': wpAjax.broken});
  652. return false;
  653. }
  654. t.revert();
  655. r = r.responses[0];
  656. id = '#comment-' + r.id;
  657. if ( 'edit-comment' == t.act )
  658. $(id).remove();
  659. if ( r.supplemental.parent_approved ) {
  660. pid = $('#comment-' + r.supplemental.parent_approved);
  661. updatePending( -1, r.supplemental.parent_post_id );
  662. if ( this.comments_listing == 'moderated' ) {
  663. pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
  664. pid.fadeOut();
  665. });
  666. return;
  667. }
  668. }
  669. if ( r.supplemental.i18n_comments_text ) {
  670. if ( isDashboard ) {
  671. updateDashboardText( r.supplemental );
  672. } else {
  673. updateApproved( 1, r.supplemental.parent_post_id );
  674. updateCountText( 'span.all-count', 1 );
  675. }
  676. }
  677. c = $.trim(r.data); // Trim leading whitespaces
  678. $(c).hide();
  679. $('#replyrow').after(c);
  680. id = $(id);
  681. t.addEvents(id);
  682. bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
  683. id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
  684. .animate( { 'backgroundColor': bg }, 300, function() {
  685. if ( pid && pid.length ) {
  686. pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
  687. .animate( { 'backgroundColor': bg }, 300 )
  688. .removeClass('unapproved').addClass('approved')
  689. .find('div.comment_status').html('1');
  690. }
  691. });
  692. },
  693. error : function(r) {
  694. var er = r.statusText;
  695. $( '#replysubmit .spinner' ).removeClass( 'is-active' );
  696. if ( r.responseText )
  697. er = r.responseText.replace( /<.[^<>]*?>/g, '' );
  698. if ( er )
  699. $('#replysubmit .error').html(er).show();
  700. },
  701. addcomment: function(post_id) {
  702. var t = this;
  703. $('#add-new-comment').fadeOut(200, function(){
  704. t.open(0, post_id, 'add');
  705. $('table.comments-box').css('display', '');
  706. $('#no-comments').remove();
  707. });
  708. },
  709. /**
  710. * Alert the user if they have unsaved changes on a comment that will be
  711. * lost if they proceed.
  712. *
  713. * @returns {boolean}
  714. */
  715. discardCommentChanges: function() {
  716. var editRow = $( '#replyrow' );
  717. if ( this.originalContent === $( '#replycontent', editRow ).val() ) {
  718. return true;
  719. }
  720. return window.confirm( adminCommentsL10n.warnCommentChanges );
  721. }
  722. };
  723. $(document).ready(function(){
  724. var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
  725. setCommentsList();
  726. commentReply.init();
  727. $(document).on( 'click', 'span.delete a.delete', function( e ) {
  728. e.preventDefault();
  729. });
  730. if ( typeof $.table_hotkeys != 'undefined' ) {
  731. make_hotkeys_redirect = function(which) {
  732. return function() {
  733. var first_last, l;
  734. first_last = 'next' == which? 'first' : 'last';
  735. l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
  736. if (l.length)
  737. window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
  738. };
  739. };
  740. edit_comment = function(event, current_row) {
  741. window.location = $('span.edit a', current_row).attr('href');
  742. };
  743. toggle_all = function() {
  744. $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' );
  745. };
  746. make_bulk = function(value) {
  747. return function() {
  748. var scope = $('select[name="action"]');
  749. $('option[value="' + value + '"]', scope).prop('selected', true);
  750. $('#doaction').click();
  751. };
  752. };
  753. $.table_hotkeys(
  754. $('table.widefat'),
  755. [
  756. 'a', 'u', 's', 'd', 'r', 'q', 'z',
  757. ['e', edit_comment],
  758. ['shift+x', toggle_all],
  759. ['shift+a', make_bulk('approve')],
  760. ['shift+s', make_bulk('spam')],
  761. ['shift+d', make_bulk('delete')],
  762. ['shift+t', make_bulk('trash')],
  763. ['shift+z', make_bulk('untrash')],
  764. ['shift+u', make_bulk('unapprove')]
  765. ],
  766. {
  767. highlight_first: adminCommentsL10n.hotkeys_highlight_first,
  768. highlight_last: adminCommentsL10n.hotkeys_highlight_last,
  769. prev_page_link_cb: make_hotkeys_redirect('prev'),
  770. next_page_link_cb: make_hotkeys_redirect('next'),
  771. hotkeys_opts: {
  772. disableInInput: true,
  773. type: 'keypress',
  774. noDisable: '.check-column input[type="checkbox"]'
  775. },
  776. cycle_expr: '#the-comment-list tr',
  777. start_row_index: 0
  778. }
  779. );
  780. }
  781. // Quick Edit and Reply have an inline comment editor.
  782. $( '#the-comment-list' ).on( 'click', '.comment-inline', function (e) {
  783. e.preventDefault();
  784. var $el = $( this ),
  785. action = 'replyto';
  786. if ( 'undefined' !== typeof $el.data( 'action' ) ) {
  787. action = $el.data( 'action' );
  788. }
  789. commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action );
  790. } );
  791. });
  792. })(jQuery);