Changeset 45558
- Timestamp:
- 06/20/2019 02:44:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/edit-comments.js
r45553 r45558 1 1 /** 2 * Handles updating and editing comments. 3 * 4 * @file This file contains functionality for the admin comments page. 5 * @since 3.5.0 2 6 * @output wp-admin/js/edit-comments.js 3 7 */ … … 12 16 titleDiv, titleRegEx; 13 17 18 /** 19 * Extracts a number from the content of a jQuery element. 20 * 21 * @since 2.9.0 22 * @access private 23 * 24 * @param {jQuery} el jQuery element. 25 * 26 * @return {number} The number found in the given element. 27 */ 14 28 getCount = function(el) { 15 29 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); … … 20 34 }; 21 35 36 /** 37 * Updates an html element with a localized number string. 38 * 39 * @since 2.9.0 40 * @access private 41 * 42 * @param {jQuery} el The jQuery element to update. 43 * @param {number} n Number to be put in the element. 44 * 45 * @return {void} 46 */ 22 47 updateCount = function(el, n) { 23 48 var n1 = ''; … … 36 61 }; 37 62 63 /** 64 * Updates the number of approved comments on a specific post and the filter bar. 65 * 66 * @since 4.4.0 67 * @access private 68 * 69 * @param {number} diff The amount to lower or raise the approved count with. 70 * @param {number} commentPostId The ID of the post to be updated. 71 * 72 * @return {void} 73 */ 38 74 updateApproved = function( diff, commentPostId ) { 39 75 var postSelector = '.post-com-count-' + commentPostId, … … 49 85 } 50 86 51 // cache selectors to not get dupes87 // Cache selectors to not get duplicates. 52 88 approved = $( 'span.' + approvedClass, postSelector ); 53 89 noComments = $( 'span.' + noClass, postSelector ); … … 77 113 }; 78 114 115 /** 116 * Updates a number count in all matched HTML elements 117 * 118 * @since 4.4.0 119 * @access private 120 * 121 * @param {string} selector The jQuery selector for elements to update a count 122 * for. 123 * @param {number} diff The amount to lower or raise the count with. 124 * 125 * @return {void} 126 */ 79 127 updateCountText = function( selector, diff ) { 80 128 $( selector ).each(function() { … … 87 135 }; 88 136 137 /** 138 * Updates a text about comment count on the dashboard. 139 * 140 * @since 4.4.0 141 * @access private 142 * 143 * @param {Object} response Ajax response from the server that includes a 144 * translated "comment count" message. 145 * 146 * @return {void} 147 */ 89 148 updateDashboardText = function( response ) { 90 149 if ( ! isDashboard || ! response || ! response.i18n_comments_text ) { … … 100 159 * @since 5.2.0 101 160 * 102 * @param {object} response Ajax response from the server. 161 * @param {object} response Ajax response from the server that includes a 162 * translated "comments in moderation" message. 103 163 * 104 164 * @return {void} … … 118 178 }; 119 179 180 /** 181 * Updates the title of the document with the number comments to be approved. 182 * 183 * @since 4.4.0 184 * @access private 185 * 186 * @param {number} diff The amount to lower or raise the number of to be 187 * approved comments with. 188 * 189 * @return {void} 190 */ 120 191 updateHtmlTitle = function( diff ) { 121 192 var newTitle, regExMatch, titleCount, commentFrag; … … 151 222 }; 152 223 224 /** 225 * Updates the number of pending comments on a specific post and the filter bar. 226 * 227 * @since 3.2.0 228 * @access private 229 * 230 * @param {number} diff The amount to lower or raise the pending count with. 231 * @param {number} commentPostId The ID of the post to be updated. 232 * 233 * @return {void} 234 */ 153 235 updatePending = function( diff, commentPostId ) { 154 236 var postSelector = '.post-com-count-' + commentPostId, … … 207 289 }; 208 290 291 /** 292 * Initializes the comments list. 293 * 294 * @since 4.4.0 295 * 296 * @global 297 * 298 * @return {void} 299 */ 209 300 window.setCommentsList = function() { 210 301 var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff, … … 215 306 pageInput = $('input[name="_page"]', '#comments-form'); 216 307 217 // Updates the current total (stored in the _total input) 308 /** 309 * Updates the total with the latest count. 310 * 311 * The time parameter makes sure that we only update the total if this value is 312 * a newer value than we previously received. 313 * 314 * The time and setConfidentTime parameters make sure that we only update the 315 * total when necessary. So a value that has been generated earlier will not 316 * update the total. 317 * 318 * @since 2.8.0 319 * @access private 320 * 321 * @param {number} total Total number of comments. 322 * @param {number} time Unix timestamp of response. 323 * @param {boolean} setConfidentTime Whether to update the last confident time 324 * with the given time. 325 * 326 * @return {void} 327 */ 218 328 updateTotalCount = function( total, time, setConfidentTime ) { 219 329 if ( time < lastConfidentTime ) … … 226 336 }; 227 337 228 // this fires when viewing "All" 338 /** 339 * Changes DOM that need to be changed after a list item has been dimmed. 340 * 341 * @since 2.5.0 342 * @access private 343 * 344 * @param {Object} r Ajax response object. 345 * @param {Object} settings Settings for the wpList object. 346 * 347 * @return {void} 348 */ 229 349 dimAfter = function( r, settings ) { 230 350 var editRow, replyID, replyButton, response, … … 266 386 }; 267 387 268 // Send current total, page, per_page and url 388 /** 389 * Handles marking a comment as spam or trashing the comment. 390 * 391 * Is executed in the list delBefore hook. 392 * 393 * @since 2.8.0 394 * @access private 395 * 396 * @param {Object} settings Settings for the wpList object. 397 * @param {HTMLElement} list Comments table element. 398 * 399 * @return {Object} The settings object. 400 */ 269 401 delBefore = function( settings, list ) { 270 402 var note, id, el, n, h, a, author, … … 325 457 }; 326 458 327 // In admin-ajax.php, we send back the unix time stamp instead of 1 on success 459 /** 460 * Handles actions that need to be done after marking as spam or thrashing a 461 * comment. 462 * 463 * The ajax requests return the unix time stamp a comment was marked as spam or 464 * trashed. We use this to have a correct total amount of comments. 465 * 466 * @since 2.5.0 467 * @access private 468 * 469 * @param {Object} r Ajax response object. 470 * @param {Object} settings Settings for the wpList object. 471 * 472 * @return {void} 473 */ 328 474 delAfter = function( r, settings ) { 329 475 var total_items_i18n, total, animated, animatedCallback, … … 546 692 }; 547 693 694 /** 695 * Retrieves additional comments to populate the extra list. 696 * 697 * @since 3.1.0 698 * @access private 699 * 700 * @param {boolean} [ev] Repopulate the extra comments list if true. 701 * 702 * @return {void} 703 */ 548 704 refillTheExtraList = function(ev) { 549 705 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val(); … … 589 745 }; 590 746 747 /** 748 * Globally available jQuery object referring to the extra comments list. 749 * 750 * @global 751 */ 591 752 window.theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); 753 754 /** 755 * Globally available jQuery object referring to the comments list. 756 * 757 * @global 758 */ 592 759 window.theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) 593 760 .bind('wpListDelEnd', function(e, s){ … … 599 766 }; 600 767 768 /** 769 * Object containing functionality regarding the comment quick editor and reply 770 * editor. 771 * 772 * @since 2.7.0 773 * 774 * @global 775 */ 601 776 window.commentReply = { 602 777 cid : '', … … 604 779 originalContent : '', 605 780 781 /** 782 * Initializes the comment reply functionality. 783 * 784 * @memberof commentReply 785 * 786 * @since 2.7.0 787 */ 606 788 init : function() { 607 789 var row = $('#replyrow'); … … 630 812 }, 631 813 814 /** 815 * Adds doubleclick event handler to the given comment list row. 816 * 817 * The double-click event will toggle the comment edit or reply form. 818 * 819 * @since 2.7.0 820 * 821 * @memberof commentReply 822 * 823 * @param {Object} r The row to add double click handlers to. 824 * 825 * @return {void} 826 */ 632 827 addEvents : function(r) { 633 828 r.each(function() { … … 638 833 }, 639 834 835 /** 836 * Opens the quick edit for the given element. 837 * 838 * @since 2.7.0 839 * 840 * @memberof commentReply 841 * 842 * @param {HTMLElement} el The element you want to open the quick editor for. 843 * 844 * @return {void} 845 */ 640 846 toggle : function(el) { 641 847 if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) { … … 644 850 }, 645 851 852 /** 853 * Closes the comment quick edit or reply form and undoes any changes. 854 * 855 * @since 2.7.0 856 * 857 * @memberof commentReply 858 * 859 * @return {void} 860 */ 646 861 revert : function() { 647 862 … … 654 869 }, 655 870 871 /** 872 * Closes the comment quick edit or reply form and undoes any changes. 873 * 874 * @since 2.7.0 875 * 876 * @memberof commentReply 877 * 878 * @return {void} 879 */ 656 880 close : function() { 657 881 var commentRow = $(), 658 882 replyRow = $( '#replyrow' ); 659 883 660 // replyrow is not showing?884 // Return if the replyrow is not showing. 661 885 if ( replyRow.parent().is( '#com-reply' ) ) { 662 886 return; … … 689 913 690 914 // reset the Quicktags buttons 691 if ( typeof QTags != 'undefined' )915 if ( typeof QTags != 'undefined' ) 692 916 QTags.closeAllTags('replycontent'); 693 917 … … 707 931 }, 708 932 933 /** 934 * Opens the comment quick edit or reply form. 935 * 936 * @since 2.7.0 937 * 938 * @memberof commentReply 939 * 940 * @param {number} comment_id The comment id to open an editor for. 941 * @param {number} post_id The post id to open an editor for. 942 * @param {string} action The action to perform. Either 'edit' or 'replyto'. 943 * 944 * @return {boolean} Always false. 945 */ 709 946 open : function(comment_id, post_id, action) { 710 947 var editRow, rowData, act, replyButton, editHeight, … … 800 1037 }, 801 1038 1039 /** 1040 * Submits the comment quick edit or reply form. 1041 * 1042 * @since 2.7.0 1043 * 1044 * @memberof commentReply 1045 * 1046 * @return {void} 1047 */ 802 1048 send : function() { 803 1049 var post = {}, … … 829 1075 }, 830 1076 1077 /** 1078 * Shows the new or updated comment or reply. 1079 * 1080 * This function needs to be passed the ajax result as received from the server. 1081 * It will handle the response and show the comment that has just been saved to 1082 * the server. 1083 * 1084 * @since 2.7.0 1085 * 1086 * @memberof commentReply 1087 * 1088 * @param {Object} xml Ajax response object. 1089 * 1090 * @return {void} 1091 */ 831 1092 show : function(xml) { 832 1093 var t = this, r, c, id, bg, pid; … … 890 1151 }, 891 1152 1153 /** 1154 * Shows an error for the failed comment update or reply. 1155 * 1156 * @since 2.7.0 1157 * 1158 * @memberof commentReply 1159 * 1160 * @param {string} r The Ajax response. 1161 * 1162 * @return {void} 1163 */ 892 1164 error : function(r) { 893 1165 var er = r.statusText, … … 906 1178 }, 907 1179 1180 /** 1181 * Opens the add comments form in the comments metabox on the post edit page. 1182 * 1183 * @since 3.4.0 1184 * 1185 * @memberof commentReply 1186 * 1187 * @param {number} post_id The post id. 1188 * 1189 * @return {void} 1190 */ 908 1191 addcomment: function(post_id) { 909 1192 var t = this; … … 917 1200 918 1201 /** 919 * Alert the user if they have unsaved changes on a comment that will be 920 * lost if they proceed. 921 * 922 * @returns {boolean} 1202 * Alert the user if they have unsaved changes on a comment that will be lost if 1203 * they proceed with the intended action. 1204 * 1205 * @since 4.6.0 1206 * 1207 * @memberof commentReply 1208 * 1209 * @return {boolean} Whether it is safe the continue with the intended action. 923 1210 */ 924 1211 discardCommentChanges: function() { … … 944 1231 945 1232 if ( typeof $.table_hotkeys != 'undefined' ) { 1233 /** 1234 * Creates a function that navigates to a previous or next page. 1235 * 1236 * @since 2.7.0 1237 * @access private 1238 * 1239 * @param {string} which What page to navigate to: either next or prev. 1240 * 1241 * @return {Function} The function that executes the navigation. 1242 */ 946 1243 make_hotkeys_redirect = function(which) { 947 1244 return function() { … … 955 1252 }; 956 1253 1254 /** 1255 * Navigates to the edit page for the selected comment. 1256 * 1257 * @since 2.7.0 1258 * @access private 1259 * 1260 * @param {Object} event The event that triggered this action. 1261 * @param {Object} current_row A jQuery object of the selected row. 1262 * 1263 * @return {void} 1264 */ 957 1265 edit_comment = function(event, current_row) { 958 1266 window.location = $('span.edit a', current_row).attr('href'); 959 1267 }; 960 1268 1269 /** 1270 * Toggles all comments on the screen, for bulk actions. 1271 * 1272 * @since 2.7.0 1273 * @access private 1274 * 1275 * @return {void} 1276 */ 961 1277 toggle_all = function() { 962 1278 $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' ); 963 1279 }; 964 1280 1281 /** 1282 * Creates a bulk action function that is executed on all selected comments. 1283 * 1284 * @since 2.7.0 1285 * @access private 1286 * 1287 * @param {string} value The name of the action to execute. 1288 * 1289 * @return {Function} The function that executes the bulk action. 1290 */ 965 1291 make_bulk = function(value) { 966 1292 return function() {
Note: See TracChangeset
for help on using the changeset viewer.