diff -r 346c88efed21 -r 5e2f62d02dcd wp/wp-admin/js/edit-comments.js --- a/wp/wp-admin/js/edit-comments.js Mon Jun 08 16:11:51 2015 +0000 +++ b/wp/wp-admin/js/edit-comments.js Tue Jun 09 03:35:32 2015 +0200 @@ -1,17 +1,20 @@ -var theList, theExtraList, toggleWithKeyboard = false; +/* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */ +var setCommentsList, theList, theExtraList, commentReply; (function($) { -var getCount, updateCount, updatePending, dashboardTotals; +var getCount, updateCount, updatePending; setCommentsList = function() { - var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList; + var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff, + lastConfidentTime = 0; totalInput = $('input[name="_total"]', '#comments-form'); perPageInput = $('input[name="_per_page"]', '#comments-form'); pageInput = $('input[name="_page"]', '#comments-form'); dimAfter = function( r, settings ) { - var c = $('#' + settings.element), editRow, replyID, replyButton; + var editRow, replyID, replyButton, + c = $( '#' + settings.element ); editRow = $('#replyrow'); replyID = $('#comment_ID', editRow).val(); @@ -29,13 +32,15 @@ c.find('div.comment_status').html('1'); } - var diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; + diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1; updatePending( diff ); }; // Send current total, page, per_page and url delBefore = function( settings, list ) { - var wpListsData = $(settings.target).attr('data-wp-lists'), id, el, n, h, a, author, action = false; + var note, id, el, n, h, a, author, + action = false, + wpListsData = $( settings.target ).attr( 'data-wp-lists' ); settings.data._total = totalInput.val() || 0; settings.data._per_page = perPageInput.val() || 0; @@ -74,13 +79,13 @@ a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce); a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1'); a.attr('class', 'vim-z vim-destructive'); - $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); + $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); a.click(function(){ list.wpList.del(this); $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){ $(this).remove(); - $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() }); + $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); }); }); return false; }); @@ -100,23 +105,6 @@ totalInput.val( total.toString() ); }; - dashboardTotals = function(n) { - var dash = $('#dashboard_right_now'), total, appr, totalN, apprN; - - n = n || 0; - if ( isNaN(n) || !dash.length ) - return; - - total = $('span.total-count', dash); - appr = $('span.approved-count', dash); - totalN = getCount(total); - - totalN = totalN + n; - apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) ); - updateCount(total, totalN); - updateCount(appr, apprN); - }; - getCount = function(el) { var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 ); if ( isNaN(n) ) @@ -144,16 +132,14 @@ var a = $(this), n = getCount(a) + diff; if ( n < 1 ) n = 0; - a.closest('.awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0'); + a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0'); updateCount( a, n ); }); - - dashboardTotals(); }; // In admin-ajax.php, we send back the unix time stamp instead of 1 on success delAfter = function( r, settings ) { - var total, N, spam, trash, pending, + var total_items_i18n, total, spam, trash, pending, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), unapproved = $('#' + settings.element).is('.unapproved'); @@ -199,10 +185,7 @@ updateCount(a, n); }); - if ( $('#dashboard_right_now').length ) { - N = trash ? -1 * trash : 0; - dashboardTotals(N); - } else { + if ( ! $('#dashboard_right_now').length ) { total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; if ( $(settings.target).parent().is('span.undo') ) total++; @@ -225,7 +208,7 @@ } } - if ( ! theExtraList || theExtraList.size() == 0 || theExtraList.children().size() == 0 || untrash || unspam ) { + if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 || untrash || unspam ) { return; } @@ -283,7 +266,7 @@ var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, ''); if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 ) - $('#undo-' + id).fadeIn(300, function(){ $(this).show() }); + $('#undo-' + id).fadeIn(300, function(){ $(this).show(); }); }); }; @@ -309,7 +292,7 @@ commentReply.toggle($(this).parent()); }); - $('#doaction, #doaction2, #post-query-submit').click(function(e){ + $('#doaction, #doaction2, #post-query-submit').click(function(){ if ( $('#the-comment-list #replyrow').length > 0 ) commentReply.close(); }); @@ -355,7 +338,7 @@ if ( this.cid && this.act == 'edit-comment' ) { c = $('#comment-' + this.cid); - c.fadeIn(300, function(){ c.show() }).css('backgroundColor', ''); + c.fadeIn(300, function(){ c.show(); }).css('backgroundColor', ''); } // reset the Quicktags buttons @@ -368,14 +351,17 @@ $('#com-reply').append( replyrow ); $('#replycontent').css('height', '').val(''); $('#edithead input').val(''); - $('.error', replyrow).html('').hide(); - $('.spinner', replyrow).hide(); + $('.error', replyrow).empty().hide(); + $( '.spinner', replyrow ).removeClass( 'is-active' ); this.cid = ''; }, open : function(comment_id, post_id, action) { - var t = this, editRow, rowData, act, c = $('#comment-' + comment_id), h = c.height(), replyButton; + var editRow, rowData, act, replyButton, editHeight, + t = this, + c = $('#comment-' + comment_id), + h = c.height(); t.close(); t.cid = comment_id; @@ -390,9 +376,6 @@ $('#comment_post_ID', editRow).val(post_id); $('#comment_ID', editRow).val(comment_id); - if ( h > 120 ) - $('#replycontent', editRow).css('height', (35+h) + 'px'); - if ( action == 'edit' ) { $('#author', editRow).val( $('div.author', rowData).text() ); $('#author-email', editRow).val( $('div.author-email', rowData).text() ); @@ -402,16 +385,23 @@ $('#edithead, #savebtn', editRow).show(); $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide(); + if ( h > 120 ) { + // Limit the maximum height when editing very long comments to make it more manageable. + // The textarea is resizable in most browsers, so the user can adjust it if needed. + editHeight = h > 500 ? 500 : h; + $('#replycontent', editRow).css('height', editHeight + 'px'); + } + c.after( editRow ).fadeOut('fast', function(){ - $('#replyrow').fadeIn(300, function(){ $(this).show() }); + $('#replyrow').fadeIn(300, function(){ $(this).show(); }); }); } else if ( action == 'add' ) { $('#addhead, #addbtn', editRow).show(); $('#replyhead, #replybtn, #edithead, #editbtn', editRow).hide(); $('#the-comment-list').prepend(editRow); $('#replyrow').fadeIn(300); - } else { - replyButton = $('#replybtn', editRow); + } else { + replyButton = $('#replybtn', editRow); $('#edithead, #savebtn, #addhead, #addbtn', editRow).hide(); $('#replyhead, #replybtn', editRow).show(); c.after(editRow); @@ -422,7 +412,7 @@ replyButton.text(adminCommentsL10n.reply); } - $('#replyrow').fadeIn(300, function(){ $(this).show() }); + $('#replyrow').fadeIn(300, function(){ $(this).show(); }); } setTimeout(function() { @@ -431,7 +421,7 @@ rtop = $('#replyrow').offset().top; rbottom = rtop + $('#replyrow').height(); scrollTop = window.pageYOffset || document.documentElement.scrollTop; - vp = document.documentElement.clientHeight || self.innerHeight || 0; + vp = document.documentElement.clientHeight || window.innerHeight || 0; scrollBottom = scrollTop + vp; if ( scrollBottom - 20 < rbottom ) @@ -452,7 +442,7 @@ var post = {}; $('#replysubmit .error').hide(); - $('#replysubmit .spinner').show(); + $( '#replysubmit .spinner' ).addClass( 'is-active' ); $('#replyrow input').not(':button').each(function() { var t = $(this); @@ -513,7 +503,7 @@ } c = $.trim(r.data); // Trim leading whitespaces - $(c).hide() + $(c).hide(); $('#replyrow').after(c); id = $(id); @@ -535,7 +525,7 @@ error : function(r) { var er = r.statusText; - $('#replysubmit .spinner').hide(); + $( '#replysubmit .spinner' ).removeClass( 'is-active' ); if ( r.responseText ) er = r.responseText.replace( /<.[^<>]*?>/g, '' ); @@ -572,7 +562,7 @@ l = $('.tablenav-pages .'+which+'-page:not(.disabled)'); if (l.length) window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; - } + }; }; edit_comment = function(event, current_row) { @@ -580,9 +570,7 @@ }; toggle_all = function() { - toggleWithKeyboard = true; - $('input:checkbox', '#cb').click().prop('checked', false); - toggleWithKeyboard = false; + $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' ); }; make_bulk = function(value) { @@ -590,19 +578,50 @@ var scope = $('select[name="action"]'); $('option[value="' + value + '"]', scope).prop('selected', true); $('#doaction').click(); - } + }; }; $.table_hotkeys( $('table.widefat'), - ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], - ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')], - ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')], - ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]], - { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, - prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') } + [ + 'a', 'u', 's', 'd', 'r', 'q', 'z', + ['e', edit_comment], + ['shift+x', toggle_all], + ['shift+a', make_bulk('approve')], + ['shift+s', make_bulk('spam')], + ['shift+d', make_bulk('delete')], + ['shift+t', make_bulk('trash')], + ['shift+z', make_bulk('untrash')], + ['shift+u', make_bulk('unapprove')] + ], + { + highlight_first: adminCommentsL10n.hotkeys_highlight_first, + highlight_last: adminCommentsL10n.hotkeys_highlight_last, + prev_page_link_cb: make_hotkeys_redirect('prev'), + next_page_link_cb: make_hotkeys_redirect('next'), + hotkeys_opts: { + disableInInput: true, + type: 'keypress', + noDisable: '.check-column input[type="checkbox"]' + }, + cycle_expr: '#the-comment-list tr', + start_row_index: 0 + } ); } + + // Quick Edit and Reply have an inline comment editor. + $( '#the-comment-list' ).on( 'click', '.comment-inline', function (e) { + e.preventDefault(); + var $el = $( this ), + action = 'replyto'; + + if ( 'undefined' !== typeof $el.data( 'action' ) ) { + action = $el.data( 'action' ); + } + + commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action ); + } ); }); })(jQuery);