Ticket #7400: activity_multiloop_js.diff
File activity_multiloop_js.diff, 11.3 KB (added by , 8 years ago) |
---|
-
src/bp-templates/bp-legacy/js/buddypress.js
116 116 var last_date_recorded = 0, 117 117 button = jq(this), 118 118 form = button.closest('form#whats-new-form'), 119 inputs = {}, post_data ;119 inputs = {}, post_data, activity_wrapper; 120 120 121 121 // Get all inputs and organize them into an object {name: value} 122 122 jq.each( form.serializeArray(), function( key, input ) { … … 148 148 form.addClass('submitted'); 149 149 150 150 /* Default POST values */ 151 activity_wrapper = jq(this).closest('div.activity'); 151 152 object = ''; 152 153 item_id = jq('#whats-new-post-in').val(); 153 154 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(); 155 156 activity_row = firstrow; 156 157 timestamp = null; 157 158 … … 197 198 form.prepend( response.substr( 2, response.length ) ); 198 199 jq( '#' + form.attr('id') + ' div.error').hide().fadeIn( 200 ); 199 200 } else { 200 if ( 0 === jq('ul.activity-list' ).length ) {201 if ( 0 === jq('ul.activity-list', activity_wrapper).length ) { 201 202 jq('div.error').slideUp(100).remove(); 202 203 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">' ); 204 205 } 205 206 206 207 if ( firstrow.hasClass( 'load-newest' ) ) { … … 207 208 firstrow.remove(); 208 209 } 209 210 210 jq('#activity-stream' ).prepend(response);211 jq('#activity-stream', activity_wrapper).prepend(response); 211 212 212 213 if ( ! last_date_recorded ) { 213 214 jq('#activity-stream li:first').addClass('new-update just-posted'); … … 255 256 /* List tabs event delegation */ 256 257 jq('div.activity-type-tabs').on( 'click', function(event) { 257 258 var target = jq(event.target).parent(), 258 scope, filter ;259 scope, filter, activity_wrapper; 259 260 260 261 if ( event.target.nodeName === 'STRONG' || event.target.nodeName === 'SPAN' ) { 261 262 target = target.parent(); … … 268 269 path: '/', 269 270 secure: ( 'https:' === window.location.protocol ) 270 271 } ); 272 activity_wrapper = jq(target).closest('div.activity'); 271 273 272 274 /* Activity Stream Tabs */ 273 275 scope = target.attr('id').substr( 9, target.attr('id').length ); … … 277 279 jq( '#' + target.attr('id') + ' a strong' ).remove(); 278 280 } 279 281 280 bp_activity_request(scope, filter );282 bp_activity_request(scope, filter, activity_wrapper); 281 283 282 284 return false; 283 285 }); … … 286 288 jq('#activity-filter-select select').change( function() { 287 289 var selected_tab = jq( 'div.activity-type-tabs li.selected' ), 288 290 filter = jq(this).val(), 289 scope ;291 scope, activity_wrapper; 290 292 291 293 if ( !selected_tab.length ) { 292 294 scope = null; … … 294 296 scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length ); 295 297 } 296 298 297 bp_activity_request(scope, filter); 299 activity_wrapper = jq(selected_tab).closest('div.activity'); 300 bp_activity_request(scope, filter, activity_wrapper); 298 301 299 302 return false; 300 303 }); … … 304 307 var target = jq(event.target), 305 308 type, parent, parent_id, 306 309 li, id, link_href, nonce, timestamp, 307 oldest_page, just_posted ;310 oldest_page, just_posted, activity_wrapper; 308 311 312 activity_wrapper = target.closest('div.activity'); 309 313 /* Favoriting activity stream items */ 310 314 if ( target.hasClass('fav') || target.hasClass('unfav') ) { 311 315 /* Bail if a request is in progress */ … … 318 322 parent_id = parent.attr('id').substr( 9, parent.attr('id').length ); 319 323 320 324 target.addClass('loading'); 321 322 325 jq.post( ajaxurl, { 323 326 action: 'activity_mark_' + type, 324 327 'cookie': bp_get_cookies(), … … 353 356 354 357 if ( !Number( jq('.item-list-tabs ul #activity-favorites span').html() ) ) { 355 358 if ( jq('.item-list-tabs ul #activity-favorites').hasClass('selected') ) { 356 bp_activity_request( null, null );359 bp_activity_request( null, null, activity_wrapper ); 357 360 } 358 361 359 362 jq('.item-list-tabs ul #activity-favorites').remove(); … … 440 443 bp_ajax_request.abort(); 441 444 } 442 445 443 jq('#buddypress li.load-more' ).addClass('loading');446 jq('#buddypress li.load-more', activity_wrapper).addClass('loading'); 444 447 445 448 if ( null === jq.cookie('bp-activity-oldestpage') ) { 446 449 jq.cookie('bp-activity-oldestpage', 1, { … … 452 455 oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1; 453 456 just_posted = []; 454 457 455 jq('.activity-list li.just-posted' ).each( function(){458 jq('.activity-list li.just-posted', activity_wrapper).each( function(){ 456 459 just_posted.push( jq(this).attr('id').replace( 'activity-','' ) ); 457 460 }); 458 461 … … 472 475 bp_ajax_request = jq.post( ajaxurl, load_more_args, 473 476 function(response) 474 477 { 475 jq('#buddypress li.load-more' ).removeClass('loading');478 jq('#buddypress li.load-more', activity_wrapper).removeClass('loading'); 476 479 jq.cookie( 'bp-activity-oldestpage', oldest_page, { 477 480 path: '/', 478 481 secure: ( 'https:' === window.location.protocol ) 479 482 } ); 480 jq('#buddypress ul.activity-list' ).append(response.contents);483 jq('#buddypress ul.activity-list', activity_wrapper).append(response.contents); 481 484 482 485 target.parent().hide(); 483 486 }, 'json' ); … … 508 511 } ); 509 512 510 513 // 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 ); 512 515 513 516 // reset the newest activities now they're displayed 514 517 newest_activities = ''; … … 521 524 link_id = target.parent().attr('id').split('-'), 522 525 a_id = link_id[3], 523 526 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'); 526 530 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 ); 528 532 jq(target).addClass('loading'); 529 533 530 534 jq.post( ajaxurl, { … … 557 561 ajaxdata, 558 562 ak_nonce, 559 563 show_all_a, new_count, 560 link_href, comment_li, nonce; 564 link_href, comment_li, nonce, 565 activity_wrapper; 561 566 567 activity_wrapper = target.closest('div.activity'); 568 562 569 /* Comment / comment reply links */ 563 570 if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) { 564 571 if ( target.parent().hasClass('acomment-reply') ) { … … 568 575 id = target.attr('id'); 569 576 ids = id.split('-'); 570 577 578 571 579 a_id = ids[2]; 572 580 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 ); 574 582 575 583 form.css( 'display', 'none' ); 576 584 form.removeClass('root'); … … 584 592 }); 585 593 586 594 if ( ids[1] !== 'comment' ) { 587 jq('#acomment-' + c_id ).append( form );595 jq('#acomment-' + c_id, activity_wrapper).append( form ); 588 596 } else { 589 jq('#activity-' + a_id + ' .activity-comments' ).append( form );597 jq('#activity-' + a_id + ' .activity-comments', activity_wrapper).append( form ); 590 598 } 591 599 592 600 if ( form.parent().hasClass( 'activity-comments' ) ) { … … 598 606 offset:-100, 599 607 easing:'swing' 600 608 } ); 601 jq('#ac-form-' + ids[2] + ' textarea' ).focus();609 jq('#ac-form-' + ids[2] + ' textarea', activity_wrapper).focus(); 602 610 603 611 return false; 604 612 } … … 616 624 comment_id = form_id[2]; 617 625 } 618 626 619 content = jq( '#' + form.attr('id') + ' textarea' );627 content = jq( '#' + form.attr('id') + ' textarea', activity_wrapper ); 620 628 621 629 /* Hide any error messages */ 622 jq( '#' + form.attr('id') + ' div.error' ).hide();630 jq( '#' + form.attr('id') + ' div.error', activity_wrapper).hide(); 623 631 target.addClass('loading').prop('disabled', true); 624 632 content.addClass('loading').prop('disabled', true); 625 633 … … 663 671 form.children('textarea').val(''); 664 672 activity_comments.parent().addClass('has-comments'); 665 673 } ); 666 jq( '#' + form.attr('id') + ' textarea' ).val('');674 jq( '#' + form.attr('id') + ' textarea', activity_wrapper).val(''); 667 675 668 676 /* 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 ); 670 678 671 679 // Increment the 'Show all x comments' string, if present 672 680 show_all_a = activity_comments.find('.show-all').find('a'); 673 681 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(); 675 683 show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) ); 676 684 } 677 685 } … … 715 723 if ( response[0] + response[1] === '-1' ) { 716 724 comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) ); 717 725 } 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'), 719 727 child_count = 0, 720 728 count_span, new_count, show_all_a; 721 729 … … 757 765 target.addClass('loading'); 758 766 759 767 // Remove any error messages 760 jq( '.activity-comments ul div.error' ).remove();768 jq( '.activity-comments ul div.error', activity_wrapper ).remove(); 761 769 762 770 // Reset the form position 763 771 comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) ); … … 775 783 comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) ); 776 784 777 785 } 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' ), 779 787 child_count = 0, 780 788 parent_li; 781 789 … … 788 796 789 797 // Decrease the "Reply (X)" button count 790 798 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 ) ); 792 800 } 793 801 }); 794 802 … … 1978 1986 } 1979 1987 1980 1988 /* Activity Loop Requesting */ 1981 function bp_activity_request(scope, filter ) {1989 function bp_activity_request(scope, filter, activity_wrapper) { 1982 1990 /* Save the type and filter to a session cookie */ 1983 1991 if ( null !== scope ) { 1984 1992 jq.cookie( 'bp-activity-scope', scope, { … … 2024 2032 { 2025 2033 jq('.widget_bp_activity_widget h2 span.ajax-loader').hide(); 2026 2034 2027 jq('div.activity' ).fadeOut( 100, function() {2035 jq('div.activity', activity_wrapper ).fadeOut( 100, function() { 2028 2036 jq(this).html(response.contents); 2029 2037 jq(this).fadeIn(100); 2030 2038