// 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' ], $whats_new = jq('#whats-new'); bp_init_objects( objects ); /* @mention Compose Scrolling */ if ( $whats_new.length && bp_get_querystring('r') ) { var $member_nicename = $whats_new.val(); jq('#whats-new-options').animate({ height:'40px' }); $whats_new.animate({ height:'50px' }); jq.scrollTo( $whats_new, 500, { offset:-125, easing:'swing' } ); $whats_new.val('').focus().val( $member_nicename ); } /**** 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); var $whats_new_form = jq("form#whats-new-form"); if ( $whats_new_form.hasClass("submitted") ) { $whats_new_form.removeClass("submitted"); } }); /* On blur, shrink if it's empty */ jq('#whats-new').blur( function(){ if (!this.value.match(/\S+/)) { this.value = ""; jq("#whats-new-options").animate({ height:'40px' }); jq("form#whats-new-form textarea").animate({ height:'20px' }); jq("#aw-whats-new-submit").prop("disabled", true); } }); /* New posts */ jq("input#aw-whats-new-submit").click( function() { var button = jq(this); var form = button.closest("form#whats-new-form"); 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); form.addClass("submitted"); /* 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': bp_get_cookies(), '_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( '