1// AJAX Functions 2var jq = jQuery; 3 4// Global variable to prevent multiple AJAX requests 5var bp_ajax_request = null; 6 7jq(document).ready( function() { 8 /**** Page Load Actions *******************************************************/ 9 10 /* Hide Forums Post Form */ 11 if ( '-1' == window.location.search.indexOf('new') && jq('div.forums').length ) 12 jq('#new-topic-post').hide(); 13 else 14 jq('#new-topic-post').show(); 15 16 /* Activity filter and scope set */ 17 bp_init_activity(); 18 19 /* Object filter and scope set. */ 20 var objects = [ 'members', 'groups', 'blogs', 'forums' ], 21 $whats_new = jq('#whats-new'); 22 23 bp_init_objects( objects ); 24 25 /* @mention Compose Scrolling */ 26 if ( $whats_new.length && bp_get_querystring('r') ) { 27 var $member_nicename = $whats_new.val(); 28 29 jq('#whats-new-options').animate({ 30 height:'40px' 31 }); 32 33 $whats_new.animate({ 34 height:'50px' 35 }); 36 37 jq.scrollTo( $whats_new, 500, { 38 offset:-125, 39 easing:'swing' 40 } ); 41 42 $whats_new.val('').focus().val( $member_nicename ); 43 } 44 45 /**** Activity Posting ********************************************************/ 46 47 /* Textarea focus */ 48 jq('#whats-new').focus( function(){ 49 jq("#whats-new-options").animate({ 50 height:'40px' 51 }); 52 jq("form#whats-new-form textarea").animate({ 53 height:'50px' 54 }); 55 jq("#aw-whats-new-submit").prop("disabled", false); 56 57 var $whats_new_form = jq("form#whats-new-form"); 58 if ( $whats_new_form.hasClass("submitted") ) { 59 $whats_new_form.removeClass("submitted"); 60 } 61 }); 62 63 /* On blur, shrink if it's empty */ 64 jq('#whats-new').blur( function(){ 65 if (!this.value.match(/\S+/)) { 66 this.value = ""; 67 jq("#whats-new-options").animate({ 68 height:'40px' 69 }); 70 jq("form#whats-new-form textarea").animate({ 71 height:'20px' 72 }); 73 jq("#aw-whats-new-submit").prop("disabled", true); 74 } 75 }); 76 77 /* New posts */ 78 jq("input#aw-whats-new-submit").click( function() { 79 var button = jq(this); 80 var form = button.closest("form#whats-new-form"); 81 82 form.children().each( function() { 83 if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) 84 jq(this).prop( 'disabled', true ); 85 }); 86 87 /* Remove any errors */ 88 jq('div.error').remove(); 89 button.addClass('loading'); 90 button.prop('disabled', true); 91 form.addClass("submitted"); 92 93 /* Default POST values */ 94 var object = ''; 95 var item_id = jq("#whats-new-post-in").val(); 96 var content = jq("textarea#whats-new").val(); 97 98 /* Set object for non-profile posts */ 99 if ( item_id > 0 ) { 100 object = jq("#whats-new-post-object").val(); 101 } 102 103 jq.post( ajaxurl, { 104 action: 'post_update', 105 'cookie': bp_get_cookies(), 106 '_wpnonce_post_update': jq("input#_wpnonce_post_update").val(), 107 'content': content, 108 'object': object, 109 'item_id': item_id, 110 '_bp_as_nonce': jq('#_bp_as_nonce').val() || '' 111 }, 112 function(response) { 113 114 form.children().each( function() { 115 if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) { 116 jq(this).prop( 'disabled', false ); 117 } 118 }); 119 120 /* Check for errors and append if found. */ 121 if ( response[0] + response[1] == '-1' ) { 122 form.prepend( response.substr( 2, response.length ) ); 123 jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 ); 124 } else { 125 if ( 0 == jq("ul.activity-list").length ) { 126 jq("div.error").slideUp(100).remove(); 127 jq("div#message").slideUp(100).remove(); 128 jq("div.activity").append( '<ul id="activity-stream" class="activity-list item-list">' ); 129 } 130 131 jq("ul#activity-stream").prepend(response); 132 jq("ul#activity-stream li:first").addClass('new-update just-posted'); 133 134 if ( 0 != jq("#latest-update").length ) { 135 var l = jq("ul#activity-stream li.new-update .activity-content .activity-inner p").html(); 136 var v = jq("ul#activity-stream li.new-update .activity-content .activity-header p a.view").attr('href'); 137 138 var ltext = jq("ul#activity-stream li.new-update .activity-content .activity-inner p").text(); 139 140 var u = ''; 141 if ( ltext != '' ) 142 u = l + ' '; 143 144 u += '<a href="' + v + '" rel="nofollow">' + BP_DTheme.view + '</a>'; 145 146 jq("#latest-update").slideUp(300,function(){ 147 jq("#latest-update").html( u ); 148 jq("#latest-update").slideDown(300); 149 }); 150 } 151 152 jq("li.new-update").hide().slideDown( 300 ); 153 jq("li.new-update").removeClass( 'new-update' ); 154 jq("textarea#whats-new").val(''); 155 } 156 157 jq("#whats-new-options").animate({ 158 height:'0px' 159 }); 160 jq("form#whats-new-form textarea").animate({ 161 height:'20px' 162 }); 163 jq("#aw-whats-new-submit").prop("disabled", true).removeClass('loading'); 164 }); 165 166 return false;
167 }); 168 169 /* List tabs event delegation */ 170 jq('div.activity-type-tabs').click( function(event) { 171 var target = jq(event.target).parent(); 172 173 if ( event.target.nodeName == 'STRONG' || event.target.nodeName == 'SPAN' ) 174 target = target.parent(); 175 else if ( event.target.nodeName != 'A' ) 176 return false; 177 178 /* Reset the page */ 179 jq.cookie( 'bp-activity-oldestpage', 1, { 180 path: '/' 181 } ); 182 183 /* Activity Stream Tabs */ 184 var scope = target.attr('id').substr( 9, target.attr('id').length ); 185 var filter = jq("#activity-filter-select select").val(); 186 187 if ( scope == 'mentions' ) 188 jq( 'li#' + target.attr('id') + ' a strong' ).remove(); 189 190 bp_activity_request(scope, filter); 191 192 return false; 193 }); 194 195 /* Activity filter select */ 196 jq('#activity-filter-select select').change( function() { 197 var selected_tab = jq( 'div.activity-type-tabs li.selected' ); 198 199 if ( !selected_tab.length ) 200 var scope = null; 201 else 202 var scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length ); 203 204 var filter = jq(this).val(); 205 206 bp_activity_request(scope, filter); 207 208 return false; 209 }); 210 211 /* Stream event delegation */ 212 jq('div.activity').click( function(event) { 213 var target = jq(event.target); 214 215 /* Favoriting activity stream items */ 216 if ( target.hasClass('fav') || target.hasClass('unfav') ) { 217 var type = target.hasClass('fav') ? 'fav' : 'unfav'; 218 var parent = target.closest('.activity-item'); 219 var parent_id = parent.attr('id').substr( 9, parent.attr('id').length ); 220 221 target.addClass('loading'); 222 223 jq.post( ajaxurl, { 224 action: 'activity_mark_' + type, 225 'cookie': bp_get_cookies(), 226 'id': parent_id 227 }, 228 function(response) { 229 target.removeClass('loading'); 230 231 target.fadeOut( 100, function() { 232 jq(this).html(response); 233 jq(this).attr('title', 'fav' == type ? BP_DTheme.remove_fav : BP_DTheme.mark_as_fav); 234 jq(this).fadeIn(100); 235 }); 236 237 if ( 'fav' == type ) { 238 if ( !jq('.item-list-tabs li#activity-favorites').length ) 239 jq('.item-list-tabs ul li#activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' <span>0</span></a></li>'); 240 241 target.removeClass('fav'); 242 target.addClass('unfav'); 243 244 jq('.item-list-tabs ul li#activity-favorites span').html( Number( jq('.item-list-tabs ul li#activity-favorites span').html() ) + 1 ); 245 } else { 246 target.removeClass('unfav'); 247 target.addClass('fav'); 248 249 jq('.item-list-tabs ul li#activity-favorites span').html( Number( jq('.item-list-tabs ul li#activity-favorites span').html() ) - 1 ); 250 251 if ( !Number( jq('.item-list-tabs ul li#activity-favorites span').html() ) ) { 252 if ( jq('.item-list-tabs ul li#activity-favorites').hasClass('selected') ) 253 bp_activity_request( null, null ); 254 255 jq('.item-list-tabs ul li#activity-favorites').remove(); 256 } 257 } 258 259 if ( 'activity-favorites' == jq( '.item-list-tabs li.selected').attr('id') ) 260 target.parent().parent().parent().slideUp(100); 261 }); 262 263 return false; 264 } 265 266 /* Delete activity stream items */ 267 if ( target.hasClass('delete-activity') ) { 268 var li = target.parents('div.activity ul li'); 269 var id = li.attr('id').substr( 9, li.attr('id').length ); 270 var link_href = target.attr('href'); 271 var nonce = link_href.split('_wpnonce='); 272 273 nonce = nonce[1]; 274 275 target.addClass('loading'); 276 277 jq.post( ajaxurl, { 278 action: 'delete_activity', 279 'cookie': bp_get_cookies(), 280 'id': id, 281 '_wpnonce': nonce 282 }, 283 function(response) { 284 285 if ( response[0] + response[1] == '-1' ) { 286 li.prepend( response.substr( 2, response.length ) ); 287 li.children('div#message').hide().fadeIn(300); 288 } else { 289 li.slideUp(300); 290 } 291 }); 292 293 return false; 294 } 295 296 // Spam activity stream items 297 if ( target.hasClass( 'spam-activity' ) ) { 298 var li = target.parents( 'div.activity ul li' ); 299 target.addClass( 'loading' ); 300 301 jq.post( ajaxurl, { 302 action: 'bp_spam_activity', 303 'cookie': encodeURIComponent( document.cookie ), 304 'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ), 305 '_wpnonce': target.attr( 'href' ).split( '_wpnonce=' )[1] 306 }, 307 308 function(response) { 309 if ( response[0] + response[1] === '-1' ) { 310 li.prepend( response.substr( 2, response.length ) ); 311 li.children( 'div#message' ).hide().fadeIn(300); 312 } else { 313 li.slideUp( 300 ); 314 } 315 }); 316 317 return false;
318 } 319 320 /* Load more updates at the end of the page */ 321 if ( target.parent().hasClass('load-more') ) { 322 jq("#content li.load-more").addClass('loading'); 323 324 if ( null == jq.cookie('bp-activity-oldestpage') ) 325 jq.cookie('bp-activity-oldestpage', 1, { 326 path: '/' 327 } ); 328 329 var oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1; 330 331 var just_posted = []; 332 333 jq('.activity-list li.just-posted').each( function(){ 334 just_posted.push( jq(this).attr('id').replace( 'activity-','' ) ); 335 }); 336 337 jq.post( ajaxurl, { 338 action: 'activity_get_older_updates', 339 'cookie': bp_get_cookies(), 340 'page': oldest_page, 341 'exclude_just_posted': just_posted.join(',') 342 }, 343 function(response) 344 { 345 jq("#content li.load-more").removeClass('loading'); 346 jq.cookie( 'bp-activity-oldestpage', oldest_page, { 347 path: '/' 348 } ); 349 jq("#content ul.activity-list").append(response.contents); 350 351 target.parent().hide(); 352 }, 'json' ); 353 354 return false; 355 } 356 }); 357 358 // Activity "Read More" links 359 jq('div.activity').on('click', '.activity-read-more a', function(event) { 360 var target = jq(event.target); 361 var link_id = target.parent().attr('id').split('-'); 362 var a_id = link_id[3]; 363 var type = link_id[0]; /* activity or acomment */ 364 365 var inner_class = type == 'acomment' ? 'acomment-content' : 'activity-inner'; 366 var a_inner = jq('li#' + type + '-' + a_id + ' .' + inner_class + ':first' ); 367 jq(target).addClass('loading'); 368 369 jq.post( ajaxurl, { 370 action: 'get_single_activity_content', 371 'activity_id': a_id 372 }, 373 function(response) { 374 jq(a_inner).slideUp(300).html(response).slideDown(300); 375 }); 376 377 return false; 378 }); 379 380 /**** Activity Comments *******************************************************/ 381 382 /* Hide all activity comment forms */ 383 jq('form.ac-form').hide(); 384 385 /* Hide excess comments */ 386 if ( jq('.activity-comments').length ) 387 bp_dtheme_hide_comments(); 388 389 /* Activity list event delegation */ 390 jq('div.activity').click( function(event) { 391 var target = jq(event.target); 392 393 /* Comment / comment reply links */ 394 if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) { 395 if ( target.parent().hasClass('acomment-reply') ) 396 target = target.parent(); 397 398 var id = target.attr('id'); 399 ids = id.split('-'); 400 401 var a_id = ids[2] 402 var c_id = target.attr('href').substr( 10, target.attr('href').length ); 403 var form = jq( '#ac-form-' + a_id ); 404 405 form.css( 'display', 'none' ); 406 form.removeClass('root'); 407 jq('.ac-form').hide(); 408 409 /* Hide any error messages */ 410 form.children('div').each( function() { 411 if ( jq(this).hasClass( 'error' ) ) 412 jq(this).hide(); 413 }); 414 415 if ( ids[1] != 'comment' ) { 416 jq('.activity-comments li#acomment-' + c_id).append( form ); 417 } else { 418 jq('li#activity-' + a_id + ' .activity-comments').append( form ); 419 } 420 421 if ( form.parent().hasClass( 'activity-comments' ) ) 422 form.addClass('root'); 423 424 form.slideDown( 200 ); 425 jq.scrollTo( form, 500, { 426 offset:-100, 427 easing:'swing' 428 } ); 429 jq('#ac-form-' + ids[2] + ' textarea').focus(); 430 431 return false; 432 } 433 434 /* Activity comment posting */ 435 if ( target.attr('name') == 'ac_form_submit' ) { 436 var form = target.parents( 'form' ); 437 var form_parent = form.parent(); 438 var form_id = form.attr('id').split('-'); 439 440 if ( !form_parent.hasClass('activity-comments') ) { 441 var tmp_id = form_parent.attr('id').split('-'); 442 var comment_id = tmp_id[1]; 443 } else { 444 var comment_id = form_id[2]; 445 } 446 447 /* Hide any error messages */ 448 jq( 'form#' + form.attr('id') + ' div.error').hide(); 449 target.addClass('loading').prop('disabled', true); 450 451 var ajaxdata = { 452 action: 'new_activity_comment', 453 'cookie': bp_get_cookies(), 454 '_wpnonce_new_activity_comment': jq("input#_wpnonce_new_activity_comment").val(), 455 'comment_id': comment_id, 456 'form_id': form_id[2], 457 'content': jq('form#' + form.attr('id') + ' textarea').val() 458 }; 459 460 // Akismet 461 var ak_nonce = jq('#_bp_as_nonce_' + comment_id).val(); 462 if ( ak_nonce ) { 463 ajaxdata['_bp_as_nonce_' + comment_id] = ak_nonce; 464 } 465
466 jq.post( ajaxurl, ajaxdata, function(response) { 467 target.removeClass('loading'); 468 469 /* Check for errors and append if found. */ 470 if ( response[0] + response[1] == '-1' ) { 471 form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) ); 472 } else { 473 var activity_comments = form.parent(); 474 form.fadeOut( 200, function() { 475 if ( 0 == activity_comments.children('ul').length ) { 476 if ( activity_comments.hasClass('activity-comments') ) { 477 activity_comments.prepend('<ul></ul>'); 478 } else { 479 activity_comments.append('<ul></ul>'); 480 } 481 } 482 483 /* Preceeding whitespace breaks output with jQuery 1.9.0 */ 484 var the_comment = jq.trim( response ); 485 486 activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) ); 487 form.children('textarea').val(''); 488 activity_comments.parent().addClass('has-comments'); 489 } ); 490 491 jq( 'form#' + form.attr('id') + ' textarea').val(''); 492 493 /* Increase the "Reply (X)" button count */ 494 jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 ); 495 496 // Increment the 'Show all x comments' string, if present 497 var show_all_a = activity_comments.find('.show-all').find('a'); 498 if ( show_all_a ) { 499 var new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html(); 500 show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) ); 501 } 502 } 503 504 jq(target).prop("disabled", false); 505 }); 506 507 return false; 508 } 509 510 /* Deleting an activity comment */ 511 if ( target.hasClass('acomment-delete') ) { 512 var link_href = target.attr('href'); 513 var comment_li = target.parent().parent(); 514 var form = comment_li.parents('div.activity-comments').children('form'); 515 516 var nonce = link_href.split('_wpnonce='); 517 nonce = nonce[1]; 518 519 var comment_id = link_href.split('cid='); 520 comment_id = comment_id[1].split('&'); 521 comment_id = comment_id[0]; 522 523 target.addClass('loading'); 524 525 /* Remove any error messages */ 526 jq('.activity-comments ul .error').remove(); 527 528 /* Reset the form position */ 529 comment_li.parents('.activity-comments').append(form); 530 531 jq.post( ajaxurl, { 532 action: 'delete_activity_comment', 533 'cookie': bp_get_cookies(), 534 '_wpnonce': nonce, 535 'id': comment_id 536 }, 537 function(response) 538 { 539 /* Check for errors and append if found. */ 540 if ( response[0] + response[1] == '-1' ) { 541 comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) ); 542 } else { 543 var children = jq( 'li#' + comment_li.attr('id') + ' ul' ).children('li'); 544 var child_count = 0; 545 jq(children).each( function() { 546 if ( !jq(this).is(':hidden') ) 547 child_count++; 548 }); 549 comment_li.fadeOut(200, function() { 550 comment_li.remove(); 551 }); 552 553 /* Decrease the "Reply (X)" button count */ 554 var count_span = jq('li#' + comment_li.parents('ul#activity-stream > li').attr('id') + ' a.acomment-reply span'); 555 var new_count = count_span.html() - ( 1 + child_count ); 556 count_span.html(new_count); 557 558 // Change the 'Show all x comments' text 559 var show_all_a = comment_li.siblings('.show-all').find('a'); 560 if ( show_all_a ) { 561 show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) ); 562 } 563 564 /* If that was the last comment for the item, remove the has-comments class to clean up the styling */ 565 if ( 0 == new_count ) { 566 jq(comment_li.parents('ul#activity-stream > li')).removeClass('has-comments'); 567 } 568 } 569 }); 570 571 return false; 572 } 573 574 // Spam an activity stream comment 575 if ( target.hasClass( 'spam-activity-comment' ) ) { 576 var link_href = target.attr( 'href' ); 577 var comment_li = target.parent().parent(); 578 579 target.addClass('loading'); 580 581 // Remove any error messages 582 jq( '.activity-comments ul div.error' ).remove(); 583 584 // Reset the form position 585 comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) ); 586 587 jq.post( ajaxurl, { 588 action: 'bp_spam_activity_comment',
589 'cookie': encodeURIComponent( document.cookie ), 590 '_wpnonce': link_href.split( '_wpnonce=' )[1], 591 'id': link_href.split( 'cid=' )[1].split( '&' )[0] 592 }, 593 594 function ( response ) { 595 // Check for errors and append if found. 596 if ( response[0] + response[1] == '-1' ) { 597 comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) ); 598 599 } else { 600 var children = jq( 'li#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' ); 601 var child_count = 0; 602 jq(children).each( function() { 603 if ( !jq( this ).is( ':hidden' ) ) { 604 child_count++; 605 } 606 }); 607 comment_li.fadeOut( 200 ); 608 609 // Decrease the "Reply (X)" button count 610 var parent_li = comment_li.parents( 'ul#activity-stream > li' ); 611 jq( 'li#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html( jq( 'li#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) ); 612 } 613 }); 614 615 return false; 616 } 617 618 /* Showing hidden comments - pause for half a second */ 619 if ( target.parent().hasClass('show-all') ) { 620 target.parent().addClass('loading'); 621 622 setTimeout( function() { 623 target.parent().parent().children('li').fadeIn(200, function() { 624 target.parent().remove(); 625 }); 626 }, 600 ); 627 628 return false; 629 } 630 }); 631 632 /* Escape Key Press for cancelling comment forms */ 633 jq(document).keydown( function(e) { 634 e = e || window.event; 635 if (e.target) 636 element = e.target; 637 else if (e.srcElement) 638 element = e.srcElement; 639 640 if( element.nodeType == 3) 641 element = element.parentNode; 642 643 if( e.ctrlKey == true || e.altKey == true || e.metaKey == true ) 644 return; 645 646 var keyCode = (e.keyCode) ? e.keyCode : e.which; 647 648 if ( keyCode == 27 ) { 649 if (element.tagName == 'TEXTAREA') { 650 if ( jq(element).hasClass('ac-input') ) 651 jq(element).parent().parent().parent().slideUp( 200 ); 652 } 653 } 654 }); 655 656 /**** Directory Search ****************************************************/ 657 658 /* The search form on all directory pages */ 659 jq('.dir-search').click( function(event) { 660 if ( jq(this).hasClass('no-ajax') ) 661 return; 662 663 var target = jq(event.target); 664 665 if ( target.attr('type') == 'submit' ) { 666 var css_id = jq('.item-list-tabs li.selected').attr('id').split( '-' ); 667 var object = css_id[0]; 668 669 bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope') , 'div.' + object, target.parent().children('label').children('input').val(), 1, jq.cookie('bp-' + object + '-extras') ); 670 671 return false; 672 } 673 }); 674 675 /**** Tabs and Filters ****************************************************/ 676 677 /* When a navigation tab is clicked - e.g. | All Groups | My Groups | */ 678 jq('div.item-list-tabs').click( function(event) { 679 if ( jq(this).hasClass('no-ajax') ) 680 return; 681 682 var targetElem = ( event.target.nodeName == 'SPAN' ) ? event.target.parentNode : event.target; 683 var target = jq( targetElem ).parent(); 684 if ( 'LI' == target[0].nodeName && !target.hasClass('last') ) { 685 var css_id = target.attr('id').split( '-' ); 686 var object = css_id[0]; 687 688 if ( 'activity' == object ) 689 return false; 690 691 var scope = css_id[1]; 692 var filter = jq("#" + object + "-order-select select").val(); 693 var search_terms = jq("#" + object + "_search").val(); 694 695 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') ); 696 697 return false; 698 } 699 }); 700 701 /* When the filter select box is changed re-query */ 702 jq('li.filter select').change( function() { 703 if ( jq('.item-list-tabs li.selected').length ) 704 var el = jq('.item-list-tabs li.selected'); 705 else 706 var el = jq(this); 707 708 var css_id = el.attr('id').split('-'); 709 var object = css_id[0]; 710 var scope = css_id[1]; 711 var filter = jq(this).val(); 712 var search_terms = false; 713 714 if ( jq('.dir-search input').length ) 715 search_terms = jq('.dir-search input').val(); 716 717 if ( 'friends' == object ) 718 object = 'members'; 719 720 bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') ); 721 722 return false; 723 }); 724 725 /* All pagination links run through this function */ 726 jq('div#content').click( function(event) { 727 var target = jq(event.target); 728 729 if ( target.hasClass('button') ) 730 return true; 731 732 if ( target.parent().parent().hasClass('pagination') && !target.parent().parent().hasClass('no-ajax') ) { 733 if ( target.hasClass('dots') || target.hasClass('current') ) 734 return false;
735 736 if ( jq('.item-list-tabs li.selected').length ) 737 var el = jq('.item-list-tabs li.selected'); 738 else 739 var el = jq('li.filter select'); 740 741 var page_number = 1; 742 var css_id = el.attr('id').split( '-' ); 743 var object = css_id[0]; 744 var search_terms = false; 745 var pagination_id = jq(target).closest('.pagination-links').attr('id'); 746 747 if ( jq('div.dir-search input').length ) 748 search_terms = jq('.dir-search input').val(); 749 750 if ( jq(target).hasClass('next') ) 751 var page_number = Number( jq('.pagination span.current').html() ) + 1; 752 else if ( jq(target).hasClass('prev') ) 753 var page_number = Number( jq('.pagination span.current').html() ) - 1; 754 else 755 var page_number = Number( jq(target).html() ); 756 757 if ( pagination_id.indexOf( 'pag-bottom' ) !== -1 ) { 758 var caller = 'pag-bottom'; 759 } else { 760 var caller = null; 761 } 762 763 bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras'), caller ); 764 765 return false; 766 } 767 768 }); 769 770 /**** New Forum Directory Post **************************************/ 771 772 /* Hit the "New Topic" button on the forums directory page */ 773 jq('a.show-hide-new').click( function() { 774 if ( !jq('#new-topic-post').length ) 775 return false; 776 777 if ( jq('#new-topic-post').is(":visible") ) 778 jq('#new-topic-post').slideUp(200); 779 else 780 jq('#new-topic-post').slideDown(200, function() { 781 jq('#topic_title').focus(); 782 } ); 783 784 return false; 785 }); 786 787 /* Cancel the posting of a new forum topic */ 788 jq('input#submit_topic_cancel').click( function() { 789 if ( !jq('#new-topic-post').length ) 790 return false; 791 792 jq('#new-topic-post').slideUp(200); 793 return false; 794 }); 795 796 /* Clicking a forum tag */ 797 jq('#forum-directory-tags a').click( function() { 798 bp_filter_request( 'forums', 'tags', jq.cookie('bp-forums-scope'), 'div.forums', jq(this).html().replace( / /g, '-' ), 1, jq.cookie('bp-forums-extras') ); 799 return false; 800 }); 801 802 /** Invite Friends Interface ****************************************/ 803 804 /* Select a user from the list of friends and add them to the invite list */ 805 jq("div#invite-list input").click( function() { 806 jq('.ajax-loader').toggle(); 807 808 var friend_id = jq(this).val(); 809 810 if ( jq(this).prop('checked') == true ) 811 var friend_action = 'invite'; 812 else 813 var friend_action = 'uninvite'; 814 815 jq('.item-list-tabs li.selected').addClass('loading'); 816 817 jq.post( ajaxurl, { 818 action: 'groups_invite_user', 819 'friend_action': friend_action, 820 'cookie': bp_get_cookies(), 821 '_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(), 822 'friend_id': friend_id, 823 'group_id': jq("input#group_id").val() 824 }, 825 function(response) 826 { 827 if ( jq("#message") ) 828 jq("#message").hide(); 829 830 jq('.ajax-loader').toggle(); 831 832 if ( friend_action == 'invite' ) { 833 jq('#friend-list').append(response); 834 } else if ( friend_action == 'uninvite' ) { 835 jq('#friend-list li#uid-' + friend_id).remove(); 836 } 837 838 jq('.item-list-tabs li.selected').removeClass('loading'); 839 }); 840 }); 841 842 /* Remove a user from the list of users to invite to a group */ 843 jq("#friend-list").on('click', 'li a.remove', function() { 844 jq('.ajax-loader').toggle(); 845 846 var friend_id = jq(this).attr('id'); 847 friend_id = friend_id.split('-'); 848 friend_id = friend_id[1]; 849 850 jq.post( ajaxurl, { 851 action: 'groups_invite_user', 852 'friend_action': 'uninvite', 853 'cookie': bp_get_cookies(), 854 '_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(), 855 'friend_id': friend_id, 856 'group_id': jq("input#group_id").val() 857 }, 858 function(response) 859 { 860 jq('.ajax-loader').toggle(); 861 jq('#friend-list li#uid-' + friend_id).remove(); 862 jq('#invite-list input#f-' + friend_id).prop('checked', false); 863 }); 864 865 return false; 866 }); 867 868 /** Profile Visibility Settings *********************************/ 869 jq('.field-visibility-settings').hide(); 870 jq( '.visibility-toggle-link' ).on( 'click', function( event ) { 871 event.preventDefault(); 872 873 jq( this ).parent().hide().addClass( 'field-visibility-settings-hide' ) 874 .siblings( '.field-visibility-settings' ).show().addClass( 'field-visibility-settings-open' ); 875 } ); 876 877 jq( '.field-visibility-settings-close' ).on( 'click', function( event ) { 878 event.preventDefault(); 879 880 var settings_div = jq( this ).parent(),
881 vis_setting_text = settings_div.find( 'input:checked' ).parent().text(); 882 883 settings_div.hide().removeClass( 'field-visibility-settings-open' ) 884 .siblings( '.field-visibility-settings-toggle' ) 885 .children( '.current-visibility-level' ).text( vis_setting_text ).end() 886 .show().removeClass( 'field-visibility-settings-hide' ); 887 } ); 888 889 jq("#profile-edit-form input:not(:submit), #profile-edit-form textarea, #profile-edit-form select, #signup_form input:not(:submit), #signup_form textarea, #signup_form select").change( function() { 890 var shouldconfirm = true; 891 892 jq('#profile-edit-form input:submit, #signup_form input:submit').on( 'click', function() { 893 shouldconfirm = false; 894 }); 895 896 window.onbeforeunload = function(e) { 897 if ( shouldconfirm ) { 898 return BP_DTheme.unsaved_changes; 899 } 900 }; 901 }); 902 903 /** Friendship Requests **************************************/ 904 905 /* Accept and Reject friendship request buttons */ 906 jq("ul#friend-list a.accept, ul#friend-list a.reject").click( function() { 907 var button = jq(this); 908 var li = jq(this).parents('ul#friend-list li'); 909 var action_div = jq(this).parents('li div.action'); 910 911 var id = li.attr('id').substr( 11, li.attr('id').length ); 912 var link_href = button.attr('href'); 913 914 var nonce = link_href.split('_wpnonce='); 915 nonce = nonce[1]; 916 917 if ( jq(this).hasClass('accepted') || jq(this).hasClass('rejected') ) 918 return false; 919 920 if ( jq(this).hasClass('accept') ) { 921 var action = 'accept_friendship'; 922 action_div.children('a.reject').css( 'visibility', 'hidden' ); 923 } else { 924 var action = 'reject_friendship'; 925 action_div.children('a.accept').css( 'visibility', 'hidden' ); 926 } 927 928 button.addClass('loading'); 929 930 jq.post( ajaxurl, { 931 action: action, 932 'cookie': bp_get_cookies(), 933 'id': id, 934 '_wpnonce': nonce 935 }, 936 function(response) { 937 button.removeClass('loading'); 938 939 if ( response[0] + response[1] == '-1' ) { 940 li.prepend( response.substr( 2, response.length ) ); 941 li.children('div#message').hide().fadeIn(200); 942 } else { 943 button.fadeOut( 100, function() { 944 if ( jq(this).hasClass('accept') ) { 945 action_div.children('a.reject').hide(); 946 jq(this).html( BP_DTheme.accepted ).contents().unwrap(); 947 } else { 948 action_div.children('a.accept').hide(); 949 jq(this).html( BP_DTheme.rejected ).contents().unwrap(); 950 } 951 }); 952 } 953 }); 954 955 return false; 956 }); 957 958 /* Add / Remove friendship buttons */ 959 jq('#members-dir-list').on('click', '.friendship-button a', function() { 960 jq(this).parent().addClass('loading'); 961 var fid = jq(this).attr('id'); 962 fid = fid.split('-'); 963 fid = fid[1]; 964 965 var nonce = jq(this).attr('href'); 966 nonce = nonce.split('?_wpnonce='); 967 nonce = nonce[1].split('&'); 968 nonce = nonce[0]; 969 970 var thelink = jq(this); 971 972 jq.post( ajaxurl, { 973 action: 'addremove_friend', 974 'cookie': bp_get_cookies(), 975 'fid': fid, 976 '_wpnonce': nonce 977 }, 978 function(response) 979 { 980 var action = thelink.attr('rel'); 981 var parentdiv = thelink.parent(); 982 983 if ( action == 'add' ) { 984 jq(parentdiv).fadeOut(200, 985 function() { 986 parentdiv.removeClass('add_friend'); 987 parentdiv.removeClass('loading'); 988 parentdiv.addClass('pending_friend'); 989 parentdiv.fadeIn(200).html(response); 990 } 991 ); 992 993 } else if ( action == 'remove' ) { 994 jq(parentdiv).fadeOut(200, 995 function() { 996 parentdiv.removeClass('remove_friend'); 997 parentdiv.removeClass('loading'); 998 parentdiv.addClass('add'); 999 parentdiv.fadeIn(200).html(response); 1000 } 1001 ); 1002 } 1003 }); 1004 return false; 1005 } ); 1006 1007 /** Group Join / Leave Buttons **************************************/ 1008 1009 jq('#groups-dir-list').on('click', '.group-button a', function() { 1010 var gid = jq(this).parent().attr('id'); 1011 gid = gid.split('-'); 1012 gid = gid[1]; 1013 1014 var nonce = jq(this).attr('href'); 1015 nonce = nonce.split('?_wpnonce='); 1016 nonce = nonce[1].split('&'); 1017 nonce = nonce[0]; 1018 1019 var thelink = jq(this); 1020 1021 jq.post( ajaxurl, { 1022 action: 'joinleave_group', 1023 'cookie': bp_get_cookies(), 1024 'gid': gid, 1025 '_wpnonce': nonce 1026 }, 1027 function(response) 1028 { 1029 var parentdiv = thelink.parent(); 1030 1031 // user groups page 1032 if ( ! jq('body.directory').length ) { 1033 location.href = location.href; 1034 1035 // groups directory 1036 } else { 1037 jq(parentdiv).fadeOut(200, 1038 function() { 1039 parentdiv.fadeIn(200).html(response); 1040 1041 var mygroups = jq('#groups-personal span'); 1042 var add = 1; 1043 1044 if( thelink.hasClass( 'leave-group' ) ) { 1045 // hidden groups slide up 1046 if ( parentdiv.hasClass( 'hidden' ) ) {
1047 parentdiv.closest('li').slideUp( 200 ); 1048 } 1049 1050 add = 0; 1051 } else if ( thelink.hasClass( 'request-membership' ) ) { 1052 add = false; 1053 } 1054 1055 // change the "My Groups" value 1056 if ( add !== false && mygroups.length ) { 1057 if ( add ) { 1058 mygroups.text( ( mygroups.text() >> 0 ) + 1 ); 1059 } else { 1060 mygroups.text( ( mygroups.text() >> 0 ) - 1 ); 1061 } 1062 } 1063 1064 } 1065 ); 1066 } 1067 }); 1068 return false; 1069 } ); 1070 1071 /** Button disabling ************************************************/ 1072 1073 jq('.pending').click(function() { 1074 return false; 1075 }); 1076 1077 /** Private Messaging ******************************************/ 1078 1079 /** Message search*/ 1080 jq('.message-search').click( function(event) { 1081 if ( jq(this).hasClass('no-ajax') ) 1082 return; 1083 1084 var target = jq(event.target); 1085 1086 if ( target.attr('type') == 'submit' ) { 1087 //var css_id = jq('.item-list-tabs li.selected').attr('id').split( '-' ); 1088 var object = 'messages'; 1089 1090 bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope') , 'div.' + object, target.parent().children('label').children('input').val(), 1, jq.cookie('bp-' + object + '-extras') ); 1091 1092 return false; 1093 } 1094 }); 1095 1096 /* AJAX send reply functionality */ 1097 jq("input#send_reply_button").click( 1098 function() { 1099 var order = jq('#messages_order').val() || 'ASC', 1100 offset = jq('#message-recipients').offset(); 1101 1102 var button = jq("input#send_reply_button"); 1103 jq(button).addClass('loading'); 1104 1105 jq.post( ajaxurl, { 1106 action: 'messages_send_reply', 1107 'cookie': bp_get_cookies(), 1108 '_wpnonce': jq("input#send_message_nonce").val(), 1109 1110 'content': jq("#message_content").val(), 1111 'send_to': jq("input#send_to").val(), 1112 'subject': jq("input#subject").val(), 1113 'thread_id': jq("input#thread_id").val() 1114 }, 1115 function(response) 1116 { 1117 if ( response[0] + response[1] == "-1" ) { 1118 jq('form#send-reply').prepend( response.substr( 2, response.length ) ); 1119 } else { 1120 jq('form#send-reply div#message').remove(); 1121 jq("#message_content").val(''); 1122 1123 if ( 'ASC' == order ) { 1124 jq('form#send-reply').before( response ); 1125 } else { 1126 jq('#message-recipients').after( response ); 1127 jq(window).scrollTop(offset.top); 1128 } 1129 1130 jq(".new-message").hide().slideDown( 200, function() { 1131 jq('.new-message').removeClass('new-message'); 1132 }); 1133 } 1134 jq(button).removeClass('loading'); 1135 }); 1136 1137 return false; 1138 } 1139 ); 1140 1141 /* Marking private messages as read and unread */ 1142 jq("a#mark_as_read, a#mark_as_unread").click(function() { 1143 var checkboxes_tosend = ''; 1144 var checkboxes = jq("#message-threads tr td input[type='checkbox']"); 1145 1146 if ( 'mark_as_unread' == jq(this).attr('id') ) { 1147 var currentClass = 'read' 1148 var newClass = 'unread' 1149 var unreadCount = 1; 1150 var inboxCount = 0; 1151 var unreadCountDisplay = 'inline'; 1152 var action = 'messages_markunread'; 1153 } else { 1154 var currentClass = 'unread' 1155 var newClass = 'read' 1156 var unreadCount = 0; 1157 var inboxCount = 1; 1158 var unreadCountDisplay = 'none'; 1159 var action = 'messages_markread'; 1160 } 1161 1162 checkboxes.each( function(i) { 1163 if(jq(this).is(':checked')) { 1164 if ( jq('tr#m-' + jq(this).attr('value')).hasClass(currentClass) ) { 1165 checkboxes_tosend += jq(this).attr('value'); 1166 jq('tr#m-' + jq(this).attr('value')).removeClass(currentClass); 1167 jq('tr#m-' + jq(this).attr('value')).addClass(newClass); 1168 var thread_count = jq('tr#m-' + jq(this).attr('value') + ' td span.unread-count').html(); 1169 1170 jq('tr#m-' + jq(this).attr('value') + ' td span.unread-count').html(unreadCount); 1171 jq('tr#m-' + jq(this).attr('value') + ' td span.unread-count').css('display', unreadCountDisplay); 1172 1173 var inboxcount = jq('tr.unread').length; 1174 1175 jq('a#user-messages span').html( inboxcount ); 1176 1177 if ( i != checkboxes.length - 1 ) { 1178 checkboxes_tosend += ',' 1179 } 1180 } 1181 } 1182 }); 1183 jq.post( ajaxurl, { 1184 action: action, 1185 'thread_ids': checkboxes_tosend 1186 }); 1187 return false; 1188 }); 1189 1190 /* Selecting unread and read messages in inbox */ 1191 jq( 'body.messages #item-body div.messages' ).on( 'change', '#message-type-select', function() { 1192 var selection = this.value; 1193 var checkboxes = jq( "td input[type='checkbox']" ); 1194 1195 checkboxes.each( function(i) { 1196 checkboxes[i].checked = ""; 1197 }); 1198 1199 var checked_value = "checked"; 1200 switch ( selection ) { 1201 case 'unread' : 1202 checkboxes = jq("tr.unread td input[type='checkbox']"); 1203 break; 1204 case 'read' : 1205 checkboxes = jq("tr.read td input[type='checkbox']"); 1206 break; 1207 case '' : 1208 checked_value = ""; 1209 break; 1210 } 1211 1212 checkboxes.each( function(i) { 1213 checkboxes[i].checked = checked_value; 1214 }); 1215 }); 1216 1217 /* Bulk delete messages */ 1218 jq( 'body.messages #item-body div.messages' ).on( 'click', '.messages-options-nav a', function() { 1219 if ( -1 == jq.inArray( this.id, Array( 'delete_sentbox_messages', 'delete_inbox_messages' ) ) ) { 1220 return; 1221 } 1222 1223 checkboxes_tosend = ''; 1224 checkboxes = jq("#message-threads tr td input[type='checkbox']"); 1225 1226 jq('#message').remove(); 1227 jq(this).addClass('loading'); 1228 1229 jq(checkboxes).each( function(i) { 1230 if( jq(this).is(':checked') ) 1231 checkboxes_tosend += jq(this).attr('value') + ','; 1232 }); 1233 1234 if ( '' == checkboxes_tosend ) { 1235 jq(this).removeClass('loading'); 1236 return false;
1237 } 1238 1239 jq.post( ajaxurl, { 1240 action: 'messages_delete', 1241 'thread_ids': checkboxes_tosend 1242 }, function(response) { 1243 if ( response[0] + response[1] == "-1" ) { 1244 jq('#message-threads').prepend( response.substr( 2, response.length ) ); 1245 } else { 1246 jq('#message-threads').before( '<div id="message" class="updated"><p>' + response + '</p></div>' ); 1247 1248 jq(checkboxes).each( function(i) { 1249 if( jq(this).is(':checked') ) { 1250 // We need to uncheck because message is only hidden 1251 // Otherwise, AJAX will be fired again with same data 1252 jq(this).attr( 'checked', false ); 1253 jq(this).parent().parent().fadeOut(150); 1254 } 1255 }); 1256 } 1257 1258 jq('#message').hide().slideDown(150); 1259 jq("#delete_inbox_messages, #delete_sentbox_messages").removeClass('loading'); 1260 }); 1261 1262 return false; 1263 }); 1264 1265 /* Close site wide notices in the sidebar */ 1266 jq("a#close-notice").click( function() { 1267 jq(this).addClass('loading'); 1268 jq('div#sidebar div.error').remove(); 1269 1270 jq.post( ajaxurl, { 1271 action: 'messages_close_notice', 1272 'notice_id': jq('.notice').attr('rel').substr( 2, jq('.notice').attr('rel').length ) 1273 }, 1274 function(response) { 1275 jq("a#close-notice").removeClass('loading'); 1276 1277 if ( response[0] + response[1] == '-1' ) { 1278 jq('.notice').prepend( response.substr( 2, response.length ) ); 1279 jq( 'div#sidebar div.error').hide().fadeIn( 200 ); 1280 } else { 1281 jq('.notice').slideUp( 100 ); 1282 } 1283 }); 1284 return false; 1285 }); 1286 1287 /* Toolbar & wp_list_pages Javascript IE6 hover class */ 1288 jq("#wp-admin-bar ul.main-nav li, #nav li").mouseover( function() { 1289 jq(this).addClass('sfhover'); 1290 }); 1291 1292 jq("#wp-admin-bar ul.main-nav li, #nav li").mouseout( function() { 1293 jq(this).removeClass('sfhover'); 1294 }); 1295 1296 /* Clear BP cookies on logout */ 1297 jq('a.logout').click( function() { 1298 jq.removeCookie('bp-activity-scope', { 1299 path: '/' 1300 }); 1301 jq.removeCookie('bp-activity-filter', { 1302 path: '/' 1303 }); 1304 jq.removeCookie('bp-activity-oldestpage', { 1305 path: '/' 1306 }); 1307 1308 var objects = [ 'members', 'groups', 'blogs', 'forums' ]; 1309 jq(objects).each( function(i) { 1310 jq.removeCookie('bp-' + objects[i] + '-scope', { 1311 path: '/' 1312 } ); 1313 jq.removeCookie('bp-' + objects[i] + '-filter', { 1314 path: '/' 1315 } ); 1316 jq.removeCookie('bp-' + objects[i] + '-extras', { 1317 path: '/' 1318 } ); 1319 }); 1320 }); 1321}); 1322 1323/* Setup activity scope and filter based on the current cookie settings. */ 1324function bp_init_activity() { 1325 /* Reset the page */ 1326 jq.cookie( 'bp-activity-oldestpage', 1, { 1327 path: '/' 1328 } ); 1329 1330 if ( null != jq.cookie('bp-activity-filter') && jq('#activity-filter-select').length ) 1331 jq('#activity-filter-select select option[value="' + jq.cookie('bp-activity-filter') + '"]').prop( 'selected', true ); 1332 1333 /* Activity Tab Set */ 1334 if ( null != jq.cookie('bp-activity-scope') && jq('.activity-type-tabs').length ) { 1335 jq('.activity-type-tabs li').each( function() { 1336 jq(this).removeClass('selected'); 1337 }); 1338 jq('li#activity-' + jq.cookie('bp-activity-scope') + ', .item-list-tabs li.current').addClass('selected'); 1339 } 1340} 1341 1342/* Setup object scope and filter based on the current cookie settings for the object. */ 1343function bp_init_objects(objects) { 1344 jq(objects).each( function(i) { 1345 if ( null != jq.cookie('bp-' + objects[i] + '-filter') && jq('li#' + objects[i] + '-order-select select').length ) 1346 jq('li#' + objects[i] + '-order-select select option[value="' + jq.cookie('bp-' + objects[i] + '-filter') + '"]').prop( 'selected', true ); 1347 1348 if ( null != jq.cookie('bp-' + objects[i] + '-scope') && jq('div.' + objects[i]).length ) { 1349 jq('.item-list-tabs li').each( function() { 1350 jq(this).removeClass('selected'); 1351 }); 1352 jq('.item-list-tabs li#' + objects[i] + '-' + jq.cookie('bp-' + objects[i] + '-scope') + ', div.item-list-tabs#object-nav li.current').addClass('selected'); 1353 } 1354 }); 1355} 1356 1357/* Filter the current content list (groups/members/blogs/topics) */ 1358function bp_filter_request( object, filter, scope, target, search_terms, page, extras, caller ) { 1359 if ( 'activity' == object ) 1360 return false; 1361 1362 if ( bp_get_querystring('s') && !search_terms ) 1363 search_terms = bp_get_querystring('s'); 1364 1365 if ( null == scope ) 1366 scope = 'all'; 1367 1368 /* Save the settings we want to remain persistent to a cookie */ 1369 jq.cookie( 'bp-' + object + '-scope', scope, { 1370 path: '/' 1371 } ); 1372 jq.cookie( 'bp-' + object + '-filter', filter, { 1373 path: '/' 1374 } ); 1375 jq.cookie( 'bp-' + object + '-extras', extras, { 1376 path: '/' 1377 } ); 1378 1379 /* Set the correct selected nav and filter */ 1380 jq('.item-list-tabs li').each( function() { 1381 jq(this).removeClass('selected'); 1382 }); 1383 jq('.item-list-tabs li#' + object + '-' + scope + ', .item-list-tabs#object-nav li.current').addClass('selected'); 1384 jq('.item-list-tabs li.selected').addClass('loading'); 1385 jq('.item-list-tabs select option[value="' + filter + '"]').prop( 'selected', true ); 1386 1387 if ( 'friends' == object ) 1388 object = 'members'; 1389 1390 if ( bp_ajax_request ) 1391 bp_ajax_request.abort(); 1392 1393 bp_ajax_request = jq.post( ajaxurl, { 1394 action: object + '_filter', 1395 'cookie': bp_get_cookies(), 1396 'object': object, 1397 'filter': filter, 1398 'search_terms': search_terms, 1399 'scope': scope, 1400 'page': page, 1401 'extras': extras 1402 }, 1403 function(response) 1404 { 1405 /* animate to top if called from bottom pagination */ 1406 if ( caller == 'pag-bottom' && jq('#subnav').length ) { 1407 var top = jq('#subnav').parent(); 1408 jq('html,body').animate({scrollTop: top.offset().top}, 'slow', function() { 1409 jq(target).fadeOut( 100, function() { 1410 jq(this).html(response); 1411 jq(this).fadeIn(100); 1412 }); 1413 }); 1414 1415 } else { 1416 jq(target).fadeOut( 100, function() { 1417 jq(this).html(response); 1418 jq(this).fadeIn(100); 1419 }); 1420 } 1421 1422 jq('.item-list-tabs li.selected').removeClass('loading'); 1423 }); 1424} 1425
1426/* Activity Loop Requesting */ 1427function bp_activity_request(scope, filter) { 1428 /* Save the type and filter to a session cookie */ 1429 jq.cookie( 'bp-activity-scope', scope, { 1430 path: '/' 1431 } ); 1432 jq.cookie( 'bp-activity-filter', filter, { 1433 path: '/' 1434 } ); 1435 jq.cookie( 'bp-activity-oldestpage', 1, { 1436 path: '/' 1437 } ); 1438 1439 /* Remove selected and loading classes from tabs */ 1440 jq('.item-list-tabs li').each( function() { 1441 jq(this).removeClass('selected loading'); 1442 }); 1443 /* Set the correct selected nav and filter */ 1444 jq('li#activity-' + scope + ', .item-list-tabs li.current').addClass('selected'); 1445 jq('#object-nav.item-list-tabs li.selected, div.activity-type-tabs li.selected').addClass('loading'); 1446 jq('#activity-filter-select select option[value="' + filter + '"]').prop( 'selected', true ); 1447 1448 /* Reload the activity stream based on the selection */ 1449 jq('.widget_bp_activity_widget h2 span.ajax-loader').show(); 1450 1451 if ( bp_ajax_request ) 1452 bp_ajax_request.abort(); 1453 1454 bp_ajax_request = jq.post( ajaxurl, { 1455 action: 'activity_widget_filter', 1456 'cookie': bp_get_cookies(), 1457 '_wpnonce_activity_filter': jq("input#_wpnonce_activity_filter").val(), 1458 'scope': scope, 1459 'filter': filter 1460 }, 1461 function(response) 1462 { 1463 jq('.widget_bp_activity_widget h2 span.ajax-loader').hide(); 1464 1465 jq('div.activity').fadeOut( 100, function() { 1466 jq(this).html(response.contents); 1467 jq(this).fadeIn(100); 1468 1469 /* Selectively hide comments */ 1470 bp_dtheme_hide_comments(); 1471 }); 1472 1473 /* Update the feed link */ 1474 if ( null != response.feed_url ) 1475 jq('.directory #subnav li.feed a, .home-page #subnav li.feed a').attr('href', response.feed_url); 1476 1477 jq('.item-list-tabs li.selected').removeClass('loading'); 1478 1479 }, 'json' ); 1480} 1481 1482/* Hide long lists of activity comments, only show the latest five root comments. */ 1483function bp_dtheme_hide_comments() { 1484 var comments_divs = jq('div.activity-comments'); 1485 1486 if ( !comments_divs.length ) 1487 return false; 1488 1489 comments_divs.each( function() { 1490 if ( jq(this).children('ul').children('li').length < 5 ) return; 1491 1492 var comments_div = jq(this); 1493 var parent_li = comments_div.parents('ul#activity-stream > li'); 1494 var comment_lis = jq(this).children('ul').children('li'); 1495 var comment_count = ' '; 1496 1497 if ( jq('li#' + parent_li.attr('id') + ' a.acomment-reply span').length ) 1498 var comment_count = jq('li#' + parent_li.attr('id') + ' a.acomment-reply span').html(); 1499 1500 comment_lis.each( function(i) { 1501 /* Show the latest 5 root comments */ 1502 if ( i < comment_lis.length - 5 ) { 1503 jq(this).addClass('hidden'); 1504 jq(this).toggle(); 1505 1506 if ( !i ) 1507 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>' ); 1508 } 1509 }); 1510 1511 }); 1512} 1513 1514/* Helper Functions */ 1515 1516function checkAll() { 1517 var checkboxes = document.getElementsByTagName("input"); 1518 for(var i=0; i<checkboxes.length; i++) { 1519 if(checkboxes[i].type == "checkbox") { 1520 if($("check_all").checked == "") { 1521 checkboxes[i].checked = ""; 1522 } 1523 else { 1524 checkboxes[i].checked = "checked"; 1525 } 1526 } 1527 } 1528} 1529 1530function clear(container) { 1531 if( !document.getElementById(container) ) return; 1532 1533 var container = document.getElementById(container); 1534 1535 if ( radioButtons = container.getElementsByTagName('INPUT') ) { 1536 for(var i=0; i<radioButtons.length; i++) { 1537 radioButtons[i].checked = ''; 1538 } 1539 } 1540 1541 if ( options = container.getElementsByTagName('OPTION') ) { 1542 for(var i=0; i<options.length; i++) { 1543 options[i].selected = false; 1544 } 1545 } 1546 1547 return; 1548} 1549 1550/* Returns a querystring of BP cookies (cookies beginning with 'bp-') */ 1551function bp_get_cookies() { 1552 // get all cookies and split into an array 1553 var allCookies = document.cookie.split(";"); 1554 1555 var bpCookies = {}; 1556 var cookiePrefix = 'bp-'; 1557 1558 // loop through cookies 1559 for (var i = 0; i < allCookies.length; i++) { 1560 var cookie = allCookies[i]; 1561 var delimiter = cookie.indexOf("="); 1562 var name = jq.trim( unescape( cookie.slice(0, delimiter) ) ); 1563 var value = unescape( cookie.slice(delimiter + 1) ); 1564 1565 // if BP cookie, store it 1566 if ( name.indexOf(cookiePrefix) == 0 ) { 1567 bpCookies[name] = value; 1568 } 1569 } 1570 1571 // returns BP cookies as querystring 1572 return encodeURIComponent( jq.param(bpCookies) ); 1573}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.