Make WordPress Core

Ticket #15898: 15898.7.diff

File 15898.7.diff, 11.6 KB (added by kirasong, 14 years ago)

Toggles Reply/Approve and Reply button text when "Approve/Unapprove" links are pressed on the current post while replying.

  • wp-admin/admin-ajax.php

    diff --git wp-admin/admin-ajax.php wp-admin/admin-ajax.php
    index d2a8d4d..2c57750 100644
    case 'replyto-comment' : 
    665665        $comment_id = wp_new_comment( $commentdata );
    666666        $comment = get_comment($comment_id);
    667667        if ( ! $comment ) die('1');
    668 
     668       
     669        $parent = get_comment( $comment_parent );
     670       
    669671        $position = ( isset($_POST['position']) && (int) $_POST['position']) ? (int) $_POST['position'] : '-1';
    670672
    671673        $x = new WP_Ajax_Response();
    case 'replyto-comment' : 
    684686                }
    685687                $comment_list_item = ob_get_contents();
    686688        ob_end_clean();
    687 
    688         $x->add( array(
     689       
     690        $response = array(
    689691                'what' => 'comment',
    690692                'id' => $comment->comment_ID,
    691693                'data' => $comment_list_item,
    692694                'position' => $position
    693         ));
    694 
     695        );
     696       
     697        // automatically approve parent comment
     698        if ( ! $parent->comment_approved ) {
     699                if ( ! wp_update_comment( array( 'comment_ID' => $comment_parent, 'comment_approved' => 'approve' ) ) )
     700                        die( '1' );
     701               
     702                // include total_items_i18n to update total item number
     703                if ( $_POST['status'] == 'moderated' ) {
     704                        $total = wp_count_comments()->moderated;
     705                        $per_page = (int) $_POST['_per_page'];
     706                        $response['supplemental'] = array(
     707                                'total_items_i18n' => sprintf( _n( '1 item', '%s items', $total ), number_format_i18n( $total ) ),
     708                                'total_pages' => ceil( $total / $per_page ),
     709                                'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
     710                                'total' => $total,
     711                                'time' => time()
     712                        );
     713                }
     714        }
     715        $x->add( $response );
    695716        $x->send();
    696717        break;
    697718case 'edit-comment' :
  • wp-admin/css/wp-admin.dev.css

    diff --git wp-admin/css/wp-admin.dev.css wp-admin/css/wp-admin.dev.css
    index 8506810..fc1b7bd 100644
    table.fixed { 
    13731373#comments-form .fixed .column-author {
    13741374        width: 20%;
    13751375}
     1376.comments tr.focus th, .comments tr.focus td {
     1377        border-top-width:1px;
     1378        border-top-style:solid;
     1379}
     1380
     1381.comments tr.blur th, .comments tr.blur td {
     1382        border-bottom-width:0;
     1383}
    13761384#commentsdiv.postbox .inside {
    13771385        line-height:1.4em;
    13781386        margin:0;
  • wp-admin/js/edit-comments.dev.js

    diff --git wp-admin/js/edit-comments.dev.js wp-admin/js/edit-comments.dev.js
    index fbadeba..f83dcf0 100644
     
    11var theList, theExtraList, toggleWithKeyboard = false;
    22(function($) {
    33
     4var dashboardTotals = function(n) {
     5        var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
     6
     7        n = n || 0;
     8        if ( isNaN(n) || !dash.length )
     9                return;
     10
     11        total = $('span.total-count', dash);
     12        appr = $('span.approved-count', dash);
     13        totalN = getCount(total);
     14
     15        totalN = totalN + n;
     16        apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
     17        updateCount(total, totalN);
     18        updateCount(appr, apprN);
     19
     20}
     21
     22var getCount = function(el) {
     23        var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
     24        if ( isNaN(n) )
     25                return 0;
     26        return n;
     27}
     28
     29var updateCount = function(el, n) {
     30        var n1 = '';
     31        if ( isNaN(n) )
     32                return;
     33        n = n < 1 ? '0' : n.toString();
     34        if ( n.length > 3 ) {
     35                while ( n.length > 3 ) {
     36                        n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
     37                        n = n.substr(0, n.length - 3);
     38                }
     39                n = n + n1;
     40        }
     41        el.html(n);
     42}
     43
     44var updatePagination = function(r) {
     45        total_items_i18n = r.total_items_i18n || '';
     46        if ( total_items_i18n ) {
     47                $('.displaying-num').text( total_items_i18n );
     48                $('.total-pages').text( r.total_pages_i18n );
     49                $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', r.total_pages == $('.current-page').val());
     50        }
     51}
     52
    453setCommentsList = function() {
    554        var totalInput, perPageInput, pageInput, lastConfidentTime = 0, dimAfter, delBefore, updateTotalCount, delAfter;
    655
     
    958        pageInput = $('input[name="_page"]', '#comments-form');
    1059
    1160        dimAfter = function( r, settings ) {
    12                 var c = $('#' + settings.element);
     61                var c = $('#' + settings.element), editRow, replyID, replyButton;
    1362
    14                 if ( c.is('.unapproved') )
     63                editRow = $('#replyrow');
     64                replyID = $('#comment_ID', editRow).val();
     65                replyButton = $('#replybtn', editRow);
     66
     67                if ( c.is('.unapproved') ) {
     68                        if (settings.data.id == replyID)
     69                                replyButton.text(adminCommentsL10n.replyApprove);
     70
    1571                        c.find('div.comment_status').html('0')
    16                 else
     72                } else {
     73                        if (settings.data.id == replyID)
     74                                replyButton.text(adminCommentsL10n.reply);
     75
    1776                        c.find('div.comment_status').html('1')
     77                }
    1878
    1979                $('span.pending-count').each( function() {
    2080                        var a = $(this), n, dif;
    setCommentsList = function() { 
    99148                });
    100149        };
    101150
    102         function dashboardTotals(n) {
    103                 var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
    104 
    105                 n = n || 0;
    106                 if ( isNaN(n) || !dash.length )
    107                         return;
    108 
    109                 total = $('span.total-count', dash);
    110                 appr = $('span.approved-count', dash);
    111                 totalN = getCount(total);
    112 
    113                 totalN = totalN + n;
    114                 apprN = totalN - getCount( $('span.pending-count', dash) ) - getCount( $('span.spam-count', dash) );
    115                 updateCount(total, totalN);
    116                 updateCount(appr, apprN);
    117 
    118         }
    119 
    120         function getCount(el) {
    121                 var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
    122                 if ( isNaN(n) )
    123                         return 0;
    124                 return n;
    125         }
    126 
    127         function updateCount(el, n) {
    128                 var n1 = '';
    129                 if ( isNaN(n) )
    130                         return;
    131                 n = n < 1 ? '0' : n.toString();
    132                 if ( n.length > 3 ) {
    133                         while ( n.length > 3 ) {
    134                                 n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
    135                                 n = n.substr(0, n.length - 3);
    136                         }
    137                         n = n + n1;
    138                 }
    139                 el.html(n);
    140         }
    141 
    142151        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    143152        delAfter = function( r, settings ) {
    144153                var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
    setCommentsList = function() { 
    185194
    186195                if ( $('#dashboard_right_now').length ) {
    187196                        N = trash ? -1 * trash : 0;
    188                         dashboardTotals(N);
     197                        dashboardTotals(N);     
    189198                } else {
    190199                        total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
    191200                        total = total - spam - trash;
    setCommentsList = function() { 
    193202                                total = 0;
    194203
    195204                        if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
    196                                 total_items_i18n = settings.parsed.responses[0].supplemental.total_items_i18n || '';
    197                                 if ( total_items_i18n ) {
    198                                         $('.displaying-num').text( total_items_i18n );
    199                                         $('.total-pages').text( settings.parsed.responses[0].supplemental.total_pages_i18n );
    200                                         $('.tablenav-pages').find('.next-page, .last-page').toggleClass('disabled', settings.parsed.responses[0].supplemental.total_pages == $('.current-page').val());
    201                                 }
     205                                updatePagination(settings.parsed.responses[0].supplemental);
    202206                                updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
    203207                        } else {
    204208                                updateTotalCount( total, r, false );
    setCommentsList = function() { 
    273277commentReply = {
    274278        cid : '',
    275279        act : '',
     280       
     281        focusOn : function(id) {
     282                var c = $('#comment-' + id),
     283                        excluded = c.find('td, th').css('opacity', 1).add('td, th', '#replyrow');
     284                theList.find('td, th').not(excluded).animate({opacity:'0.2'}, 300);
     285                c.addClass('focus');
     286                c.prev().addClass('blur');
     287        },
     288       
     289        focusOff : function() {
     290                theList.
     291                        find('.blur').removeClass('blur').end().
     292                        find('.focus').removeClass('focus');
     293        },
    276294
    277295        init : function() {
    278296                var row = $('#replyrow');
    commentReply = { 
    321339
    322340                if ( $('#the-comment-list #replyrow').length < 1 )
    323341                        return false;
     342                       
     343                theList.find('th, td').animate({opacity : 1}, 300);
    324344
    325345                $('#replyrow').fadeOut('fast', function(){
    326346                        commentReply.close();
    commentReply = { 
    344364                        $('input', '#edithead').val('');
    345365                        $('.error', '#replysubmit').html('').hide();
    346366                        $('.waiting', '#replysubmit').hide();
     367                        this.focusOff();
    347368
    348369                        if ( $.browser.msie )
    349370                                $('#replycontainer, #replycontent').css('height', '120px');
    commentReply = { 
    355376        },
    356377
    357378        open : function(id, p, a) {
    358                 var t = this, editRow, rowData, act, h, c = $('#comment-' + id);
     379                var t = this, editRow, rowData, act, h, c = $('#comment-' + id), replyButton;
    359380                t.close();
    360381                t.cid = id;
    361382
    commentReply = { 
    366387                $('#action', editRow).val(act);
    367388                $('#comment_post_ID', editRow).val(p);
    368389                $('#comment_ID', editRow).val(id);
     390                t.focusOn(id);
    369391
    370392                if ( a == 'edit' ) {
    371393                        $('#author', editRow).val( $('div.author', rowData).text() );
    commentReply = { 
    387409                                $('#replyrow').fadeIn(300, function(){ $(this).show() });
    388410                        });
    389411                } else {
     412                        replyButton = $('#replybtn', editRow);
    390413                        $('#edithead, #savebtn', editRow).hide();
    391414                        $('#replyhead, #replybtn', editRow).show();
     415                        $('#status', editRow).val($('input[name=comment_status]').val());
    392416                        c.after(editRow);
     417                        if (c.hasClass('unapproved')) {
     418                                replyButton.text(adminCommentsL10n.replyApprove);
     419                        } else {
     420                                replyButton.text(adminCommentsL10n.reply);
     421                        }
    393422                        $('#replyrow').fadeIn(300, function(){ $(this).show() });
    394423                }
    395424
    commentReply = { 
    427456        },
    428457
    429458        send : function() {
    430                 var post = {};
     459                var post = {}, c;
    431460
    432461                $('#replysubmit .error').hide();
    433462                $('#replysubmit .waiting').show();
    commentReply = { 
    440469                post.id = post.comment_post_ID;
    441470                post.comments_listing = this.comments_listing;
    442471                post.p = $('[name=p]').val();
    443 
     472                post._per_page = $('input[name="_per_page"]', '#comments-form').val();
     473                c = $('#comment-' + post.comment_ID);
    444474                $.ajax({
    445475                        type : 'POST',
    446476                        url : ajaxurl,
    447477                        data : post,
    448                         success : function(x) { commentReply.show(x); },
     478                        success : function(x) {
     479                                var pending_count;
     480                               
     481                                /**
     482                                 * Check if reply creation was successful.
     483                                 * Show error, if error -- otherwise show reply and approve.
     484                                 */
     485                                if (commentReply.show(x) != false) {
     486                                        if (c.hasClass('unapproved')) {
     487                                                c.removeClass('unapproved').addClass('approved');
     488                                                $('span.pending-count').each( function() {
     489                                                        var a = $(this), n = getCount(a);
     490                                                        if (! isNaN(n)) {
     491                                                                n = n - 1;
     492                                                                if ( n < 0 ) { n = 0; }
     493                                                                a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
     494                                                                updateCount(a, n);
     495                                                                dashboardTotals();
     496                                                        }
     497                                                });
     498                                        }
     499                                }
     500                        },
    449501                        error : function(r) { commentReply.error(r); }
    450502                });
    451503
    commentReply = { 
    483526                        .animate( { 'backgroundColor':'#CCEEBB' }, 600 )
    484527                        .animate( { 'backgroundColor': bg }, 600 );
    485528
     529                if (r.supplemental)
     530                        updatePagination(r.supplemental);
     531
    486532                // $.fn.wpList.process($(id));
    487533        },
    488534
  • wp-admin/js/post.dev.js

    diff --git wp-admin/js/post.dev.js wp-admin/js/post.dev.js
    index 1c39edf..d3bcd52 100644
    commentsBox = { 
    185185                                if ( 'object' == typeof r && r.responses[0] ) {
    186186                                        $('#the-comment-list').append( r.responses[0].data );
    187187
    188                                         theList = theExtraList = null;
     188//                                      theList = theExtraList = null;
    189189                                        $("a[className*=':']").unbind();
    190190
    191191                                        if ( commentsBox.st > commentsBox.total )
  • wp-includes/script-loader.php

    diff --git wp-includes/script-loader.php wp-includes/script-loader.php
    index b8d234e..d3f32cb 100644
    function wp_default_scripts( &$scripts ) { 
    303303                $scripts->add_data( 'admin-comments', 'group', 1 );
    304304                $scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
    305305                        'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
    306                         'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last'])
     306                        'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
     307                        'replyApprove' => __( 'Approve and Reply' ),
     308                        'reply' => __( 'Reply' ),
    307309                ) );
    308310
    309311                $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array('jquery'), '20100403' );