|
1 /** |
|
2 * @output wp-admin/js/edit-comments.js |
|
3 */ |
|
4 |
1 /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */ |
5 /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */ |
2 var setCommentsList, theList, theExtraList, commentReply; |
6 /* global commentReply, theExtraList, theList, setCommentsList */ |
3 |
7 |
4 (function($) { |
8 (function($) { |
5 var getCount, updateCount, updateCountText, updatePending, updateApproved, |
9 var getCount, updateCount, updateCountText, updatePending, updateApproved, |
6 updateHtmlTitle, updateDashboardText, adminTitle = document.title, |
10 updateHtmlTitle, updateDashboardText, updateInModerationText, adminTitle = document.title, |
7 isDashboard = $('#dashboard_right_now').length, |
11 isDashboard = $('#dashboard_right_now').length, |
8 titleDiv, titleRegEx; |
12 titleDiv, titleRegEx; |
9 |
13 |
10 getCount = function(el) { |
14 getCount = function(el) { |
11 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); |
15 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); |
80 } |
84 } |
81 updateCount( a, n ); |
85 updateCount( a, n ); |
82 }); |
86 }); |
83 }; |
87 }; |
84 |
88 |
85 updateDashboardText = function ( response ) { |
89 updateDashboardText = function( response ) { |
86 if ( ! isDashboard || ! response || ! response.i18n_comments_text ) { |
90 if ( ! isDashboard || ! response || ! response.i18n_comments_text ) { |
87 return; |
91 return; |
88 } |
92 } |
89 |
93 |
90 var rightNow = $( '#dashboard_right_now' ); |
94 $( '.comment-count a', '#dashboard_right_now' ).text( response.i18n_comments_text ); |
91 |
95 }; |
92 $( '.comment-count a', rightNow ).text( response.i18n_comments_text ); |
96 |
93 $( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text ) |
97 /** |
94 .parent() |
98 * Updates the "comments in moderation" text across the UI. |
95 [ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' ); |
99 * |
96 }; |
100 * @since 5.2.0 |
97 |
101 * |
98 updateHtmlTitle = function ( diff ) { |
102 * @param {object} response Ajax response from the server. |
|
103 * |
|
104 * @return {void} |
|
105 */ |
|
106 updateInModerationText = function( response ) { |
|
107 if ( ! response || ! response.i18n_moderation_text ) { |
|
108 return; |
|
109 } |
|
110 |
|
111 // Update the "comment in moderation" text across the UI. |
|
112 $( '.comments-in-moderation-text' ).text( response.i18n_moderation_text ); |
|
113 // Hide the "comment in moderation" text in the Dashboard "At a Glance" widget. |
|
114 if ( isDashboard && response.in_moderation ) { |
|
115 $( '.comment-mod-count', '#dashboard_right_now' ) |
|
116 [ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' ); |
|
117 } |
|
118 }; |
|
119 |
|
120 updateHtmlTitle = function( diff ) { |
99 var newTitle, regExMatch, titleCount, commentFrag; |
121 var newTitle, regExMatch, titleCount, commentFrag; |
100 |
122 |
101 titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' ); |
123 titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' ); |
102 // count funcs operate on a $'d element |
124 // count funcs operate on a $'d element |
103 titleDiv = titleDiv || $( '<div />' ); |
125 titleDiv = titleDiv || $( '<div />' ); |
182 } |
204 } |
183 updateCount( a, diff ); |
205 updateCount( a, diff ); |
184 }); |
206 }); |
185 }; |
207 }; |
186 |
208 |
187 setCommentsList = function() { |
209 window.setCommentsList = function() { |
188 var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff, |
210 var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff, |
189 lastConfidentTime = 0; |
211 lastConfidentTime = 0; |
190 |
212 |
191 totalInput = $('input[name="_total"]', '#comments-form'); |
213 totalInput = $('input[name="_total"]', '#comments-form'); |
192 perPageInput = $('input[name="_per_page"]', '#comments-form'); |
214 perPageInput = $('input[name="_per_page"]', '#comments-form'); |
232 } |
254 } |
233 |
255 |
234 diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; |
256 diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; |
235 if ( response ) { |
257 if ( response ) { |
236 updateDashboardText( response.supplemental ); |
258 updateDashboardText( response.supplemental ); |
|
259 updateInModerationText( response.supplemental ); |
237 updatePending( diff, response.supplemental.postId ); |
260 updatePending( diff, response.supplemental.postId ); |
238 updateApproved( -1 * diff, response.supplemental.postId ); |
261 updateApproved( -1 * diff, response.supplemental.postId ); |
239 } else { |
262 } else { |
240 updatePending( diff ); |
263 updatePending( diff ); |
241 updateApproved( -1 * diff ); |
264 updateApproved( -1 * diff ); |
282 |
305 |
283 $('strong', '#undo-' + id).text(author); |
306 $('strong', '#undo-' + id).text(author); |
284 a = $('.undo a', '#undo-' + id); |
307 a = $('.undo a', '#undo-' + id); |
285 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); |
308 a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); |
286 a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1'); |
309 a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1'); |
287 a.attr('class', 'vim-z vim-destructive'); |
310 a.attr('class', 'vim-z vim-destructive aria-button-if-js'); |
288 $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); |
311 $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); |
289 |
312 |
290 a.click(function( e ){ |
313 a.click(function( e ){ |
291 e.preventDefault(); |
314 e.preventDefault(); |
292 e.stopPropagation(); // ticket #35904 |
315 e.stopPropagation(); // ticket #35904 |
312 targetParent = $( settings.target ).parent(), |
335 targetParent = $( settings.target ).parent(), |
313 commentRow = $('#' + settings.element), |
336 commentRow = $('#' + settings.element), |
314 |
337 |
315 spamDiff, trashDiff, pendingDiff, approvedDiff, |
338 spamDiff, trashDiff, pendingDiff, approvedDiff, |
316 |
339 |
317 approved = commentRow.hasClass( 'approved' ), |
340 /* |
|
341 * As `wpList` toggles only the `unapproved` class, the approved comment |
|
342 * rows can have both the `approved` and `unapproved` classes. |
|
343 */ |
|
344 approved = commentRow.hasClass( 'approved' ) && ! commentRow.hasClass( 'unapproved' ), |
318 unapproved = commentRow.hasClass( 'unapproved' ), |
345 unapproved = commentRow.hasClass( 'unapproved' ), |
319 spammed = commentRow.hasClass( 'spam' ), |
346 spammed = commentRow.hasClass( 'spam' ), |
320 trashed = commentRow.hasClass( 'trash' ), |
347 trashed = commentRow.hasClass( 'trash' ), |
321 undoing = false; // ticket #35904 |
348 undoing = false; // ticket #35904 |
322 |
349 |
323 updateDashboardText( newTotal ); |
350 updateDashboardText( newTotal ); |
|
351 updateInModerationText( newTotal ); |
324 |
352 |
325 // the order of these checks is important |
353 // the order of these checks is important |
326 // .unspam can also have .approve or .unapprove |
354 // .unspam can also have .approve or .unapprove |
327 // .untrash can also have .approve or .unapprove |
355 // .untrash can also have .approve or .unapprove |
328 |
356 |
502 theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() ); |
530 theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() ); |
503 |
531 |
504 refillTheExtraList(); |
532 refillTheExtraList(); |
505 |
533 |
506 animated = $( ':animated', '#the-comment-list' ); |
534 animated = $( ':animated', '#the-comment-list' ); |
507 animatedCallback = function () { |
535 animatedCallback = function() { |
508 if ( ! $( '#the-comment-list tr:visible' ).length ) { |
536 if ( ! $( '#the-comment-list tr:visible' ).length ) { |
509 theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() ); |
537 theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() ); |
510 } |
538 } |
511 }; |
539 }; |
512 |
540 |
558 theExtraList.get(0).wpList.add( response.rows ); |
586 theExtraList.get(0).wpList.add( response.rows ); |
559 } |
587 } |
560 }); |
588 }); |
561 }; |
589 }; |
562 |
590 |
563 theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); |
591 window.theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); |
564 theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) |
592 window.theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) |
565 .bind('wpListDelEnd', function(e, s){ |
593 .bind('wpListDelEnd', function(e, s){ |
566 var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, ''); |
594 var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, ''); |
567 |
595 |
568 if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 ) |
596 if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 ) |
569 $('#undo-' + id).fadeIn(300, function(){ $(this).show(); }); |
597 $('#undo-' + id).fadeIn(300, function(){ $(this).show(); }); |
570 }); |
598 }); |
571 }; |
599 }; |
572 |
600 |
573 commentReply = { |
601 window.commentReply = { |
574 cid : '', |
602 cid : '', |
575 act : '', |
603 act : '', |
576 originalContent : '', |
604 originalContent : '', |
577 |
605 |
578 init : function() { |
606 init : function() { |
579 var row = $('#replyrow'); |
607 var row = $('#replyrow'); |
580 |
608 |
581 $('a.cancel', row).click(function() { return commentReply.revert(); }); |
609 $( '.cancel', row ).click( function() { return commentReply.revert(); } ); |
582 $('a.save', row).click(function() { return commentReply.send(); }); |
610 $( '.save', row ).click( function() { return commentReply.send(); } ); |
583 $( 'input#author-name, input#author-email, input#author-url', row ).keypress( function( e ) { |
611 $( 'input#author-name, input#author-email, input#author-url', row ).keypress( function( e ) { |
584 if ( e.which == 13 ) { |
612 if ( e.which == 13 ) { |
585 commentReply.send(); |
613 commentReply.send(); |
586 e.preventDefault(); |
614 e.preventDefault(); |
587 return false; |
615 return false; |
597 if ( $('#the-comment-list #replyrow').length > 0 ) |
625 if ( $('#the-comment-list #replyrow').length > 0 ) |
598 commentReply.close(); |
626 commentReply.close(); |
599 }); |
627 }); |
600 |
628 |
601 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; |
629 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; |
602 |
|
603 /* $(listTable).bind('beforeChangePage', function(){ |
|
604 commentReply.close(); |
|
605 }); */ |
|
606 }, |
630 }, |
607 |
631 |
608 addEvents : function(r) { |
632 addEvents : function(r) { |
609 r.each(function() { |
633 r.each(function() { |
610 $(this).find('.column-comment > p').dblclick(function(){ |
634 $(this).find('.column-comment > p').dblclick(function(){ |
625 return false; |
649 return false; |
626 |
650 |
627 $('#replyrow').fadeOut('fast', function(){ |
651 $('#replyrow').fadeOut('fast', function(){ |
628 commentReply.close(); |
652 commentReply.close(); |
629 }); |
653 }); |
630 |
|
631 return false; |
|
632 }, |
654 }, |
633 |
655 |
634 close : function() { |
656 close : function() { |
635 var c, replyrow = $('#replyrow'); |
657 var commentRow = $(), |
|
658 replyRow = $( '#replyrow' ); |
636 |
659 |
637 // replyrow is not showing? |
660 // replyrow is not showing? |
638 if ( replyrow.parent().is('#com-reply') ) |
661 if ( replyRow.parent().is( '#com-reply' ) ) { |
639 return; |
662 return; |
640 |
663 } |
641 if ( this.cid && this.act == 'edit-comment' ) { |
664 |
642 c = $('#comment-' + this.cid); |
665 if ( this.cid ) { |
643 c.fadeIn(300, function(){ c.show(); }).css('backgroundColor', ''); |
666 commentRow = $( '#comment-' + this.cid ); |
|
667 } |
|
668 |
|
669 /* |
|
670 * When closing the Quick Edit form, show the comment row and move focus |
|
671 * back to the Quick Edit button. |
|
672 */ |
|
673 if ( 'edit-comment' === this.act ) { |
|
674 commentRow.fadeIn( 300, function() { |
|
675 commentRow |
|
676 .show() |
|
677 .find( '.vim-q' ) |
|
678 .attr( 'aria-expanded', 'false' ) |
|
679 .focus(); |
|
680 } ).css( 'backgroundColor', '' ); |
|
681 } |
|
682 |
|
683 // When closing the Reply form, move focus back to the Reply button. |
|
684 if ( 'replyto-comment' === this.act ) { |
|
685 commentRow.find( '.vim-r' ) |
|
686 .attr( 'aria-expanded', 'false' ) |
|
687 .focus(); |
644 } |
688 } |
645 |
689 |
646 // reset the Quicktags buttons |
690 // reset the Quicktags buttons |
647 if ( typeof QTags != 'undefined' ) |
691 if ( typeof QTags != 'undefined' ) |
648 QTags.closeAllTags('replycontent'); |
692 QTags.closeAllTags('replycontent'); |
649 |
693 |
650 $('#add-new-comment').css('display', ''); |
694 $('#add-new-comment').css('display', ''); |
651 |
695 |
652 replyrow.hide(); |
696 replyRow.hide(); |
653 $('#com-reply').append( replyrow ); |
697 $( '#com-reply' ).append( replyRow ); |
654 $('#replycontent').css('height', '').val(''); |
698 $('#replycontent').css('height', '').val(''); |
655 $('#edithead input').val(''); |
699 $('#edithead input').val(''); |
656 $( '.notice-error', replyrow ) |
700 $( '.notice-error', replyRow ) |
657 .addClass( 'hidden' ) |
701 .addClass( 'hidden' ) |
658 .find( '.error' ).empty(); |
702 .find( '.error' ).empty(); |
659 $( '.spinner', replyrow ).removeClass( 'is-active' ); |
703 $( '.spinner', replyRow ).removeClass( 'is-active' ); |
660 |
704 |
661 this.cid = ''; |
705 this.cid = ''; |
662 this.originalContent = ''; |
706 this.originalContent = ''; |
663 }, |
707 }, |
664 |
708 |
780 url : ajaxurl, |
824 url : ajaxurl, |
781 data : post, |
825 data : post, |
782 success : function(x) { commentReply.show(x); }, |
826 success : function(x) { commentReply.show(x); }, |
783 error : function(r) { commentReply.error(r); } |
827 error : function(r) { commentReply.error(r); } |
784 }); |
828 }); |
785 |
|
786 return false; |
|
787 }, |
829 }, |
788 |
830 |
789 show : function(xml) { |
831 show : function(xml) { |
790 var t = this, r, c, id, bg, pid; |
832 var t = this, r, c, id, bg, pid; |
791 |
833 |
819 return; |
861 return; |
820 } |
862 } |
821 } |
863 } |
822 |
864 |
823 if ( r.supplemental.i18n_comments_text ) { |
865 if ( r.supplemental.i18n_comments_text ) { |
824 if ( isDashboard ) { |
866 updateDashboardText( r.supplemental ); |
825 updateDashboardText( r.supplemental ); |
867 updateInModerationText( r.supplemental ); |
826 } else { |
868 updateApproved( 1, r.supplemental.parent_post_id ); |
827 updateApproved( 1, r.supplemental.parent_post_id ); |
869 updateCountText( 'span.all-count', 1 ); |
828 updateCountText( 'span.all-count', 1 ); |
|
829 } |
|
830 } |
870 } |
831 |
871 |
832 c = $.trim(r.data); // Trim leading whitespaces |
872 c = $.trim(r.data); // Trim leading whitespaces |
833 $(c).hide(); |
873 $(c).hide(); |
834 $('#replyrow').after(c); |
874 $('#replyrow').after(c); |
958 } |
998 } |
959 ); |
999 ); |
960 } |
1000 } |
961 |
1001 |
962 // Quick Edit and Reply have an inline comment editor. |
1002 // Quick Edit and Reply have an inline comment editor. |
963 $( '#the-comment-list' ).on( 'click', '.comment-inline', function (e) { |
1003 $( '#the-comment-list' ).on( 'click', '.comment-inline', function() { |
964 e.preventDefault(); |
|
965 var $el = $( this ), |
1004 var $el = $( this ), |
966 action = 'replyto'; |
1005 action = 'replyto'; |
967 |
1006 |
968 if ( 'undefined' !== typeof $el.data( 'action' ) ) { |
1007 if ( 'undefined' !== typeof $el.data( 'action' ) ) { |
969 action = $el.data( 'action' ); |
1008 action = $el.data( 'action' ); |
970 } |
1009 } |
971 |
1010 |
|
1011 $( this ).attr( 'aria-expanded', 'true' ); |
972 commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action ); |
1012 commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action ); |
973 } ); |
1013 } ); |
974 }); |
1014 }); |
975 |
1015 |
976 })(jQuery); |
1016 })(jQuery); |