~katiekitty/+junk/wordpress-byet

« back to all changes in this revision

Viewing changes to wp-admin/js/edit-comments.dev.js

  • Committer: kserver
  • Date: 2010-05-15 01:16:36 UTC
  • Revision ID: kserver@kserver-desktop-20100515011636-mnr1j7t637suptdq
Wordpress 2.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
setCommentsList = function() {
5
5
        var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
6
6
 
7
 
        totalInput = $('#comments-form .tablenav :input[name="_total"]');
8
 
        perPageInput = $('#comments-form .tablenav :input[name="_per_page"]');
9
 
        pageInput = $('#comments-form .tablenav :input[name="_page"]');
 
7
        totalInput = $('.tablenav input[name="_total"]', '#comments-form');
 
8
        perPageInput = $('.tablenav input[name="_per_page"]', '#comments-form');
 
9
        pageInput = $('.tablenav input[name="_page"]', '#comments-form');
10
10
 
11
11
        dimAfter = function( r, settings ) {
12
12
                var c = $('#' + settings.element);
17
17
                        c.find('div.comment_status').html('1')
18
18
 
19
19
                $('span.pending-count').each( function() {
20
 
                        var a = $(this), n;
21
 
                        n = a.html().replace(/[ ,.]+/g, '');
 
20
                        var a = $(this), n, dif;
 
21
                        n = a.html().replace(/[^0-9]+/g, '');
22
22
                        n = parseInt(n,10);
23
23
                        if ( isNaN(n) ) return;
24
 
                        n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 );
 
24
                        dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
 
25
                        n = n + dif;
25
26
                        if ( n < 0 ) { n = 0; }
26
 
                        a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
27
 
                        n = n.toString();
28
 
                        if ( n.length > 3 )
29
 
                                n = n.substr(0, n.length-3)+' '+n.substr(-3);
30
 
                        a.html(n);
 
27
                        a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
 
28
                        updateCount(a, n);
 
29
                        dashboardTotals();
31
30
                });
32
31
        };
33
32
 
34
33
        // Send current total, page, per_page and url
35
 
        delBefore = function( settings ) {
36
 
                settings.data._total = totalInput.val();
37
 
                settings.data._per_page = perPageInput.val();
38
 
                settings.data._page = pageInput.val();
 
34
        delBefore = function( settings, list ) {
 
35
                var cl = $(settings.target).attr('className'), id, el, n, h, a, author, action = false;
 
36
 
 
37
                settings.data._total = totalInput.val() || 0;
 
38
                settings.data._per_page = perPageInput.val() || 0;
 
39
                settings.data._page = pageInput.val() || 0;
39
40
                settings.data._url = document.location.href;
40
41
 
41
 
                if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && !settings.data.spam )
42
 
                        return showNotice.warn() ? settings : false;
 
42
                if ( cl.indexOf(':trash=1') != -1 )
 
43
                        action = 'trash';
 
44
                else if ( cl.indexOf(':spam=1') != -1 )
 
45
                        action = 'spam';
 
46
 
 
47
                if ( action ) {
 
48
                        id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
 
49
                        el = $('#comment-' + id);
 
50
                        note = $('#' + action + '-undo-holder').html();
 
51
 
 
52
                        if ( el.siblings('#replyrow').length && commentReply.cid == id )
 
53
                                commentReply.close();
 
54
 
 
55
                        if ( el.is('tr') ) {
 
56
                                n = el.children(':visible').length;
 
57
                                author = $('.author strong', el).text();
 
58
                                h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
 
59
                        } else {
 
60
                                author = $('.comment-author', el).text();
 
61
                                h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
 
62
                        }
 
63
 
 
64
                        el.before(h);
 
65
 
 
66
                        $('strong', '#undo-' + id).text(author + ' ');
 
67
                        a = $('.undo a', '#undo-' + id);
 
68
                        a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
 
69
                        a.attr('className', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
 
70
                        $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
 
71
 
 
72
                        a.click(function(){
 
73
                                list.wpList.del(this);
 
74
                                $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
 
75
                                        $(this).remove();
 
76
                                        $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
 
77
                                });
 
78
                                return false;
 
79
                        });
 
80
                }
43
81
 
44
82
                return settings;
45
83
        };
46
84
 
47
 
        /* Updates the current total (as displayed visibly)
48
 
        */
 
85
        // Updates the current total (as displayed visibly)
