Skip to:
Content

BuddyPress.org

Ticket #7400: activity_multiloop_js.diff

File activity_multiloop_js.diff, 11.3 KB (added by sbrajesh, 8 years ago)
  • src/bp-templates/bp-legacy/js/buddypress.js

     
    116116                var last_date_recorded = 0,
    117117                        button = jq(this),
    118118                        form   = button.closest('form#whats-new-form'),
    119                         inputs = {}, post_data;
     119                        inputs = {}, post_data, activity_wrapper;
    120120
    121121                // Get all inputs and organize them into an object {name: value}
    122122                jq.each( form.serializeArray(), function( key, input ) {
     
    148148                form.addClass('submitted');
    149149
    150150                /* Default POST values */
     151                activity_wrapper = jq(this).closest('div.activity');
    151152                object = '';
    152153                item_id = jq('#whats-new-post-in').val();
    153154                content = jq('#whats-new').val();
    154                 firstrow = jq( '#buddypress ul.activity-list li' ).first();
     155                firstrow = jq( '#buddypress ul.activity-list li', activity_wrapper ).first();
    155156                activity_row = firstrow;
    156157                timestamp = null;
    157158
     
    197198                                form.prepend( response.substr( 2, response.length ) );
    198199                                jq( '#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
    199200                        } else {
    200                                 if ( 0 === jq('ul.activity-list').length ) {
     201                                if ( 0 === jq('ul.activity-list', activity_wrapper).length ) {
    201202                                        jq('div.error').slideUp(100).remove();
    202203                                        jq('#message').slideUp(100).remove();
    203                                         jq('div.activity').append( '<ul id="activity-stream" class="activity-list item-list">' );
     204                                        jq('div.activity', activity_wrapper).append( '<ul id="activity-stream" class="activity-list item-list">' );
    204205                                }
    205206
    206207                                if ( firstrow.hasClass( 'load-newest' ) ) {
     
    207208                                        firstrow.remove();
    208209                                }
    209210
    210                                 jq('#activity-stream').prepend(response);
     211                                jq('#activity-stream', activity_wrapper).prepend(response);
    211212
    212213                                if ( ! last_date_recorded ) {
    213214                                        jq('#activity-stream li:first').addClass('new-update just-posted');
     
    255256        /* List tabs event delegation */
    256257        jq('div.activity-type-tabs').on( 'click', function(event) {
    257258                var target = jq(event.target).parent(),
    258                         scope, filter;
     259                        scope, filter, activity_wrapper;
    259260
    260261                if ( event.target.nodeName === 'STRONG' || event.target.nodeName === 'SPAN' ) {
    261262                        target = target.parent();
     
    268269                        path: '/',
    269270                        secure: ( 'https:' === window.location.protocol )
    270271                } );
     272                activity_wrapper = jq(target).closest('div.activity');
    271273
    272274                /* Activity Stream Tabs */
    273275                scope  = target.attr('id').substr( 9, target.attr('id').length );
     
    277279                        jq( '#' + target.attr('id') + ' a strong' ).remove();
    278280                }
    279281
    280                 bp_activity_request(scope, filter);
     282                bp_activity_request(scope, filter, activity_wrapper);
    281283
    282284                return false;
    283285        });
     
    286288        jq('#activity-filter-select select').change( function() {
    287289                var selected_tab = jq( 'div.activity-type-tabs li.selected' ),
    288290                        filter = jq(this).val(),
    289                         scope;
     291                        scope, activity_wrapper;
    290292
    291293                if ( !selected_tab.length ) {
    292294                        scope = null;
     
    294296                        scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length );
    295297                }
    296298
    297                 bp_activity_request(scope, filter);
     299                activity_wrapper = jq(selected_tab).closest('div.activity');
     300                bp_activity_request(scope, filter, activity_wrapper);
    298301
    299302                return false;
    300303        });
     
    304307                var target = jq(event.target),
    305308                        type, parent, parent_id,
    306309                        li, id, link_href, nonce, timestamp,
    307                         oldest_page, just_posted;
     310                        oldest_page, just_posted, activity_wrapper;
    308311
     312                activity_wrapper = target.closest('div.activity');
    309313                /* Favoriting activity stream items */
    310314                if ( target.hasClass('fav') || target.hasClass('unfav') ) {
    311315                        /* Bail if a request is in progress */
     
    318322                        parent_id = parent.attr('id').substr( 9, parent.attr('id').length );
    319323
    320324                        target.addClass('loading');
    321 
    322325                        jq.post( ajaxurl, {
    323326                                action: 'activity_mark_' + type,
    324327                                'cookie': bp_get_cookies(),
     
    353356
    354357                                        if ( !Number( jq('.item-list-tabs ul #activity-favorites span').html() ) ) {
    355358                                                if ( jq('.item-list-tabs ul #activity-favorites').hasClass('selected') ) {
    356                                                         bp_activity_request( null, null );
     359                                                        bp_activity_request( null, null, activity_wrapper );
    357360                                                }
    358361
    359362                                                jq('.item-list-tabs ul #activity-favorites').remove();
     
    440443                                bp_ajax_request.abort();
    441444                        }
    442445
    443                         jq('#buddypress li.load-more').addClass('loading');
     446                        jq('#buddypress li.load-more', activity_wrapper).addClass('loading');
    444447
    445448                        if ( null === jq.cookie('bp-activity-oldestpage') ) {
    446449                                jq.cookie('bp-activity-oldestpage', 1, {
     
    452455                        oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1;
    453456                        just_posted = [];
    454457
    455                         jq('.activity-list li.just-posted').each( function(){
     458                        jq('.activity-list li.just-posted', activity_wrapper).each( function(){
    456459                                just_posted.push( jq(this).attr('id').replace( 'activity-','' ) );
    457460                        });
    458461
     
    472475                        bp_ajax_request = jq.post( ajaxurl, load_more_args,
    473476                        function(response)
    474477                        {
    475                                 jq('#buddypress li.load-more').removeClass('loading');
     478                                jq('#buddypress li.load-more', activity_wrapper).removeClass('loading');
    476479                                jq.cookie( 'bp-activity-oldestpage', oldest_page, {
    477480                                        path: '/',
    478481                                        secure: ( 'https:' === window.location.protocol )
    479482                                } );
    480                                 jq('#buddypress ul.activity-list').append(response.contents);
     483                                jq('#buddypress ul.activity-list', activity_wrapper).append(response.contents);
    481484
    482485                                target.parent().hide();
    483486                        }, 'json' );
     
    508511                        } );
    509512
    510513                        // Now the stream is cleaned, prepend newest
    511                         jq( '#buddypress ul.activity-list' ).prepend( newest_activities );
     514                        jq( '#buddypress ul.activity-list', activity_wrapper ).prepend( newest_activities );
    512515
    513516                        // reset the newest activities now they're displayed
    514517                        newest_activities = '';
     
    521524                        link_id = target.parent().attr('id').split('-'),
    522525                        a_id    = link_id[3],
    523526                        type    = link_id[0], /* activity or acomment */
    524                         inner_class, a_inner;
    525 
     527                        inner_class, a_inner,
     528                        activity_wrapper;
     529                activity_wrapper = target.closest('div.activity');
    526530                inner_class = type === 'acomment' ? 'acomment-content' : 'activity-inner';
    527                 a_inner = jq('#' + type + '-' + a_id + ' .' + inner_class + ':first' );
     531                a_inner = jq('#' + type + '-' + a_id + ' .' + inner_class + ':first', activity_wrapper );
    528532                jq(target).addClass('loading');
    529533
    530534                jq.post( ajaxurl, {
     
    557561                        ajaxdata,
    558562                        ak_nonce,
    559563                        show_all_a, new_count,
    560                         link_href, comment_li, nonce;
     564                        link_href, comment_li, nonce,
     565                        activity_wrapper;
    561566
     567                        activity_wrapper = target.closest('div.activity');
     568
    562569                /* Comment / comment reply links */
    563570                if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) {
    564571                        if ( target.parent().hasClass('acomment-reply') ) {
     
    568575                        id  = target.attr('id');
    569576                        ids = id.split('-');
    570577
     578
    571579                        a_id = ids[2];
    572580                        c_id = target.attr('href').substr( 10, target.attr('href').length );
    573                         form = jq( '#ac-form-' + a_id );
     581                        form = jq( '#ac-form-' + a_id, activity_wrapper );
    574582
    575583                        form.css( 'display', 'none' );
    576584                        form.removeClass('root');
     
    584592                        });
    585593
    586594                        if ( ids[1] !== 'comment' ) {
    587                                 jq('#acomment-' + c_id).append( form );
     595                                jq('#acomment-' + c_id, activity_wrapper).append( form );
    588596                        } else {
    589                                 jq('#activity-' + a_id + ' .activity-comments').append( form );
     597                                jq('#activity-' + a_id + ' .activity-comments', activity_wrapper).append( form );
    590598                        }
    591599
    592600                        if ( form.parent().hasClass( 'activity-comments' ) ) {
     
    598606                                offset:-100,
    599607                                easing:'swing'
    600608                        } );
    601                         jq('#ac-form-' + ids[2] + ' textarea').focus();
     609                        jq('#ac-form-' + ids[2] + ' textarea', activity_wrapper).focus();
    602610
    603611                        return false;
    604612                }
     
    616624                                comment_id = form_id[2];
    617625                        }
    618626
    619                         content = jq( '#' + form.attr('id') + ' textarea' );
     627                        content = jq( '#' + form.attr('id') + ' textarea', activity_wrapper );
    620628
    621629                        /* Hide any error messages */
    622                         jq( '#' + form.attr('id') + ' div.error').hide();
     630                        jq( '#' + form.attr('id') + ' div.error', activity_wrapper).hide();
    623631                        target.addClass('loading').prop('disabled', true);
    624632                        content.addClass('loading').prop('disabled', true);
    625633
     
    663671                                                form.children('textarea').val('');
    664672                                                activity_comments.parent().addClass('has-comments');
    665673                                        } );
    666                                         jq( '#' + form.attr('id') + ' textarea').val('');
     674                                        jq( '#' + form.attr('id') + ' textarea', activity_wrapper).val('');
    667675
    668676                                        /* Increase the "Reply (X)" button count */
    669                                         jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
     677                                        jq('#activity-' + form_id[2] + ' a.acomment-reply span', activity_wrapper).html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span', activity_wrapper).html() ) + 1 );
    670678
    671679                                        // Increment the 'Show all x comments' string, if present
    672680                                        show_all_a = activity_comments.find('.show-all').find('a');
    673681                                        if ( show_all_a ) {
    674                                                 new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html();
     682                                                new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span', activity_wrapper).html();
    675683                                                show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
    676684                                        }
    677685                                }
     
    715723                                if ( response[0] + response[1] === '-1' ) {
    716724                                        comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
    717725                                } else {
    718                                         var children  = jq( '#' + comment_li.attr('id') + ' ul' ).children('li'),
     726                                        var children  = jq( '#' + comment_li.attr('id') + ' ul' , activity_wrapper).children('li'),
    719727                                                child_count = 0,
    720728                                                count_span, new_count, show_all_a;
    721729
     
    757765                        target.addClass('loading');
    758766
    759767                        // Remove any error messages
    760                         jq( '.activity-comments ul div.error' ).remove();
     768                        jq( '.activity-comments ul div.error', activity_wrapper ).remove();
    761769
    762770                        // Reset the form position
    763771                        comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) );
     
    775783                                        comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
    776784
    777785                                } else {
    778                                         var children  = jq( '#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' ),
     786                                        var children  = jq( '#' + comment_li.attr( 'id' ) + ' ul', activity_wrapper ).children( 'li' ),
    779787                                                child_count = 0,
    780788                                                parent_li;
    781789
     
    788796
    789797                                        // Decrease the "Reply (X)" button count
    790798                                        parent_li = comment_li.parents( '#activity-stream > li' );
    791                                         jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html( jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
     799                                        jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span', activity_wrapper ).html( jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
    792800                                }
    793801                        });
    794802
     
    19781986}
    19791987
    19801988/* Activity Loop Requesting */
    1981 function bp_activity_request(scope, filter) {
     1989function bp_activity_request(scope, filter, activity_wrapper) {
    19821990        /* Save the type and filter to a session cookie */
    19831991        if ( null !== scope ) {
    19841992                jq.cookie( 'bp-activity-scope', scope, {
     
    20242032        {
    20252033                jq('.widget_bp_activity_widget h2 span.ajax-loader').hide();
    20262034
    2027                 jq('div.activity').fadeOut( 100, function() {
     2035                jq('div.activity', activity_wrapper ).fadeOut( 100, function() {
    20282036                        jq(this).html(response.contents);
    20292037                        jq(this).fadeIn(100);
    20302038