rdusnr

Untitled

Jan 3rd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.93 KB | None | 0 0
  1. /* jshint undef: false, unused:false */
  2. // AJAX Functions
  3. var jq = jQuery;
  4.  
  5. // Global variable to prevent multiple AJAX requests
  6. var bp_ajax_request = null;
  7.  
  8. // Global variables to temporarily store newest activities
  9. var newest_activities = '';
  10. var activity_last_recorded = 0;
  11.  
  12. jq(document).ready( function() {
  13. /**** Page Load Actions *******************************************************/
  14.  
  15. /* Hide Forums Post Form */
  16. if ( '-1' === window.location.search.indexOf('new') && jq('div.forums').length ) {
  17. jq('#new-topic-post').hide();
  18. } else {
  19. jq('#new-topic-post').show();
  20. }
  21.  
  22. /* Activity filter and scope set */
  23. bp_init_activity();
  24.  
  25. var objects = [ 'members', 'groups', 'blogs', 'forums', 'group_members' ],
  26. $whats_new = jq('#whats-new');
  27.  
  28. /* Object filter and scope set. */
  29. bp_init_objects( objects );
  30.  
  31. /* @mention Compose Scrolling */
  32. if ( $whats_new.length && bp_get_querystring('r') ) {
  33. var $member_nicename = $whats_new.val();
  34.  
  35. jq('#whats-new-options').animate({
  36. height:'50px'
  37. });
  38.  
  39. $whats_new.animate({
  40. height:'50px'
  41. });
  42.  
  43. jq.scrollTo( $whats_new, 500, {
  44. offset:-125,
  45. easing:'swing'
  46. } );
  47.  
  48. $whats_new.val('').focus().val( $member_nicename );
  49. }
  50.  
  51. /**** Activity Posting ********************************************************/
  52.  
  53. /* Textarea focus */
  54. $whats_new.focus( function(){
  55. jq('#whats-new-options').animate({
  56. height:'50px'
  57. });
  58. jq('#whats-new-form textarea').animate({
  59. height:'50px'
  60. });
  61. jq('#aw-whats-new-submit').prop('disabled', false);
  62.  
  63. jq( this ).parent().addClass( 'active' );
  64. jq( '#whats-new-content' ).addClass( 'active' );
  65.  
  66. var $whats_new_form = jq('form#whats-new-form'),
  67. $activity_all = jq( '#activity-all' );
  68.  
  69. if ( $whats_new_form.hasClass('submitted') ) {
  70. $whats_new_form.removeClass('submitted');
  71. }
  72.  
  73. // Return to the 'All Members' tab and 'Everything' filter,
  74. // to avoid inconsistencies with the heartbeat integration
  75. if ( $activity_all.length ) {
  76. if ( ! $activity_all.hasClass( 'selected' ) ) {
  77. // reset to everything
  78. jq( '#activity-filter-select select' ).val( '-1' );
  79. $activity_all.children( 'a' ).trigger( 'click' );
  80. } else if ( '-1' !== jq( '#activity-filter-select select' ).val() ) {
  81. jq( '#activity-filter-select select' ).val( '-1' );
  82. jq( '#activity-filter-select select' ).trigger( 'change' );
  83. }
  84. }
  85. });
  86.  
  87. /* For the "What's New" form, do the following on focusout. */
  88. jq( '#whats-new-form' ).on( 'focusout', function( e ) {
  89. var elem = jq( this );
  90.  
  91. // Let child hover actions passthrough.
  92. // This allows click events to go through without focusout.
  93. setTimeout( function () {
  94. if ( ! elem.find(':hover').length ) {
  95. // Do not slide up if textarea has content.
  96. if ( '' !== $whats_new.val() ) {
  97. return;
  98. }
  99.  
  100. jq('#whats-new-options').animate({
  101. height:'0'
  102. });
  103. jq('form#whats-new-form textarea').animate({
  104. height:'50px'
  105. });
  106. jq('#aw-whats-new-submit').prop('disabled', true);
  107.  
  108. jq( '#whats-new-content' ).removeClass( 'active' );
  109. $whats_new.parent().removeClass( 'active' );
  110. }
  111. }, 0 );
  112. } );
  113.  
  114. /* New posts */
  115. jq('#aw-whats-new-submit').on( 'click', function() {
  116. var last_date_recorded = 0,
  117. button = jq(this),
  118. form = button.closest('form#whats-new-form'),
  119. inputs = {}, post_data;
  120.  
  121. // Get all inputs and organize them into an object {name: value}
  122. jq.each( form.serializeArray(), function( key, input ) {
  123. // Only include public extra data
  124. if ( '_' !== input.name.substr( 0, 1 ) && 'whats-new' !== input.name.substr( 0, 9 ) ) {
  125. if ( ! inputs[ input.name ] ) {
  126. inputs[ input.name ] = input.value;
  127. } else {
  128. // Checkboxes/dropdown list can have multiple selected value
  129. if ( ! jq.isArray( inputs[ input.name ] ) ) {
  130. inputs[ input.name ] = new Array( inputs[ input.name ], input.value );
  131. } else {
  132. inputs[ input.name ].push( input.value );
  133. }
  134. }
  135. }
  136. } );
  137.  
  138. form.find( '*' ).each( function() {
  139. if ( jq.nodeName( this, 'textarea' ) || jq.nodeName( this, 'input' ) ) {
  140. jq(this).prop( 'disabled', true );
  141. }
  142. } );
  143.  
  144. /* Remove any errors */
  145. jq('div.error').remove();
  146. button.addClass('loading');
  147. button.prop('disabled', true);
  148. form.addClass('submitted');
  149.  
  150. /* Default POST values */
  151. object = '';
  152. item_id = jq('#whats-new-post-in').val();
  153. content = jq('#whats-new').val();
  154. firstrow = jq( '#buddypress ul.activity-list li' ).first();
  155. activity_row = firstrow;
  156. timestamp = null;
  157.  
  158. // Checks if at least one activity exists
  159. if ( firstrow.length ) {
  160.  
  161. if ( activity_row.hasClass( 'load-newest' ) ) {
  162. activity_row = firstrow.next();
  163. }
  164.  
  165. timestamp = activity_row.prop( 'class' ).match( /date-recorded-([0-9]+)/ );
  166. }
  167.  
  168. if ( timestamp ) {
  169. last_date_recorded = timestamp[1];
  170. }
  171.  
  172. /* Set object for non-profile posts */
  173. if ( item_id > 0 ) {
  174. object = jq('#whats-new-post-object').val();
  175. }
  176.  
  177. jq.post( ajaxurl, {
  178. action: 'post_update',
  179. 'cookie': bp_get_cookies(),
  180. '_wpnonce_post_update': jq('#_wpnonce_post_update').val(),
  181. 'content': content,
  182. 'object': object,
  183. 'item_id': item_id,
  184. 'since': last_date_recorded,
  185. '_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
  186. },
  187. function(response) {
  188.  
  189. form.find( '*' ).each( function() {
  190. if ( jq.nodeName(this, 'textarea') || jq.nodeName(this, 'input') ) {
  191. jq(this).prop( 'disabled', false );
  192. }
  193. });
  194.  
  195. /* Check for errors and append if found. */
  196. if ( response[0] + response[1] === '-1' ) {
  197. form.prepend( response.substr( 2, response.length ) );
  198. jq( '#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
  199. } else {
  200. if ( 0 === jq('ul.activity-list').length ) {
  201. jq('div.error').slideUp(100).remove();
  202. jq('#message').slideUp(100).remove();
  203. jq('div.activity').append( '<ul id="activity-stream" class="activity-list item-list">' );
  204. }
  205.  
  206. if ( firstrow.hasClass( 'load-newest' ) ) {
  207. firstrow.remove();
  208. }
  209.  
  210. jq('#activity-stream').prepend(response);
  211.  
  212. /* kleo added */
  213. jq('body').trigger('bpActivityLoaded');
  214.  
  215. if ( ! last_date_recorded ) {
  216. jq('#activity-stream li:first').addClass('new-update just-posted');
  217. }
  218.  
  219. if ( 0 !== jq('#latest-update').length ) {
  220. var l = jq('#activity-stream li.new-update .activity-content .activity-inner p').text(),
  221. v = jq('#activity-stream li.new-update .activity-content .activity-header p a.view').attr('href'),
  222. ltext = jq('#activity-stream li.new-update .activity-content .activity-inner p').text(),
  223. u = '';
  224.  
  225. if ( ltext !== '' ) {
  226. u = l + ' ';
  227. }
  228.  
  229. u += '<a href="' + v + '" rel="nofollow">' + BP_DTheme.view + '</a>';
  230.  
  231. jq('#latest-update').slideUp(300,function(){
  232. jq('#latest-update').html( u );
  233. jq('#latest-update').slideDown(300);
  234. });
  235. }
  236.  
  237. jq('li.new-update').hide().slideDown( 300 );
  238. jq('li.new-update').removeClass( 'new-update' );
  239. jq('#whats-new').val('');
  240. form.get(0).reset();
  241.  
  242. // reset vars to get newest activities
  243. newest_activities = '';
  244. activity_last_recorded = 0;
  245. }
  246.  
  247. jq('#whats-new-options').animate({
  248. height:'0px'
  249. });
  250. jq('#whats-new-form textarea').animate({
  251. height:'50px'
  252. });
  253. jq('#aw-whats-new-submit').prop('disabled', true).removeClass('loading');
  254. });
  255.  
  256. return false;
  257. });
  258.  
  259. /* List tabs event delegation */
  260. jq('div.activity-type-tabs').on( 'click', function(event) {
  261. var target = jq(event.target).parent(),
  262. scope, filter;
  263.  
  264. if ( event.target.nodeName === 'STRONG' || event.target.nodeName === 'SPAN' ) {
  265. target = target.parent();
  266. } else if ( event.target.nodeName !== 'A' ) {
  267. return false;
  268. }
  269.  
  270. /* Reset the page */
  271. jq.cookie( 'bp-activity-oldestpage', 1, {
  272. path: '/'
  273. } );
  274.  
  275. /* Activity Stream Tabs */
  276. scope = target.attr('id').substr( 9, target.attr('id').length );
  277. filter = jq('#activity-filter-select select').val();
  278.  
  279. if ( scope === 'mentions' ) {
  280. jq( '#' + target.attr('id') + ' a strong' ).remove();
  281. }
  282.  
  283. bp_activity_request(scope, filter);
  284.  
  285. return false;
  286. });
  287.  
  288. /* Activity filter select */
  289. jq('#activity-filter-select select').change( function() {
  290. var selected_tab = jq( 'div.activity-type-tabs li.selected' ),
  291. filter = jq(this).val(),
  292. scope;
  293.  
  294. if ( !selected_tab.length ) {
  295. scope = null;
  296. } else {
  297. scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length );
  298. }
  299.  
  300. bp_activity_request(scope, filter);
  301.  
  302. return false;
  303. });
  304.  
  305. /* Stream event delegation */
  306. jq('div.activity').on( 'click', function(event) {
  307. var target = jq(event.target),
  308. type, parent, parent_id,
  309. li, id, link_href, nonce, timestamp,
  310. oldest_page, just_posted;
  311.  
  312. /* Favoriting activity stream items */
  313. if ( target.hasClass('fav') || target.hasClass('unfav') ) {
  314. type = target.hasClass('fav') ? 'fav' : 'unfav';
  315. parent = target.closest('.activity-item');
  316. parent_id = parent.attr('id').substr( 9, parent.attr('id').length );
  317.  
  318. target.addClass('loading');
  319.  
  320. jq.post( ajaxurl, {
  321. action: 'activity_mark_' + type,
  322. 'cookie': bp_get_cookies(),
  323. 'id': parent_id
  324. },
  325. function(response) {
  326. target.removeClass('loading');
  327.  
  328. target.fadeOut( 200, function() {
  329. jq(this).html(response);
  330. jq(this).attr('title', 'fav' === type ? BP_DTheme.remove_fav : BP_DTheme.mark_as_fav);
  331. jq(this).fadeIn(200);
  332. });
  333.  
  334. if ( 'fav' === type ) {
  335. if ( !jq('.item-list-tabs #activity-favs-personal-li').length ) {
  336. if ( !jq('.item-list-tabs #activity-favorites').length ) {
  337. jq('.item-list-tabs ul #activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' <span>0</span></a></li>');
  338. }
  339.  
  340. jq('.item-list-tabs ul #activity-favorites span').html( Number( jq('.item-list-tabs ul #activity-favorites span').html() ) + 1 );
  341. }
  342.  
  343. target.removeClass('fav');
  344. target.addClass('unfav');
  345.  
  346. } else {
  347. target.removeClass('unfav');
  348. target.addClass('fav');
  349.  
  350. jq('.item-list-tabs ul #activity-favorites span').html( Number( jq('.item-list-tabs ul #activity-favorites span').html() ) - 1 );
  351.  
  352. if ( !Number( jq('.item-list-tabs ul #activity-favorites span').html() ) ) {
  353. if ( jq('.item-list-tabs ul #activity-favorites').hasClass('selected') ) {
  354. bp_activity_request( null, null );
  355. }
  356.  
  357. jq('.item-list-tabs ul #activity-favorites').remove();
  358. }
  359. }
  360.  
  361. if ( 'activity-favorites' === jq( '.item-list-tabs li.selected').attr('id') ) {
  362. target.closest( '.activity-item' ).slideUp( 100 );
  363. }
  364. });
  365.  
  366. return false;
  367. }
  368.  
  369. /* Delete activity stream items */
  370. if ( target.hasClass('delete-activity') ) {
  371. li = target.parents('div.activity ul li');
  372. id = li.attr('id').substr( 9, li.attr('id').length );
  373. link_href = target.attr('href');
  374. nonce = link_href.split('_wpnonce=');
  375. timestamp = li.prop( 'class' ).match( /date-recorded-([0-9]+)/ );
  376. nonce = nonce[1];
  377.  
  378. target.addClass('loading');
  379.  
  380. jq.post( ajaxurl, {
  381. action: 'delete_activity',
  382. 'cookie': bp_get_cookies(),
  383. 'id': id,
  384. '_wpnonce': nonce
  385. },
  386. function(response) {
  387.  
  388. if ( response[0] + response[1] === '-1' ) {
  389. li.prepend( response.substr( 2, response.length ) );
  390. li.children('#message').hide().fadeIn(300);
  391. } else {
  392. li.slideUp(300);
  393.  
  394. // reset vars to get newest activities
  395. if ( timestamp && activity_last_recorded === timestamp[1] ) {
  396. newest_activities = '';
  397. activity_last_recorded = 0;
  398. }
  399. }
  400. });
  401.  
  402. return false;
  403. }
  404.  
  405. // Spam activity stream items
  406. if ( target.hasClass( 'spam-activity' ) ) {
  407. li = target.parents( 'div.activity ul li' );
  408. timestamp = li.prop( 'class' ).match( /date-recorded-([0-9]+)/ );
  409. target.addClass( 'loading' );
  410.  
  411. jq.post( ajaxurl, {
  412. action: 'bp_spam_activity',
  413. 'cookie': encodeURIComponent( document.cookie ),
  414. 'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ),
  415. '_wpnonce': target.attr( 'href' ).split( '_wpnonce=' )[1]
  416. },
  417.  
  418. function(response) {
  419. if ( response[0] + response[1] === '-1' ) {
  420. li.prepend( response.substr( 2, response.length ) );
  421. li.children( '#message' ).hide().fadeIn(300);
  422. } else {
  423. li.slideUp( 300 );
  424. // reset vars to get newest activities
  425. if ( timestamp && activity_last_recorded === timestamp[1] ) {
  426. newest_activities = '';
  427. activity_last_recorded = 0;
  428. }
  429. }
  430. });
  431.  
  432. return false;
  433. }
  434.  
  435. /* Load more updates at the end of the page */
  436. if ( target.parent().hasClass('load-more') ) {
  437. if ( bp_ajax_request ) {
  438. bp_ajax_request.abort();
  439. }
  440.  
  441. jq('#buddypress li.load-more').addClass('loading');
  442.  
  443. if ( null === jq.cookie('bp-activity-oldestpage') ) {
  444. jq.cookie('bp-activity-oldestpage', 1, {
  445. path: '/'
  446. } );
  447. }
  448.  
  449. oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1;
  450. just_posted = [];
  451.  
  452. jq('.activity-list li.just-posted').each( function(){
  453. just_posted.push( jq(this).attr('id').replace( 'activity-','' ) );
  454. });
  455.  
  456. load_more_args = {
  457. action: 'activity_get_older_updates',
  458. 'cookie': bp_get_cookies(),
  459. 'page': oldest_page,
  460. 'exclude_just_posted': just_posted.join(',')
  461. };
  462.  
  463. load_more_search = bp_get_querystring('s');
  464.  
  465. if ( load_more_search ) {
  466. load_more_args.search_terms = load_more_search;
  467. }
  468.  
  469. bp_ajax_request = jq.post( ajaxurl, load_more_args,
  470. function(response)
  471. {
  472. jq('#buddypress li.load-more').removeClass('loading');
  473. jq.cookie( 'bp-activity-oldestpage', oldest_page, {
  474. path: '/'
  475. } );
  476. jq('#buddypress ul.activity-list').append(response.contents);
  477.  
  478. target.parent().hide();
  479. }, 'json' );
  480.  
  481. return false;
  482. }
  483.  
  484. /* Load newest updates at the top of the list */
  485. if ( target.parent().hasClass('load-newest') ) {
  486.  
  487. event.preventDefault();
  488.  
  489. target.parent().hide();
  490.  
  491. /**
  492. * If a plugin is updating the recorded_date of an activity
  493. * it will be loaded as a new one. We need to look in the
  494. * stream and eventually remove similar ids to avoid "double".
  495. */
  496. activity_html = jq.parseHTML( newest_activities );
  497.  
  498. jq.each( activity_html, function( i, el ){
  499. if( 'LI' === el.nodeName && jq(el).hasClass( 'just-posted' ) ) {
  500. if( jq( '#' + jq(el).attr( 'id' ) ).length ) {
  501. jq( '#' + jq(el).attr( 'id' ) ).remove();
  502. }
  503. }
  504. } );
  505.  
  506. // Now the stream is cleaned, prepend newest
  507. jq( '#buddypress ul.activity-list' ).prepend( newest_activities );
  508.  
  509. // reset the newest activities now they're displayed
  510. newest_activities = '';
  511. }
  512. });
  513.  
  514. // Activity "Read More" links
  515. jq('div.activity').on('click', '.activity-read-more a', function(event) {
  516. var target = jq(event.target),
  517. link_id = target.parent().attr('id').split('-'),
  518. a_id = link_id[3],
  519. type = link_id[0], /* activity or acomment */
  520. inner_class, a_inner;
  521.  
  522. inner_class = type === 'acomment' ? 'acomment-content' : 'activity-inner';
  523. a_inner = jq('#' + type + '-' + a_id + ' .' + inner_class + ':first' );
  524. jq(target).addClass('loading');
  525.  
  526. jq.post( ajaxurl, {
  527. action: 'get_single_activity_content',
  528. 'activity_id': a_id
  529. },
  530. function(response) {
  531. jq(a_inner).slideUp(300).html(response).slideDown(300);
  532. });
  533.  
  534. return false;
  535. });
  536.  
  537. /**** Activity Comments *******************************************************/
  538.  
  539. /* Hide all activity comment forms */
  540. jq('form.ac-form').hide();
  541.  
  542. /* Hide excess comments */
  543. if ( jq('.activity-comments').length ) {
  544. bp_legacy_theme_hide_comments();
  545. }
  546.  
  547. /* Activity list event delegation */
  548. jq('div.activity').on( 'click', function(event) {
  549. var target = jq(event.target),
  550. id, ids, a_id, c_id, form,
  551. form_parent, form_id,
  552. tmp_id, comment_id, comment,
  553. ajaxdata,
  554. ak_nonce,
  555. show_all_a, new_count,
  556. link_href, comment_li, nonce;
  557.  
  558. /* Comment / comment reply links */
  559. if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) {
  560. if ( target.parent().hasClass('acomment-reply') ) {
  561. target = target.parent();
  562. }
  563.  
  564. id = target.attr('id');
  565. ids = id.split('-');
  566.  
  567. a_id = ids[2];
  568. c_id = target.attr('href').substr( 10, target.attr('href').length );
  569. form = jq( '#ac-form-' + a_id );
  570.  
  571. form.css( 'display', 'none' );
  572. form.removeClass('root');
  573. jq('.ac-form').hide();
  574.  
  575. /* Hide any error messages */
  576. form.children('div').each( function() {
  577. if ( jq(this).hasClass( 'error' ) ) {
  578. jq(this).hide();
  579. }
  580. });
  581.  
  582. if ( ids[1] !== 'comment' ) {
  583. jq('#acomment-' + c_id).append( form );
  584. } else {
  585. jq('#activity-' + a_id + ' .activity-comments').append( form );
  586. }
  587.  
  588. if ( form.parent().hasClass( 'activity-comments' ) ) {
  589. form.addClass('root');
  590. }
  591.  
  592. form.slideDown( 200 );
  593. jq.scrollTo( form, 500, {
  594. offset:-100,
  595. easing:'swing'
  596. } );
  597. jq('#ac-form-' + ids[2] + ' textarea').focus();
  598.  
  599. return false;
  600. }
  601.  
  602. /* Activity comment posting */
  603. if ( target.attr('name') === 'ac_form_submit' ) {
  604. form = target.parents( 'form' );
  605. form_parent = form.parent();
  606. form_id = form.attr('id').split('-');
  607.  
  608. if ( !form_parent.hasClass('activity-comments') ) {
  609. tmp_id = form_parent.attr('id').split('-');
  610. comment_id = tmp_id[1];
  611. } else {
  612. comment_id = form_id[2];
  613. }
  614.  
  615. content = jq( '#' + form.attr('id') + ' textarea' );
  616.  
  617. /* Hide any error messages */
  618. jq( '#' + form.attr('id') + ' div.error').hide();
  619. target.addClass('loading').prop('disabled', true);
  620. content.addClass('loading').prop('disabled', true);
  621.  
  622. ajaxdata = {
  623. action: 'new_activity_comment',
  624. 'cookie': bp_get_cookies(),
  625. '_wpnonce_new_activity_comment': jq('#_wpnonce_new_activity_comment').val(),
  626. 'comment_id': comment_id,
  627. 'form_id': form_id[2],
  628. 'content': content.val()
  629. };
  630.  
  631. // Akismet
  632. ak_nonce = jq('#_bp_as_nonce_' + comment_id).val();
  633. if ( ak_nonce ) {
  634. ajaxdata['_bp_as_nonce_' + comment_id] = ak_nonce;
  635. }
  636.  
  637. jq.post( ajaxurl, ajaxdata, function(response) {
  638. target.removeClass('loading');
  639. content.removeClass('loading');
  640.  
  641. /* Check for errors and append if found. */
  642. if ( response[0] + response[1] === '-1' ) {
  643. form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
  644. } else {
  645. var activity_comments = form.parent();
  646. form.fadeOut( 200, function() {
  647. if ( 0 === activity_comments.children('ul').length ) {
  648. if ( activity_comments.hasClass('activity-comments') ) {
  649. activity_comments.prepend('<ul></ul>');
  650. } else {
  651. activity_comments.append('<ul></ul>');
  652. }
  653. }
  654.  
  655. /* Preceding whitespace breaks output with jQuery 1.9.0 */
  656. var the_comment = jq.trim( response );
  657.  
  658. activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
  659. form.children('textarea').val('');
  660. activity_comments.parent().addClass('has-comments');
  661. } );
  662. jq( '#' + form.attr('id') + ' textarea').val('');
  663.  
  664. /* Increase the "Reply (X)" button count */
  665. jq('#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
  666.  
  667. // Increment the 'Show all x comments' string, if present
  668. show_all_a = activity_comments.find('.show-all').find('a');
  669. if ( show_all_a ) {
  670. new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html();
  671. show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
  672. }
  673. }
  674.  
  675. jq(target).prop('disabled', false);
  676. jq(content).prop('disabled', false);
  677. });
  678.  
  679. return false;
  680. }
  681.  
  682. /* Deleting an activity comment */
  683. if ( target.hasClass('acomment-delete') ) {
  684. link_href = target.attr('href');
  685. comment_li = target.parent().parent();
  686. form = comment_li.parents('div.activity-comments').children('form');
  687.  
  688. nonce = link_href.split('_wpnonce=');
  689. nonce = nonce[1];
  690.  
  691. comment_id = link_href.split('cid=');
  692. comment_id = comment_id[1].split('&');
  693. comment_id = comment_id[0];
  694.  
  695. target.addClass('loading');
  696.  
  697. /* Remove any error messages */
  698. jq('.activity-comments ul .error').remove();
  699.  
  700. /* Reset the form position */
  701. comment_li.parents('.activity-comments').append(form);
  702.  
  703. jq.post( ajaxurl, {
  704. action: 'delete_activity_comment',
  705. 'cookie': bp_get_cookies(),
  706. '_wpnonce': nonce,
  707. 'id': comment_id
  708. },
  709. function(response) {
  710. /* Check for errors and append if found. */
  711. if ( response[0] + response[1] === '-1' ) {
  712. comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
  713. } else {
  714. var children = jq( '#' + comment_li.attr('id') + ' ul' ).children('li'),
  715. child_count = 0,
  716. count_span, new_count, show_all_a;
  717.  
  718. jq(children).each( function() {
  719. if ( !jq(this).is(':hidden') ) {
  720. child_count++;
  721. }
  722. });
  723. comment_li.fadeOut(200, function() {
  724. comment_li.remove();
  725. });
  726.  
  727. /* Decrease the "Reply (X)" button count */
  728. count_span = jq('#' + comment_li.parents('#activity-stream > li').attr('id') + ' a.acomment-reply span');
  729. new_count = count_span.html() - ( 1 + child_count );
  730. count_span.html(new_count);
  731.  
  732. // Change the 'Show all x comments' text
  733. show_all_a = comment_li.siblings('.show-all').find('a');
  734. if ( show_all_a ) {
  735. show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
  736. }
  737.  
  738. /* If that was the last comment for the item, remove the has-comments class to clean up the styling */
  739. if ( 0 === new_count ) {
  740. jq(comment_li.parents('#activity-stream > li')).removeClass('has-comments');
  741. }
  742. }
  743. });
  744.  
  745. return false;
  746. }
  747.  
  748. // Spam an activity stream comment
  749. if ( target.hasClass( 'spam-activity-comment' ) ) {
  750. link_href = target.attr( 'href' );
  751. comment_li = target.parent().parent();
  752.  
  753. target.addClass('loading');
  754.  
  755. // Remove any error messages
  756. jq( '.activity-comments ul div.error' ).remove();
  757.  
  758. // Reset the form position
  759. comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) );
  760.  
  761. jq.post( ajaxurl, {
  762. action: 'bp_spam_activity_comment',
  763. 'cookie': encodeURIComponent( document.cookie ),
  764. '_wpnonce': link_href.split( '_wpnonce=' )[1],
  765. 'id': link_href.split( 'cid=' )[1].split( '&' )[0]
  766. },
  767.  
  768. function ( response ) {
  769. // Check for errors and append if found.
  770. if ( response[0] + response[1] === '-1' ) {
  771. comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
  772.  
  773. } else {
  774. var children = jq( '#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' ),
  775. child_count = 0,
  776. parent_li;
  777.  
  778. jq(children).each( function() {
  779. if ( !jq( this ).is( ':hidden' ) ) {
  780. child_count++;
  781. }
  782. });
  783. comment_li.fadeOut( 200 );
  784.  
  785. // Decrease the "Reply (X)" button count
  786. parent_li = comment_li.parents( '#activity-stream > li' );
  787. jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html( jq( '#' + parent_li.attr( 'id' ) + ' a.acomment-reply span' ).html() - ( 1 + child_count ) );
  788. }
  789. });
  790.  
  791. return false;
  792. }
  793.  
  794. /* Showing hidden comments - pause for half a second */
  795. if ( target.parent().hasClass('show-all') ) {
  796. target.parent().addClass('loading');
  797.  
  798. setTimeout( function() {
  799. target.parent().parent().children('li').fadeIn(200, function() {
  800. target.parent().remove();
  801. });
  802. }, 600 );
  803.  
  804. return false;
  805. }
  806.  
  807. // Canceling an activity comment
  808. if ( target.hasClass( 'ac-reply-cancel' ) ) {
  809. jq(target).closest('.ac-form').slideUp( 200 );
  810. return false;
  811. }
  812. });
  813.  
  814. /* Escape Key Press for cancelling comment forms */
  815. jq(document).keydown( function(e) {
  816. e = e || window.event;
  817. if (e.target) {
  818. element = e.target;
  819. } else if (e.srcElement) {
  820. element = e.srcElement;
  821. }
  822.  
  823. if( element.nodeType === 3) {
  824. element = element.parentNode;
  825. }
  826.  
  827. if( e.ctrlKey === true || e.altKey === true || e.metaKey === true ) {
  828. return;
  829. }
  830.  
  831. var keyCode = (e.keyCode) ? e.keyCode : e.which;
  832.  
  833. if ( keyCode === 27 ) {
  834. if (element.tagName === 'TEXTAREA') {
  835. if ( jq(element).hasClass('ac-input') ) {
  836. jq(element).parent().parent().parent().slideUp( 200 );
  837. }
  838. }
  839. }
  840. });
  841.  
  842. /**** Directory Search ****************************************************/
  843.  
  844. /* The search form on all directory pages */
  845. jq( '.dir-search, .groups-members-search' ).on( 'click', function(event) {
  846. if ( jq(this).hasClass('no-ajax') ) {
  847. return;
  848. }
  849.  
  850. var target = jq(event.target),
  851. css_id, object, template;
  852.  
  853. if ( target.attr('type') === 'submit' ) {
  854. css_id = jq('.item-list-tabs li.selected').attr('id').split( '-' );
  855. object = css_id[0];
  856. template = null;
  857.  
  858. // The Group Members page specifies its own template
  859. if ( event.currentTarget.className === 'groups-members-search' ) {
  860. object = 'group_members';
  861. template = 'groups/single/members';
  862. }
  863.  
  864. 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'), null, template );
  865.  
  866. return false;
  867. }
  868. });
  869.  
  870. /**** Tabs and Filters ****************************************************/
  871.  
  872. /* When a navigation tab is clicked - e.g. | All Groups | My Groups | */
  873. jq('div.item-list-tabs').on( 'click', function(event) {
  874. if ( jq(this).hasClass('no-ajax') || jq( event.target ).hasClass('no-ajax') ) {
  875. return;
  876. }
  877.  
  878. var targetElem = ( event.target.nodeName === 'SPAN' ) ? event.target.parentNode : event.target,
  879. target = jq( targetElem ).parent(),
  880. css_id, object, scope, filter, search_terms;
  881.  
  882. if ( 'LI' === target[0].nodeName && !target.hasClass( 'last' ) ) {
  883. css_id = target.attr('id').split( '-' );
  884. object = css_id[0];
  885.  
  886. if ( 'activity' === object ) {
  887. return false;
  888. }
  889.  
  890. scope = css_id[1];
  891. filter = jq('#' + object + '-order-select select').val();
  892. search_terms = jq('#' + object + '_search').val();
  893.  
  894. bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') );
  895.  
  896. return false;
  897. }
  898. });
  899.  
  900. /* When the filter select box is changed re-query */
  901. jq('li.filter select').change( function() {
  902. var el,
  903. css_id, object, scope, filter, search_terms, template,
  904. $gm_search;
  905.  
  906. if ( jq('.item-list-tabs li.selected').length ) {
  907. el = jq('.item-list-tabs li.selected');
  908. } else {
  909. el = jq(this);
  910. }
  911.  
  912. css_id = el.attr('id').split('-');
  913. object = css_id[0];
  914. scope = css_id[1];
  915. filter = jq(this).val();
  916. search_terms = false;
  917. template = null;
  918.  
  919. if ( jq('.dir-search input').length ) {
  920. search_terms = jq('.dir-search input').val();
  921. }
  922.  
  923. // The Group Members page has a different selector for its
  924. // search terms box
  925. $gm_search = jq( '.groups-members-search input' );
  926. if ( $gm_search.length ) {
  927. search_terms = $gm_search.val();
  928. object = 'members';
  929. scope = 'groups';
  930. }
  931.  
  932. // On the Groups Members page, we specify a template
  933. if ( 'members' === object && 'groups' === scope ) {
  934. object = 'group_members';
  935. template = 'groups/single/members';
  936. }
  937.  
  938. if ( 'friends' === object ) {
  939. object = 'members';
  940. }
  941.  
  942. bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras'), null, template );
  943.  
  944. return false;
  945. });
  946.  
  947. /* All pagination links run through this function */
  948. jq('#buddypress').on( 'click', function(event) {
  949. var target = jq(event.target),
  950. el,
  951. css_id, object, search_terms, pagination_id, template,
  952. url_parameters, page_number,
  953. $gm_search,
  954. caller;
  955.  
  956. if ( target.hasClass('button') ) {
  957. return true;
  958. }
  959.  
  960. if ( target.parent().parent().hasClass('pagination') && !target.parent().parent().hasClass('no-ajax') ) {
  961. if ( target.hasClass('dots') || target.hasClass('current') ) {
  962. return false;
  963. }
  964.  
  965. if ( jq('.item-list-tabs li.selected').length ) {
  966. el = jq('.item-list-tabs li.selected');
  967. } else {
  968. el = jq('li.filter select');
  969. }
  970.  
  971. css_id = el.attr('id').split( '-' );
  972. object = css_id[0];
  973. search_terms = false;
  974. pagination_id = jq(target).closest('.pagination-links').attr('id');
  975. template = null;
  976.  
  977. url_parameters = target.attr('href').split( '&' );
  978. // The page number is the first parameter.
  979. page_number = url_parameters[0].split( '=' );
  980. page_number = page_number[1];
  981.  
  982. // Search terms
  983. if ( jq('div.dir-search input').length ) {
  984. search_terms = jq('.dir-search input').val();
  985.  
  986. if ( ! search_terms && bp_get_querystring('s') ) {
  987. search_terms = jq('.dir-search input').prop('placeholder');
  988. }
  989. }
  990.  
  991. // The Group Members page has a different selector for
  992. // its search terms box
  993. $gm_search = jq( '.groups-members-search input' );
  994. if ( $gm_search.length ) {
  995. search_terms = $gm_search.val();
  996. object = 'members';
  997. }
  998.  
  999. // On the Groups Members page, we specify a template
  1000. if ( 'members' === object && 'groups' === css_id[1] ) {
  1001. object = 'group_members';
  1002. template = 'groups/single/members';
  1003. }
  1004.  
  1005. // On the Admin > Requests page, we need to reset the object,
  1006. // since "admin" isn't specific enough
  1007. if ( 'admin' === object && jq( 'body' ).hasClass( 'membership-requests' ) ) {
  1008. object = 'requests';
  1009. }
  1010.  
  1011. if ( pagination_id.indexOf( 'pag-bottom' ) !== -1 ) {
  1012. caller = 'pag-bottom';
  1013. } else {
  1014. caller = null;
  1015. }
  1016.  
  1017. 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, template );
  1018.  
  1019. return false;
  1020. }
  1021.  
  1022. });
  1023.  
  1024. /**** New Forum Directory Post **************************************/
  1025.  
  1026. /* Hit the "New Topic" button on the forums directory page */
  1027. jq('a.show-hide-new').on( 'click', function() {
  1028. if ( !jq('#new-topic-post').length ) {
  1029. return false;
  1030. }
  1031.  
  1032. if ( jq('#new-topic-post').is(':visible') ) {
  1033. jq('#new-topic-post').slideUp(200);
  1034. } else {
  1035. jq('#new-topic-post').slideDown(200, function() {
  1036. jq('#topic_title').focus();
  1037. } );
  1038. }
  1039.  
  1040. return false;
  1041. });
  1042.  
  1043. /* Cancel the posting of a new forum topic */
  1044. jq('#submit_topic_cancel').on( 'click', function() {
  1045. if ( !jq('#new-topic-post').length ) {
  1046. return false;
  1047. }
  1048.  
  1049. jq('#new-topic-post').slideUp(200);
  1050. return false;
  1051. });
  1052.  
  1053. /* Clicking a forum tag */
  1054. jq('#forum-directory-tags a').on( 'click', function() {
  1055. bp_filter_request( 'forums', 'tags', jq.cookie('bp-forums-scope'), 'div.forums', jq(this).html().replace( /&nbsp;/g, '-' ), 1, jq.cookie('bp-forums-extras') );
  1056. return false;
  1057. });
  1058.  
  1059. /** Invite Friends Interface ****************************************/
  1060.  
  1061. /* Select a user from the list of friends and add them to the invite list */
  1062. jq('#send-invite-form').on( 'click', '#invite-list input', function() {
  1063. // invites-loop template contains a div with the .invite class
  1064. // We use the existence of this div to check for old- vs new-
  1065. // style templates.
  1066. var invites_new_template = jq( '#send-invite-form > .invite' ).length,
  1067. friend_id, friend_action;
  1068.  
  1069. jq('.ajax-loader').toggle();
  1070.  
  1071. // Dim the form until the response arrives
  1072. if ( invites_new_template ) {
  1073. jq( this ).parents( 'ul' ).find( 'input' ).prop( 'disabled', true );
  1074. }
  1075.  
  1076. friend_id = jq(this).val();
  1077.  
  1078. if ( jq(this).prop('checked') === true ) {
  1079. friend_action = 'invite';
  1080. } else {
  1081. friend_action = 'uninvite';
  1082. }
  1083.  
  1084. if ( ! invites_new_template ) {
  1085. jq( '.item-list-tabs li.selected' ).addClass( 'loading' );
  1086. }
  1087.  
  1088. jq.post( ajaxurl, {
  1089. action: 'groups_invite_user',
  1090. 'friend_action': friend_action,
  1091. 'cookie': bp_get_cookies(),
  1092. '_wpnonce': jq('#_wpnonce_invite_uninvite_user').val(),
  1093. 'friend_id': friend_id,
  1094. 'group_id': jq('#group_id').val()
  1095. },
  1096. function(response)
  1097. {
  1098. if ( jq('#message') ) {
  1099. jq('#message').hide();
  1100. }
  1101.  
  1102. if ( invites_new_template ) {
  1103. // With new-style templates, we refresh the
  1104. // entire list
  1105. bp_filter_request( 'invite', 'bp-invite-filter', 'bp-invite-scope', 'div.invite', false, 1, '', '', '' );
  1106. } else {
  1107. // Old-style templates manipulate only the
  1108. // single invitation element
  1109. jq('.ajax-loader').toggle();
  1110.  
  1111. if ( friend_action === 'invite' ) {
  1112. jq('#friend-list').append(response);
  1113. } else if ( friend_action === 'uninvite' ) {
  1114. jq('#friend-list li#uid-' + friend_id).remove();
  1115. }
  1116.  
  1117. jq('.item-list-tabs li.selected').removeClass('loading');
  1118. }
  1119. });
  1120. });
  1121.  
  1122. /* Remove a user from the list of users to invite to a group */
  1123. jq('#send-invite-form').on('click', 'a.remove', function() {
  1124. // invites-loop template contains a div with the .invite class
  1125. // We use the existence of this div to check for old- vs new-
  1126. // style templates.
  1127. var invites_new_template = jq('#send-invite-form > .invite').length,
  1128. friend_id = jq(this).attr('id');
  1129.  
  1130. jq('.ajax-loader').toggle();
  1131.  
  1132. friend_id = friend_id.split('-');
  1133. friend_id = friend_id[1];
  1134.  
  1135. jq.post( ajaxurl, {
  1136. action: 'groups_invite_user',
  1137. 'friend_action': 'uninvite',
  1138. 'cookie': bp_get_cookies(),
  1139. '_wpnonce': jq('#_wpnonce_invite_uninvite_user').val(),
  1140. 'friend_id': friend_id,
  1141. 'group_id': jq('#group_id').val()
  1142. },
  1143. function(response)
  1144. {
  1145. if ( invites_new_template ) {
  1146. // With new-style templates, we refresh the
  1147. // entire list
  1148. bp_filter_request( 'invite', 'bp-invite-filter', 'bp-invite-scope', 'div.invite', false, 1, '', '', '' );
  1149. } else {
  1150. // Old-style templates manipulate only the
  1151. // single invitation element
  1152. jq('.ajax-loader').toggle();
  1153. jq('#friend-list #uid-' + friend_id).remove();
  1154. jq('#invite-list #f-' + friend_id).prop('checked', false);
  1155. }
  1156. });
  1157.  
  1158. return false;
  1159. });
  1160.  
  1161. /** Profile Visibility Settings *********************************/
  1162. jq( '.visibility-toggle-link' ).on( 'click', function( event ) {
  1163. event.preventDefault();
  1164.  
  1165. jq( this ).parent().hide().addClass( 'field-visibility-settings-hide' )
  1166. .siblings( '.field-visibility-settings' ).show().addClass( 'field-visibility-settings-open' );
  1167. } );
  1168.  
  1169. jq( '.field-visibility-settings-close' ).on( 'click', function( event ) {
  1170. event.preventDefault();
  1171.  
  1172. var settings_div = jq( this ).parent(),
  1173. vis_setting_text = settings_div.find( 'input:checked' ).parent().text();
  1174.  
  1175. settings_div.hide().removeClass( 'field-visibility-settings-open' )
  1176. .siblings( '.field-visibility-settings-toggle' )
  1177. .children( '.current-visibility-level' ).text( vis_setting_text ).end()
  1178. .show().removeClass( 'field-visibility-settings-hide' );
  1179. } );
  1180.  
  1181. 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() {
  1182. var shouldconfirm = true;
  1183.  
  1184. jq('#profile-edit-form input:submit, #signup_form input:submit').on( 'click', function() {
  1185. shouldconfirm = false;
  1186. });
  1187.  
  1188. window.onbeforeunload = function(e) {
  1189. if ( shouldconfirm ) {
  1190. return BP_DTheme.unsaved_changes;
  1191. }
  1192. };
  1193. });
  1194.  
  1195. /** Friendship Requests **************************************/
  1196.  
  1197. /* Accept and Reject friendship request buttons */
  1198. jq('#friend-list a.accept, #friend-list a.reject').on( 'click', function() {
  1199. var button = jq(this),
  1200. li = jq(this).parents('#friend-list li'),
  1201. action_div = jq(this).parents('li div.action'),
  1202. id = li.attr('id').substr( 11, li.attr('id').length ),
  1203. link_href = button.attr('href'),
  1204. nonce = link_href.split('_wpnonce=')[1],
  1205. action;
  1206.  
  1207. if ( jq(this).hasClass('accepted') || jq(this).hasClass('rejected') ) {
  1208. return false;
  1209. }
  1210.  
  1211. if ( jq(this).hasClass('accept') ) {
  1212. action = 'accept_friendship';
  1213. action_div.children('a.reject').css( 'visibility', 'hidden' );
  1214. } else {
  1215. action = 'reject_friendship';
  1216. action_div.children('a.accept').css( 'visibility', 'hidden' );
  1217. }
  1218.  
  1219. button.addClass('loading');
  1220.  
  1221. jq.post( ajaxurl, {
  1222. action: action,
  1223. 'cookie': bp_get_cookies(),
  1224. 'id': id,
  1225. '_wpnonce': nonce
  1226. },
  1227. function(response) {
  1228. button.removeClass('loading');
  1229.  
  1230. if ( response[0] + response[1] === '-1' ) {
  1231. li.prepend( response.substr( 2, response.length ) );
  1232. li.children('#message').hide().fadeIn(200);
  1233. } else {
  1234. button.fadeOut( 100, function() {
  1235. if ( jq(this).hasClass('accept') ) {
  1236. action_div.children('a.reject').hide();
  1237. jq(this).html( BP_DTheme.accepted ).contents().unwrap();
  1238. } else {
  1239. action_div.children('a.accept').hide();
  1240. jq(this).html( BP_DTheme.rejected ).contents().unwrap();
  1241. }
  1242. });
  1243. }
  1244. });
  1245.  
  1246. return false;
  1247. });
  1248.  
  1249. /* Add / Remove friendship buttons */
  1250. jq( '#members-dir-list, #members-group-list, #item-header' ).on('click', '.friendship-button a', function() {
  1251. jq(this).parent().addClass('loading');
  1252. var fid = jq(this).attr('id'),
  1253. nonce = jq(this).attr('href'),
  1254. thelink = jq(this);
  1255.  
  1256. fid = fid.split('-');
  1257. fid = fid[1];
  1258.  
  1259. nonce = nonce.split('?_wpnonce=');
  1260. nonce = nonce[1].split('&');
  1261. nonce = nonce[0];
  1262.  
  1263. jq.post( ajaxurl, {
  1264. action: 'addremove_friend',
  1265. 'cookie': bp_get_cookies(),
  1266. 'fid': fid,
  1267. '_wpnonce': nonce
  1268. },
  1269. function(response)
  1270. {
  1271. var action = thelink.attr('rel');
  1272. parentdiv = thelink.parent();
  1273.  
  1274. if ( action === 'add' ) {
  1275. jq(parentdiv).fadeOut(200,
  1276. function() {
  1277. parentdiv.removeClass('add_friend');
  1278. parentdiv.removeClass('loading');
  1279. parentdiv.addClass('pending_friend');
  1280. parentdiv.fadeIn(200).html(response);
  1281. }
  1282. );
  1283.  
  1284. } else if ( action === 'remove' ) {
  1285. jq(parentdiv).fadeOut(200,
  1286. function() {
  1287. parentdiv.removeClass('remove_friend');
  1288. parentdiv.removeClass('loading');
  1289. parentdiv.addClass('add');
  1290. parentdiv.fadeIn(200).html(response);
  1291. }
  1292. );
  1293. }
  1294. });
  1295. return false;
  1296. } );
  1297.  
  1298. /** Group Join / Leave Buttons **************************************/
  1299.  
  1300. // Confirmation when clicking Leave Group in group headers
  1301. jq('#buddypress').on('click', '.group-button .leave-group', function() {
  1302. if ( false === confirm( BP_DTheme.leave_group_confirm ) ) {
  1303. return false;
  1304. }
  1305. });
  1306.  
  1307. jq('#groups-dir-list').on('click', '.group-button a', function() {
  1308. var gid = jq(this).parent().attr('id'),
  1309. nonce = jq(this).attr('href'),
  1310. thelink = jq(this);
  1311.  
  1312. gid = gid.split('-');
  1313. gid = gid[1];
  1314.  
  1315. nonce = nonce.split('?_wpnonce=');
  1316. nonce = nonce[1].split('&');
  1317. nonce = nonce[0];
  1318.  
  1319. // Leave Group confirmation within directories - must intercept
  1320. // AJAX request
  1321. if ( thelink.hasClass( 'leave-group' ) && false === confirm( BP_DTheme.leave_group_confirm ) ) {
  1322. return false;
  1323. }
  1324.  
  1325. jq.post( ajaxurl, {
  1326. action: 'joinleave_group',
  1327. 'cookie': bp_get_cookies(),
  1328. 'gid': gid,
  1329. '_wpnonce': nonce
  1330. },
  1331. function(response)
  1332. {
  1333. var parentdiv = thelink.parent();
  1334.  
  1335. // user groups page
  1336. if ( ! jq('body.directory').length ) {
  1337. window.location.reload();
  1338.  
  1339. // groups directory
  1340. } else {
  1341. jq(parentdiv).fadeOut(200,
  1342. function() {
  1343. parentdiv.fadeIn(200).html(response);
  1344.  
  1345. var mygroups = jq('#groups-personal span'),
  1346. add = 1;
  1347.  
  1348. if( thelink.hasClass( 'leave-group' ) ) {
  1349. // hidden groups slide up
  1350. if ( parentdiv.hasClass( 'hidden' ) ) {
  1351. parentdiv.closest('li').slideUp( 200 );
  1352. }
  1353.  
  1354. add = 0;
  1355. } else if ( thelink.hasClass( 'request-membership' ) ) {
  1356. add = false;
  1357. }
  1358.  
  1359. // change the "My Groups" value
  1360. if ( mygroups.length && add !== false ) {
  1361. if ( add ) {
  1362. mygroups.text( ( mygroups.text() >> 0 ) + 1 );
  1363. } else {
  1364. mygroups.text( ( mygroups.text() >> 0 ) - 1 );
  1365. }
  1366. }
  1367.  
  1368. }
  1369. );
  1370. }
  1371. });
  1372. return false;
  1373. } );
  1374.  
  1375. /** Button disabling ************************************************/
  1376.  
  1377. jq('#buddypress').on( 'click', '.pending', function() {
  1378. return false;
  1379. });
  1380.  
  1381. /** Registration ***********************************************/
  1382.  
  1383. if ( jq('body').hasClass('register') ) {
  1384. var blog_checked = jq('#signup_with_blog');
  1385.  
  1386. // hide "Blog Details" block if not checked by default
  1387. if ( ! blog_checked.prop('checked') ) {
  1388. jq('#blog-details').toggle();
  1389. }
  1390.  
  1391. // toggle "Blog Details" block whenever checkbox is checked
  1392. blog_checked.change(function() {
  1393. jq('#blog-details').toggle();
  1394. });
  1395. }
  1396.  
  1397. /** Private Messaging ******************************************/
  1398.  
  1399. /** Message search */
  1400. jq('.message-search').on( 'click', function(event) {
  1401. if ( jq(this).hasClass('no-ajax') ) {
  1402. return;
  1403. }
  1404.  
  1405. var target = jq(event.target),
  1406. object;
  1407.  
  1408. if ( target.attr('type') === 'submit' || target.attr('type') === 'button' ) {
  1409. object = 'messages';
  1410.  
  1411. bp_filter_request(
  1412. object,
  1413. jq.cookie('bp-' + object + '-filter'),
  1414. jq.cookie('bp-' + object + '-scope'),
  1415. 'div.' + object, jq('#messages_search').val(),
  1416. 1,
  1417. jq.cookie('bp-' + object + '-extras')
  1418. );
  1419.  
  1420. return false;
  1421. }
  1422. });
  1423.  
  1424. /* AJAX send reply functionality */
  1425. jq('#send_reply_button').click(
  1426. function() {
  1427. var order = jq('#messages_order').val() || 'ASC',
  1428. offset = jq('#message-recipients').offset(),
  1429. button = jq('#send_reply_button');
  1430.  
  1431. jq(button).addClass('loading');
  1432.  
  1433. jq.post( ajaxurl, {
  1434. action: 'messages_send_reply',
  1435. 'cookie': bp_get_cookies(),
  1436. '_wpnonce': jq('#send_message_nonce').val(),
  1437.  
  1438. 'content': jq('#message_content').val(),
  1439. 'send_to': jq('#send_to').val(),
  1440. 'subject': jq('#subject').val(),
  1441. 'thread_id': jq('#thread_id').val()
  1442. },
  1443. function(response)
  1444. {
  1445. if ( response[0] + response[1] === '-1' ) {
  1446. jq('#send-reply').prepend( response.substr( 2, response.length ) );
  1447. } else {
  1448. jq('#send-reply #message').remove();
  1449. jq('#message_content').val('');
  1450.  
  1451. if ( 'ASC' === order ) {
  1452. jq('#send-reply').before( response );
  1453. } else {
  1454. jq('#message-recipients').after( response );
  1455. jq(window).scrollTop(offset.top);
  1456. }
  1457.  
  1458. jq('.new-message').hide().slideDown( 200, function() {
  1459. jq('.new-message').removeClass('new-message');
  1460. });
  1461. }
  1462. jq(button).removeClass('loading');
  1463. });
  1464.  
  1465. return false;
  1466. }
  1467. );
  1468.  
  1469. /* Marking private messages as read and unread */
  1470. jq('#mark_as_read, #mark_as_unread').click(function() {
  1471. var checkboxes_tosend = '',
  1472. checkboxes = jq('#message-threads tr td input[type="checkbox"]'),
  1473. currentClass, newClass, unreadCount, inboxCount, unreadCountDisplay, action,
  1474. inboxcount, thread_count;
  1475.  
  1476. if ( 'mark_as_unread' === jq(this).attr('id') ) {
  1477. currentClass = 'read';
  1478. newClass = 'unread';
  1479. unreadCount = 1;
  1480. inboxCount = 0;
  1481. unreadCountDisplay = 'inline';
  1482. action = 'messages_markunread';
  1483. } else {
  1484. currentClass = 'unread';
  1485. newClass = 'read';
  1486. unreadCount = 0;
  1487. inboxCount = 1;
  1488. unreadCountDisplay = 'none';
  1489. action = 'messages_markread';
  1490. }
  1491.  
  1492. checkboxes.each( function(i) {
  1493. if(jq(this).is(':checked')) {
  1494. if ( jq('#m-' + jq(this).attr('value')).hasClass(currentClass) ) {
  1495. checkboxes_tosend += jq(this).attr('value');
  1496. jq('#m-' + jq(this).attr('value')).removeClass(currentClass);
  1497. jq('#m-' + jq(this).attr('value')).addClass(newClass);
  1498. thread_count = jq('#m-' + jq(this).attr('value') + ' td span.unread-count').html();
  1499.  
  1500. jq('#m-' + jq(this).attr('value') + ' td span.unread-count').html(unreadCount);
  1501. jq('#m-' + jq(this).attr('value') + ' td span.unread-count').css('display', unreadCountDisplay);
  1502.  
  1503. inboxcount = jq('tr.unread').length;
  1504.  
  1505. jq('#user-messages span').html( inboxcount );
  1506.  
  1507. if ( i !== checkboxes.length - 1 ) {
  1508. checkboxes_tosend += ',';
  1509. }
  1510. }
  1511. }
  1512. });
  1513. jq.post( ajaxurl, {
  1514. action: action,
  1515. 'thread_ids': checkboxes_tosend
  1516. });
  1517. return false;
  1518. });
  1519.  
  1520. /* Selecting unread and read messages in inbox */
  1521. jq( 'body.messages #item-body div.messages' ).on( 'change', '#message-type-select', function() {
  1522. var selection = this.value,
  1523. checkboxes = jq( 'td input[type="checkbox"]' ),
  1524. checked_value = 'checked';
  1525.  
  1526. checkboxes.each( function(i) {
  1527. checkboxes[i].checked = '';
  1528. });
  1529.  
  1530. switch ( selection ) {
  1531. case 'unread':
  1532. checkboxes = jq('tr.unread td input[type="checkbox"]');
  1533. break;
  1534. case 'read':
  1535. checkboxes = jq('tr.read td input[type="checkbox"]');
  1536. break;
  1537. case '':
  1538. checked_value = '';
  1539. break;
  1540. }
  1541.  
  1542. checkboxes.each( function(i) {
  1543. checkboxes[i].checked = checked_value;
  1544. });
  1545. });
  1546.  
  1547. /* Bulk delete messages */
  1548. jq( 'body.messages #item-body div.messages' ).on( 'click', '.messages-options-nav a', function() {
  1549. if ( -1 === jq.inArray( this.id, Array( 'delete_sentbox_messages', 'delete_inbox_messages' ) ) ) {
  1550. return;
  1551. }
  1552.  
  1553. checkboxes_tosend = '';
  1554. checkboxes = jq('#message-threads tr td input[type="checkbox"]');
  1555.  
  1556. jq('#message').remove();
  1557. jq(this).addClass('loading');
  1558.  
  1559. jq(checkboxes).each( function(i) {
  1560. if( jq(this).is(':checked') ) {
  1561. checkboxes_tosend += jq(this).attr('value') + ',';
  1562. }
  1563. });
  1564.  
  1565. if ( '' === checkboxes_tosend ) {
  1566. jq(this).removeClass('loading');
  1567. return false;
  1568. }
  1569.  
  1570. jq.post( ajaxurl, {
  1571. action: 'messages_delete',
  1572. 'thread_ids': checkboxes_tosend
  1573. }, function(response) {
  1574. if ( response[0] + response[1] === '-1' ) {
  1575. jq('#message-threads').prepend( response.substr( 2, response.length ) );
  1576. } else {
  1577. jq('#message-threads').before( '<div id="message" class="updated"><p>' + response + '</p></div>' );
  1578.  
  1579. jq(checkboxes).each( function(i) {
  1580. if( jq(this).is(':checked') ) {
  1581. // We need to uncheck because message is only hidden
  1582. // Otherwise, AJAX will be fired again with same data
  1583. jq(this).attr( 'checked', false );
  1584. jq(this).parent().parent().fadeOut(150);
  1585. }
  1586. });
  1587. }
  1588.  
  1589. jq('#message').hide().slideDown(150);
  1590. jq('#delete_inbox_messages, #delete_sentbox_messages').removeClass('loading');
  1591. });
  1592.  
  1593. return false;
  1594. });
  1595.  
  1596. /* Selecting/Deselecting all messages */
  1597. jq('#select-all-messages').click(function(event) {
  1598. if( this.checked ) {
  1599. jq('.message-check').each(function() {
  1600. this.checked = true;
  1601. });
  1602. } else {
  1603. jq('.message-check').each(function() {
  1604. this.checked = false;
  1605. });
  1606. }
  1607. });
  1608.  
  1609. /* Make sure a 'Bulk Action' is selected before submitting the messages bulk action form */
  1610. jq('#messages-bulk-manage').attr('disabled', 'disabled');
  1611.  
  1612. /* Remove the disabled attribute from the messages form submit button when bulk action has a value */
  1613. jq('#messages-select').on('change', function(){
  1614. jq('#messages-bulk-manage').attr('disabled', jq(this).val().length <= 0);
  1615. });
  1616.  
  1617. /* Star action function */
  1618. starAction = function() {
  1619. var link = jq(this);
  1620.  
  1621. jq.post( ajaxurl, {
  1622. action: 'messages_star',
  1623. 'message_id': link.data('message-id'),
  1624. 'star_status': link.data('star-status'),
  1625. 'nonce': link.data('star-nonce'),
  1626. 'bulk': link.data('star-bulk')
  1627. },
  1628. function(response) {
  1629. if ( 1 === parseInt( response, 10 ) ) {
  1630. if ( 'unstar' === link.data('star-status') ) {
  1631. link.data('star-status', 'star');
  1632. link.removeClass('message-action-unstar').addClass('message-action-star');
  1633. link.find('.bp-screen-reader-text').text( BP_PM_Star.strings.text_star );
  1634.  
  1635. if ( 1 === BP_PM_Star.is_single_thread ) {
  1636. link.prop('title', BP_PM_Star.strings.title_star );
  1637. } else {
  1638. link.prop('title', BP_PM_Star.strings.title_star_thread );
  1639. }
  1640.  
  1641. } else {
  1642. link.data('star-status', 'unstar');
  1643. link.removeClass('message-action-star').addClass('message-action-unstar');
  1644. link.find('.bp-screen-reader-text').text(BP_PM_Star.strings.text_unstar);
  1645.  
  1646. if ( 1 === BP_PM_Star.is_single_thread ) {
  1647. link.prop('title', BP_PM_Star.strings.title_unstar );
  1648. } else {
  1649. link.prop('title', BP_PM_Star.strings.title_unstar_thread );
  1650. }
  1651. }
  1652. }
  1653. });
  1654. return false;
  1655. };
  1656.  
  1657. /* Star actions */
  1658. jq('#message-threads').on('click', 'td.thread-star a', starAction );
  1659. jq('#message-thread').on('click', '.message-star-actions a', starAction );
  1660.  
  1661. /* Star bulk manage - Show only the valid action based on the starred item. */
  1662. jq('#message-threads td.bulk-select-check :checkbox').on('change', function() {
  1663. var box = jq(this),
  1664. star = box.closest('tr').find('.thread-star a');
  1665.  
  1666. if ( box.prop('checked') ) {
  1667. if( 'unstar' === star.data('star-status') ) {
  1668. BP_PM_Star.star_counter++;
  1669. } else {
  1670. BP_PM_Star.unstar_counter++;
  1671. }
  1672. } else {
  1673. if( 'unstar' === star.data('star-status') ) {
  1674. BP_PM_Star.star_counter--;
  1675. } else {
  1676. BP_PM_Star.unstar_counter--;
  1677. }
  1678. }
  1679.  
  1680. if ( BP_PM_Star.star_counter > 0 && parseInt( BP_PM_Star.unstar_counter, 10 ) === 0 ) {
  1681. jq('option[value="star"]').hide();
  1682. } else {
  1683. jq('option[value="star"]').show();
  1684. }
  1685.  
  1686. if ( BP_PM_Star.unstar_counter > 0 && parseInt( BP_PM_Star.star_counter, 10 ) === 0 ) {
  1687. jq('option[value="unstar"]').hide();
  1688. } else {
  1689. jq('option[value="unstar"]').show();
  1690. }
  1691. });
  1692.  
  1693. /** Notifications **********************************************/
  1694.  
  1695. /* Selecting/Deselecting all notifications */
  1696. jq('#select-all-notifications').click(function(event) {
  1697. if( this.checked ) {
  1698. jq('.notification-check').each(function() {
  1699. this.checked = true;
  1700. });
  1701. } else {
  1702. jq('.notification-check').each(function() {
  1703. this.checked = false;
  1704. });
  1705. }
  1706. });
  1707.  
  1708. /* Make sure a 'Bulk Action' is selected before submitting the form */
  1709. jq('#notification-bulk-manage').attr('disabled', 'disabled');
  1710.  
  1711. /* Remove the disabled attribute from the form submit button when bulk action has a value */
  1712. jq('#notification-select').on('change', function(){
  1713. jq('#notification-bulk-manage').attr('disabled', jq(this).val().length <= 0);
  1714. });
  1715.  
  1716. /* Close site wide notices in the sidebar */
  1717. jq('#close-notice').on( 'click', function() {
  1718. jq(this).addClass('loading');
  1719. jq('#sidebar div.error').remove();
  1720.  
  1721. jq.post( ajaxurl, {
  1722. action: 'messages_close_notice',
  1723. 'notice_id': jq('.notice').attr('rel').substr( 2, jq('.notice').attr('rel').length )
  1724. },
  1725. function(response) {
  1726. jq('#close-notice').removeClass('loading');
  1727.  
  1728. if ( response[0] + response[1] === '-1' ) {
  1729. jq('.notice').prepend( response.substr( 2, response.length ) );
  1730. jq( '#sidebar div.error').hide().fadeIn( 200 );
  1731. } else {
  1732. jq('.notice').slideUp( 100 );
  1733. }
  1734. });
  1735. return false;
  1736. });
  1737.  
  1738. /* Toolbar & wp_list_pages JavaScript IE6 hover class */
  1739. jq('#wp-admin-bar ul.main-nav li, #nav li').mouseover( function() {
  1740. jq(this).addClass('sfhover');
  1741. });
  1742.  
  1743. jq('#wp-admin-bar ul.main-nav li, #nav li').mouseout( function() {
  1744. jq(this).removeClass('sfhover');
  1745. });
  1746.  
  1747. /* Clear BP cookies on logout */
  1748. jq('#wp-admin-bar-logout, a.logout').on( 'click', function() {
  1749. jq.removeCookie('bp-activity-scope', {
  1750. path: '/'
  1751. });
  1752. jq.removeCookie('bp-activity-filter', {
  1753. path: '/'
  1754. });
  1755. jq.removeCookie('bp-activity-oldestpage', {
  1756. path: '/'
  1757. });
  1758.  
  1759. var objects = [ 'members', 'groups', 'blogs', 'forums' ];
  1760. jq(objects).each( function(i) {
  1761. jq.removeCookie('bp-' + objects[i] + '-scope', {
  1762. path: '/'
  1763. } );
  1764. jq.removeCookie('bp-' + objects[i] + '-filter', {
  1765. path: '/'
  1766. } );
  1767. jq.removeCookie('bp-' + objects[i] + '-extras', {
  1768. path: '/'
  1769. } );
  1770. });
  1771. });
  1772.  
  1773. /* if js is enabled then replace the no-js class by a js one */
  1774. if( jq('body').hasClass('no-js') ) {
  1775. jq('body').attr('class', jq('body').attr('class').replace( /no-js/,'js' ) );
  1776. }
  1777.  
  1778. /** Activity HeartBeat ************************************************/
  1779.  
  1780. // Set the interval and the namespace event
  1781. if ( typeof wp !== 'undefined' && typeof wp.heartbeat !== 'undefined' && typeof BP_DTheme.pulse !== 'undefined' ) {
  1782.  
  1783. wp.heartbeat.interval( Number( BP_DTheme.pulse ) );
  1784.  
  1785. jq.fn.extend({
  1786. 'heartbeat-send': function() {
  1787. return this.bind( 'heartbeat-send.buddypress' );
  1788. }
  1789. });
  1790. }
  1791.  
  1792. // Set the last id to request after
  1793. var first_item_recorded = 0;
  1794. jq( document ).on( 'heartbeat-send.buddypress', function( e, data ) {
  1795.  
  1796. first_item_recorded = 0;
  1797.  
  1798. // First row is default latest activity id
  1799. if ( jq( '#buddypress ul.activity-list li' ).first().prop( 'id' ) ) {
  1800. // getting the timestamp
  1801. timestamp = jq( '#buddypress ul.activity-list li' ).first().prop( 'class' ).match( /date-recorded-([0-9]+)/ );
  1802.  
  1803. if ( timestamp ) {
  1804. first_item_recorded = timestamp[1];
  1805. }
  1806. }
  1807.  
  1808. if ( 0 === activity_last_recorded || Number( first_item_recorded ) > activity_last_recorded ) {
  1809. activity_last_recorded = Number( first_item_recorded );
  1810. }
  1811.  
  1812. data.bp_activity_last_recorded = activity_last_recorded;
  1813.  
  1814. last_recorded_search = bp_get_querystring('s');
  1815.  
  1816. if ( last_recorded_search ) {
  1817. data.bp_activity_last_recorded_search_terms = last_recorded_search;
  1818. }
  1819. });
  1820.  
  1821. // Increment newest_activities and activity_last_recorded if data has been returned
  1822. jq( document ).on( 'heartbeat-tick', function( e, data ) {
  1823.  
  1824. // Only proceed if we have newest activities
  1825. if ( ! data.bp_activity_newest_activities ) {
  1826. return;
  1827. }
  1828.  
  1829. newest_activities = data.bp_activity_newest_activities.activities + newest_activities;
  1830. activity_last_recorded = Number( data.bp_activity_newest_activities.last_recorded );
  1831.  
  1832. if ( jq( '#buddypress ul.activity-list li' ).first().hasClass( 'load-newest' ) ) {
  1833. return;
  1834. }
  1835.  
  1836. jq( '#buddypress ul.activity-list' ).prepend( '<li class="load-newest"><a href="#newest">' + BP_DTheme.newest + '</a></li>' );
  1837. });
  1838. });
  1839.  
  1840. /* Setup activity scope and filter based on the current cookie settings. */
  1841. function bp_init_activity() {
  1842. /* Reset the page */
  1843. jq.cookie( 'bp-activity-oldestpage', 1, {
  1844. path: '/'
  1845. } );
  1846.  
  1847. if ( undefined !== jq.cookie('bp-activity-filter') && jq('#activity-filter-select').length ) {
  1848. jq('#activity-filter-select select option[value="' + jq.cookie('bp-activity-filter') + '"]').prop( 'selected', true );
  1849. }
  1850.  
  1851. /* Activity Tab Set */
  1852. if ( undefined !== jq.cookie('bp-activity-scope') && jq('.activity-type-tabs').length ) {
  1853. jq('.activity-type-tabs li').each( function() {
  1854. jq(this).removeClass('selected');
  1855. });
  1856. jq('#activity-' + jq.cookie('bp-activity-scope') + ', .item-list-tabs li.current').addClass('selected');
  1857. }
  1858. }
  1859.  
  1860. /* Setup object scope and filter based on the current cookie settings for the object. */
  1861. function bp_init_objects(objects) {
  1862. jq(objects).each( function(i) {
  1863. if ( undefined !== jq.cookie('bp-' + objects[i] + '-filter') && jq('#' + objects[i] + '-order-select select').length ) {
  1864. jq('#' + objects[i] + '-order-select select option[value="' + jq.cookie('bp-' + objects[i] + '-filter') + '"]').prop( 'selected', true );
  1865. }
  1866.  
  1867. if ( undefined !== jq.cookie('bp-' + objects[i] + '-scope') && jq('div.' + objects[i]).length ) {
  1868. jq('.item-list-tabs li').each( function() {
  1869. jq(this).removeClass('selected');
  1870. });
  1871. jq('#' + objects[i] + '-' + jq.cookie('bp-' + objects[i] + '-scope') + ', #object-nav li.current').addClass('selected');
  1872. }
  1873. });
  1874. }
  1875.  
  1876. /* Filter the current content list (groups/members/blogs/topics) */
  1877. function bp_filter_request( object, filter, scope, target, search_terms, page, extras, caller, template ) {
  1878. if ( 'activity' === object ) {
  1879. return false;
  1880. }
  1881.  
  1882. if ( null === scope ) {
  1883. scope = 'all';
  1884. }
  1885.  
  1886. /* Save the settings we want to remain persistent to a cookie */
  1887. jq.cookie( 'bp-' + object + '-scope', scope, {
  1888. path: '/'
  1889. } );
  1890. jq.cookie( 'bp-' + object + '-filter', filter, {
  1891. path: '/'
  1892. } );
  1893. jq.cookie( 'bp-' + object + '-extras', extras, {
  1894. path: '/'
  1895. } );
  1896.  
  1897. /* Set the correct selected nav and filter */
  1898. jq('.item-list-tabs li').each( function() {
  1899. jq(this).removeClass('selected');
  1900. });
  1901. jq('#' + object + '-' + scope + ', #object-nav li.current').addClass('selected');
  1902. jq('.item-list-tabs li.selected').addClass('loading');
  1903. jq('.item-list-tabs select option[value="' + filter + '"]').prop( 'selected', true );
  1904.  
  1905. if ( 'friends' === object || 'group_members' === object ) {
  1906. object = 'members';
  1907. }
  1908.  
  1909. if ( bp_ajax_request ) {
  1910. bp_ajax_request.abort();
  1911. }
  1912.  
  1913. bp_ajax_request = jq.post( ajaxurl, {
  1914. action: object + '_filter',
  1915. 'cookie': bp_get_cookies(),
  1916. 'object': object,
  1917. 'filter': filter,
  1918. 'search_terms': search_terms,
  1919. 'scope': scope,
  1920. 'page': page,
  1921. 'extras': extras,
  1922. 'template': template
  1923. },
  1924. function(response)
  1925. {
  1926. /* animate to top if called from bottom pagination */
  1927. if ( caller === 'pag-bottom' && jq('#subnav').length ) {
  1928. var top = jq('#subnav').parent();
  1929. jq('html,body').animate({scrollTop: top.offset().top}, 'slow', function() {
  1930. jq(target).fadeOut( 100, function() {
  1931. jq(this).html(response);
  1932. /* KLEO added */
  1933. jq(this).fadeIn(100, function(){
  1934. jq("body").trigger('gridLoaded');
  1935. });
  1936. });
  1937. });
  1938.  
  1939. } else {
  1940. jq(target).fadeOut( 100, function() {
  1941. jq(this).html(response);
  1942. jq(this).fadeIn(100, function(){
  1943. jq("body").trigger('gridLoaded');
  1944. });
  1945. });
  1946. }
  1947.  
  1948. jq('.item-list-tabs li.selected').removeClass('loading');
  1949. });
  1950. }
  1951.  
  1952. /* Activity Loop Requesting */
  1953. function bp_activity_request(scope, filter) {
  1954. /* Save the type and filter to a session cookie */
  1955. if ( null !== scope ) {
  1956. jq.cookie( 'bp-activity-scope', scope, {
  1957. path: '/'
  1958. } );
  1959. }
  1960. if ( null !== filter ) {
  1961. jq.cookie( 'bp-activity-filter', filter, {
  1962. path: '/'
  1963. } );
  1964. }
  1965. jq.cookie( 'bp-activity-oldestpage', 1, {
  1966. path: '/'
  1967. } );
  1968.  
  1969. /* Remove selected and loading classes from tabs */
  1970. jq('.item-list-tabs li').each( function() {
  1971. jq(this).removeClass('selected loading');
  1972. });
  1973. /* Set the correct selected nav and filter */
  1974. jq('#activity-' + scope + ', .item-list-tabs li.current').addClass('selected');
  1975. jq('#object-nav.item-list-tabs li.selected, div.activity-type-tabs li.selected').addClass('loading');
  1976. jq('#activity-filter-select select option[value="' + filter + '"]').prop( 'selected', true );
  1977.  
  1978. /* Reload the activity stream based on the selection */
  1979. jq('.widget_bp_activity_widget h2 span.ajax-loader').show();
  1980.  
  1981. if ( bp_ajax_request ) {
  1982. bp_ajax_request.abort();
  1983. }
  1984.  
  1985. bp_ajax_request = jq.post( ajaxurl, {
  1986. action: 'activity_widget_filter',
  1987. 'cookie': bp_get_cookies(),
  1988. '_wpnonce_activity_filter': jq('#_wpnonce_activity_filter').val(),
  1989. 'scope': scope,
  1990. 'filter': filter
  1991. },
  1992. function(response)
  1993. {
  1994. jq('.widget_bp_activity_widget h2 span.ajax-loader').hide();
  1995.  
  1996. jq('div.activity').fadeOut( 100, function() {
  1997. jq(this).html(response.contents);
  1998. jq(this).fadeIn(100);
  1999.  
  2000. /* Selectively hide comments */
  2001. bp_legacy_theme_hide_comments();
  2002. });
  2003.  
  2004. /* Update the feed link */
  2005. if ( undefined !== response.feed_url ) {
  2006. jq('.directory #subnav li.feed a, .home-page #subnav li.feed a').attr('href', response.feed_url);
  2007. }
  2008.  
  2009. jq('.item-list-tabs li.selected').removeClass('loading');
  2010.  
  2011. }, 'json' );
  2012. }
  2013.  
  2014. /* Hide long lists of activity comments, only show the latest five root comments. */
  2015. function bp_legacy_theme_hide_comments() {
  2016. var comments_divs = jq('div.activity-comments'),
  2017. parent_li, comment_lis, comment_count;
  2018.  
  2019. if ( !comments_divs.length ) {
  2020. return false;
  2021. }
  2022.  
  2023. comments_divs.each( function() {
  2024. if ( jq(this).children('ul').children('li').length < 5 ) {
  2025. return;
  2026. }
  2027.  
  2028. comments_div = jq(this);
  2029. parent_li = comments_div.parents('#activity-stream > li');
  2030. comment_lis = jq(this).children('ul').children('li');
  2031. comment_count = ' ';
  2032.  
  2033. if ( jq('#' + parent_li.attr('id') + ' a.acomment-reply span').length ) {
  2034. comment_count = jq('#' + parent_li.attr('id') + ' a.acomment-reply span').html();
  2035. }
  2036.  
  2037. comment_lis.each( function(i) {
  2038. /* Show the latest 5 root comments */
  2039. if ( i < comment_lis.length - 5 ) {
  2040. /* jq(this).addClass('hidden'); */
  2041. jq(this).toggle();
  2042.  
  2043. if ( !i ) {
  2044. 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>' );
  2045. }
  2046. }
  2047. });
  2048.  
  2049. });
  2050. }
  2051.  
  2052. /* Helper Functions */
  2053.  
  2054. function checkAll() {
  2055. var checkboxes = document.getElementsByTagName('input'),
  2056. i;
  2057.  
  2058. for(i=0; i<checkboxes.length; i++) {
  2059. if(checkboxes[i].type === 'checkbox') {
  2060. if($('check_all').checked === '') {
  2061. checkboxes[i].checked = '';
  2062. }
  2063. else {
  2064. checkboxes[i].checked = 'checked';
  2065. }
  2066. }
  2067. }
  2068. }
  2069.  
  2070. /**
  2071. * Deselects any select options or input options for the specified field element.
  2072. *
  2073. * @param {String} container HTML ID of the field
  2074. * @since 1.2.0
  2075. */
  2076. function clear( container ) {
  2077. container = document.getElementById( container );
  2078. if ( ! container ) {
  2079. return;
  2080. }
  2081.  
  2082. var radioButtons = container.getElementsByTagName( 'INPUT' ),
  2083. options = container.getElementsByTagName( 'OPTION' ),
  2084. i = 0;
  2085.  
  2086. if ( radioButtons ) {
  2087. for ( i = 0; i < radioButtons.length; i++ ) {
  2088. radioButtons[i].checked = '';
  2089. }
  2090. }
  2091.  
  2092. if ( options ) {
  2093. for ( i = 0; i < options.length; i++ ) {
  2094. options[i].selected = false;
  2095. }
  2096. }
  2097. }
  2098.  
  2099. /* Returns a querystring of BP cookies (cookies beginning with 'bp-') */
  2100. function bp_get_cookies() {
  2101. var allCookies = document.cookie.split(';'), // get all cookies and split into an array
  2102. bpCookies = {},
  2103. cookiePrefix = 'bp-',
  2104. i, cookie, delimiter, name, value;
  2105.  
  2106. // loop through cookies
  2107. for (i = 0; i < allCookies.length; i++) {
  2108. cookie = allCookies[i];
  2109. delimiter = cookie.indexOf('=');
  2110. name = jq.trim( unescape( cookie.slice(0, delimiter) ) );
  2111. value = unescape( cookie.slice(delimiter + 1) );
  2112.  
  2113. // if BP cookie, store it
  2114. if ( name.indexOf(cookiePrefix) === 0 ) {
  2115. bpCookies[name] = value;
  2116. }
  2117. }
  2118.  
  2119. // returns BP cookies as querystring
  2120. return encodeURIComponent( jq.param(bpCookies) );
  2121. }
Advertisement
Add Comment
Please, Sign In to add comment