49
86
        updateTotalCount = function( total, time, setConfidentTime ) {
50
 
                if ( time < lastConfidentTime ) {
 
87
                if ( time < lastConfidentTime )
51
88
                        return;
52
 
                }
 
89
 
 
90
                if ( setConfidentTime )
 
91
                        lastConfidentTime = time;
 
92
 
53
93
                totalInput.val( total.toString() );
54
 
                if ( setConfidentTime ) {
55
 
                        lastConfidentTime = time;
56
 
                }
57
94
                $('span.total-type-count').each( function() {
58
 
                        var a = $(this), n;
59
 
                        n = totalInput.val().toString();
60
 
                        if ( n.length > 3 )
61
 
                                n = n.substr(0, n.length-3)+' '+n.substr(-3);
62
 
                        a.html(n);
 
95
                        updateCount( $(this), total );
63
96
                });
64
 
 
65
97
        };
66
98
 
 
99
        function dashboardTotals(n) {
 
100
                var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
 
101
 
 
102
                n = n || 0;
 
103
                if ( isNaN(n) || !dash.length )
 
104
                        return;
 
105
 
 
106
                total = $('span.total-count', dash);
 
107
                appr = $('span.approved-count', dash);
 
108
                totalN = getCount(total);
 
109
 
 
110
                totalN = totalN + n;
 
111
                apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
 
112
                updateCount(total, totalN);
 
113
                updateCount(appr, apprN);
 
114
 
 
115
        }
 
116
 
 
117
        function getCount(el) {
 
118
                var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
 
119
                if ( isNaN(n) )
 
120
                        return 0;
 
121
                return n;
 
122
        }
 
123
 
 
124
        function updateCount(el, n) {
 
125
                var n1 = '';
 
126
                if ( isNaN(n) )
 
127
                        return;
 
128
                n = n < 1 ? '0' : n.toString();
 
129
                if ( n.length > 3 ) {
 
130
                        while ( n.length > 3 ) {
 
131
                                n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
 
132
                                n = n.substr(0, n.length - 3);
 
133
                        }
 
134
                        n = n + n1;
 
135
                }
 
136
                el.html(n);
 
137
        }
 
138
 
67
139
        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
68
140
        delAfter = function( r, settings ) {
 
141
                var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
 
142
 
 
143
                function getUpdate(s) {
 
144
                        if ( $(settings.target).parent().is('span.' + s) )
 
145
                                return 1;
 
146
                        else if ( $('#' + settings.element).is('.' + s) )
 
147
                                return -1;
 
148
 
 
149
                        return 0;
 
150
                }
 
151
                spam = getUpdate('spam');
 
152
                trash = getUpdate('trash');
 
153
 
 
154
                if ( untrash )
 
155
                        trash = -1;
 
156
                if ( unspam )
 
157
                        spam = -1;
 
158
 
69
159
                $('span.pending-count').each( function() {
70
 
                        var a = $(this), n;
71
 
                        n = a.html().replace(/[ ,.]+/g, '');
72
 
                        n = parseInt(n,10);
73
 
                        if ( isNaN(n) ) return;
74
 
                        if ( $('#' + settings.element).is('.unapproved') ) { // we deleted a formerly unapproved comment
 
160
                        var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
 
161
 
 
162
                        if ( $(settings.target).parent().is('span.unapprove') || ( ( untrash || unspam ) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
 
163
                                n = n + 1;
 
164
                        } else if ( unapproved ) { // we deleted a formerly unapproved comment
75
165
                                n = n - 1;
76
 
                        } else if ( $(settings.target).parents( 'span.unapprove' ).size() ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
77
 
                                n = n + 1;
78
166
                        }
79
167
                        if ( n < 0 ) { n = 0; }
80
 
                        a.parents('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
81
 
                        n = n.toString();
82
 
                        if ( n.length > 3 )
83
 
                                n = n.substr(0, n.length-3)+' '+n.substr(-3);
84
 
                        a.html(n);
 
168
                        a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
 
169
                        updateCount(a, n);
 
170
                        dashboardTotals();
85
171
                });
86
172
 
87
173
                $('span.spam-count').each( function() {
88
 
                        var a = $(this), n;
89
 
                        n = a.html().replace(/[ ,.]+/g, '');
90
 
                        n = parseInt(n,10);
91
 
                        if ( isNaN(n) ) return;
92
 
                        if ( $(settings.target).parents( 'span.spam' ).size() ) { // we marked a comment as spam
93
 
                                n = n + 1;
94
 
                        } else if ( $('#' + settings.element).is('.spam') ) { // we approved or deleted a comment marked as spam
95
 
                                n = n - 1;
96
 
                        }
97
 
                        if ( n < 0 ) { n = 0; }
98
 
                        n = n.toString();
99
 
                        if ( n.length > 3 )
100
 
                                n = n.substr(0, n.length-3)+' '+n.substr(-3);
101
 
                        a.html(n);
102
 
                });
103
 
 
104
 
 
105
 
                // XML response
106
 
                if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
107
 
                        // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links)
108
 
                        updateTotalCount( settings.parsed.responses[0].supplemental.total, settings.parsed.responses[0].supplemental.time, true );
109
 
                        if ( $.trim( settings.parsed.responses[0].supplemental.pageLinks ) ) {
110
 
                                $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( settings.parsed.responses[0].supplemental.pageLinks ) );
111
 
                        } else if ( 'undefined' != typeof settings.parsed.responses[0].supplemental.pageLinks ) {
112
 
                                $('.tablenav-pages').find( '.page-numbers' ).remove();
113
 
                        }
 
174
                        var a = $(this), n = getCount(a) + spam;
 
175
                        updateCount(a, n);
 
176
                });
 
177
 
 
178
                $('span.trash-count').each( function() {
 
179
                        var a = $(this), n = getCount(a) + trash;
 
180
                        updateCount(a, n);
 
181
                });
 
182
 
 
183
                if ( $('#dashboard_right_now').length ) {
 
184
                        N = trash ? -1 * trash : 0;
 
185
                        dashboardTotals(N);
114
186
                } else {
115
 
                        // Decrement the total
116
 
                        var total = parseInt( totalInput.val(), 10 );
117
 
                        if ( total-- < 0 )
 
187
                        total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
 
188
                        total = total - spam - trash;
 
189
                        if ( total < 0 )
118
190
                                total = 0;
119
 
                        updateTotalCount( total, r, false );
 
191
 
 
192
                        if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
 
193
                                pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
 
194
                                if ( $.trim( pageLinks ) )
 
195
                                        $('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
 
196
                                else
 
197
                                        $('.tablenav-pages').find( '.page-numbers' ).remove();
 
198
 
 
199
                                updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
 
200
                        } else {
 
201
                                updateTotalCount( total, r, false );
 
202
                        }
120
203
                }
121
204
 
122
 
                if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) {
 
205
                if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash ) {
123
206
                        return;
124
207
                }
