Make WordPress Core

Ticket #41545: 41545.diff

File 41545.diff, 59.2 KB (added by Lindstromer, 6 years ago)

Added support for Ctrl/Cmd+Enter to submit replies in wp-admin and frontend. + code style for the specified js-files.

  • src/wp-admin/js/edit-comments.js

    diff --git a/src/wp-admin/js/edit-comments.js b/src/wp-admin/js/edit-comments.js
    index 9e0fc09602..d09699073f 100644
    a b  
    11/* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
    22var setCommentsList, theList, theExtraList, commentReply;
    33
    4 (function($) {
    5 var getCount, updateCount, updateCountText, updatePending, updateApproved,
    6         updateHtmlTitle, updateDashboardText, adminTitle = document.title,
    7         isDashboard = $('#dashboard_right_now').length,
    8         titleDiv, titleRegEx;
    9 
    10         getCount = function(el) {
    11                 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
    12                 if ( isNaN(n) ) {
     4(function ($) {
     5        var getCount, updateCount, updateCountText, updatePending, updateApproved,
     6                updateHtmlTitle, updateDashboardText, adminTitle = document.title,
     7                isDashboard = $('#dashboard_right_now').length,
     8                titleDiv, titleRegEx;
     9
     10        getCount = function (el) {
     11                var n = parseInt(el.html().replace(/[^0-9]+/g, ''), 10);
     12                if (isNaN(n)) {
    1313                        return 0;
    1414                }
    1515                return n;
    1616        };
    1717
    18         updateCount = function(el, n) {
     18        updateCount = function (el, n) {
    1919                var n1 = '';
    20                 if ( isNaN(n) ) {
     20                if (isNaN(n)) {
    2121                        return;
    2222                }
    2323                n = n < 1 ? '0' : n.toString();
    24                 if ( n.length > 3 ) {
    25                         while ( n.length > 3 ) {
     24                if (n.length > 3) {
     25                        while (n.length > 3) {
    2626                                n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
    2727                                n = n.substr(0, n.length - 3);
    2828                        }
    var getCount, updateCount, updateCountText, updatePending, updateApproved, 
    3131                el.html(n);
    3232        };
    3333
    34         updateApproved = function( diff, commentPostId ) {
     34        updateApproved = function (diff, commentPostId) {
    3535                var postSelector = '.post-com-count-' + commentPostId,
    3636                        noClass = 'comment-count-no-comments',
    3737                        approvedClass = 'comment-count-approved',
    3838                        approved,
    3939                        noComments;
    4040
    41                 updateCountText( 'span.approved-count', diff );
     41                updateCountText('span.approved-count', diff);
    4242
    43                 if ( ! commentPostId ) {
     43                if (!commentPostId) {
    4444                        return;
    4545                }
    4646
    4747                // cache selectors to not get dupes
    48                 approved = $( 'span.' + approvedClass, postSelector );
    49                 noComments = $( 'span.' + noClass, postSelector );
     48                approved = $('span.' + approvedClass, postSelector);
     49                noComments = $('span.' + noClass, postSelector);
    5050
    51                 approved.each(function() {
     51                approved.each(function () {
    5252                        var a = $(this), n = getCount(a) + diff;
    53                         if ( n < 1 )
     53                        if (n < 1)
    5454                                n = 0;
    5555
    56                         if ( 0 === n ) {
    57                                 a.removeClass( approvedClass ).addClass( noClass );
     56                        if (0 === n) {
     57                                a.removeClass(approvedClass).addClass(noClass);
    5858                        } else {
    59                                 a.addClass( approvedClass ).removeClass( noClass );
     59                                a.addClass(approvedClass).removeClass(noClass);
    6060                        }
    61                         updateCount( a, n );
     61                        updateCount(a, n);
    6262                });
    6363
    64                 noComments.each(function() {
     64                noComments.each(function () {
    6565                        var a = $(this);
    66                         if ( diff > 0 ) {
    67                                 a.removeClass( noClass ).addClass( approvedClass );
     66                        if (diff > 0) {
     67                                a.removeClass(noClass).addClass(approvedClass);
    6868                        } else {
    69                                 a.addClass( noClass ).removeClass( approvedClass );
     69                                a.addClass(noClass).removeClass(approvedClass);
    7070                        }
    71                         updateCount( a, diff );
     71                        updateCount(a, diff);
    7272                });
    7373        };
    7474
    75         updateCountText = function( selector, diff ) {
    76                 $( selector ).each(function() {
     75        updateCountText = function (selector, diff) {
     76                $(selector).each(function () {
    7777                        var a = $(this), n = getCount(a) + diff;
    78                         if ( n < 1 ) {
     78                        if (n < 1) {
    7979                                n = 0;
    8080                        }
    81                         updateCount( a, n );
     81                        updateCount(a, n);
    8282                });
    8383        };
    8484
    85         updateDashboardText = function ( response ) {
    86                 if ( ! isDashboard || ! response || ! response.i18n_comments_text ) {
     85        updateDashboardText = function (response) {
     86                if (!isDashboard || !response || !response.i18n_comments_text) {
    8787                        return;
    8888                }
    8989
    90                 var rightNow = $( '#dashboard_right_now' );
     90                var rightNow = $('#dashboard_right_now');
    9191
    92                 $( '.comment-count a', rightNow ).text( response.i18n_comments_text );
    93                 $( '.comment-mod-count a', rightNow ).text( response.i18n_moderation_text )
     92                $('.comment-count a', rightNow).text(response.i18n_comments_text);
     93                $('.comment-mod-count a', rightNow).text(response.i18n_moderation_text)
    9494                        .parent()
    95                         [ response.in_moderation > 0 ? 'removeClass' : 'addClass' ]( 'hidden' );
     95                        [response.in_moderation > 0 ? 'removeClass' : 'addClass']('hidden');
    9696        };
    9797
    98         updateHtmlTitle = function ( diff ) {
     98        updateHtmlTitle = function (diff) {
    9999                var newTitle, regExMatch, titleCount, commentFrag;
    100100
    101                 titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
     101                titleRegEx = titleRegEx || new RegExp(adminCommentsL10n.docTitleCommentsCount.replace('%s', '\\([0-9' + thousandsSeparator + ']+\\)') + '?');
    102102                // count funcs operate on a $'d element
    103                 titleDiv = titleDiv || $( '<div />' );
     103                titleDiv = titleDiv || $('<div />');
    104104                newTitle = adminTitle;
    105105
    106                 commentFrag = titleRegEx.exec( document.title );
    107                 if ( commentFrag ) {
     106                commentFrag = titleRegEx.exec(document.title);
     107                if (commentFrag) {
    108108                        commentFrag = commentFrag[0];
    109                         titleDiv.html( commentFrag );
    110                         titleCount = getCount( titleDiv ) + diff;
     109                        titleDiv.html(commentFrag);
     110                        titleCount = getCount(titleDiv) + diff;
    111111                } else {
    112                         titleDiv.html( 0 );
     112                        titleDiv.html(0);
    113113                        titleCount = diff;
    114114                }
    115115
    116                 if ( titleCount >= 1 ) {
    117                         updateCount( titleDiv, titleCount );
    118                         regExMatch = titleRegEx.exec( document.title );
    119                         if ( regExMatch ) {
    120                                 newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
     116                if (titleCount >= 1) {
     117                        updateCount(titleDiv, titleCount);
     118                        regExMatch = titleRegEx.exec(document.title);
     119                        if (regExMatch) {
     120                                newTitle = document.title.replace(regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace('%s', titleDiv.text()) + ' ');
    121121                        }
    122122                } else {
    123                         regExMatch = titleRegEx.exec( newTitle );
    124                         if ( regExMatch ) {
    125                                 newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
     123                        regExMatch = titleRegEx.exec(newTitle);
     124                        if (regExMatch) {
     125                                newTitle = newTitle.replace(regExMatch[0], adminCommentsL10n.docTitleComments);
    126126                        }
    127127                }
    128128                document.title = newTitle;
    129129        };
    130130
    131         updatePending = function( diff, commentPostId ) {
     131        updatePending = function (diff, commentPostId) {
    132132                var postSelector = '.post-com-count-' + commentPostId,
    133133                        noClass = 'comment-count-no-pending',
    134134                        noParentClass = 'post-com-count-no-pending',
    var getCount, updateCount, updateCountText, updatePending, updateApproved, 
    136136                        pending,
    137137                        noPending;
    138138
    139                 if ( ! isDashboard ) {
    140                         updateHtmlTitle( diff );
     139                if (!isDashboard) {
     140                        updateHtmlTitle(diff);
    141141                }
    142142
    143                 $( 'span.pending-count' ).each(function() {
     143                $('span.pending-count').each(function () {
    144144                        var a = $(this), n = getCount(a) + diff;
    145                         if ( n < 1 )
     145                        if (n < 1)
    146146                                n = 0;
    147                         a.closest('.awaiting-mod')[ 0 === n ? 'addClass' : 'removeClass' ]('count-0');
    148                         updateCount( a, n );
     147                        a.closest('.awaiting-mod')[0 === n ? 'addClass' : 'removeClass']('count-0');
     148                        updateCount(a, n);
    149149                });
    150150
    151                 if ( ! commentPostId ) {
     151                if (!commentPostId) {
    152152                        return;
    153153                }
    154154
    155155                // cache selectors to not get dupes
    156                 pending = $( 'span.' + pendingClass, postSelector );
    157                 noPending = $( 'span.' + noClass, postSelector );
     156                pending = $('span.' + pendingClass, postSelector);
     157                noPending = $('span.' + noClass, postSelector);
    158158
    159                 pending.each(function() {
     159                pending.each(function () {
    160160                        var a = $(this), n = getCount(a) + diff;
    161                         if ( n < 1 )
     161                        if (n < 1)
    162162                                n = 0;
    163163
    164                         if ( 0 === n ) {
    165                                 a.parent().addClass( noParentClass );
    166                                 a.removeClass( pendingClass ).addClass( noClass );
     164                        if (0 === n) {
     165                                a.parent().addClass(noParentClass);
     166                                a.removeClass(pendingClass).addClass(noClass);
    167167                        } else {
    168                                 a.parent().removeClass( noParentClass );
    169                                 a.addClass( pendingClass ).removeClass( noClass );
     168                                a.parent().removeClass(noParentClass);
     169                                a.addClass(pendingClass).removeClass(noClass);
    170170                        }
    171                         updateCount( a, n );
     171                        updateCount(a, n);
    172172                });
    173173
    174                 noPending.each(function() {
     174                noPending.each(function () {
    175175                        var a = $(this);
    176                         if ( diff > 0 ) {
    177                                 a.parent().removeClass( noParentClass );
    178                                 a.removeClass( noClass ).addClass( pendingClass );
     176                        if (diff > 0) {
     177                                a.parent().removeClass(noParentClass);
     178                                a.removeClass(noClass).addClass(pendingClass);
    179179                        } else {
    180                                 a.parent().addClass( noParentClass );
    181                                 a.addClass( noClass ).removeClass( pendingClass );
     180                                a.parent().addClass(noParentClass);
     181                                a.addClass(noClass).removeClass(pendingClass);
    182182                        }
    183                         updateCount( a, diff );
     183                        updateCount(a, diff);
    184184                });
    185185        };
    186186
    187 setCommentsList = function() {
    188         var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList, diff,
    189                 lastConfidentTime = 0;
     187        setCommentsList = function () {
     188                var totalInput, perPageInput, pageInput, dimAfter, delBefore, updateTotalCount, delAfter, refillTheExtraList,
     189                        diff,
     190                        lastConfidentTime = 0;
    190191
    191         totalInput = $('input[name="_total"]', '#comments-form');
    192         perPageInput = $('input[name="_per_page"]', '#comments-form');
    193         pageInput = $('input[name="_page"]', '#comments-form');
     192                totalInput = $('input[name="_total"]', '#comments-form');
     193                perPageInput = $('input[name="_per_page"]', '#comments-form');
     194                pageInput = $('input[name="_page"]', '#comments-form');
    194195
    195         // Updates the current total (stored in the _total input)
    196         updateTotalCount = function( total, time, setConfidentTime ) {
    197                 if ( time < lastConfidentTime )
    198                         return;
    199 
    200                 if ( setConfidentTime )
    201                         lastConfidentTime = time;
    202 
    203                 totalInput.val( total.toString() );
    204         };
    205 
    206         // this fires when viewing "All"
    207         dimAfter = function( r, settings ) {
    208                 var editRow, replyID, replyButton, response,
    209                         c = $( '#' + settings.element );
    210 
    211                 if ( true !== settings.parsed ) {
    212                         response = settings.parsed.responses[0];
    213                 }
    214 
    215                 editRow = $('#replyrow');
    216                 replyID = $('#comment_ID', editRow).val();
    217                 replyButton = $('#replybtn', editRow);
     196                // Updates the current total (stored in the _total input)
     197                updateTotalCount = function (total, time, setConfidentTime) {
     198                        if (time < lastConfidentTime)
     199                                return;
    218200
    219                 if ( c.is('.unapproved') ) {
    220                         if ( settings.data.id == replyID )
    221                                 replyButton.text(adminCommentsL10n.replyApprove);
     201                        if (setConfidentTime)
     202                                lastConfidentTime = time;
    222203
    223                         c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
    224                                 .find( 'div.comment_status' ).html( '0' );
     204                        totalInput.val(total.toString());
     205                };
    225206
    226                 } else {
    227                         if ( settings.data.id == replyID )
    228                                 replyButton.text(adminCommentsL10n.reply);
     207                // this fires when viewing "All"
     208                dimAfter = function (r, settings) {
     209                        var editRow, replyID, replyButton, response,
     210                                c = $('#' + settings.element);
    229211
    230                         c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
    231                                 .find( 'div.comment_status' ).html( '1' );
    232                 }
     212                        if (true !== settings.parsed) {
     213                                response = settings.parsed.responses[0];
     214                        }
    233215
    234                 diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
    235                 if ( response ) {
    236                         updateDashboardText( response.supplemental );
    237                         updatePending( diff, response.supplemental.postId );
    238                         updateApproved( -1 * diff, response.supplemental.postId );
    239                 } else {
    240                         updatePending( diff );
    241                         updateApproved( -1 * diff  );
    242                 }
    243         };
     216                        editRow = $('#replyrow');
     217                        replyID = $('#comment_ID', editRow).val();
     218                        replyButton = $('#replybtn', editRow);
    244219
    245         // Send current total, page, per_page and url
    246         delBefore = function( settings, list ) {
    247                 var note, id, el, n, h, a, author,
    248                         action = false,
    249                         wpListsData = $( settings.target ).attr( 'data-wp-lists' );
     220                        if (c.is('.unapproved')) {
     221                                if (settings.data.id == replyID)
     222                                        replyButton.text(adminCommentsL10n.replyApprove);
    250223
    251                 settings.data._total = totalInput.val() || 0;
    252                 settings.data._per_page = perPageInput.val() || 0;
    253                 settings.data._page = pageInput.val() || 0;
    254                 settings.data._url = document.location.href;
    255                 settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
     224                                c.find('.row-actions span.view').addClass('hidden').end()
     225                                        .find('div.comment_status').html('0');
    256226
    257                 if ( wpListsData.indexOf(':trash=1') != -1 )
    258                         action = 'trash';
    259                 else if ( wpListsData.indexOf(':spam=1') != -1 )
    260                         action = 'spam';
     227                        } else {
     228                                if (settings.data.id == replyID)
     229                                        replyButton.text(adminCommentsL10n.reply);
    261230
    262                 if ( action ) {
    263                         id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1');
    264                         el = $('#comment-' + id);
    265                         note = $('#' + action + '-undo-holder').html();
     231                                c.find('.row-actions span.view').removeClass('hidden').end()
     232                                        .find('div.comment_status').html('1');
     233                        }
    266234
    267                         el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
     235                        diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
     236                        if (response) {
     237                                updateDashboardText(response.supplemental);
     238                                updatePending(diff, response.supplemental.postId);
     239                                updateApproved(-1 * diff, response.supplemental.postId);
     240                        } else {
     241                                updatePending(diff);
     242                                updateApproved(-1 * diff);
     243                        }
     244                };
    268245
    269                         if ( el.siblings('#replyrow').length && commentReply.cid == id )
    270                                 commentReply.close();
     246                // Send current total, page, per_page and url
     247                delBefore = function (settings, list) {
     248                        var note, id, el, n, h, a, author,
     249                                action = false,
     250                                wpListsData = $(settings.target).attr('data-wp-lists');
     251
     252                        settings.data._total = totalInput.val() || 0;
     253                        settings.data._per_page = perPageInput.val() || 0;
     254                        settings.data._page = pageInput.val() || 0;
     255                        settings.data._url = document.location.href;
     256                        settings.data.comment_status = $('input[name="comment_status"]', '#comments-form').val();
     257
     258                        if (wpListsData.indexOf(':trash=1') != -1)
     259                                action = 'trash';
     260                        else if (wpListsData.indexOf(':spam=1') != -1)
     261                                action = 'spam';
     262
     263                        if (action) {
     264                                id = wpListsData.replace(/.*?comment-([0-9]+).*/, '$1');
     265                                el = $('#comment-' + id);
     266                                note = $('#' + action + '-undo-holder').html();
     267
     268                                el.find('.check-column :checkbox').prop('checked', false); // Uncheck the row so as not to be affected by Bulk Edits.
     269
     270                                if (el.siblings('#replyrow').length && commentReply.cid == id)
     271                                        commentReply.close();
     272
     273                                if (el.is('tr')) {
     274                                        n = el.children(':visible').length;
     275                                        author = $('.author strong', el).text();
     276                                        h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
     277                                } else {
     278                                        author = $('.comment-author', el).text();
     279                                        h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
     280                                }
    271281
    272                         if ( el.is('tr') ) {
    273                                 n = el.children(':visible').length;
    274                                 author = $('.author strong', el).text();
    275                                 h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
    276                         } else {
    277                                 author = $('.comment-author', el).text();
    278                                 h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
    279                         }
    280 
    281                         el.before(h);
    282 
    283                         $('strong', '#undo-' + id).text(author);
    284                         a = $('.undo a', '#undo-' + id);
    285                         a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
    286                         a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
    287                         a.attr('class', 'vim-z vim-destructive');
    288                         $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    289 
    290                         a.click(function( e ){
    291                                 e.preventDefault();
    292                                 e.stopPropagation(); // ticket #35904
    293                                 list.wpList.del(this);
    294                                 $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
    295                                         $(this).remove();
    296                                         $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show(); });
     282                                el.before(h);
     283
     284                                $('strong', '#undo-' + id).text(author);
     285                                a = $('.undo a', '#undo-' + id);
     286                                a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
     287                                a.attr('data-wp-lists', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1');
     288                                a.attr('class', 'vim-z vim-destructive');
     289                                $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
     290
     291                                a.click(function (e) {
     292                                        e.preventDefault();
     293                                        e.stopPropagation(); // ticket #35904
     294                                        list.wpList.del(this);
     295                                        $('#undo-' + id).css({backgroundColor: '#ceb'}).fadeOut(350, function () {
     296                                                $(this).remove();
     297                                                $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function () {
     298                                                        $(this).show();
     299                                                });
     300                                        });
    297301                                });
    298                         });
    299                 }
    300 
    301                 return settings;
    302         };
     302                        }
    303303
    304         // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    305         delAfter = function( r, settings ) {
    306                 var total_items_i18n, total, animated, animatedCallback,
    307                         response = true === settings.parsed ? {} : settings.parsed.responses[0],
    308                         commentStatus = true === settings.parsed ? '' : response.supplemental.status,
    309                         commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
    310                         newTotal = true === settings.parsed ? '' : response.supplemental,
     304                        return settings;
     305                };
    311306
    312                         targetParent = $( settings.target ).parent(),
    313                         commentRow = $('#' + settings.element),
     307                // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
     308                delAfter = function (r, settings) {
     309                        var total_items_i18n, total, animated, animatedCallback,
     310                                response = true === settings.parsed ? {} : settings.parsed.responses[0],
     311                                commentStatus = true === settings.parsed ? '' : response.supplemental.status,
     312                                commentPostId = true === settings.parsed ? '' : response.supplemental.postId,
     313                                newTotal = true === settings.parsed ? '' : response.supplemental,
     314
     315                                targetParent = $(settings.target).parent(),
     316                                commentRow = $('#' + settings.element),
     317
     318                                spamDiff, trashDiff, pendingDiff, approvedDiff,
     319
     320                                approved = commentRow.hasClass('approved'),
     321                                unapproved = commentRow.hasClass('unapproved'),
     322                                spammed = commentRow.hasClass('spam'),
     323                                trashed = commentRow.hasClass('trash'),
     324                                undoing = false; // ticket #35904
     325
     326                        updateDashboardText(newTotal);
     327
     328                        // the order of these checks is important
     329                        // .unspam can also have .approve or .unapprove
     330                        // .untrash can also have .approve or .unapprove
     331
     332                        if (targetParent.is('span.undo')) {
     333                                // the comment was spammed
     334                                if (targetParent.hasClass('unspam')) {
     335                                        spamDiff = -1;
     336
     337                                        if ('trash' === commentStatus) {
     338                                                trashDiff = 1;
     339                                        } else if ('1' === commentStatus) {
     340                                                approvedDiff = 1;
     341                                        } else if ('0' === commentStatus) {
     342                                                pendingDiff = 1;
     343                                        }
    314344
    315                         spamDiff, trashDiff, pendingDiff, approvedDiff,
     345                                        // the comment was trashed
     346                                } else if (targetParent.hasClass('untrash')) {
     347                                        trashDiff = -1;
    316348
    317                         approved = commentRow.hasClass( 'approved' ),
    318                         unapproved = commentRow.hasClass( 'unapproved' ),
    319                         spammed = commentRow.hasClass( 'spam' ),
    320                         trashed = commentRow.hasClass( 'trash' ),
    321                         undoing = false; // ticket #35904
     349                                        if ('spam' === commentStatus) {
     350                                                spamDiff = 1;
     351                                        } else if ('1' === commentStatus) {
     352                                                approvedDiff = 1;
     353                                        } else if ('0' === commentStatus) {
     354                                                pendingDiff = 1;
     355                                        }
     356                                }
    322357
    323                 updateDashboardText( newTotal );
     358                                undoing = true;
     359
     360                                // user clicked "Spam"
     361                        } else if (targetParent.is('span.spam')) {
     362                                // the comment is currently approved
     363                                if (approved) {
     364                                        approvedDiff = -1;
     365                                        // the comment is currently pending
     366                                } else if (unapproved) {
     367                                        pendingDiff = -1;
     368                                        // the comment was in the trash
     369                                } else if (trashed) {
     370                                        trashDiff = -1;
     371                                }
     372                                // you can't spam an item on the spam screen
     373                                spamDiff = 1;
    324374
    325                 // the order of these checks is important
    326                 // .unspam can also have .approve or .unapprove
    327                 // .untrash can also have .approve or .unapprove
     375                                // user clicked "Unspam"
     376                        } else if (targetParent.is('span.unspam')) {
     377                                if (approved) {
     378                                        pendingDiff = 1;
     379                                } else if (unapproved) {
     380                                        approvedDiff = 1;
     381                                } else if (trashed) {
     382                                        // the comment was previously approved
     383                                        if (targetParent.hasClass('approve')) {
     384                                                approvedDiff = 1;
     385                                                // the comment was previously pending
     386                                        } else if (targetParent.hasClass('unapprove')) {
     387                                                pendingDiff = 1;
     388                                        }
     389                                } else if (spammed) {
     390                                        if (targetParent.hasClass('approve')) {
     391                                                approvedDiff = 1;
    328392
    329                 if ( targetParent.is( 'span.undo' ) ) {
    330                         // the comment was spammed
    331                         if ( targetParent.hasClass( 'unspam' ) ) {
     393                                        } else if (targetParent.hasClass('unapprove')) {
     394                                                pendingDiff = 1;
     395                                        }
     396                                }
     397                                // you can Unspam an item on the spam screen
    332398                                spamDiff = -1;
    333399
    334                                 if ( 'trash' === commentStatus ) {
    335                                         trashDiff = 1;
    336                                 } else if ( '1' === commentStatus ) {
    337                                         approvedDiff = 1;
    338                                 } else if ( '0' === commentStatus ) {
    339                                         pendingDiff = 1;
     400                                // user clicked "Trash"
     401                        } else if (targetParent.is('span.trash')) {
     402                                if (approved) {
     403                                        approvedDiff = -1;
     404                                } else if (unapproved) {
     405                                        pendingDiff = -1;
     406                                        // the comment was in the spam queue
     407                                } else if (spammed) {
     408                                        spamDiff = -1;
    340409                                }
     410                                // you can't trash an item on the trash screen
     411                                trashDiff = 1;
    341412
    342                         // the comment was trashed
    343                         } else if ( targetParent.hasClass( 'untrash' ) ) {
    344                                 trashDiff = -1;
    345 
    346                                 if ( 'spam' === commentStatus ) {
    347                                         spamDiff = 1;
    348                                 } else if ( '1' === commentStatus ) {
    349                                         approvedDiff = 1;
    350                                 } else if ( '0' === commentStatus ) {
     413                                // user clicked "Restore"
     414                        } else if (targetParent.is('span.untrash')) {
     415                                if (approved) {
    351416                                        pendingDiff = 1;
     417                                } else if (unapproved) {
     418                                        approvedDiff = 1;
     419                                } else if (trashed) {
     420                                        if (targetParent.hasClass('approve')) {
     421                                                approvedDiff = 1;
     422                                        } else if (targetParent.hasClass('unapprove')) {
     423                                                pendingDiff = 1;
     424                                        }
    352425                                }
    353                         }
    354 
    355                         undoing = true;
     426                                // you can't go from trash to spam
     427                                // you can untrash on the trash screen
     428                                trashDiff = -1;
    356429
    357                 // user clicked "Spam"
    358                 } else if ( targetParent.is( 'span.spam' ) ) {
    359                         // the comment is currently approved
    360                         if ( approved ) {
    361                                 approvedDiff = -1;
    362                         // the comment is currently pending
    363                         } else if ( unapproved ) {
     430                                // User clicked "Approve"
     431                        } else if (targetParent.is('span.approve:not(.unspam):not(.untrash)')) {
     432                                approvedDiff = 1;
    364433                                pendingDiff = -1;
    365                         // the comment was in the trash
    366                         } else if ( trashed ) {
    367                                 trashDiff = -1;
    368                         }
    369                         // you can't spam an item on the spam screen
    370                         spamDiff = 1;
    371434
    372                 // user clicked "Unspam"
    373                 } else if ( targetParent.is( 'span.unspam' ) ) {
    374                         if ( approved ) {
     435                                // User clicked "Unapprove"
     436                        } else if (targetParent.is('span.unapprove:not(.unspam):not(.untrash)')) {
     437                                approvedDiff = -1;
    375438                                pendingDiff = 1;
    376                         } else if ( unapproved ) {
    377                                 approvedDiff = 1;
    378                         } else if ( trashed ) {
    379                                 // the comment was previously approved
    380                                 if ( targetParent.hasClass( 'approve' ) ) {
    381                                         approvedDiff = 1;
    382                                 // the comment was previously pending
    383                                 } else if ( targetParent.hasClass( 'unapprove' ) ) {
    384                                         pendingDiff = 1;
    385                                 }
    386                         } else if ( spammed ) {
    387                                 if ( targetParent.hasClass( 'approve' ) ) {
    388                                         approvedDiff = 1;
    389439
    390                                 } else if ( targetParent.hasClass( 'unapprove' ) ) {
    391                                         pendingDiff = 1;
     440                                // User clicked "Delete Permanently"
     441                        } else if (targetParent.is('span.delete')) {
     442                                if (spammed) {
     443                                        spamDiff = -1;
     444                                } else if (trashed) {
     445                                        trashDiff = -1;
    392446                                }
    393447                        }
    394                         // you can Unspam an item on the spam screen
    395                         spamDiff = -1;
    396448
    397                 // user clicked "Trash"
    398                 } else if ( targetParent.is( 'span.trash' ) ) {
    399                         if ( approved ) {
    400                                 approvedDiff = -1;
    401                         } else if ( unapproved ) {
    402                                 pendingDiff = -1;
    403                         // the comment was in the spam queue
    404                         } else if ( spammed ) {
    405                                 spamDiff = -1;
     449                        if (pendingDiff) {
     450                                updatePending(pendingDiff, commentPostId);
     451                                updateCountText('span.all-count', pendingDiff);
    406452                        }
    407                         // you can't trash an item on the trash screen
    408                         trashDiff = 1;
    409453
    410                 // user clicked "Restore"
    411                 } else if ( targetParent.is( 'span.untrash' ) ) {
    412                         if ( approved ) {
    413                                 pendingDiff = 1;
    414                         } else if ( unapproved ) {
    415                                 approvedDiff = 1;
    416                         } else if ( trashed ) {
    417                                 if ( targetParent.hasClass( 'approve' ) ) {
    418                                         approvedDiff = 1;
    419                                 } else if ( targetParent.hasClass( 'unapprove' ) ) {
    420                                         pendingDiff = 1;
    421                                 }
     454                        if (approvedDiff) {
     455                                updateApproved(approvedDiff, commentPostId);
     456                                updateCountText('span.all-count', approvedDiff);
    422457                        }
    423                         // you can't go from trash to spam
    424                         // you can untrash on the trash screen
    425                         trashDiff = -1;
    426 
    427                 // User clicked "Approve"
    428                 } else if ( targetParent.is( 'span.approve:not(.unspam):not(.untrash)' ) ) {
    429                         approvedDiff = 1;
    430                         pendingDiff = -1;
    431 
    432                 // User clicked "Unapprove"
    433                 } else if ( targetParent.is( 'span.unapprove:not(.unspam):not(.untrash)' ) ) {
    434                         approvedDiff = -1;
    435                         pendingDiff = 1;
    436458
    437                 // User clicked "Delete Permanently"
    438                 } else if ( targetParent.is( 'span.delete' ) ) {
    439                         if ( spammed ) {
    440                                 spamDiff = -1;
    441                         } else if ( trashed ) {
    442                                 trashDiff = -1;
     459                        if (spamDiff) {
     460                                updateCountText('span.spam-count', spamDiff);
    443461                        }
    444                 }
    445 
    446                 if ( pendingDiff ) {
    447                         updatePending( pendingDiff, commentPostId );
    448                         updateCountText( 'span.all-count', pendingDiff );
    449                 }
    450 
    451                 if ( approvedDiff ) {
    452                         updateApproved( approvedDiff, commentPostId );
    453                         updateCountText( 'span.all-count', approvedDiff );
    454                 }
    455 
    456                 if ( spamDiff ) {
    457                         updateCountText( 'span.spam-count', spamDiff );
    458                 }
    459462
    460                 if ( trashDiff ) {
    461                         updateCountText( 'span.trash-count', trashDiff );
    462                 }
     463                        if (trashDiff) {
     464                                updateCountText('span.trash-count', trashDiff);
     465                        }
    463466
    464                 if (
    465                         ( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) ||
    466                         ( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) )
    467                 ) {
    468                         $( '#delete_all' ).hide();
    469                 }
     467                        if (
     468                                ( ( 'trash' === settings.data.comment_status ) && !getCount($('span.trash-count')) ) ||
     469                                ( ( 'spam' === settings.data.comment_status ) && !getCount($('span.spam-count')) )
     470                        ) {
     471                                $('#delete_all').hide();
     472                        }
    470473
    471                 if ( ! isDashboard ) {
    472                         total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
    473                         if ( $(settings.target).parent().is('span.undo') )
    474                                 total++;
    475                         else
    476                                 total--;
    477 
    478                         if ( total < 0 )
    479                                 total = 0;
    480 
    481                         if ( 'object' === typeof r ) {
    482                                 if ( response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time ) {
    483                                         total_items_i18n = response.supplemental.total_items_i18n || '';
    484                                         if ( total_items_i18n ) {
    485                                                 $('.displaying-num').text( total_items_i18n );
    486                                                 $('.total-pages').text( response.supplemental.total_pages_i18n );
    487                                                 $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
     474                        if (!isDashboard) {
     475                                total = totalInput.val() ? parseInt(totalInput.val(), 10) : 0;
     476                                if ($(settings.target).parent().is('span.undo'))
     477                                        total++;
     478                                else
     479                                        total--;
     480
     481                                if (total < 0)
     482                                        total = 0;
     483
     484                                if ('object' === typeof r) {
     485                                        if (response.supplemental.total_items_i18n && lastConfidentTime < response.supplemental.time) {
     486                                                total_items_i18n = response.supplemental.total_items_i18n || '';
     487                                                if (total_items_i18n) {
     488                                                        $('.displaying-num').text(total_items_i18n);
     489                                                        $('.total-pages').text(response.supplemental.total_pages_i18n);
     490                                                        $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', response.supplemental.total_pages == $('.current-page').val());
     491                                                }
     492                                                updateTotalCount(total, response.supplemental.time, true);
     493                                        } else if (response.supplemental.time) {
     494                                                updateTotalCount(total, response.supplemental.time, false);
    488495                                        }
    489                                         updateTotalCount( total, response.supplemental.time, true );
    490                                 } else if ( response.supplemental.time ) {
    491                                         updateTotalCount( total, response.supplemental.time, false );
     496                                } else {
     497                                        updateTotalCount(total, r, false);
    492498                                }
    493                         } else {
    494                                 updateTotalCount( total, r, false );
    495499                        }
    496                 }
    497500
    498                 if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
    499                         return;
    500                 }
     501                        if (!theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing) {
     502                                return;
     503                        }
    501504
    502                 theList.get(0).wpList.add( theExtraList.children( ':eq(0):not(.no-items)' ).remove().clone() );
     505                        theList.get(0).wpList.add(theExtraList.children(':eq(0):not(.no-items)').remove().clone());
    503506
    504                 refillTheExtraList();
     507                        refillTheExtraList();
     508
     509                        animated = $(':animated', '#the-comment-list');
     510                        animatedCallback = function () {
     511                                if (!$('#the-comment-list tr:visible').length) {
     512                                        theList.get(0).wpList.add(theExtraList.find('.no-items').clone());
     513                                }
     514                        };
    505515
    506                 animated = $( ':animated', '#the-comment-list' );
    507                 animatedCallback = function () {
    508                         if ( ! $( '#the-comment-list tr:visible' ).length ) {
    509                                 theList.get(0).wpList.add( theExtraList.find( '.no-items' ).clone() );
     516                        if (animated.length) {
     517                                animated.promise().done(animatedCallback);
     518                        } else {
     519                                animatedCallback();
    510520                        }
    511521                };
    512522
    513                 if ( animated.length ) {
    514                         animated.promise().done( animatedCallback );
    515                 } else {
    516                         animatedCallback();
    517                 }
    518         };
     523                refillTheExtraList = function (ev) {
     524                        var args = $.query.get(), total_pages = $('.total-pages').text(),
     525                                per_page = $('input[name="_per_page"]', '#comments-form').val();
    519526
    520         refillTheExtraList = function(ev) {
    521                 var args = $.query.get(), total_pages = $('.total-pages').text(), per_page = $('input[name="_per_page"]', '#comments-form').val();
     527                        if (!args.paged)
     528                                args.paged = 1;
    522529
    523                 if (! args.paged)
    524                         args.paged = 1;
     530                        if (args.paged > total_pages) {
     531                                return;
     532                        }
    525533
    526                 if (args.paged > total_pages) {
    527                         return;
    528                 }
     534                        if (ev) {
     535                                theExtraList.empty();
     536                                args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
     537                        } else {
     538                                args.number = 1;
     539                                args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
     540                        }
    529541
    530                 if (ev) {
    531                         theExtraList.empty();
    532                         args.number = Math.min(8, per_page); // see WP_Comments_List_Table::prepare_items() @ class-wp-comments-list-table.php
    533                 } else {
    534                         args.number = 1;
    535                         args.offset = Math.min(8, per_page) - 1; // fetch only the next item on the extra list
    536                 }
     542                        args.no_placeholder = true;
    537543
    538                 args.no_placeholder = true;
     544                        args.paged++;
    539545
    540                 args.paged ++;
     546                        // $.query.get() needs some correction to be sent into an ajax request
     547                        if (true === args.comment_type)
     548                                args.comment_type = '';
    541549
    542                 // $.query.get() needs some correction to be sent into an ajax request
    543                 if ( true === args.comment_type )
    544                         args.comment_type = '';
     550                        args = $.extend(args, {
     551                                'action': 'fetch-list',
     552                                'list_args': list_args,
     553                                '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
     554                        });
    545555
    546                 args = $.extend(args, {
    547                         'action': 'fetch-list',
    548                         'list_args': list_args,
    549                         '_ajax_fetch_list_nonce': $('#_ajax_fetch_list_nonce').val()
    550                 });
     556                        $.ajax({
     557                                url: ajaxurl,
     558                                global: false,
     559                                dataType: 'json',
     560                                data: args,
     561                                success: function (response) {
     562                                        theExtraList.get(0).wpList.add(response.rows);
     563                                }
     564                        });
     565                };
    551566
    552                 $.ajax({
    553                         url: ajaxurl,
    554                         global: false,
    555                         dataType: 'json',
    556                         data: args,
    557                         success: function(response) {
    558                                 theExtraList.get(0).wpList.add( response.rows );
    559                         }
    560                 });
     567                theExtraList = $('#the-extra-comment-list').wpList({alt: '', delColor: 'none', addColor: 'none'});
     568                theList = $('#the-comment-list').wpList({
     569                        alt: '',
     570                        delBefore: delBefore,
     571                        dimAfter: dimAfter,
     572                        delAfter: delAfter,
     573                        addColor: 'none'
     574                })
     575                        .bind('wpListDelEnd', function (e, s) {
     576                                var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, '');
     577
     578                                if (wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1)
     579                                        $('#undo-' + id).fadeIn(300, function () {
     580                                                $(this).show();
     581                                        });
     582                        });
    561583        };
    562584
    563         theExtraList = $('#the-extra-comment-list').wpList( { alt: '', delColor: 'none', addColor: 'none' } );
    564         theList = $('#the-comment-list').wpList( { alt: '', delBefore: delBefore, dimAfter: dimAfter, delAfter: delAfter, addColor: 'none' } )
    565                 .bind('wpListDelEnd', function(e, s){
    566                         var wpListsData = $(s.target).attr('data-wp-lists'), id = s.element.replace(/[^0-9]+/g, '');
     585        commentReply = {
     586                cid: '',
     587                act: '',
     588                originalContent: '',
    567589
    568                         if ( wpListsData.indexOf(':trash=1') != -1 || wpListsData.indexOf(':spam=1') != -1 )
    569                                 $('#undo-' + id).fadeIn(300, function(){ $(this).show(); });
    570                 });
    571 };
    572 
    573 commentReply = {
    574         cid : '',
    575         act : '',
    576         originalContent : '',
    577 
    578         init : function() {
    579                 var row = $('#replyrow');
    580 
    581                 $('a.cancel', row).click(function() { return commentReply.revert(); });
    582                 $('a.save', row).click(function() { return commentReply.send(); });
    583                 $( 'input#author-name, input#author-email, input#author-url', row ).keypress( function( e ) {
    584                         if ( e.which == 13 ) {
    585                                 commentReply.send();
    586                                 e.preventDefault();
    587                                 return false;
    588                         }
    589                 });
     590                init: function () {
     591                        var row, editRow;
     592                        row = $('#replyrow');
     593                        editRow = $('#replyrow');
    590594
    591                 // add events
    592                 $('#the-comment-list .column-comment > p').dblclick(function(){
    593                         commentReply.toggle($(this).parent());
    594                 });
    595 
    596                 $('#doaction, #doaction2, #post-query-submit').click(function(){
    597                         if ( $('#the-comment-list #replyrow').length > 0 )
    598                                 commentReply.close();
    599                 });
     595                        $('a.cancel', row).click(function () {
     596                                return commentReply.revert();
     597                        });
     598                        $('a.save', row).click(function () {
     599                                return commentReply.send();
     600                        });
    600601
    601                 this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
     602                        // Allow users to use Ctrl/Cmd+Enter to submit comment
     603                        $('#replycontent', editRow).keydown(function (e) {
     604                                if (( e.metaKey || e.ctrlKey ) && e.keyCode == 13) {
     605                                        commentReply.send();
     606                                        e.preventDefault();
     607                                        return false;
     608                                }
     609                        });
    602610
    603                 /* $(listTable).bind('beforeChangePage', function(){
    604                         commentReply.close();
    605                 }); */
    606         },
     611                        $('input#author-name, input#author-email, input#author-url', row).keypress(function (e) {
     612                                if (e.which == 13) {
     613                                        commentReply.send();
     614                                        e.preventDefault();
     615                                        return false;
     616                                }
     617                        });
    607618
    608         addEvents : function(r) {
    609                 r.each(function() {
    610                         $(this).find('.column-comment > p').dblclick(function(){
     619                        // add events
     620                        $('#the-comment-list .column-comment > p').dblclick(function () {
    611621                                commentReply.toggle($(this).parent());
    612622                        });
    613                 });
    614         },
    615623
    616         toggle : function(el) {
    617                 if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) {
    618                         $( el ).find( 'a.vim-q' ).click();
    619                 }
    620         },
     624                        $('#doaction, #doaction2, #post-query-submit').click(function () {
     625                                if ($('#the-comment-list #replyrow').length > 0)
     626                                        commentReply.close();
     627                        });
    621628
    622         revert : function() {
     629                        this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || '';
    623630
    624                 if ( $('#the-comment-list #replyrow').length < 1 )
    625                         return false;
     631                        /* $(listTable).bind('beforeChangePage', function(){
     632                                commentReply.close();
     633                        }); */
     634                },
    626635
    627                 $('#replyrow').fadeOut('fast', function(){
    628                         commentReply.close();
    629                 });
     636                addEvents: function (r) {
     637                        r.each(function () {
     638                                $(this).find('.column-comment > p').dblclick(function () {
     639                                        commentReply.toggle($(this).parent());
     640                                });
     641                        });
     642                },
    630643
    631                 return false;
    632         },
     644                toggle: function (el) {
     645                        if ('none' !== $(el).css('display') && ( $('#replyrow').parent().is('#com-reply') || window.confirm(adminCommentsL10n.warnQuickEdit) )) {
     646                                $(el).find('a.vim-q').click();
     647                        }
     648                },
    633649
    634         close : function() {
    635                 var c, replyrow = $('#replyrow');
     650                revert: function () {
    636651
    637                 // replyrow is not showing?
    638                 if ( replyrow.parent().is('#com-reply') )
    639                         return;
     652                        if ($('#the-comment-list #replyrow').length < 1)
     653                                return false;
    640654
    641                 if ( this.cid && this.act == 'edit-comment' ) {
    642                         c = $('#comment-' + this.cid);
    643                         c.fadeIn(300, function(){ c.show(); }).css('backgroundColor', '');
    644                 }
     655                        $('#replyrow').fadeOut('fast', function () {
     656                                commentReply.close();
     657                        });
    645658
    646                 // reset the Quicktags buttons
    647                 if ( typeof QTags != 'undefined' )
    648                         QTags.closeAllTags('replycontent');
     659                        return false;
     660                },
    649661
    650                 $('#add-new-comment').css('display', '');
     662                close: function () {
     663                        var c, replyrow = $('#replyrow');
    651664
    652                 replyrow.hide();
    653                 $('#com-reply').append( replyrow );
    654                 $('#replycontent').css('height', '').val('');
    655                 $('#edithead input').val('');
    656                 $('.error', replyrow).empty().hide();
    657                 $( '.spinner', replyrow ).removeClass( 'is-active' );
     665                        // replyrow is not showing?
     666                        if (replyrow.parent().is('#com-reply'))
     667                                return;
    658668
    659                 this.cid = '';
    660                 this.originalContent = '';
    661         },
     669                        if (this.cid && this.act == 'edit-comment') {
     670                                c = $('#comment-' + this.cid);
     671                                c.fadeIn(300, function () {
     672                                        c.show();
     673                                }).css('backgroundColor', '');
     674                        }
    662675
    663         open : function(comment_id, post_id, action) {
    664                 var editRow, rowData, act, replyButton, editHeight,
    665                         t = this,
    666                         c = $('#comment-' + comment_id),
    667                         h = c.height(),
    668                         colspanVal = 0;
     676                        // reset the Quicktags buttons
     677                        if (typeof QTags != 'undefined')
     678                                QTags.closeAllTags('replycontent');
    669679
    670                 if ( ! this.discardCommentChanges() ) {
    671                         return false;
    672                 }
     680                        $('#add-new-comment').css('display', '');
    673681
    674                 t.close();
    675                 t.cid = comment_id;
     682                        replyrow.hide();
     683                        $('#com-reply').append(replyrow);
     684                        $('#replycontent').css('height', '').val('');
     685                        $('#edithead input').val('');
     686                        $('.error', replyrow).empty().hide();
     687                        $('.spinner', replyrow).removeClass('is-active');
    676688
    677                 editRow = $('#replyrow');
    678                 rowData = $('#inline-'+comment_id);
    679                 action = action || 'replyto';
    680                 act = 'edit' == action ? 'edit' : 'replyto';
    681                 act = t.act = act + '-comment';
    682                 t.originalContent = $('textarea.comment', rowData).val();
    683                 colspanVal = $( '> th:visible, > td:visible', c ).length;
     689                        this.cid = '';
     690                        this.originalContent = '';
     691                },
    684692
    685                 // Make sure it's actually a table and there's a `colspan` value to apply.
    686                 if ( editRow.hasClass( 'inline-edit-row' ) && 0 !== colspanVal ) {
    687                         $( 'td', editRow ).attr( 'colspan', colspanVal );
    688                 }
     693                open: function (comment_id, post_id, action) {
     694                        var editRow, rowData, act, replyButton, editHeight,
     695                                t = this,
     696                                c = $('#comment-' + comment_id),
     697                                h = c.height(),
     698                                colspanVal = 0;
     699
     700                        if (!this.discardCommentChanges()) {
     701                                return false;
     702                        }
    689703
    690                 $('#action', editRow).val(act);
    691                 $('#comment_post_ID', editRow).val(post_id);
    692                 $('#comment_ID', editRow).val(comment_id);
     704                        t.close();
     705                        t.cid = comment_id;
    693706
    694                 if ( action == 'edit' ) {
    695                         $( '#author-name', editRow ).val( $( 'div.author', rowData ).text() );
    696                         $('#author-email', editRow).val( $('div.author-email', rowData).text() );
    697                         $('#author-url', editRow).val( $('div.author-url', rowData).text() );
    698                         $('#status', editRow).val( $('div.comment_status', rowData).text() );
    699                         $('#replycontent', editRow).val( $('textarea.comment', rowData).val() );
    700                         $( '#edithead, #editlegend, #savebtn', editRow ).show();
    701                         $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
     707                        editRow = $('#replyrow');
     708                        rowData = $('#inline-' + comment_id);
     709                        action = action || 'replyto';
     710                        act = 'edit' == action ? 'edit' : 'replyto';
     711                        act = t.act = act + '-comment';
     712                        t.originalContent = $('textarea.comment', rowData).val();
     713                        colspanVal = $('> th:visible, > td:visible', c).length;
    702714
    703                         if ( h > 120 ) {
    704                                 // Limit the maximum height when editing very long comments to make it more manageable.
    705                                 // The textarea is resizable in most browsers, so the user can adjust it if needed.
    706                                 editHeight = h > 500 ? 500 : h;
    707                                 $('#replycontent', editRow).css('height', editHeight + 'px');
     715                        // Make sure it's actually a table and there's a `colspan` value to apply.
     716                        if (editRow.hasClass('inline-edit-row') && 0 !== colspanVal) {
     717                                $('td', editRow).attr('colspan', colspanVal);
    708718                        }
    709719
    710                         c.after( editRow ).fadeOut('fast', function(){
    711                                 $('#replyrow').fadeIn(300, function(){ $(this).show(); });
    712                         });
    713                 } else if ( action == 'add' ) {
    714                         $('#addhead, #addbtn', editRow).show();
    715                         $( '#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow ) .hide();
    716                         $('#the-comment-list').prepend(editRow);
    717                         $('#replyrow').fadeIn(300);
    718                 } else {
    719                         replyButton = $('#replybtn', editRow);
    720                         $( '#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow ).hide();
    721                         $('#replyhead, #replybtn', editRow).show();
    722                         c.after(editRow);
     720                        $('#action', editRow).val(act);
     721                        $('#comment_post_ID', editRow).val(post_id);
     722                        $('#comment_ID', editRow).val(comment_id);
     723
     724                        if (action == 'edit') {
     725                                $('#author-name', editRow).val($('div.author', rowData).text());
     726                                $('#author-email', editRow).val($('div.author-email', rowData).text());
     727                                $('#author-url', editRow).val($('div.author-url', rowData).text());
     728                                $('#status', editRow).val($('div.comment_status', rowData).text());
     729                                $('#replycontent', editRow).val($('textarea.comment', rowData).val());
     730                                $('#edithead, #editlegend, #savebtn', editRow).show();
     731                                $('#replyhead, #replybtn, #addhead, #addbtn', editRow).hide();
     732
     733                                if (h > 120) {
     734                                        // Limit the maximum height when editing very long comments to make it more manageable.
     735                                        // The textarea is resizable in most browsers, so the user can adjust it if needed.
     736                                        editHeight = h > 500 ? 500 : h;
     737                                        $('#replycontent', editRow).css('height', editHeight + 'px');
     738                                }
    723739
    724                         if ( c.hasClass('unapproved') ) {
    725                                 replyButton.text(adminCommentsL10n.replyApprove);
     740                                c.after(editRow).fadeOut('fast', function () {
     741                                        $('#replyrow').fadeIn(300, function () {
     742                                                $(this).show();
     743                                        });
     744                                });
     745                        } else if (action == 'add') {
     746                                $('#addhead, #addbtn', editRow).show();
     747                                $('#replyhead, #replybtn, #edithead, #editlegend, #savebtn', editRow).hide();
     748                                $('#the-comment-list').prepend(editRow);
     749                                $('#replyrow').fadeIn(300);
    726750                        } else {
    727                                 replyButton.text(adminCommentsL10n.reply);
    728                         }
     751                                replyButton = $('#replybtn', editRow);
     752                                $('#edithead, #editlegend, #savebtn, #addhead, #addbtn', editRow).hide();
     753                                $('#replyhead, #replybtn', editRow).show();
     754                                c.after(editRow);
     755
     756                                if (c.hasClass('unapproved')) {
     757                                        replyButton.text(adminCommentsL10n.replyApprove);
     758                                } else {
     759                                        replyButton.text(adminCommentsL10n.reply);
     760                                }
    729761
    730                         $('#replyrow').fadeIn(300, function(){ $(this).show(); });
    731                 }
     762                                $('#replyrow').fadeIn(300, function () {
     763                                        $(this).show();
     764                                });
     765                        }
    732766
    733                 setTimeout(function() {
    734                         var rtop, rbottom, scrollTop, vp, scrollBottom;
     767                        setTimeout(function () {
     768                                var rtop, rbottom, scrollTop, vp, scrollBottom;
    735769
    736                         rtop = $('#replyrow').offset().top;
    737                         rbottom = rtop + $('#replyrow').height();
    738                         scrollTop = window.pageYOffset || document.documentElement.scrollTop;
    739                         vp = document.documentElement.clientHeight || window.innerHeight || 0;
    740                         scrollBottom = scrollTop + vp;
     770                                rtop = $('#replyrow').offset().top;
     771                                rbottom = rtop + $('#replyrow').height();
     772                                scrollTop = window.pageYOffset || document.documentElement.scrollTop;
     773                                vp = document.documentElement.clientHeight || window.innerHeight || 0;
     774                                scrollBottom = scrollTop + vp;
    741775
    742                         if ( scrollBottom - 20 < rbottom )
    743                                 window.scroll(0, rbottom - vp + 35);
    744                         else if ( rtop - 20 < scrollTop )
    745                                 window.scroll(0, rtop - 35);
     776                                if (scrollBottom - 20 < rbottom)
     777                                        window.scroll(0, rbottom - vp + 35);
     778                                else if (rtop - 20 < scrollTop)
     779                                        window.scroll(0, rtop - 35);
    746780
    747                         $('#replycontent').focus().keyup(function(e){
    748                                 if ( e.which == 27 )
    749                                         commentReply.revert(); // close on Escape
    750                         });
    751                 }, 600);
     781                                $('#replycontent').focus().keyup(function (e) {
     782                                        if (e.which == 27)
     783                                                commentReply.revert(); // close on Escape
     784                                });
     785                        }, 600);
    752786
    753                 return false;
    754         },
     787                        return false;
     788                },
    755789
    756         send : function() {
    757                 var post = {};
     790                send: function () {
     791                        var post = {};
    758792
    759                 $('#replysubmit .error').hide();
    760                 $( '#replysubmit .spinner' ).addClass( 'is-active' );
     793                        $('#replysubmit .error').hide();
     794                        $('#replysubmit .spinner').addClass('is-active');
    761795
    762                 $('#replyrow input').not(':button').each(function() {
    763                         var t = $(this);
    764                         post[ t.attr('name') ] = t.val();
    765                 });
     796                        $('#replyrow input').not(':button').each(function () {
     797                                var t = $(this);
     798                                post[t.attr('name')] = t.val();
     799                        });
    766800
    767                 post.content = $('#replycontent').val();
    768                 post.id = post.comment_post_ID;
    769                 post.comments_listing = this.comments_listing;
    770                 post.p = $('[name="p"]').val();
     801                        post.content = $('#replycontent').val();
     802                        post.id = post.comment_post_ID;
     803                        post.comments_listing = this.comments_listing;
     804                        post.p = $('[name="p"]').val();
    771805
    772                 if ( $('#comment-' + $('#comment_ID').val()).hasClass('unapproved') )
    773                         post.approve_parent = 1;
     806                        if ($('#comment-' + $('#comment_ID').val()).hasClass('unapproved'))
     807                                post.approve_parent = 1;
    774808
    775                 $.ajax({
    776                         type : 'POST',
    777                         url : ajaxurl,
    778                         data : post,
    779                         success : function(x) { commentReply.show(x); },
    780                         error : function(r) { commentReply.error(r); }
    781                 });
     809                        $.ajax({
     810                                type: 'POST',
     811                                url: ajaxurl,
     812                                data: post,
     813                                success: function (x) {
     814                                        commentReply.show(x);
     815                                },
     816                                error: function (r) {
     817                                        commentReply.error(r);
     818                                }
     819                        });
    782820
    783                 return false;
    784         },
     821                        return false;
     822                },
    785823
    786         show : function(xml) {
    787                 var t = this, r, c, id, bg, pid;
     824                show: function (xml) {
     825                        var t = this, r, c, id, bg, pid;
    788826
    789                 if ( typeof(xml) == 'string' ) {
    790                         t.error({'responseText': xml});
    791                         return false;
    792                 }
     827                        if (typeof(xml) == 'string') {
     828                                t.error({'responseText': xml});
     829                                return false;
     830                        }
    793831
    794                 r = wpAjax.parseAjaxResponse(xml);
    795                 if ( r.errors ) {
    796                         t.error({'responseText': wpAjax.broken});
    797                         return false;
    798                 }
     832                        r = wpAjax.parseAjaxResponse(xml);
     833                        if (r.errors) {
     834                                t.error({'responseText': wpAjax.broken});
     835                                return false;
     836                        }
    799837
    800                 t.revert();
     838                        t.revert();
    801839
    802                 r = r.responses[0];
    803                 id = '#comment-' + r.id;
     840                        r = r.responses[0];
     841                        id = '#comment-' + r.id;
    804842
    805                 if ( 'edit-comment' == t.act )
    806                         $(id).remove();
     843                        if ('edit-comment' == t.act)
     844                                $(id).remove();
    807845
    808                 if ( r.supplemental.parent_approved ) {
    809                         pid = $('#comment-' + r.supplemental.parent_approved);
    810                         updatePending( -1, r.supplemental.parent_post_id );
     846                        if (r.supplemental.parent_approved) {
     847                                pid = $('#comment-' + r.supplemental.parent_approved);
     848                                updatePending(-1, r.supplemental.parent_post_id);
    811849
    812                         if ( this.comments_listing == 'moderated' ) {
    813                                 pid.animate( { 'backgroundColor':'#CCEEBB' }, 400, function(){
    814                                         pid.fadeOut();
    815                                 });
    816                                 return;
     850                                if (this.comments_listing == 'moderated') {
     851                                        pid.animate({'backgroundColor': '#CCEEBB'}, 400, function () {
     852                                                pid.fadeOut();
     853                                        });
     854                                        return;
     855                                }
    817856                        }
    818                 }
    819857
    820                 if ( r.supplemental.i18n_comments_text ) {
    821                         if ( isDashboard ) {
    822                                 updateDashboardText( r.supplemental );
    823                         } else {
    824                                 updateApproved( 1, r.supplemental.parent_post_id );
    825                                 updateCountText( 'span.all-count', 1 );
     858                        if (r.supplemental.i18n_comments_text) {
     859                                if (isDashboard) {
     860                                        updateDashboardText(r.supplemental);
     861                                } else {
     862                                        updateApproved(1, r.supplemental.parent_post_id);
     863                                        updateCountText('span.all-count', 1);
     864                                }
    826865                        }
    827                 }
    828866
    829                 c = $.trim(r.data); // Trim leading whitespaces
    830                 $(c).hide();
    831                 $('#replyrow').after(c);
    832 
    833                 id = $(id);
    834                 t.addEvents(id);
    835                 bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
    836 
    837                 id.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
    838                         .animate( { 'backgroundColor': bg }, 300, function() {
    839                                 if ( pid && pid.length ) {
    840                                         pid.animate( { 'backgroundColor':'#CCEEBB' }, 300 )
    841                                                 .animate( { 'backgroundColor': bg }, 300 )
    842                                                 .removeClass('unapproved').addClass('approved')
    843                                                 .find('div.comment_status').html('1');
    844                                 }
    845                         });
     867                        c = $.trim(r.data); // Trim leading whitespaces
     868                        $(c).hide();
     869                        $('#replyrow').after(c);
     870
     871                        id = $(id);
     872                        t.addEvents(id);
     873                        bg = id.hasClass('unapproved') ? '#FFFFE0' : id.closest('.widefat, .postbox').css('backgroundColor');
     874
     875                        id.animate({'backgroundColor': '#CCEEBB'}, 300)
     876                                .animate({'backgroundColor': bg}, 300, function () {
     877                                        if (pid && pid.length) {
     878                                                pid.animate({'backgroundColor': '#CCEEBB'}, 300)
     879                                                        .animate({'backgroundColor': bg}, 300)
     880                                                        .removeClass('unapproved').addClass('approved')
     881                                                        .find('div.comment_status').html('1');
     882                                        }
     883                                });
    846884
    847         },
     885                },
    848886
    849         error : function(r) {
    850                 var er = r.statusText;
     887                error: function (r) {
     888                        var er = r.statusText;
    851889
    852                 $( '#replysubmit .spinner' ).removeClass( 'is-active' );
     890                        $('#replysubmit .spinner').removeClass('is-active');
    853891
    854                 if ( r.responseText )
    855                         er = r.responseText.replace( /<.[^<>]*?>/g, '' );
     892                        if (r.responseText)
     893                                er = r.responseText.replace(/<.[^<>]*?>/g, '');
    856894
    857                 if ( er )
    858                         $('#replysubmit .error').html(er).show();
     895                        if (er)
     896                                $('#replysubmit .error').html(er).show();
    859897
    860         },
     898                },
    861899
    862         addcomment: function(post_id) {
    863                 var t = this;
     900                addcomment: function (post_id) {
     901                        var t = this;
    864902
    865                 $('#add-new-comment').fadeOut(200, function(){
    866                         t.open(0, post_id, 'add');
    867                         $('table.comments-box').css('display', '');
    868                         $('#no-comments').remove();
    869                 });
    870         },
    871 
    872         /**
    873         * Alert the user if they have unsaved changes on a comment that will be
    874         * lost if they proceed.
    875         *
    876         * @returns {boolean}
    877         */
    878         discardCommentChanges: function() {
    879                 var editRow = $( '#replyrow' );
    880 
    881                 if  ( this.originalContent === $( '#replycontent', editRow ).val() ) {
    882                         return true;
    883                 }
     903                        $('#add-new-comment').fadeOut(200, function () {
     904                                t.open(0, post_id, 'add');
     905                                $('table.comments-box').css('display', '');
     906                                $('#no-comments').remove();
     907                        });
     908                },
     909
     910                /**
     911                * Alert the user if they have unsaved changes on a comment that will be
     912                * lost if they proceed.
     913                *
     914                * @returns {boolean}
     915                */
     916                discardCommentChanges: function () {
     917                        var editRow = $('#replyrow');
     918
     919                        if (this.originalContent === $('#replycontent', editRow).val()) {
     920                                return true;
     921                        }
    884922
    885                 return window.confirm( adminCommentsL10n.warnCommentChanges );
    886         }
    887 };
     923                        return window.confirm(adminCommentsL10n.warnCommentChanges);
     924                }
     925        };
    888926
    889 $(document).ready(function(){
    890         var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
     927        $(document).ready(function () {
     928                var make_hotkeys_redirect, edit_comment, toggle_all, make_bulk;
    891929
    892         setCommentsList();
    893         commentReply.init();
     930                setCommentsList();
     931                commentReply.init();
    894932
    895         $(document).on( 'click', 'span.delete a.delete', function( e ) {
    896                 e.preventDefault();
    897         });
     933                $(document).on('click', 'span.delete a.delete', function (e) {
     934                        e.preventDefault();
     935                });
    898936
    899         if ( typeof $.table_hotkeys != 'undefined' ) {
    900                 make_hotkeys_redirect = function(which) {
    901                         return function() {
    902                                 var first_last, l;
     937                if (typeof $.table_hotkeys != 'undefined') {
     938                        make_hotkeys_redirect = function (which) {
     939                                return function () {
     940                                        var first_last, l;
    903941
    904                                 first_last = 'next' == which? 'first' : 'last';
    905                                 l = $('.tablenav-pages .'+which+'-page:not(.disabled)');
    906                                 if (l.length)
    907                                         window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
     942                                        first_last = 'next' == which ? 'first' : 'last';
     943                                        l = $('.tablenav-pages .' + which + '-page:not(.disabled)');
     944                                        if (l.length)
     945                                                window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '') + '&hotkeys_highlight_' + first_last + '=1';
     946                                };
    908947                        };
    909                 };
    910948
    911                 edit_comment = function(event, current_row) {
    912                         window.location = $('span.edit a', current_row).attr('href');
    913                 };
     949                        edit_comment = function (event, current_row) {
     950                                window.location = $('span.edit a', current_row).attr('href');
     951                        };
    914952
    915                 toggle_all = function() {
    916                         $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' );
    917                 };
     953                        toggle_all = function () {
     954                                $('#cb-select-all-1').data('wp-toggle', 1).trigger('click').removeData('wp-toggle');
     955                        };
    918956
    919                 make_bulk = function(value) {
    920                         return function() {
    921                                 var scope = $('select[name="action"]');
    922                                 $('option[value="' + value + '"]', scope).prop('selected', true);
    923                                 $('#doaction').click();
     957                        make_bulk = function (value) {
     958                                return function () {
     959                                        var scope = $('select[name="action"]');
     960                                        $('option[value="' + value + '"]', scope).prop('selected', true);
     961                                        $('#doaction').click();
     962                                };
    924963                        };
    925                 };
    926964
    927                 $.table_hotkeys(
    928                         $('table.widefat'),
    929                         [
    930                                 'a', 'u', 's', 'd', 'r', 'q', 'z',
    931                                 ['e', edit_comment],
    932                                 ['shift+x', toggle_all],
    933                                 ['shift+a', make_bulk('approve')],
    934                                 ['shift+s', make_bulk('spam')],
    935                                 ['shift+d', make_bulk('delete')],
    936                                 ['shift+t', make_bulk('trash')],
    937                                 ['shift+z', make_bulk('untrash')],
    938                                 ['shift+u', make_bulk('unapprove')]
    939                         ],
    940                         {
    941                                 highlight_first: adminCommentsL10n.hotkeys_highlight_first,
    942                                 highlight_last: adminCommentsL10n.hotkeys_highlight_last,
    943                                 prev_page_link_cb: make_hotkeys_redirect('prev'),
    944                                 next_page_link_cb: make_hotkeys_redirect('next'),
    945                                 hotkeys_opts: {
    946                                         disableInInput: true,
    947                                         type: 'keypress',
    948                                         noDisable: '.check-column input[type="checkbox"]'
    949                                 },
    950                                 cycle_expr: '#the-comment-list tr',
    951                                 start_row_index: 0
    952                         }
    953                 );
    954         }
     965                        $.table_hotkeys(
     966                                $('table.widefat'),
     967                                [
     968                                        'a', 'u', 's', 'd', 'r', 'q', 'z',
     969                                        ['e', edit_comment],
     970                                        ['shift+x', toggle_all],
     971                                        ['shift+a', make_bulk('approve')],
     972                                        ['shift+s', make_bulk('spam')],
     973                                        ['shift+d', make_bulk('delete')],
     974                                        ['shift+t', make_bulk('trash')],
     975                                        ['shift+z', make_bulk('untrash')],
     976                                        ['shift+u', make_bulk('unapprove')]
     977                                ],
     978                                {
     979                                        highlight_first: adminCommentsL10n.hotkeys_highlight_first,
     980                                        highlight_last: adminCommentsL10n.hotkeys_highlight_last,
     981                                        prev_page_link_cb: make_hotkeys_redirect('prev'),
     982                                        next_page_link_cb: make_hotkeys_redirect('next'),
     983                                        hotkeys_opts: {
     984                                                disableInInput: true,
     985                                                type: 'keypress',
     986                                                noDisable: '.check-column input[type="checkbox"]'
     987                                        },
     988                                        cycle_expr: '#the-comment-list tr',
     989                                        start_row_index: 0
     990                                }
     991                        );
     992                }
    955993
    956         // Quick Edit and Reply have an inline comment editor.
    957         $( '#the-comment-list' ).on( 'click', '.comment-inline', function (e) {
    958                 e.preventDefault();
    959                 var $el = $( this ),
    960                         action = 'replyto';
     994                // Quick Edit and Reply have an inline comment editor.
     995                $('#the-comment-list').on('click', '.comment-inline', function (e) {
     996                        e.preventDefault();
     997                        var $el = $(this),
     998                                action = 'replyto';
    961999
    962                 if ( 'undefined' !== typeof $el.data( 'action' ) ) {
    963                         action = $el.data( 'action' );
    964                 }
     1000                        if ('undefined' !== typeof $el.data('action')) {
     1001                                action = $el.data('action');
     1002                        }
    9651003
    966                 commentReply.open( $el.data( 'commentId' ), $el.data( 'postId' ), action );
    967         } );
    968 });
     1004                        commentReply.open($el.data('commentId'), $el.data('postId'), action);
     1005                });
     1006        });
    9691007
    970 })(jQuery);
     1008})(jQuery);
     1009 No newline at end of file
  • src/wp-includes/js/comment-reply.js

    diff --git a/src/wp-includes/js/comment-reply.js b/src/wp-includes/js/comment-reply.js
    index 184726d35e..36134fdf90 100644
    a b  
    11var addComment = {
    2         moveForm: function( commId, parentId, respondId, postId ) {
     2        submitForm: function (e, textareaId) {
     3                if (( e.metaKey || e.ctrlKey ) && e.keyCode == 13) {
     4                        var t = this,
     5                                textarea = t.I(textareaId),
     6                                commentForm = t.I(textarea.form.id);
     7
     8                        document.createElement('form').submit.call(commentForm);
     9                        e.preventDefault();
     10                        return false;
     11                }
     12        },
     13
     14        moveForm: function (commId, parentId, respondId, postId) {
    315                var div, element, style, cssHidden,
    4                         t           = this,
    5                         comm        = t.I( commId ),
    6                         respond     = t.I( respondId ),
    7                         cancel      = t.I( 'cancel-comment-reply-link' ),
    8                         parent      = t.I( 'comment_parent' ),
    9                         post        = t.I( 'comment_post_ID' ),
    10                         commentForm = respond.getElementsByTagName( 'form' )[0];
    11 
    12                 if ( ! comm || ! respond || ! cancel || ! parent || ! commentForm ) {
     16                        t = this,
     17                        comm = t.I(commId),
     18                        respond = t.I(respondId),
     19                        cancel = t.I('cancel-comment-reply-link'),
     20                        parent = t.I('comment_parent'),
     21                        post = t.I('comment_post_ID'),
     22                        commentForm = respond.getElementsByTagName('form')[0];
     23
     24                if (!comm || !respond || !cancel || !parent || !commentForm) {
    1325                        return;
    1426                }
    1527
    1628                t.respondId = respondId;
    1729                postId = postId || false;
    1830
    19                 if ( ! t.I( 'wp-temp-form-div' ) ) {
    20                         div = document.createElement( 'div' );
     31                if (!t.I('wp-temp-form-div')) {
     32                        div = document.createElement('div');
    2133                        div.id = 'wp-temp-form-div';
    2234                        div.style.display = 'none';
    23                         respond.parentNode.insertBefore( div, respond );
     35                        respond.parentNode.insertBefore(div, respond);
    2436                }
    2537
    26                 comm.parentNode.insertBefore( respond, comm.nextSibling );
    27                 if ( post && postId ) {
     38                comm.parentNode.insertBefore(respond, comm.nextSibling);
     39                if (post && postId) {
    2840                        post.value = postId;
    2941                }
    3042                parent.value = parentId;
    3143                cancel.style.display = '';
    3244
    33                 cancel.onclick = function() {
    34                         var t       = addComment,
    35                                 temp    = t.I( 'wp-temp-form-div' ),
    36                                 respond = t.I( t.respondId );
     45                cancel.onclick = function () {
     46                        var t = addComment,
     47                                temp = t.I('wp-temp-form-div'),
     48                                respond = t.I(t.respondId);
    3749
    38                         if ( ! temp || ! respond ) {
     50                        if (!temp || !respond) {
    3951                                return;
    4052                        }
    4153
    42                         t.I( 'comment_parent' ).value = '0';
    43                         temp.parentNode.insertBefore( respond, temp );
    44                         temp.parentNode.removeChild( temp );
     54                        t.I('comment_parent').value = '0';
     55                        temp.parentNode.insertBefore(respond, temp);
     56                        temp.parentNode.removeChild(temp);
    4557                        this.style.display = 'none';
    4658                        this.onclick = null;
    4759                        return false;
    var addComment = { 
    5365                 * 'inherit' when the visibility value is inherited from an ancestor.
    5466                 */
    5567                try {
    56                         for ( var i = 0; i < commentForm.elements.length; i++ ) {
     68                        for (var i = 0; i < commentForm.elements.length; i++) {
    5769                                element = commentForm.elements[i];
    5870                                cssHidden = false;
    5971
    6072                                // Modern browsers.
    61                                 if ( 'getComputedStyle' in window ) {
    62                                         style = window.getComputedStyle( element );
    63                                 // IE 8.
    64                                 } else if ( document.documentElement.currentStyle ) {
     73                                if ('getComputedStyle' in window) {
     74                                        style = window.getComputedStyle(element);
     75                                        // IE 8.
     76                                } else if (document.documentElement.currentStyle) {
    6577                                        style = element.currentStyle;
    6678                                }
    6779
    var addComment = { 
    7183                                 * the job for us. In fact, the visibility computed style is the actual
    7284                                 * computed value and already takes into account the element ancestors.
    7385                                 */
    74                                 if ( ( element.offsetWidth <= 0 && element.offsetHeight <= 0 ) || style.visibility === 'hidden' ) {
     86                                if (( element.offsetWidth <= 0 && element.offsetHeight <= 0 ) || style.visibility === 'hidden') {
    7587                                        cssHidden = true;
    7688                                }
    7789
    7890                                // Skip form elements that are hidden or disabled.
    79                                 if ( 'hidden' === element.type || element.disabled || cssHidden ) {
     91                                if ('hidden' === element.type || element.disabled || cssHidden) {
    8092                                        continue;
    8193                                }
    8294
    var addComment = { 
    8597                                break;
    8698                        }
    8799
    88                 } catch( er ) {}
     100                } catch (er) {
     101                }
    89102
    90103                return false;
    91104        },
    92105
    93         I: function( id ) {
    94                 return document.getElementById( id );
     106        I: function (id) {
     107                return document.getElementById(id);
    95108        }
    96 };
     109};
     110 No newline at end of file