Advertisement
Guest User

Untitled

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