125
208
 
128
211
        };
129
212
 
130
213
        theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
131
 
        theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } );
 
214
        theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
 
215
                .bind('wpListDelEnd', function(e, s){
 
216
                        var id = s.element.replace(/[^0-9]+/g, '');
132
217
 
 
218
                        if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
 
219
                                $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
 
220
                });
133
221
};
134
222
 
135
223
commentReply = {
 
224
        cid : '',
 
225
        act : '',
136
226
 
137
227
        init : function() {
138
228
                var row = $('#replyrow');
187
277
        },
188
278
 
189
279
        close : function() {
190
 
                $(this.o).fadeIn('fast').css('backgroundColor', '');
191
 
                $('#com-reply').append( $('#replyrow') );
192
 
                $('#replycontent').val('');
193
 
                $('#edithead input').val('');
194
 
                $('#replysubmit .error').html('').hide();
195
 
                $('#replysubmit .waiting').hide();
196
 
                if ( $.browser.msie )
197
 
                        $('#replycontainer, #replycontent').css('height', '120px');
198
 
                else
199
 
                        $('#replycontainer').resizable('destroy').css('height', '120px');
 
280
                var c;
 
281
 
 
282
                if ( this.cid ) {
 
283
                        c = $('#comment-' + this.cid);
 
284
 
 
285
                        if ( this.act == 'edit-comment' )
 
286
                                c.fadeIn(300, function(){ c.show() }).css('backgroundColor', '');
 
287
 
 
288
                        $('#replyrow').hide();
 
289
                        $('#com-reply').append( $('#replyrow') );
 
290
                        $('#replycontent').val('');
 
291
                        $('input', '#edithead').val('');
 
292
                        $('.error', '#replysubmit').html('').hide();
 
293
                        $('.waiting', '#replysubmit').hide();
 
294
 
 
295
                        if ( $.browser.msie )
 
296
                                $('#replycontainer, #replycontent').css('height', '120px');
 
297
                        else
 
298
                                $('#replycontainer').resizable('destroy').css('height', '120px');
 
299
 
 
300
                        this.cid = '';
 
301
                }
200
302
        },
201
303
 
202
304
        open : function(id, p, a) {
203
 
                var t = this, editRow, act, h;
 
305
                var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
204
306
                t.close();
205
 
                t.o = '#comment-'+id;
 
307
                t.cid = id;
206
308
 
207
 
                $('#replyrow td').attr('colspan', $('.widefat thead th:visible').length);
208
 
                editRow = $('#replyrow'), rowData = $('#inline-'+id);
 
309
                $('td', '#replyrow').attr('colspan', $('table.widefat thead th:visible').length);
 
310
                editRow = $('#replyrow');
 
311
                rowData = $('#inline-'+id);
209
312
                act = t.act = (a == 'edit') ? 'edit-comment' : 'replyto-comment';
210
313
 
211
314
                $('#action', editRow).val(act);
221
324
                        $('#edithead, #savebtn', editRow).show();
222
325
                        $('#replyhead, #replybtn', editRow).hide();
223
326
 
224
 
                        h = $(t.o).height();
 
327
                        h = c.height();
225
328
                        if ( h > 220 )
226
329
                                if ( $.browser.msie )
227
330
                                        $('#replycontainer, #replycontent', editRow).height(h-105);
228
331
                                else
229
332
                                        $('#replycontainer', editRow).height(h-105);
230
333
 
231
 
                        $(t.o).after(editRow.hide()).fadeOut('fast', function(){
232
 
                                $('#replyrow').fadeIn('fast');
 
334
                        c.after( editRow ).fadeOut('fast', function(){
 
335
                                $('#replyrow').fadeIn(300, function(){ $(this).show() });
233
336
                        });
234
337
                } else {
235
338
                        $('#edithead, #savebtn', editRow).hide();
236
339
                        $('#replyhead, #replybtn', editRow).show();
237
 
                        $(t.o).after(editRow);
238
 
                        $('#replyrow').hide().fadeIn('fast');
 
340
                        c.after(editRow);
 
341
                        $('#replyrow').fadeIn(300, function(){ $(this).show() });
239
342
                }
240
343
 
241
344
                if ( ! $.browser.msie )
263
366
                                window.scroll(0, rtop - 35);
264
367
 
265
368
                        $('#replycontent').focus().keyup(function(e){
266
 
                                if (e.which == 27) commentReply.revert(); // close on Escape
 
369
                                if ( e.which == 27 )
 
370
                                        commentReply.revert(); // close on Escape
267
371
                        });
268
372
                }, 600);
269
373
 
285
389
 
286
390
                $.ajax({
287
391
                        type : 'POST',
288
 
                        url : wpListL10n.url,
 
392
                        url : ajaxurl,
289
393
                        data : post,
290
394
                        success : function(x) { commentReply.show(x); },
291
395
                        error : function(r) { commentReply.error(r); }
308
412
                        return false;
309
413
                }
310
414
 
311
 
                if ( 'edit-comment' == this.act )
312
 
                        $(this.o).remove();
313
 
 
314
415
                r = r.responses[0];
315
416
                c = r.data;
 
417
                id = '#comment-' + r.id;
 
418
                if ( 'edit-comment' == this.act )
 
419
                        $(id).remove();
316
420
 
317
421
                $(c).hide()
318
422
                $('#replyrow').after(c);
319
423
 
320
 
                this.o = id = '#comment-'+r.id;
321
424
                this.revert();
322
425
                this.addEvents($(id));
323
426
                bg = $(id).hasClass('unapproved') ? '#ffffe0' : '#fff';
364
467
                                        window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
365
468
                        }
366
469
                };
 
