Make WordPress Core

Ticket #28326: 28326.2.diff

File 28326.2.diff, 2.4 KB (added by garrett-eclipse, 4 years ago)

Initial patch to update sticky counts using similar functions as in comment-reply.js

  • src/js/_enqueues/admin/inline-edit-post.js

     
    390390         *                       Enter on a focused field.
    391391         */
    392392        save : function(id) {
    393                 var params, fields, page = $('.post_status_page').val() || '';
     393                var params, fields, rowData, was_sticky, is_sticky, page = $('.post_status_page').val() || '';
    394394
    395395                if ( typeof(id) === 'object' ) {
    396396                        id = this.getId(id);
     
    409409                fields = $('#edit-'+id).find(':input').serialize();
    410410                params = fields + '&' + $.param(params);
    411411
     412                rowData   = $('#inline_'+id);
     413                was_sticky = $( '.sticky', rowData ).text() === 'sticky';
     414                console.log(rowData);
     415                console.log(was_sticky);
    412416                // Make ajax request.
    413417                $.post( ajaxurl, params,
    414418                        function(r) {
     
    422426                                        if ( -1 !== r.indexOf( '<tr' ) ) {
    423427                                                $(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove();
    424428                                                $('#edit-'+id).before(r).remove();
     429                                                is_sticky = -1 !== r.indexOf( '<div class="sticky">sticky</div>' );
     430                                                if ( was_sticky && ! is_sticky ) {
     431                                                        inlineEditPost.updateCountText( '.sticky span.count', -1 );
     432                                                } else if ( is_sticky && ! was_sticky ) {
     433                                                        inlineEditPost.updateCountText( '.sticky span.count', 1 );
     434                                                }
     435                                                console.log(r);
     436                                                console.log(is_sticky);
    425437                                                $( inlineEditPost.what + id ).hide().fadeIn( 400, function() {
    426438                                                        // Move focus back to the Quick Edit button. $( this ) is the row being animated.
    427439                                                        $( this ).find( '.editinline' )
     
    504516                var id = $(o).closest('tr').attr('id'),
    505517                        parts = id.split('-');
    506518                return parts[parts.length - 1];
     519        },
     520
     521        getCount : function(el) {
     522                var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
     523                if ( isNaN(n) ) {
     524                        return 0;
     525                }
     526                return n;
     527        },
     528
     529        updateCount : function(el, n) {
     530                var n1 = '';
     531                if ( isNaN(n) ) {
     532                        return;
     533                }
     534                n = n < 1 ? '0' : n.toString();
     535                if ( n.length > 3 ) {
     536                        while ( n.length > 3 ) {
     537                                n1 = thousandsSeparator + n.substr(n.length - 3) + n1;
     538                                n = n.substr(0, n.length - 3);
     539                        }
     540                        n = n + n1;
     541                }
     542                el.html('('+n+')');
     543        },
     544
     545        updateCountText : function( selector, diff ) {
     546                $( selector ).each(function() {
     547                        var a = $(this), n = inlineEditPost.getCount(a) + diff;
     548                        if ( n < 1 ) {
     549                                n = 0;
     550                        }
     551                        inlineEditPost.updateCount( a, n );
     552                });
    507553        }
    508554};
    509555