author | Anthony Ly <anthonyly.com@gmail.com> |
Wed, 12 Dec 2012 18:57:40 -0800 | |
changeset 199 | 9ff3c84d7b27 |
parent 194 | 32102edaa81b |
permissions | -rw-r--r-- |
136 | 1 |
var theList, theExtraList, toggleWithKeyboard = false; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2 |
|
136 | 3 |
(function($) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
4 |
var getCount, updateCount, updatePending, dashboardTotals; |
136 | 5 |
|
6 |
setCommentsList = function() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
7 |
var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList; |
136 | 8 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
9 |
totalInput = $('input[name="_total"]', '#comments-form'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
10 |
perPageInput = $('input[name="_per_page"]', '#comments-form'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
11 |
pageInput = $('input[name="_page"]', '#comments-form'); |
136 | 12 |
|
13 |
dimAfter = function( r, settings ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
14 |
var c = $('#' + settings.element), editRow, replyID, replyButton; |
136 | 15 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
16 |
editRow = $('#replyrow'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
17 |
replyID = $('#comment_ID', editRow).val(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
18 |
replyButton = $('#replybtn', editRow); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
19 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
20 |
if ( c.is('.unapproved') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
21 |
if ( settings.data.id == replyID ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
22 |
replyButton.text(adminCommentsL10n.replyApprove); |
136 | 23 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
c.find('div.comment_status').html('0'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
25 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
if ( settings.data.id == replyID ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
27 |
replyButton.text(adminCommentsL10n.reply); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
28 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
29 |
c.find('div.comment_status').html('1'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
30 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
31 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
32 |
var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
33 |
updatePending( diff ); |
136 | 34 |
}; |
35 |
||
36 |
// Send current total, page, per_page and url |
|
37 |
delBefore = function( settings, list ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
38 |
var cl = $(settings.target).attr('class'), id, el, n, h, a, author, action = false; |
136 | 39 |
|
40 |
settings.data._total = totalInput.val() || 0; |
|
41 |
settings.data._per_page = perPageInput.val() || 0; |
|
42 |
settings.data._page = pageInput.val() || 0; |
|
43 |
settings.data._url = document.location.href; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
44 |
settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val(); |
136 | 45 |
|
46 |
if ( cl.indexOf(':trash=1') != -1 ) |
|
47 |
action = 'trash'; |
|
48 |
else if ( cl.indexOf(':spam=1') != -1 ) |
|
49 |
action = 'spam'; |
|
50 |
||
51 |
if ( action ) { |
|
52 |
id = cl.replace(/.*?comment-([0-9]+).*/, '$1'); |
|
53 |
el = $('#comment-' + id); |
|
54 |
note = $('#' + action + '-undo-holder').html(); |
|
55 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
56 |
el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
57 |
|
136 | 58 |
if ( el.siblings('#replyrow').length && commentReply.cid == id ) |
59 |
commentReply.close(); |
|
60 |
||
61 |
if ( el.is('tr') ) { |
|
62 |
n = el.children(':visible').length; |
|
63 |
author = $('.author strong', el).text(); |
|
64 |
h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>'); |
|
65 |
} else { |
|
66 |
author = $('.comment-author', el).text(); |
|
67 |
h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>'); |
|
68 |
} |
|
69 |
||
70 |
el.before(h); |
|
71 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
72 |
$('strong', '#undo-' + id).text(author); |
136 | 73 |
a = $('.undo a', '#undo-' + id); |
74 |
a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
75 |
a.attr('class', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive'); |
136 | 76 |
$('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); |
77 |
||
78 |
a.click(function(){ |
|
79 |
list.wpList.del(this); |
|
80 |
$('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ |
|
81 |
$(this).remove(); |
|
82 |
$('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() }); |
|
83 |
}); |
|
84 |
return false; |
|
85 |
}); |
|
86 |
} |
|
87 |
||
88 |
return settings; |
|
89 |
}; |
|
90 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
91 |
// Updates the current total (stored in the _total input) |
136 | 92 |
updateTotalCount = function( total, time, setConfidentTime ) { |
93 |
if ( time < lastConfidentTime ) |
|
94 |
return; |
|
95 |
||
96 |
if ( setConfidentTime ) |
|
97 |
lastConfidentTime = time; |
|
98 |
||
99 |
totalInput.val( total.toString() ); |
|
100 |
}; |
|
101 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
102 |
dashboardTotals = function(n) { |
136 | 103 |
var dash = $('#dashboard_right_now'), total, appr, totalN, apprN; |
104 |
||
105 |
n = n || 0; |
|
106 |
if ( isNaN(n) || !dash.length ) |
|
107 |
return; |
|
108 |
||
109 |
total = $('span.total-count', dash); |
|
110 |
appr = $('span.approved-count', dash); |
|
111 |
totalN = getCount(total); |
|
112 |
||
113 |
totalN = totalN + n; |
|
114 |
apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) ); |
|
115 |
updateCount(total, totalN); |
|
116 |
updateCount(appr, apprN); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
}; |
136 | 118 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
119 |
getCount = function(el) { |
136 | 120 |
var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); |
121 |
if ( isNaN(n) ) |
|
122 |
return 0; |
|
123 |
return n; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
124 |
}; |
136 | 125 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
126 |
updateCount = function(el, n) { |
136 | 127 |
var n1 = ''; |
128 |
if ( isNaN(n) ) |
|
129 |
return; |
|
130 |
n = n < 1 ? '0' : n.toString(); |
|
131 |
if ( n.length > 3 ) { |
|
132 |
while ( n.length > 3 ) { |
|
133 |
n1 = thousandsSeparator + n.substr(n.length - 3) + n1; |
|
134 |
n = n.substr(0, n.length - 3); |
|
135 |
} |
|
136 |
n = n + n1; |
|
137 |
} |
|
138 |
el.html(n); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
139 |
}; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
140 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
141 |
updatePending = function( diff ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
142 |
$('span.pending-count').each(function() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
143 |
var a = $(this), n = getCount(a) + diff; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
144 |
if ( n < 1 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
145 |
n = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
146 |
a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
147 |
updateCount( a, n ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
148 |
}); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
149 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
150 |
dashboardTotals(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
151 |
}; |
136 | 152 |
|
153 |
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success |
|
154 |
delAfter = function( r, settings ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
var total, N, spam, trash, pending, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
untrash = $(settings.target).parent().is('span.untrash'), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
157 |
unspam = $(settings.target).parent().is('span.unspam'), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
158 |
unapproved = $('#' + settings.element).is('.unapproved'); |
136 | 159 |
|
160 |
function getUpdate(s) { |
|
161 |
if ( $(settings.target).parent().is('span.' + s) ) |
|
162 |
return 1; |
|
163 |
else if ( $('#' + settings.element).is('.' + s) ) |
|
164 |
return -1; |
|
165 |
||
166 |
return 0; |
|
167 |
} |
|
168 |
||
169 |
if ( untrash ) |
|
170 |
trash = -1; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
171 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
172 |
trash = getUpdate('trash'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
173 |
|
136 | 174 |
if ( unspam ) |
175 |
spam = -1; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
176 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
177 |
spam = getUpdate('spam'); |
136 | 178 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
179 |
if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
180 |
// a comment was 'deleted' from another list (e.g. approved, spam, trash) and moved to pending, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
181 |
// or a trash/spam of a pending comment was undone |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
182 |
pending = 1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
183 |
} else if ( unapproved ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
184 |
// a pending comment was trashed/spammed/approved |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
185 |
pending = -1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
186 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
187 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
188 |
if ( pending ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
189 |
updatePending(pending); |
136 | 190 |
|
191 |
$('span.spam-count').each( function() { |
|
192 |
var a = $(this), n = getCount(a) + spam; |
|
193 |
updateCount(a, n); |
|
194 |
}); |
|
195 |
||
196 |
$('span.trash-count').each( function() { |
|
197 |
var a = $(this), n = getCount(a) + trash; |
|
198 |
updateCount(a, n); |
|
199 |
}); |
|
200 |
||
201 |
if ( $('#dashboard_right_now').length ) { |
|
202 |
N = trash ? -1 * trash : 0; |
|
203 |
dashboardTotals(N); |
|
204 |
} else { |
|
205 |
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
206 |
if ( $(settings.target).parent().is('span.undo') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
total++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
208 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
209 |
total--; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
210 |
|
136 | 211 |
if ( total < 0 ) |
212 |
total = 0; |
|
213 |
||
214 |
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
215 |
total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
216 |
if ( total_items_i18n ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
217 |
$('.displaying-num').text( total_items_i18n ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
$('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
$('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val()); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
} |
136 | 221 |
updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true ); |
222 |
} else { |
|
223 |
updateTotalCount( total, r, false ); |
|
224 |
} |
|
225 |
} |
|
226 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
227 |
if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) { |
136 | 228 |
return; |
229 |
} |
|
230 |
||
231 |
theList.get(0).wpList.add( theExtraList.children(':eq(0)').remove().clone() ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
232 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
233 |
refillTheExtraList(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
234 |
}; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
235 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
236 |
refillTheExtraList = function(ev) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
237 |
var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
238 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
239 |
if (! args.paged) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
240 |
args.paged = 1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
241 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
242 |
if (args.paged > total_pages) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
243 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
244 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
245 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
if (ev) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
247 |
theExtraList.empty(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
248 |
args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
249 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
250 |
args.number = 1; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
251 |
args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
252 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
253 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
254 |
args.no_placeholder = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
255 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
256 |
args.paged ++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
257 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
258 |
// $.query.get() needs some correction to be sent into an ajax request |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
259 |
if ( true === args.comment_type ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
260 |
args.comment_type = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
261 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
262 |
args = $.extend(args, { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
263 |
'action': 'fetch-list', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
'list_args': list_args, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
265 |
'_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
266 |
}); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
267 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
268 |
$.ajax({ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
url: ajaxurl, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
270 |
global: false, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
271 |
dataType: 'json', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
272 |
data: args, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
273 |
success: function(response) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
274 |
theExtraList.get(0).wpList.add( response.rows ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
275 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
276 |
}); |
136 | 277 |
}; |
278 |
||
279 |
theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } ); |
|
280 |
theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } ) |
|
281 |
.bind('wpListDelEnd', function(e, s){ |
|
282 |
var id = s.element.replace(/[^0-9]+/g, ''); |
|
283 |
||
284 |
if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 ) |
|
285 |
$('#undo-' + id).fadeIn(300, function(){ $(this).show() }); |
|
286 |
}); |
|
287 |
}; |
|
288 |
||
289 |
commentReply = { |
|
290 |
cid : '', |
|
291 |
act : '', |
|
292 |
||
293 |
init : function() { |
|
294 |
var row = $('#replyrow'); |
|
295 |
||
296 |
$('a.cancel', row).click(function() { return commentReply.revert(); }); |
|
297 |
$('a.save', row).click(function() { return commentReply.send(); }); |
|
298 |
$('input#author, input#author-email, input#author-url', row).keypress(function(e){ |
|
299 |
if ( e.which == 13 ) { |
|
300 |
commentReply.send(); |
|
301 |
e.preventDefault(); |
|
302 |
return false; |
|
303 |
} |
|
304 |
}); |
|
305 |
||
306 |
// add events |
|
307 |
$('#the-comment-list .column-comment > p').dblclick(function(){ |
|
308 |
commentReply.toggle($(this).parent()); |
|
309 |
}); |
|
310 |
||
311 |
$('#doaction, #doaction2, #post-query-submit').click(function(e){ |
|
312 |
if ( $('#the-comment-list #replyrow').length > 0 ) |
|
313 |
commentReply.close(); |
|
314 |
}); |
|
315 |
||
316 |
this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; |
|
317 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
318 |
/* $(listTable).bind('beforeChangePage', function(){ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
319 |
commentReply.close(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
320 |
}); */ |
136 | 321 |
}, |
322 |
||
323 |
addEvents : function(r) { |
|
324 |
r.each(function() { |
|
325 |
$(this).find('.column-comment > p').dblclick(function(){ |
|
326 |
commentReply.toggle($(this).parent()); |
|
327 |
}); |
|
328 |
}); |
|
329 |
}, |
|
330 |
||
331 |
toggle : function(el) { |
|
332 |
if ( $(el).css('display') != 'none' ) |
|
333 |
$(el).find('a.vim-q').click(); |
|
334 |
}, |
|
335 |
||
336 |
revert : function() { |
|
337 |
||
338 |
if ( $('#the-comment-list #replyrow').length < 1 ) |
|
339 |
return false; |
|
340 |
||
341 |
$('#replyrow').fadeOut('fast', function(){ |
|
342 |
commentReply.close(); |
|
343 |
}); |
|
344 |
||
345 |
return false; |
|
346 |
}, |
|
347 |
||
348 |
close : function() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
349 |
var c, replyrow = $('#replyrow'); |
136 | 350 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
351 |
// replyrow is not showing? |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
352 |
if ( replyrow.parent().is('#com-reply') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
353 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
354 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
355 |
if ( this.cid && this.act == 'edit-comment' ) { |
136 | 356 |
c = $('#comment-' + this.cid); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
357 |
c.fadeIn(300, function(){ c.show() }).css('backgroundColor', ''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
358 |
} |
136 | 359 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
360 |
// reset the Quicktags buttons |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
361 |
if ( typeof QTags != 'undefined' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
362 |
QTags.closeAllTags('replycontent'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
363 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
364 |
$('#add-new-comment').css('display', ''); |
136 | 365 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
366 |
replyrow.hide(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
367 |
$('#com-reply').append( replyrow ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
368 |
$('#replycontent').css('height', '').val(''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
369 |
$('#edithead input').val(''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
370 |
$('.error', replyrow).html('').hide(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
371 |
$('.waiting', replyrow).hide(); |
136 | 372 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
373 |
this.cid = ''; |
136 | 374 |
}, |
375 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
376 |
open : function(comment_id, post_id, action) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
377 |
var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
378 |
|
136 | 379 |
t.close(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
380 |
t.cid = comment_id; |
136 | 381 |
|
382 |
editRow = $('#replyrow'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
383 |
rowData = $('#inline-'+comment_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
384 |
action = action || 'replyto'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
385 |
act = 'edit' == action ? 'edit' : 'replyto'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
386 |
act = t.act = act + '-comment'; |
136 | 387 |
|
388 |
$('#action', editRow).val(act); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
389 |
$('#comment_post_ID', editRow).val(post_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
390 |
$('#comment_ID', editRow).val(comment_id); |
136 | 391 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
392 |
if ( h > 120 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
393 |
$('#replycontent', editRow).css('height', (35+h) + 'px'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
394 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
395 |
if ( action == 'edit' ) { |
136 | 396 |
$('#author', editRow).val( $('div.author', rowData).text() ); |
397 |
$('#author-email', editRow).val( $('div.author-email', rowData).text() ); |
|
398 |
$('#author-url', editRow).val( $('div.author-url', rowData).text() ); |
|
399 |
$('#status', editRow).val( $('div.comment_status', rowData).text() ); |
|
400 |
$('#replycontent', editRow).val( $('textarea.comment', rowData).val() ); |
|
401 |
$('#edithead, #savebtn', editRow).show(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
402 |
$('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide(); |
136 | 403 |
|
404 |
c.after( editRow ).fadeOut('fast', function(){ |
|
405 |
$('#replyrow').fadeIn(300, function(){ $(this).show() }); |
|
406 |
}); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
407 |
} else if ( action == 'add' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
408 |
$('#addhead, #addbtn', editRow).show(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
409 |
$('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
410 |
$('#the-comment-list').prepend(editRow); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
411 |
$('#replyrow').fadeIn(300); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
412 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
413 |
replyButton = $('#replybtn', editRow); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
414 |
$('#edithead, #savebtn, #addhead, #addbtn', editRow).hide(); |
136 | 415 |
$('#replyhead, #replybtn', editRow).show(); |
416 |
c.after(editRow); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
417 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
418 |
if ( c.hasClass('unapproved') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
419 |
replyButton.text(adminCommentsL10n.replyApprove); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
420 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
421 |
replyButton.text(adminCommentsL10n.reply); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
422 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
423 |
|
136 | 424 |
$('#replyrow').fadeIn(300, function(){ $(this).show() }); |
425 |
} |
|
426 |
||
427 |
setTimeout(function() { |
|
428 |
var rtop, rbottom, scrollTop, vp, scrollBottom; |
|
429 |
||
430 |
rtop = $('#replyrow').offset().top; |
|
431 |
rbottom = rtop + $('#replyrow').height(); |
|
432 |
scrollTop = window.pageYOffset || document.documentElement.scrollTop; |
|
433 |
vp = document.documentElement.clientHeight || self.innerHeight || 0; |
|
434 |
scrollBottom = scrollTop + vp; |
|
435 |
||
436 |
if ( scrollBottom - 20 < rbottom ) |
|
437 |
window.scroll(0, rbottom - vp + 35); |
|
438 |
else if ( rtop - 20 < scrollTop ) |
|
439 |
window.scroll(0, rtop - 35); |
|
440 |
||
441 |
$('#replycontent').focus().keyup(function(e){ |
|
442 |
if ( e.which == 27 ) |
|
443 |
commentReply.revert(); // close on Escape |
|
444 |
}); |
|
445 |
}, 600); |
|
446 |
||
447 |
return false; |
|
448 |
}, |
|
449 |
||
450 |
send : function() { |
|
451 |
var post = {}; |
|
452 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
453 |
$('#replysubmit .error').hide(); |
136 | 454 |
$('#replysubmit .waiting').show(); |
455 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
456 |
$('#replyrow input').not(':button').each(function() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
457 |
var t = $(this); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
458 |
post[ t.attr('name') ] = t.val(); |
136 | 459 |
}); |
460 |
||
461 |
post.content = $('#replycontent').val(); |
|
462 |
post.id = post.comment_post_ID; |
|
463 |
post.comments_listing = this.comments_listing; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
464 |
post.p = $('[name="p"]').val(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
465 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
466 |
if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
467 |
post.approve_parent = 1; |
136 | 468 |
|
469 |
$.ajax({ |
|
470 |
type : 'POST', |
|
471 |
url : ajaxurl, |
|
472 |
data : post, |
|
473 |
success : function(x) { commentReply.show(x); }, |
|
474 |
error : function(r) { commentReply.error(r); } |
|
475 |
}); |
|
476 |
||
477 |
return false; |
|
478 |
}, |
|
479 |
||
480 |
show : function(xml) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
481 |
var t = this, r, c, id, bg, pid; |
136 | 482 |
|
483 |
if ( typeof(xml) == 'string' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
484 |
t.error({'responseText': xml}); |
136 | 485 |
return false; |
486 |
} |
|
487 |
||
488 |
r = wpAjax.parseAjaxResponse(xml); |
|
489 |
if ( r.errors ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
490 |
t.error({'responseText': wpAjax.broken}); |
136 | 491 |
return false; |
492 |
} |
|
493 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
494 |
t.revert(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
495 |
|
136 | 496 |
r = r.responses[0]; |
497 |
c = r.data; |
|
498 |
id = '#comment-' + r.id; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
499 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
500 |
if ( 'edit-comment' == t.act ) |
136 | 501 |
$(id).remove(); |
502 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
503 |
if ( r.supplemental.parent_approved ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
504 |
pid = $('#comment-' + r.supplemental.parent_approved); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
505 |
updatePending( -1 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
506 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
507 |
if ( this.comments_listing == 'moderated' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
508 |
pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
509 |
pid.fadeOut(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
510 |
}); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
511 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
512 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
513 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
514 |
|
136 | 515 |
$(c).hide() |
516 |
$('#replyrow').after(c); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
517 |
id = $(id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
518 |
t.addEvents(id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
519 |
bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor'); |
136 | 520 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
521 |
id.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
522 |
.animate( { 'backgroundColor': bg }, 300, function() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
523 |
if ( pid && pid.length ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
524 |
pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
525 |
.animate( { 'backgroundColor': bg }, 300 ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
526 |
.removeClass('unapproved').addClass('approved') |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
527 |
.find('div.comment_status').html('1'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
528 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
529 |
}); |
136 | 530 |
|
531 |
}, |
|
532 |
||
533 |
error : function(r) { |
|
534 |
var er = r.statusText; |
|
535 |
||
536 |
$('#replysubmit .waiting').hide(); |
|
537 |
||
538 |
if ( r.responseText ) |
|
539 |
er = r.responseText.replace( /<.[^<>]*?>/g, '' ); |
|
540 |
||
541 |
if ( er ) |
|
542 |
$('#replysubmit .error').html(er).show(); |
|
543 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
544 |
}, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
545 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
546 |
addcomment: function(post_id) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
547 |
var t = this; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
548 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
549 |
$('#add-new-comment').fadeOut(200, function(){ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
550 |
t.open(0, post_id, 'add'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
551 |
$('table.comments-box').css('display', ''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
552 |
$('#no-comments').remove(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
553 |
}); |
136 | 554 |
} |
555 |
}; |
|
556 |
||
557 |
$(document).ready(function(){ |
|
558 |
var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk; |
|
559 |
||
560 |
setCommentsList(); |
|
561 |
commentReply.init(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
562 |
$(document).delegate('span.delete a.delete', 'click', function(){return false;}); |
136 | 563 |
|
564 |
if ( typeof $.table_hotkeys != 'undefined' ) { |
|
565 |
make_hotkeys_redirect = function(which) { |
|
566 |
return function() { |
|
567 |
var first_last, l; |
|
568 |
||
569 |
first_last = 'next' == which? 'first' : 'last'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
570 |
l = $('.tablenav-pages .'+which+'-page:not(.disabled)'); |
136 | 571 |
if (l.length) |
572 |
window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; |
|
573 |
} |
|
574 |
}; |
|
575 |
||
576 |
edit_comment = function(event, current_row) { |
|
577 |
window.location = $('span.edit a', current_row).attr('href'); |
|
578 |
}; |
|
579 |
||
580 |
toggle_all = function() { |
|
581 |
toggleWithKeyboard = true; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
582 |
$('input:checkbox', '#cb').click().prop('checked', false); |
136 | 583 |
toggleWithKeyboard = false; |
584 |
}; |
|
585 |
||
586 |
make_bulk = function(value) { |
|
587 |
return function() { |
|
588 |
var scope = $('select[name="action"]'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
589 |
$('option[value="' + value + '"]', scope).prop('selected', true); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
590 |
$('#doaction').click(); |
136 | 591 |
} |
592 |
}; |
|
593 |
||
594 |
$.table_hotkeys( |
|
595 |
$('table.widefat'), |
|
596 |
['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
597 |
['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')], |
136 | 598 |
['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')], |
599 |
['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]], |
|
600 |
{ highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, |
|
601 |
prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') } |
|
602 |
); |
|
603 |
} |
|
604 |
}); |
|
605 |
||
606 |
})(jQuery); |