Skip to:
Content

BuddyPress.org

Changeset 7002


Ignore:
Timestamp:
05/06/2013 12:49:35 AM (13 years ago)
Author:
boonebgorges
Message:

Update 'Show all x comments' count after creating or deleting activity comments

On activity permalink pages, the comment list is collapsed if the item has more
than 6 responses, and a link is appended that reads 'Show all x comments'. This
changeset introduces additional JavaScript to update this count when a new
activity comment is created, or an existing one is deleted, via AJAX.

In the process of making the change, the logic for constructing the 'Show all
x comments' string was changed, so that it's now properly translatable.

Also cached a JS variable that was being used many times, to avoid unnecessary
DOM traversal.

Fixes #4844

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-templates/bp-legacy/buddypress-functions.php

    r6867 r7002  
    253253                        'rejected'          => __( 'Rejected', 'buddypress' ),
    254254                        'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
     255                        'show_x_comments'   => __( 'Show all %d comments', 'buddypress' ),
    255256                        'show_all'          => __( 'Show all', 'buddypress' ),
    256257                        'comments'          => __( 'comments', 'buddypress' ),
  • trunk/bp-templates/bp-legacy/js/buddypress.js

    r7000 r7002  
    444444                                        form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
    445445                                } else {
     446                                        var activity_comments = form.parent();
    446447                                        form.fadeOut( 200, function() {
    447                                                 if ( 0 == form.parent().children('ul').length ) {
    448                                                         if ( form.parent().hasClass('activity-comments') ) {
    449                                                                 form.parent().prepend('<ul></ul>');
     448                                                if ( 0 == activity_comments.children('ul').length ) {
     449                                                        if ( activity_comments.hasClass('activity-comments') ) {
     450                                                                activity_comments.prepend('<ul></ul>');
    450451                                                        } else {
    451                                                                 form.parent().append('<ul></ul>');
     452                                                                activity_comments.append('<ul></ul>');
    452453                                                        }
    453454                                                }
     
    456457                                                var the_comment = jq.trim( response );
    457458
    458                                                 form.parent().children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
     459                                                activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
    459460                                                form.children('textarea').val('');
    460                                                 form.parent().parent().addClass('has-comments');
     461                                                activity_comments.parent().addClass('has-comments');
    461462                                        } );
    462463                                        jq( '#' + form.attr('id') + ' textarea').val('');
     
    464465                                        /* Increase the "Reply (X)" button count */
    465466                                        jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
     467
     468                                        // Increment the 'Show all x comments' string, if present
     469                                        var show_all_a = activity_comments.find('.show-all').find('a');
     470                                        if ( show_all_a ) {
     471                                                var new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html();
     472                                                show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
     473                                        }
    466474                                }
    467475
     
    519527                                        var new_count = count_span.html() - ( 1 + child_count );
    520528                                        count_span.html(new_count);
     529                                       
     530                                        // Change the 'Show all x comments' text
     531                                        var show_all_a = comment_li.siblings('.show-all').find('a');
     532                                        if ( show_all_a ) {
     533                                                show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
     534                                        }
    521535
    522536                                        /* If that was the last comment for the item, remove the has-comments class to clean up the styling */
     
    14071421                                jq(this).toggle();
    14081422
    1409                                 if ( !i )
    1410                                         jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_all + ' ' + comment_count + ' ' + BP_DTheme.comments + '</a></li>' );
     1423                                if ( !i ) 
     1424                                        jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_x_comments.replace( '%d', comment_count ) + '</a></li>' );
    14111425                        }
    14121426                });
  • trunk/bp-themes/bp-default/_inc/global.js

    r7000 r7002  
    437437                                        form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
    438438                                } else {
     439                                        var activity_comments = form.parent();
    439440                                        form.fadeOut( 200, function() {
    440                                                 if ( 0 == form.parent().children('ul').length ) {
    441                                                         if ( form.parent().hasClass('activity-comments') ) {
    442                                                                 form.parent().prepend('<ul></ul>');
     441                                                if ( 0 == activity_comments.children('ul').length ) {
     442                                                        if ( activity_comments.hasClass('activity-comments') ) {
     443                                                                activity_comments.prepend('<ul></ul>');
    443444                                                        } else {
    444                                                                 form.parent().append('<ul></ul>');
     445                                                                activity_comments.append('<ul></ul>');
    445446                                                        }
    446447                                                }
     
    449450                                                var the_comment = jq.trim( response );
    450451
    451                                                 form.parent().children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
     452                                                activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
    452453                                                form.children('textarea').val('');
    453                                                 form.parent().parent().addClass('has-comments');
     454                                                activity_comments.parent().addClass('has-comments');
    454455                                        } );
    455456
     
    458459                                        /* Increase the "Reply (X)" button count */
    459460                                        jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
     461
     462                                        // Increment the 'Show all x comments' string, if present
     463                                        var show_all_a = activity_comments.find('.show-all').find('a');
     464                                        if ( show_all_a ) {
     465                                                var new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html();
     466                                                show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
     467                                        }
    460468                                }
    461469
     
    513521                                        var new_count = count_span.html() - ( 1 + child_count );
    514522                                        count_span.html(new_count);
     523       
     524                                        // Change the 'Show all x comments' text
     525                                        var show_all_a = comment_li.siblings('.show-all').find('a');
     526                                        if ( show_all_a ) {
     527                                                show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
     528                                        }
    515529
    516530                                        /* If that was the last comment for the item, remove the has-comments class to clean up the styling */
     
    13911405
    13921406                                if ( !i )
    1393                                         jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_all + ' ' + comment_count + ' ' + BP_DTheme.comments + '</a></li>' );
     1407                                        jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_x_comments.replace( '%d', comment_count ) + '</a></li>' );
    13941408                        }
    13951409                });
  • trunk/bp-themes/bp-default/functions.php

    r6726 r7002  
    160160                'rejected'          => __( 'Rejected', 'buddypress' ),
    161161                'show_all_comments' => __( 'Show all comments for this thread', 'buddypress' ),
     162                'show_x_comments'   => __( 'Show all %d comments', 'buddypress' ),
    162163                'show_all'          => __( 'Show all', 'buddypress' ),
    163164                'comments'          => __( 'comments', 'buddypress' ),
Note: See TracChangeset for help on using the changeset viewer.