author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
9 | 1 |
/** |
16 | 2 |
* Handles updating and editing comments. |
3 |
* |
|
4 |
* @file This file contains functionality for the admin comments page. |
|
5 |
* @since 2.1.0 |
|
9 | 6 |
* @output wp-admin/js/edit-comments.js |
7 |
*/ |
|
8 |
||
16 | 9 |
/* global adminCommentsSettings, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */ |
9 | 10 |
/* global commentReply, theExtraList, theList, setCommentsList */ |
0 | 11 |
|
12 |
(function($) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
var getCount, updateCount, updateCountText, updatePending, updateApproved, |
9 | 14 |
updateHtmlTitle, updateDashboardText, updateInModerationText, adminTitle = document.title, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
isDashboard = $('#dashboard_right_now').length, |
16 | 16 |
titleDiv, titleRegEx, |
17 |
__ = wp.i18n.__; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
|
16 | 19 |
/** |
20 |
* Extracts a number from the content of a jQuery element. |
|
21 |
* |
|
22 |
* @since 2.9.0 |
|
23 |
* @access private |
|
24 |
* |
|
25 |
* @param {jQuery} el jQuery element. |
|
26 |
* |
|
27 |
* @return {number} The number found in the given element. |
|
28 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
getCount = function(el) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
if ( isNaN(n) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
return 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
return n; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
|
16 | 37 |
/** |
38 |
* Updates an html element with a localized number string. |
|
39 |
* |
|
40 |
* @since 2.9.0 |
|
41 |
* @access private |
|
42 |
* |
|
43 |
* @param {jQuery} el The jQuery element to update. |
|
44 |
* @param {number} n Number to be put in the element. |
|
45 |
* |
|
46 |
* @return {void} |
|
47 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
updateCount = function(el, n) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
var n1 = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
if ( isNaN(n) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
n = n < 1 ? '0' : n.toString(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
if ( n.length > 3 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
while ( n.length > 3 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
n1 = thousandsSeparator + n.substr(n.length - 3) + n1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
n = n.substr(0, n.length - 3); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
n = n + n1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
el.html(n); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
|
16 | 64 |
/** |
65 |
* Updates the number of approved comments on a specific post and the filter bar. |
|
66 |
* |
|
67 |
* @since 4.4.0 |
|
68 |
* @access private |
|
69 |
* |
|
70 |
* @param {number} diff The amount to lower or raise the approved count with. |
|
71 |
* @param {number} commentPostId The ID of the post to be updated. |
|
72 |
* |
|
73 |
* @return {void} |
|
74 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
updateApproved = function( diff, commentPostId ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
var postSelector = '.post-com-count-' + commentPostId, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
noClass = 'comment-count-no-comments', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
approvedClass = 'comment-count-approved', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
approved, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
noComments; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
updateCountText( 'span.approved-count', diff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
if ( ! commentPostId ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
|
16 | 88 |
// Cache selectors to not get duplicates. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
approved = $( 'span.' + approvedClass, postSelector ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
noComments = $( 'span.' + noClass, postSelector ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
approved.each(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
var a = $(this), n = getCount(a) + diff; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
if ( n < 1 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
n = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
if ( 0 === n ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
a.removeClass( approvedClass ).addClass( noClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
a.addClass( approvedClass ).removeClass( noClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
updateCount( a, n ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
noComments.each(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
var a = $(this); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
if ( diff > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
a.removeClass( noClass ).addClass( approvedClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
a.addClass( noClass ).removeClass( approvedClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
updateCount( a, diff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
|
16 | 116 |
/** |
117 |
* Updates a number count in all matched HTML elements |
|
118 |
* |
|
119 |
* @since 4.4.0 |
|
120 |
* @access private |
|
121 |
* |
|
122 |
* @param {string} selector The jQuery selector for elements to update a count |
|
123 |
* for. |
|
124 |
* @param {number} diff The amount to lower or raise the count with. |
|
125 |
* |
|
126 |
* @return {void} |
|
127 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
updateCountText = function( selector, diff ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
$( selector ).each(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
var a = $(this), n = getCount(a) + diff; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
if ( n < 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
n = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
updateCount( a, n ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
|
16 | 138 |
/** |
139 |
* Updates a text about comment count on the dashboard. |
|
140 |
* |
|
141 |
* @since 4.4.0 |
|
142 |
* @access private |
|
143 |
* |
|
144 |
* @param {Object} response Ajax response from the server that includes a |
|
145 |
* translated "comment count" message. |
|
146 |
* |
|
147 |
* @return {void} |
|
148 |
*/ |
|
9 | 149 |
updateDashboardText = function( response ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
if ( ! isDashboard || ! response || ! response.i18n_comments_text ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
|
9 | 154 |
$( '.comment-count a', '#dashboard_right_now' ).text( response.i18n_comments_text ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
|
9 | 157 |
/** |
158 |
* Updates the "comments in moderation" text across the UI. |
|
159 |
* |
|
160 |
* @since 5.2.0 |
|
161 |
* |
|
16 | 162 |
* @param {Object} response Ajax response from the server that includes a |
163 |
* translated "comments in moderation" message. |
|
9 | 164 |
* |
165 |
* @return {void} |
|
166 |
*/ |
|
167 |
updateInModerationText = function( response ) { |
|
168 |
if ( ! response || ! response.i18n_moderation_text ) { |
|
169 |
return; |
|
170 |
} |
|
171 |
||
172 |
// Update the "comment in moderation" text across the UI. |
|
173 |
$( '.comments-in-moderation-text' ).text( response.i18n_moderation_text ); |
|
174 |
// Hide the "comment in moderation" text in the Dashboard "At a Glance" widget. |
|
175 |
if ( isDashboard && response.in_moderation ) { |
|
176 |
$( '.comment-mod-count', '#dashboard_right_now' ) |
|
177 |
[ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' ); |
|
178 |
} |
|
179 |
}; |
|
180 |
||
16 | 181 |
/** |
182 |
* Updates the title of the document with the number comments to be approved. |
|
183 |
* |
|
184 |
* @since 4.4.0 |
|
185 |
* @access private |
|
186 |
* |
|
187 |
* @param {number} diff The amount to lower or raise the number of to be |
|
188 |
* approved comments with. |
|
189 |
* |
|
190 |
* @return {void} |
|
191 |
*/ |
|
9 | 192 |
updateHtmlTitle = function( diff ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
var newTitle, regExMatch, titleCount, commentFrag; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
|
16 | 195 |
/* translators: %s: Comments count. */ |
196 |
titleRegEx = titleRegEx || new RegExp( __( 'Comments (%s)' ).replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' ); |
|
197 |
// Count funcs operate on a $'d element. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
titleDiv = titleDiv || $( '<div />' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
newTitle = adminTitle; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
commentFrag = titleRegEx.exec( document.title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
if ( commentFrag ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
commentFrag = commentFrag[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
titleDiv.html( commentFrag ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
titleCount = getCount( titleDiv ) + diff; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
titleDiv.html( 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
titleCount = diff; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
if ( titleCount >= 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
updateCount( titleDiv, titleCount ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
regExMatch = titleRegEx.exec( document.title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
if ( regExMatch ) { |
16 | 215 |
/* translators: %s: Comments count. */ |
216 |
newTitle = document.title.replace( regExMatch[0], __( 'Comments (%s)' ).replace( '%s', titleDiv.text() ) + ' ' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
regExMatch = titleRegEx.exec( newTitle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
if ( regExMatch ) { |
16 | 221 |
newTitle = newTitle.replace( regExMatch[0], __( 'Comments' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
document.title = newTitle; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
|
16 | 227 |
/** |
228 |
* Updates the number of pending comments on a specific post and the filter bar. |
|
229 |
* |
|
230 |
* @since 3.2.0 |
|
231 |
* @access private |
|
232 |
* |
|
233 |
* @param {number} diff The amount to lower or raise the pending count with. |
|
234 |
* @param {number} commentPostId The ID of the post to be updated. |
|
235 |
* |
|
236 |
* @return {void} |
|
237 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
updatePending = function( diff, commentPostId ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
var postSelector = '.post-com-count-' + commentPostId, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
noClass = 'comment-count-no-pending', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
noParentClass = 'post-com-count-no-pending', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
pendingClass = 'comment-count-pending', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
pending, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
noPending; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
if ( ! isDashboard ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
updateHtmlTitle( diff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
$( 'span.pending-count' ).each(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
var a = $(this), n = getCount(a) + diff; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
if ( n < 1 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
n = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
updateCount( a, n ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
if ( ! commentPostId ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
|
16 | 262 |
// Cache selectors to not get dupes. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
pending = $( 'span.' + pendingClass, postSelector ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
noPending = $( 'span.' + noClass, postSelector ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
pending.each(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
var a = $(this), n = getCount(a) + diff; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
if ( n < 1 ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
n = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
if ( 0 === n ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
a.parent().addClass( noParentClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
a.removeClass( pendingClass ).addClass( noClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
a.parent().removeClass( noParentClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
a.addClass( pendingClass ).removeClass( noClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
updateCount( a, n ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
noPending.each(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
var a = $(this); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
if ( diff > 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
a.parent().removeClass( noParentClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
a.removeClass( noClass ).addClass( pendingClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
a.parent().addClass( noParentClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
a.addClass( noClass ).removeClass( pendingClass ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
updateCount( a, diff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
}; |
0 | 293 |
|
16 | 294 |
/** |
295 |
* Initializes the comments list. |
|
296 |
* |
|
297 |
* @since 4.4.0 |
|
298 |
* |
|
299 |
* @global |
|
300 |
* |
|
301 |
* @return {void} |
|
302 |
*/ |
|
9 | 303 |
window.setCommentsList = function() { |
5 | 304 |
var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff, |
305 |
lastConfidentTime = 0; |
|
0 | 306 |
|
307 |
totalInput = $('input[name="_total"]', '#comments-form'); |
|
308 |
perPageInput = $('input[name="_per_page"]', '#comments-form'); |
|
309 |
pageInput = $('input[name="_page"]', '#comments-form'); |
|
310 |
||
16 | 311 |
/** |
312 |
* Updates the total with the latest count. |
|
313 |
* |
|
314 |
* The time parameter makes sure that we only update the total if this value is |
|
315 |
* a newer value than we previously received. |
|
316 |
* |
|
317 |
* The time and setConfidentTime parameters make sure that we only update the |
|
318 |
* total when necessary. So a value that has been generated earlier will not |
|
319 |
* update the total. |
|
320 |
* |
|
321 |
* @since 2.8.0 |
|
322 |
* @access private |
|
323 |
* |
|
324 |
* @param {number} total Total number of comments. |
|
325 |
* @param {number} time Unix timestamp of response. |
|
326 |
* @param {boolean} setConfidentTime Whether to update the last confident time |
|
327 |
* with the given time. |
|
328 |
* |
|
329 |
* @return {void} |
|
330 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
updateTotalCount = function( total, time, setConfidentTime ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
if ( time < lastConfidentTime ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
if ( setConfidentTime ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
lastConfidentTime = time; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
337 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
totalInput.val( total.toString() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
|
16 | 341 |
/** |
342 |
* Changes DOM that need to be changed after a list item has been dimmed. |
|
343 |
* |
|
344 |
* @since 2.5.0 |
|
345 |
* @access private |
|
346 |
* |
|
347 |
* @param {Object} r Ajax response object. |
|
348 |
* @param {Object} settings Settings for the wpList object. |
|
349 |
* |
|
350 |
* @return {void} |
|
351 |
*/ |
|
0 | 352 |
dimAfter = function( r, settings ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
var editRow, replyID, replyButton, response, |
5 | 354 |
c = $( '#' + settings.element ); |
0 | 355 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
if ( true !== settings.parsed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
response = settings.parsed.responses[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
|
0 | 360 |
editRow = $('#replyrow'); |
361 |
replyID = $('#comment_ID', editRow).val(); |
|
362 |
replyButton = $('#replybtn', editRow); |
|
363 |
||
364 |
if ( c.is('.unapproved') ) { |
|
365 |
if ( settings.data.id == replyID ) |
|
16 | 366 |
replyButton.text( __( 'Approve and Reply' ) ); |
0 | 367 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
c.find( '.row-actions span.view' ).addClass( 'hidden' ).end() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
.find( 'div.comment_status' ).html( '0' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
|
0 | 371 |
} else { |
372 |
if ( settings.data.id == replyID ) |
|
16 | 373 |
replyButton.text( __( 'Reply' ) ); |
0 | 374 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
.find( 'div.comment_status' ).html( '1' ); |
0 | 377 |
} |
378 |
||
5 | 379 |
diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
if ( response ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
updateDashboardText( response.supplemental ); |
9 | 382 |
updateInModerationText( response.supplemental ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
updatePending( diff, response.supplemental.postId ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
updateApproved( -1 * diff, response.supplemental.postId ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
updatePending( diff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
updateApproved( -1 * diff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
} |
0 | 389 |
}; |
390 |
||
16 | 391 |
/** |
392 |
* Handles marking a comment as spam or trashing the comment. |
|
393 |
* |
|
394 |
* Is executed in the list delBefore hook. |
|
395 |
* |
|
396 |
* @since 2.8.0 |
|
397 |
* @access private |
|
398 |
* |
|
399 |
* @param {Object} settings Settings for the wpList object. |
|
400 |
* @param {HTMLElement} list Comments table element. |
|
401 |
* |
|
402 |
* @return {Object} The settings object. |
|
403 |
*/ |
|
0 | 404 |
delBefore = function( settings, list ) { |
5 | 405 |
var note, id, el, n, h, a, author, |
406 |
action = false, |
|
407 |
wpListsData = $( settings.target ).attr( 'data-wp-lists' ); |
|
0 | 408 |
|
409 |
settings.data._total = totalInput.val() || 0; |
|
410 |
settings.data._per_page = perPageInput.val() || 0; |
|
411 |
settings.data._page = pageInput.val() || 0; |
|
412 |
settings.data._url = document.location.href; |
|
413 |
settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val(); |
|
414 |
||
415 |
if ( wpListsData.indexOf(':trash=1') != -1 ) |
|
416 |
action = 'trash'; |
|
417 |
else if ( wpListsData.indexOf(':spam=1') != -1 ) |
|
418 |
action = 'spam'; |
|
419 |
||
420 |
if ( action ) { |
|
421 |
id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1'); |
|
422 |
el = $('#comment-' + id); |
|
423 |
note = $('#' + action + '-undo-holder').html(); |
|
424 |
||
425 |
el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits. |
|
426 |
||
427 |
if ( el.siblings('#replyrow').length && commentReply.cid == id ) |
|
428 |
commentReply.close(); |
|
429 |
||
430 |
if ( el.is('tr') ) { |
|
431 |
n = el.children(':visible').length; |
|
432 |
author = $('.author strong', el).text(); |
|
433 |
h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>'); |
|
434 |
} else { |
|
435 |
author = $('.comment-author', el).text(); |
|
436 |
h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>'); |
|
437 |
} |
|
438 |
||
439 |
el.before(h); |
|
440 |
||
441 |
$('strong', '#undo-' + id).text(author); |
|
442 |
a = $('.undo a', '#undo-' + id); |
|
443 |
a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); |
|
444 |
a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1'); |
|
9 | 445 |
a.attr('class', 'vim-z vim-destructive aria-button-if-js'); |
5 | 446 |
$('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); |
0 | 447 |
|
18 | 448 |
a.on( 'click', function( e ){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
e.preventDefault(); |
16 | 450 |
e.stopPropagation(); // Ticket #35904. |
0 | 451 |
list.wpList.del(this); |
452 |
$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ |
|
453 |
$(this).remove(); |
|
5 | 454 |
$('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); }); |
0 | 455 |
}); |
456 |
}); |
|
457 |
} |
|
458 |
||
459 |
return settings; |
|
460 |
}; |
|
461 |
||
16 | 462 |
/** |
463 |
* Handles actions that need to be done after marking as spam or thrashing a |
|
464 |
* comment. |
|
465 |
* |
|
466 |
* The ajax requests return the unix time stamp a comment was marked as spam or |
|
467 |
* trashed. We use this to have a correct total amount of comments. |
|
468 |
* |
|
469 |
* @since 2.5.0 |
|
470 |
* @access private |
|
471 |
* |
|
472 |
* @param {Object} r Ajax response object. |
|
473 |
* @param {Object} settings Settings for the wpList object. |
|
474 |
* |
|
475 |
* @return {void} |
|
476 |
*/ |
|
0 | 477 |
delAfter = function( r, settings ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
var total_items_i18n, total, animated, animatedCallback, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
response = true === settings.parsed ? {} : settings.parsed.responses[0], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
commentStatus = true === settings.parsed ? '' : response.supplemental.status, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
commentPostId = true === settings.parsed ? '' : response.supplemental.postId, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
newTotal = true === settings.parsed ? '' : response.supplemental, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
targetParent = $( settings.target ).parent(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
commentRow = $('#' + settings.element), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
spamDiff, trashDiff, pendingDiff, approvedDiff, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
|
9 | 489 |
/* |
490 |
* As `wpList` toggles only the `unapproved` class, the approved comment |
|
491 |
* rows can have both the `approved` and `unapproved` classes. |
|
492 |
*/ |
|
493 |
approved = commentRow.hasClass( 'approved' ) && ! commentRow.hasClass( 'unapproved' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
unapproved = commentRow.hasClass( 'unapproved' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
spammed = commentRow.hasClass( 'spam' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
trashed = commentRow.hasClass( 'trash' ), |
16 | 497 |
undoing = false; // Ticket #35904. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
updateDashboardText( newTotal ); |
9 | 500 |
updateInModerationText( newTotal ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
|
16 | 502 |
/* |
503 |
* The order of these checks is important. |
|
504 |
* .unspam can also have .approve or .unapprove. |
|
505 |
* .untrash can also have .approve or .unapprove. |
|
506 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
if ( targetParent.is( 'span.undo' ) ) { |
16 | 509 |
// The comment was spammed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
if ( targetParent.hasClass( 'unspam' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
spamDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
if ( 'trash' === commentStatus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
trashDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
} else if ( '1' === commentStatus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
516 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
} else if ( '0' === commentStatus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
|
16 | 521 |
// The comment was trashed. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
} else if ( targetParent.hasClass( 'untrash' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
trashDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
if ( 'spam' === commentStatus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
spamDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
} else if ( '1' === commentStatus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
} else if ( '0' === commentStatus ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
undoing = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
|
16 | 536 |
// User clicked "Spam". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
} else if ( targetParent.is( 'span.spam' ) ) { |
16 | 538 |
// The comment is currently approved. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
if ( approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
approvedDiff = -1; |
16 | 541 |
// The comment is currently pending. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
} else if ( unapproved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
pendingDiff = -1; |
16 | 544 |
// The comment was in the Trash. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
} else if ( trashed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
trashDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
} |
16 | 548 |
// You can't spam an item on the Spam screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
spamDiff = 1; |
0 | 550 |
|
16 | 551 |
// User clicked "Unspam". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
} else if ( targetParent.is( 'span.unspam' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
if ( approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
} else if ( unapproved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
} else if ( trashed ) { |
16 | 558 |
// The comment was previously approved. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
if ( targetParent.hasClass( 'approve' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
approvedDiff = 1; |
16 | 561 |
// The comment was previously pending. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
} else if ( targetParent.hasClass( 'unapprove' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
563 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
564 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
} else if ( spammed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
566 |
if ( targetParent.hasClass( 'approve' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
567 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
569 |
} else if ( targetParent.hasClass( 'unapprove' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
571 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
} |
16 | 573 |
// You can unspam an item on the Spam screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
spamDiff = -1; |
0 | 575 |
|
16 | 576 |
// User clicked "Trash". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
} else if ( targetParent.is( 'span.trash' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
578 |
if ( approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
approvedDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
580 |
} else if ( unapproved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
581 |
pendingDiff = -1; |
16 | 582 |
// The comment was in the spam queue. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
} else if ( spammed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
584 |
spamDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
} |
16 | 586 |
// You can't trash an item on the Trash screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
trashDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
|
16 | 589 |
// User clicked "Restore". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
} else if ( targetParent.is( 'span.untrash' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
if ( approved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
593 |
} else if ( unapproved ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
} else if ( trashed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
596 |
if ( targetParent.hasClass( 'approve' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
598 |
} else if ( targetParent.hasClass( 'unapprove' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
599 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
600 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
} |
16 | 602 |
// You can't go from Trash to Spam. |
603 |
// You can untrash on the Trash screen. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
trashDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
|
16 | 606 |
// User clicked "Approve". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
} else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
608 |
approvedDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
609 |
pendingDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
610 |
|
16 | 611 |
// User clicked "Unapprove". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
612 |
} else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
approvedDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
pendingDiff = 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
|
16 | 616 |
// User clicked "Delete Permanently". |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
} else if ( targetParent.is( 'span.delete' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
if ( spammed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
spamDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
} else if ( trashed ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
trashDiff = -1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
} |
0 | 623 |
} |
624 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
if ( pendingDiff ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
updatePending( pendingDiff, commentPostId ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
updateCountText( 'span.all-count', pendingDiff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
} |
0 | 629 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
if ( approvedDiff ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
updateApproved( approvedDiff, commentPostId ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
updateCountText( 'span.all-count', approvedDiff ); |
0 | 633 |
} |
634 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
if ( spamDiff ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
updateCountText( 'span.spam-count', spamDiff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
if ( trashDiff ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
updateCountText( 'span.trash-count', trashDiff ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
} |
0 | 642 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
if ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) || |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
$( '#delete_all' ).hide(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
} |
0 | 649 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
if ( ! isDashboard ) { |
0 | 651 |
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; |
652 |
if ( $(settings.target).parent().is('span.undo') ) |
|
653 |
total++; |
|
654 |
else |
|
655 |
total--; |
|
656 |
||
657 |
if ( total < 0 ) |
|
658 |
total = 0; |
|
659 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
if ( 'object' === typeof r ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
661 |
if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
total_items_i18n = response.supplemental.total_items_i18n || ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
663 |
if ( total_items_i18n ) { |
16 | 664 |
$('.displaying-num').text( total_items_i18n.replace( ' ', String.fromCharCode( 160 ) ) ); |
665 |
$('.total-pages').text( response.supplemental.total_pages_i18n.replace( ' ', String.fromCharCode( 160 ) ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
666 |
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val()); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
667 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
668 |
updateTotalCount( total, response.supplemental.time, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
669 |
} else if ( response.supplemental.time ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
670 |
updateTotalCount( total, response.supplemental.time, false ); |
0 | 671 |
} |
672 |
} else { |
|
673 |
updateTotalCount( total, r, false ); |
|
674 |
} |
|
675 |
} |
|
676 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) { |
0 | 678 |
return; |
679 |
} |
|
680 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
681 |
theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() ); |
0 | 682 |
|
683 |
refillTheExtraList(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
684 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
animated = $( ':animated', '#the-comment-list' ); |
9 | 686 |
animatedCallback = function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
if ( ! $( '#the-comment-list tr:visible' ).length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
if ( animated.length ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
animated.promise().done( animatedCallback ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
animatedCallback(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
} |
0 | 697 |
}; |
698 |
||
16 | 699 |
/** |
700 |
* Retrieves additional comments to populate the extra list. |
|
701 |
* |
|
702 |
* @since 3.1.0 |
|
703 |
* @access private |
|
704 |
* |
|
705 |
* @param {boolean} [ev] Repopulate the extra comments list if true. |
|
706 |
* |
|
707 |
* @return {void} |
|
708 |
*/ |
|
0 | 709 |
refillTheExtraList = function(ev) { |
710 |
var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val(); |
|
711 |
||
712 |
if (! args.paged) |
|
713 |
args.paged = 1; |
|
714 |
||
715 |
if (args.paged > total_pages) { |
|
716 |
return; |
|
717 |
} |
|
718 |
||
719 |
if (ev) { |
|
720 |
theExtraList.empty(); |
|
16 | 721 |
args.number = Math.min(8, per_page); // See WP_Comments_List_Table::prepare_items() in class-wp-comments-list-table.php. |
0 | 722 |
} else { |
723 |
args.number = 1; |
|
16 | 724 |
args.offset = Math.min(8, per_page) - 1; // Fetch only the next item on the extra list. |
0 | 725 |
} |
726 |
||
727 |
args.no_placeholder = true; |
|
728 |
||
729 |
args.paged ++; |
|
730 |
||
16 | 731 |
// $.query.get() needs some correction to be sent into an Ajax request. |
0 | 732 |
if ( true === args.comment_type ) |
733 |
args.comment_type = ''; |
|
734 |
||
735 |
args = $.extend(args, { |
|
736 |
'action': 'fetch-list', |
|
737 |
'list_args': list_args, |
|
738 |
'_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val() |
|
739 |
}); |
|
740 |
||
741 |
$.ajax({ |
|
742 |
url: ajaxurl, |
|
743 |
global: false, |
|
744 |
dataType: 'json', |
|
745 |
data: args, |
|
746 |
success: function(response) { |
|
747 |
theExtraList.get(0).wpList.add( response.rows ); |
|
748 |
} |
|
749 |
}); |
|
750 |
}; |
|
751 |
||
16 | 752 |
/** |
753 |
* Globally available jQuery object referring to the extra comments list. |
|
754 |
* |
|
755 |
* @global |
|
756 |
*/ |
|
9 | 757 |
window.theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); |
16 | 758 |
|
759 |
/** |
|
760 |
* Globally available jQuery object referring to the comments list. |
|
761 |
* |
|
762 |
* @global |
|
763 |
*/ |
|
9 | 764 |
window.theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) |
18 | 765 |
.on('wpListDelEnd', function(e, s){ |
0 | 766 |
var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, ''); |
767 |
||
768 |
if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 ) |
|
5 | 769 |
$('#undo-' + id).fadeIn(300, function(){ $(this).show(); }); |
0 | 770 |
}); |
771 |
}; |
|
772 |
||
16 | 773 |
/** |
774 |
* Object containing functionality regarding the comment quick editor and reply |
|
775 |
* editor. |
|
776 |
* |
|
777 |
* @since 2.7.0 |
|
778 |
* |
|
779 |
* @global |
|
780 |
*/ |
|
9 | 781 |
window.commentReply = { |
0 | 782 |
cid : '', |
783 |
act : '', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
originalContent : '', |
0 | 785 |
|
16 | 786 |
/** |
787 |
* Initializes the comment reply functionality. |
|
788 |
* |
|
789 |
* @since 2.7.0 |
|
790 |
* |
|
791 |
* @memberof commentReply |
|
792 |
*/ |
|
0 | 793 |
init : function() { |
794 |
var row = $('#replyrow'); |
|
795 |
||
18 | 796 |
$( '.cancel', row ).on( 'click', function() { return commentReply.revert(); } ); |
797 |
$( '.save', row ).on( 'click', function() { return commentReply.send(); } ); |
|
798 |
$( 'input#author-name, input#author-email, input#author-url', row ).on( 'keypress', function( e ) { |
|
0 | 799 |
if ( e.which == 13 ) { |
800 |
commentReply.send(); |
|
801 |
e.preventDefault(); |
|
802 |
return false; |
|
803 |
} |
|
804 |
}); |
|
805 |
||
16 | 806 |
// Add events. |
18 | 807 |
$('#the-comment-list .column-comment > p').on( 'dblclick', function(){ |
0 | 808 |
commentReply.toggle($(this).parent()); |
809 |
}); |
|
810 |
||
18 | 811 |
$('#doaction, #post-query-submit').on( 'click', function(){ |
0 | 812 |
if ( $('#the-comment-list #replyrow').length > 0 ) |
813 |
commentReply.close(); |
|
814 |
}); |
|
815 |
||
816 |
this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; |
|
817 |
}, |
|
818 |
||
16 | 819 |
/** |
820 |
* Adds doubleclick event handler to the given comment list row. |
|
821 |
* |
|
822 |
* The double-click event will toggle the comment edit or reply form. |
|
823 |
* |
|
824 |
* @since 2.7.0 |
|
825 |
* |
|
826 |
* @memberof commentReply |
|
827 |
* |
|
828 |
* @param {Object} r The row to add double click handlers to. |
|
829 |
* |
|
830 |
* @return {void} |
|
831 |
*/ |
|
0 | 832 |
addEvents : function(r) { |
833 |
r.each(function() { |
|
18 | 834 |
$(this).find('.column-comment > p').on( 'dblclick', function(){ |
0 | 835 |
commentReply.toggle($(this).parent()); |
836 |
}); |
|
837 |
}); |
|
838 |
}, |
|
839 |
||
16 | 840 |
/** |
841 |
* Opens the quick edit for the given element. |
|
842 |
* |
|
843 |
* @since 2.7.0 |
|
844 |
* |
|
845 |
* @memberof commentReply |
|
846 |
* |
|
847 |
* @param {HTMLElement} el The element you want to open the quick editor for. |
|
848 |
* |
|
849 |
* @return {void} |
|
850 |
*/ |
|
0 | 851 |
toggle : function(el) { |
16 | 852 |
if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( __( 'Are you sure you want to edit this comment?\nThe changes you made will be lost.' ) ) ) ) { |
18 | 853 |
$( el ).find( 'button.vim-q' ).trigger( 'click' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
854 |
} |
0 | 855 |
}, |
856 |
||
16 | 857 |
/** |
858 |
* Closes the comment quick edit or reply form and undoes any changes. |
|
859 |
* |
|
860 |
* @since 2.7.0 |
|
861 |
* |
|
862 |
* @memberof commentReply |
|
863 |
* |
|
864 |
* @return {void} |
|
865 |
*/ |
|
0 | 866 |
revert : function() { |
867 |
||
868 |
if ( $('#the-comment-list #replyrow').length < 1 ) |
|
869 |
return false; |
|
870 |
||
871 |
$('#replyrow').fadeOut('fast', function(){ |
|
872 |
commentReply.close(); |
|
873 |
}); |
|
874 |
}, |
|
875 |
||
16 | 876 |
/** |
877 |
* Closes the comment quick edit or reply form and undoes any changes. |
|
878 |
* |
|
879 |
* @since 2.7.0 |
|
880 |
* |
|
881 |
* @memberof commentReply |
|
882 |
* |
|
883 |
* @return {void} |
|
884 |
*/ |
|
0 | 885 |
close : function() { |
9 | 886 |
var commentRow = $(), |
887 |
replyRow = $( '#replyrow' ); |
|
0 | 888 |
|
16 | 889 |
// Return if the replyrow is not showing. |
9 | 890 |
if ( replyRow.parent().is( '#com-reply' ) ) { |
0 | 891 |
return; |
9 | 892 |
} |
893 |
||
894 |
if ( this.cid ) { |
|
895 |
commentRow = $( '#comment-' + this.cid ); |
|
896 |
} |
|
0 | 897 |
|
9 | 898 |
/* |
899 |
* When closing the Quick Edit form, show the comment row and move focus |
|
900 |
* back to the Quick Edit button. |
|
901 |
*/ |
|
902 |
if ( 'edit-comment' === this.act ) { |
|
903 |
commentRow.fadeIn( 300, function() { |
|
904 |
commentRow |
|
905 |
.show() |
|
906 |
.find( '.vim-q' ) |
|
907 |
.attr( 'aria-expanded', 'false' ) |
|
18 | 908 |
.trigger( 'focus' ); |
9 | 909 |
} ).css( 'backgroundColor', '' ); |
910 |
} |
|
911 |
||
912 |
// When closing the Reply form, move focus back to the Reply button. |
|
913 |
if ( 'replyto-comment' === this.act ) { |
|
914 |
commentRow.find( '.vim-r' ) |
|
915 |
.attr( 'aria-expanded', 'false' ) |
|
18 | 916 |
.trigger( 'focus' ); |
0 | 917 |
} |
918 |
||
16 | 919 |
// Reset the Quicktags buttons. |
920 |
if ( typeof QTags != 'undefined' ) |
|
0 | 921 |
QTags.closeAllTags('replycontent'); |
922 |
||
923 |
$('#add-new-comment').css('display', ''); |
|
924 |
||
9 | 925 |
replyRow.hide(); |
926 |
$( '#com-reply' ).append( replyRow ); |
|
0 | 927 |
$('#replycontent').css('height', '').val(''); |
928 |
$('#edithead input').val(''); |
|
9 | 929 |
$( '.notice-error', replyRow ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
.addClass( 'hidden' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
.find( '.error' ).empty(); |
9 | 932 |
$( '.spinner', replyRow ).removeClass( 'is-active' ); |
0 | 933 |
|
934 |
this.cid = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
this.originalContent = ''; |
0 | 936 |
}, |
937 |
||
16 | 938 |
/** |
939 |
* Opens the comment quick edit or reply form. |
|
940 |
* |
|
941 |
* @since 2.7.0 |
|
942 |
* |
|
943 |
* @memberof commentReply |
|
944 |
* |
|
945 |
* @param {number} comment_id The comment ID to open an editor for. |
|
946 |
* @param {number} post_id The post ID to open an editor for. |
|
947 |
* @param {string} action The action to perform. Either 'edit' or 'replyto'. |
|
948 |
* |
|
949 |
* @return {boolean} Always false. |
|
950 |
*/ |
|
0 | 951 |
open : function(comment_id, post_id, action) { |
5 | 952 |
var editRow, rowData, act, replyButton, editHeight, |
953 |
t = this, |
|
954 |
c = $('#comment-' + comment_id), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
h = c.height(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
colspanVal = 0; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
if ( ! this.discardCommentChanges() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
} |
0 | 961 |
|
962 |
t.close(); |
|
963 |
t.cid = comment_id; |
|
964 |
||
965 |
editRow = $('#replyrow'); |
|
966 |
rowData = $('#inline-'+comment_id); |
|
967 |
action = action || 'replyto'; |
|
968 |
act = 'edit' == action ? 'edit' : 'replyto'; |
|
969 |
act = t.act = act + '-comment'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
t.originalContent = $('textarea.comment', rowData).val(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
colspanVal = $( '> th:visible, > td:visible', c ).length; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
// Make sure it's actually a table and there's a `colspan` value to apply. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
if ( editRow.hasClass( 'inline-edit-row' ) && 0 !== colspanVal ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
$( 'td', editRow ).attr( 'colspan', colspanVal ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
} |
0 | 977 |
|
978 |
$('#action', editRow).val(act); |
|
979 |
$('#comment_post_ID', editRow).val(post_id); |
|
980 |
$('#comment_ID', editRow).val(comment_id); |
|
981 |
||
982 |
if ( action == 'edit' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
$( '#author-name', editRow ).val( $( 'div.author', rowData ).text() ); |
0 | 984 |
$('#author-email', editRow).val( $('div.author-email', rowData).text() ); |
985 |
$('#author-url', editRow).val( $('div.author-url', rowData).text() ); |
|
986 |
$('#status', editRow).val( $('div.comment_status', rowData).text() ); |
|
987 |
$('#replycontent', editRow).val( $('textarea.comment', rowData).val() ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
$( '#edithead, #editlegend, #savebtn', editRow ).show(); |
0 | 989 |
$('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide(); |
990 |
||
5 | 991 |
if ( h > 120 ) { |
992 |
// Limit the maximum height when editing very long comments to make it more manageable. |
|
993 |
// The textarea is resizable in most browsers, so the user can adjust it if needed. |
|
994 |
editHeight = h > 500 ? 500 : h; |
|
995 |
$('#replycontent', editRow).css('height', editHeight + 'px'); |
|
996 |
} |
|
997 |
||
0 | 998 |
c.after( editRow ).fadeOut('fast', function(){ |
5 | 999 |
$('#replyrow').fadeIn(300, function(){ $(this).show(); }); |
0 | 1000 |
}); |
1001 |
} else if ( action == 'add' ) { |
|
1002 |
$('#addhead, #addbtn', editRow).show(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
$( '#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow ) .hide(); |
0 | 1004 |
$('#the-comment-list').prepend(editRow); |
1005 |
$('#replyrow').fadeIn(300); |
|
5 | 1006 |
} else { |
1007 |
replyButton = $('#replybtn', editRow); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
$( '#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow ).hide(); |
0 | 1009 |
$('#replyhead, #replybtn', editRow).show(); |
1010 |
c.after(editRow); |
|
1011 |
||
1012 |
if ( c.hasClass('unapproved') ) { |
|
16 | 1013 |
replyButton.text( __( 'Approve and Reply' ) ); |
0 | 1014 |
} else { |
16 | 1015 |
replyButton.text( __( 'Reply' ) ); |
0 | 1016 |
} |
1017 |
||
5 | 1018 |
$('#replyrow').fadeIn(300, function(){ $(this).show(); }); |
0 | 1019 |
} |
1020 |
||
1021 |
setTimeout(function() { |
|
19 | 1022 |
var rtop, rbottom, scrollTop, vp, scrollBottom, |
1023 |
isComposing = false; |
|
0 | 1024 |
|
1025 |
rtop = $('#replyrow').offset().top; |
|
1026 |
rbottom = rtop + $('#replyrow').height(); |
|
1027 |
scrollTop = window.pageYOffset || document.documentElement.scrollTop; |
|
5 | 1028 |
vp = document.documentElement.clientHeight || window.innerHeight || 0; |
0 | 1029 |
scrollBottom = scrollTop + vp; |
1030 |
||
1031 |
if ( scrollBottom - 20 < rbottom ) |
|
1032 |
window.scroll(0, rbottom - vp + 35); |
|
1033 |
else if ( rtop - 20 < scrollTop ) |
|
1034 |
window.scroll(0, rtop - 35); |
|
1035 |
||
19 | 1036 |
$( '#replycontent' ) |
1037 |
.trigger( 'focus' ) |
|
1038 |
.on( 'keyup', function( e ) { |
|
1039 |
// Close on Escape except when Input Method Editors (IMEs) are in use. |
|
1040 |
if ( e.which === 27 && ! isComposing ) { |
|
1041 |
commentReply.revert(); |
|
1042 |
} |
|
1043 |
} ) |
|
1044 |
.on( 'compositionstart', function() { |
|
1045 |
isComposing = true; |
|
1046 |
} ); |
|
0 | 1047 |
}, 600); |
1048 |
||
1049 |
return false; |
|
1050 |
}, |
|
1051 |
||
16 | 1052 |
/** |
1053 |
* Submits the comment quick edit or reply form. |
|
1054 |
* |
|
1055 |
* @since 2.7.0 |
|
1056 |
* |
|
1057 |
* @memberof commentReply |
|
1058 |
* |
|
1059 |
* @return {void} |
|
1060 |
*/ |
|
0 | 1061 |
send : function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
var post = {}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
$errorNotice = $( '#replysubmit .error-notice' ); |
0 | 1064 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
$errorNotice.addClass( 'hidden' ); |
5 | 1066 |
$( '#replysubmit .spinner' ).addClass( 'is-active' ); |
0 | 1067 |
|
1068 |
$('#replyrow input').not(':button').each(function() { |
|
1069 |
var t = $(this); |
|
1070 |
post[ t.attr('name') ] = t.val(); |
|
1071 |
}); |
|
1072 |
||
1073 |
post.content = $('#replycontent').val(); |
|
1074 |
post.id = post.comment_post_ID; |
|
1075 |
post.comments_listing = this.comments_listing; |
|
1076 |
post.p = $('[name="p"]').val(); |
|
1077 |
||
1078 |
if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') ) |
|
1079 |
post.approve_parent = 1; |
|
1080 |
||
1081 |
$.ajax({ |
|
1082 |
type : 'POST', |
|
1083 |
url : ajaxurl, |
|
1084 |
data : post, |
|
1085 |
success : function(x) { commentReply.show(x); }, |
|
1086 |
error : function(r) { commentReply.error(r); } |
|
1087 |
}); |
|
1088 |
}, |
|
1089 |
||
16 | 1090 |
/** |
1091 |
* Shows the new or updated comment or reply. |
|
1092 |
* |
|
1093 |
* This function needs to be passed the ajax result as received from the server. |
|
1094 |
* It will handle the response and show the comment that has just been saved to |
|
1095 |
* the server. |
|
1096 |
* |
|
1097 |
* @since 2.7.0 |
|
1098 |
* |
|
1099 |
* @memberof commentReply |
|
1100 |
* |
|
1101 |
* @param {Object} xml Ajax response object. |
|
1102 |
* |
|
1103 |
* @return {void} |
|
1104 |
*/ |
|
0 | 1105 |
show : function(xml) { |
1106 |
var t = this, r, c, id, bg, pid; |
|
1107 |
||
1108 |
if ( typeof(xml) == 'string' ) { |
|
1109 |
t.error({'responseText': xml}); |
|
1110 |
return false; |
|
1111 |
} |
|
1112 |
||
1113 |
r = wpAjax.parseAjaxResponse(xml); |
|
1114 |
if ( r.errors ) { |
|
1115 |
t.error({'responseText': wpAjax.broken}); |
|
1116 |
return false; |
|
1117 |
} |
|
1118 |
||
1119 |
t.revert(); |
|
1120 |
||
1121 |
r = r.responses[0]; |
|
1122 |
id = '#comment-' + r.id; |
|
1123 |
||
1124 |
if ( 'edit-comment' == t.act ) |
|
1125 |
$(id).remove(); |
|
1126 |
||
1127 |
if ( r.supplemental.parent_approved ) { |
|
1128 |
pid = $('#comment-' + r.supplemental.parent_approved); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
updatePending( -1, r.supplemental.parent_post_id ); |
0 | 1130 |
|
1131 |
if ( this.comments_listing == 'moderated' ) { |
|
1132 |
pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){ |
|
1133 |
pid.fadeOut(); |
|
1134 |
}); |
|
1135 |
return; |
|
1136 |
} |
|
1137 |
} |
|
1138 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
if ( r.supplemental.i18n_comments_text ) { |
9 | 1140 |
updateDashboardText( r.supplemental ); |
1141 |
updateInModerationText( r.supplemental ); |
|
1142 |
updateApproved( 1, r.supplemental.parent_post_id ); |
|
1143 |
updateCountText( 'span.all-count', 1 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
|
18 | 1146 |
r.data = r.data || ''; |
1147 |
c = r.data.toString().trim(); // Trim leading whitespaces. |
|
5 | 1148 |
$(c).hide(); |
0 | 1149 |
$('#replyrow').after(c); |
1150 |
||
1151 |
id = $(id); |
|
1152 |
t.addEvents(id); |
|
1153 |
bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor'); |
|
1154 |
||
1155 |
id.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) |
|
1156 |
.animate( { 'backgroundColor': bg }, 300, function() { |
|
1157 |
if ( pid && pid.length ) { |
|
1158 |
pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) |
|
1159 |
.animate( { 'backgroundColor': bg }, 300 ) |
|
1160 |
.removeClass('unapproved').addClass('approved') |
|
1161 |
.find('div.comment_status').html('1'); |
|
1162 |
} |
|
1163 |
}); |
|
1164 |
||
1165 |
}, |
|
1166 |
||
16 | 1167 |
/** |
1168 |
* Shows an error for the failed comment update or reply. |
|
1169 |
* |
|
1170 |
* @since 2.7.0 |
|
1171 |
* |
|
1172 |
* @memberof commentReply |
|
1173 |
* |
|
1174 |
* @param {string} r The Ajax response. |
|
1175 |
* |
|
1176 |
* @return {void} |
|
1177 |
*/ |
|
0 | 1178 |
error : function(r) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1179 |
var er = r.statusText, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1180 |
$errorNotice = $( '#replysubmit .notice-error' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
$error = $errorNotice.find( '.error' ); |
0 | 1182 |
|
5 | 1183 |
$( '#replysubmit .spinner' ).removeClass( 'is-active' ); |
0 | 1184 |
|
1185 |
if ( r.responseText ) |
|
1186 |
er = r.responseText.replace( /<.[^<>]*?>/g, '' ); |
|
1187 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
if ( er ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
$errorNotice.removeClass( 'hidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
$error.html( er ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
} |
0 | 1192 |
}, |
1193 |
||
16 | 1194 |
/** |
1195 |
* Opens the add comments form in the comments metabox on the post edit page. |
|
1196 |
* |
|
1197 |
* @since 3.4.0 |
|
1198 |
* |
|
1199 |
* @memberof commentReply |
|
1200 |
* |
|
1201 |
* @param {number} post_id The post ID. |
|
1202 |
* |
|
1203 |
* @return {void} |
|
1204 |
*/ |
|
0 | 1205 |
addcomment: function(post_id) { |
1206 |
var t = this; |
|
1207 |
||
1208 |
$('#add-new-comment').fadeOut(200, function(){ |
|
1209 |
t.open(0, post_id, 'add'); |
|
1210 |
$('table.comments-box').css('display', ''); |
|
1211 |
$('#no-comments').remove(); |
|
1212 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
}, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
/** |
16 | 1216 |
* Alert the user if they have unsaved changes on a comment that will be lost if |
1217 |
* they proceed with the intended action. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* |
16 | 1219 |
* @since 4.6.0 |
1220 |
* |
|
1221 |
* @memberof commentReply |
|
1222 |
* |
|
1223 |
* @return {boolean} Whether it is safe the continue with the intended action. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
discardCommentChanges: function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
var editRow = $( '#replyrow' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
if ( this.originalContent === $( '#replycontent', editRow ).val() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
|
16 | 1232 |
return window.confirm( __( 'Are you sure you want to do this?\nThe comment changes you made will be lost.' ) ); |
0 | 1233 |
} |
1234 |
}; |
|
1235 |
||
18 | 1236 |
$( function(){ |
0 | 1237 |
var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk; |
1238 |
||
1239 |
setCommentsList(); |
|
1240 |
commentReply.init(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
$(document).on( 'click', 'span.delete a.delete', function( e ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1243 |
e.preventDefault(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1244 |
}); |
0 | 1245 |
|
1246 |
if ( typeof $.table_hotkeys != 'undefined' ) { |
|
16 | 1247 |
/** |
1248 |
* Creates a function that navigates to a previous or next page. |
|
1249 |
* |
|
1250 |
* @since 2.7.0 |
|
1251 |
* @access private |
|
1252 |
* |
|
1253 |
* @param {string} which What page to navigate to: either next or prev. |
|
1254 |
* |
|
1255 |
* @return {Function} The function that executes the navigation. |
|
1256 |
*/ |
|
0 | 1257 |
make_hotkeys_redirect = function(which) { |
1258 |
return function() { |
|
1259 |
var first_last, l; |
|
1260 |
||
1261 |
first_last = 'next' == which? 'first' : 'last'; |
|
1262 |
l = $('.tablenav-pages .'+which+'-page:not(.disabled)'); |
|
1263 |
if (l.length) |
|
1264 |
window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; |
|
5 | 1265 |
}; |
0 | 1266 |
}; |
1267 |
||
16 | 1268 |
/** |
1269 |
* Navigates to the edit page for the selected comment. |
|
1270 |
* |
|
1271 |
* @since 2.7.0 |
|
1272 |
* @access private |
|
1273 |
* |
|
1274 |
* @param {Object} event The event that triggered this action. |
|
1275 |
* @param {Object} current_row A jQuery object of the selected row. |
|
1276 |
* |
|
1277 |
* @return {void} |
|
1278 |
*/ |
|
0 | 1279 |
edit_comment = function(event, current_row) { |
1280 |
window.location = $('span.edit a', current_row).attr('href'); |
|
1281 |
}; |
|
1282 |
||
16 | 1283 |
/** |
1284 |
* Toggles all comments on the screen, for bulk actions. |
|
1285 |
* |
|
1286 |
* @since 2.7.0 |
|
1287 |
* @access private |
|
1288 |
* |
|
1289 |
* @return {void} |
|
1290 |
*/ |
|
0 | 1291 |
toggle_all = function() { |
5 | 1292 |
$('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' ); |
0 | 1293 |
}; |
1294 |
||
16 | 1295 |
/** |
1296 |
* Creates a bulk action function that is executed on all selected comments. |
|
1297 |
* |
|
1298 |
* @since 2.7.0 |
|
1299 |
* @access private |
|
1300 |
* |
|
1301 |
* @param {string} value The name of the action to execute. |
|
1302 |
* |
|
1303 |
* @return {Function} The function that executes the bulk action. |
|
1304 |
*/ |
|
0 | 1305 |
make_bulk = function(value) { |
1306 |
return function() { |
|
1307 |
var scope = $('select[name="action"]'); |
|
1308 |
$('option[value="' + value + '"]', scope).prop('selected', true); |
|
18 | 1309 |
$('#doaction').trigger( 'click' ); |
5 | 1310 |
}; |
0 | 1311 |
}; |
1312 |
||
1313 |
$.table_hotkeys( |
|
1314 |
$('table.widefat'), |
|
5 | 1315 |
[ |
1316 |
'a', 'u', 's', 'd', 'r', 'q', 'z', |
|
1317 |
['e', edit_comment], |
|
1318 |
['shift+x', toggle_all], |
|
1319 |
['shift+a', make_bulk('approve')], |
|
1320 |
['shift+s', make_bulk('spam')], |
|
1321 |
['shift+d', make_bulk('delete')], |
|
1322 |
['shift+t', make_bulk('trash')], |
|
1323 |
['shift+z', make_bulk('untrash')], |
|
1324 |
['shift+u', make_bulk('unapprove')] |
|
1325 |
], |
|
1326 |
{ |
|
16 | 1327 |
highlight_first: adminCommentsSettings.hotkeys_highlight_first, |
1328 |
highlight_last: adminCommentsSettings.hotkeys_highlight_last, |
|
5 | 1329 |
prev_page_link_cb: make_hotkeys_redirect('prev'), |
1330 |
next_page_link_cb: make_hotkeys_redirect('next'), |
|
1331 |
hotkeys_opts: { |
|
1332 |
disableInInput: true, |
|
1333 |
type: 'keypress', |
|
1334 |
noDisable: '.check-column input[type="checkbox"]' |
|
1335 |
}, |
|
1336 |
cycle_expr: '#the-comment-list tr', |
|
1337 |
start_row_index: 0 |
|
1338 |
} |
|
0 | 1339 |
); |
1340 |
} |
|
5 | 1341 |
|
1342 |
// Quick Edit and Reply have an inline comment editor. |
|
9 | 1343 |
$( '#the-comment-list' ).on( 'click', '.comment-inline', function() { |
5 | 1344 |
var $el = $( this ), |
1345 |
action = 'replyto'; |
|
1346 |
||
1347 |
if ( 'undefined' !== typeof $el.data( 'action' ) ) { |
|
1348 |
action = $el.data( 'action' ); |
|
1349 |
} |
|
1350 |
||
9 | 1351 |
$( this ).attr( 'aria-expanded', 'true' ); |
5 | 1352 |
commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action ); |
1353 |
} ); |
|
0 | 1354 |
}); |
1355 |
||
1356 |
})(jQuery); |