470
 
367
471
                edit_comment = function(event, current_row) {
368
472
                        window.location = $('span.edit a', current_row).attr('href');
369
473
                };
 
474
 
370
475
                toggle_all = function() {
371
476
                        toggleWithKeyboard = true;
372
 
                        $('#comments-form thead #cb input:checkbox').click().attr('checked', '');
 
477
                        $('input:checkbox', '#cb').click().attr('checked', '');
373
478
                        toggleWithKeyboard = false;
374
 
                }
 
479
                };
 
480
 
375
481
                make_bulk = function(value) {
376
 
                        return function(event, _) {
377
 
                                $('option[value='+value+']').attr('selected', 'selected');
378
 
                                $('form#comments-form')[0].submit();
 
482
                        return function() {
 
483
                                var scope = $('select[name="action"]');
 
484
                                $('option[value='+value+']', scope).attr('selected', 'selected');
 
485
                                $('#comments-form').submit();
379
486
                        }
380
487
                };
381
 
                $.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment],
382
 
                                ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
383
 
                                ['shift+d', make_bulk('delete')], ['shift+x', toggle_all],
384
 
                                ['shift+u', make_bulk('unapprove')]],
385
 
                                {highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
386
 
                                prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next')}
 
488
 
 
489
                $.table_hotkeys(
 
490
                        $('table.widefat'),
 
491
                        ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
 
492
                        ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
 
493
                        ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
 
494
                        ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
 
495
                        { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
 
496
                        prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }
387
497
                );
388
498
        }
389
499
});