// AJAX Functions var jq = jQuery; // Global variable to prevent multiple AJAX requests var bp_ajax_request = null; jq(document).ready( function() { /**** Page Load Actions *******************************************************/ /* Hide Forums Post Form */ if ( '-1' == window.location.search.indexOf('new') && jq('div.forums').length ) jq('#new-topic-post').hide(); else jq('#new-topic-post').show(); /* Activity filter and scope set */ bp_init_activity(); /* Object filter and scope set. */ var objects = [ 'members', 'groups', 'blogs', 'forums' ]; bp_init_objects( objects ); /* @mention Compose Scrolling */ if ( jq.query.get('r') && jq('textarea#whats-new').length ) { jq('#whats-new-options').animate({ height:'40px' }); jq("form#whats-new-form textarea").animate({ height:'50px' }); jq.scrollTo( jq('textarea#whats-new'), 500, { offset:-125, easing:'easeOutQuad' } ); jq('textarea#whats-new').focus(); } /**** Activity Posting ********************************************************/ /* Textarea focus */ jq('#whats-new').focus( function(){ jq("#whats-new-options").animate({ height:'40px' }); jq("form#whats-new-form textarea").animate({ height:'50px' }); jq("#aw-whats-new-submit").prop("disabled", false); }); /* New posts */ jq("input#aw-whats-new-submit").click( function() { var button = jq(this); var form = button.parent().parent().parent().parent(); form.children().each( function() { if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) jq(this).prop( 'disabled', true ); }); /* Remove any errors */ jq('div.error').remove(); button.addClass('loading'); button.prop('disabled', true); /* Default POST values */ var object = ''; var item_id = jq("#whats-new-post-in").val(); var content = jq("textarea#whats-new").val(); /* Set object for non-profile posts */ if ( item_id > 0 ) { object = jq("#whats-new-post-object").val(); } jq.post( ajaxurl, { action: 'post_update', 'cookie': encodeURIComponent(document.cookie), '_wpnonce_post_update': jq("input#_wpnonce_post_update").val(), 'content': content, 'object': object, 'item_id': item_id, '_bp_as_nonce': jq('#_bp_as_nonce').val() || '' }, function(response) { form.children().each( function() { if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) { jq(this).prop( 'disabled', false ); } }); /* Check for errors and append if found. */ if ( response[0] + response[1] == '-1' ) { form.prepend( response.substr( 2, response.length ) ); jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 ); } else { if ( 0 == jq("ul.activity-list").length ) { jq("div.error").slideUp(100).remove(); jq("div#message").slideUp(100).remove(); jq("div.activity").append( '