/* jshint undef: false, unused:false */ /* @version 1.7.0 */ /* @version 10.0.0 */ // AJAX Functions var jq = jQuery; // Global variable to prevent multiple AJAX requests var bp_ajax_request = null; // Global variables to temporarily store newest activities var newest_activities = ''; var activity_last_recorded = 0; var directoryPreferences = {}; jq( function() { var activity_oldestpage = 1; /**** Page Load Actions *******************************************************/ /* Activity filter and scope set */ bp_init_activity(); var objects = [ 'members', 'groups', 'blogs', 'group_members' ], $whats_new = jq('#whats-new'); /* Object filter and scope set. */ 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').slideDown(); $whats_new.animate({ height:'3.8em' }); jq.scrollTo( $whats_new, 500, { offset:-125, easing:'swing' } ); $whats_new.val('').trigger( 'focus' ).val( $member_nicename ); } else { jq('#whats-new-options').hide(); } /**** Activity Posting ********************************************************/ /* Textarea focus */ $whats_new.on( 'focus', function() { jq( '#whats-new-options' ).slideDown(); jq( this ).animate({ height:'3.8em' }); jq('#aw-whats-new-submit').prop('disabled', false); jq( this ).parent().addClass( 'active' ); jq( '#whats-new-content' ).addClass( 'active' ); var $whats_new_form = jq('form#whats-new-form'), $activity_all = jq( '#activity-all' ); if ( $whats_new_form.hasClass('submitted') ) { $whats_new_form.removeClass('submitted'); } // Return to the 'All Members' tab and 'Everything' filter, // to avoid inconsistencies with the heartbeat integration if ( $activity_all.length ) { if ( ! $activity_all.hasClass( 'selected' ) ) { // reset to everything jq( '#activity-filter-select select' ).val( '-1' ); $activity_all.children( 'a' ).trigger( 'click' ); } else if ( '-1' !== jq( '#activity-filter-select select' ).val() ) { jq( '#activity-filter-select select' ).val( '-1' ); jq( '#activity-filter-select select' ).trigger( 'change' ); } } } ); /* For the "What's New" form, do the following on focusout. */ jq( '#whats-new-form' ).on( 'focusout', function( e ) { var elem = jq( this ); // Let child hover actions passthrough. // This allows click events to go through without focusout. setTimeout( function () { if ( ! elem.find(':hover').length ) { // Do not slide up if textarea has content. if ( '' !== $whats_new.val() ) { return; } $whats_new.animate({ height:'2.2em' }); jq( '#whats-new-options' ).slideUp(); jq('#aw-whats-new-submit').prop( 'disabled', true ); jq( '#whats-new-content' ).removeClass( 'active' ); $whats_new.parent().removeClass( 'active' ); } }, 0 ); } ); /* New posts */ jq('#aw-whats-new-submit').on( 'click', function() { var last_date_recorded = 0, button = jq(this), form = button.closest('form#whats-new-form'), inputs = {}, post_data; // Get all inputs and organize them into an object {name: value} jq.each( form.serializeArray(), function( key, input ) { // Only include public extra data if ( '_' !== input.name.substr( 0, 1 ) && 'whats-new' !== input.name.substr( 0, 9 ) ) { if ( ! inputs[ input.name ] ) { inputs[ input.name ] = input.value; } else { // Checkboxes/dropdown list can have multiple selected value if ( ! Array.isArray( inputs[ input.name ] ) ) { inputs[ input.name ] = new Array( inputs[ input.name ], input.value ); } else { inputs[ input.name ].push( input.value ); } } } } ); form.find( '*' ).each( function( i, elem ) { if ( elem.nodeName.toLowerCase() === 'textarea' || elem.nodeName.toLowerCase() ==='input' ) { jq( elem ).prop( 'disabled', true ); } } ); /* Remove any errors */ jq('div.error').remove(); button.addClass('loading'); button.prop('disabled', true); form.addClass('submitted'); /* Default POST values */ object = ''; item_id = jq('#whats-new-post-in').val(); content = jq('#whats-new').val(); firstrow = jq( '#buddypress ul.activity-list li' ).first(); activity_row = firstrow; timestamp = null; // Checks if at least one activity exists if ( firstrow.length ) { if ( activity_row.hasClass( 'load-newest' ) ) { activity_row = firstrow.next(); } timestamp = activity_row.prop( 'class' ).match( /date-recorded-([0-9]+)/ ); } if ( timestamp ) { last_date_recorded = timestamp[1]; } /* Set object for non-profile posts */ if ( item_id > 0 ) { object = jq('#whats-new-post-object').val(); } post_data = jq.extend( { action: 'post_update', 'cookie': bp_get_cookies(), '_wpnonce_post_update': jq('#_wpnonce_post_update').val(), 'content': content, 'object': object, 'item_id': item_id, 'since': last_date_recorded, '_bp_as_nonce': jq('#_bp_as_nonce').val() || '' }, inputs ); jq.post( ajaxurl, post_data, function( response ) { form.find( '*' ).each( function( i, elem ) { if ( elem.nodeName.toLowerCase() === 'textarea' || elem.nodeName.toLowerCase() ==='input' ) { jq( elem ).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.attr('id') + ' div.error').hide().fadeIn( 200 ); } else { if ( 0 === jq('ul.activity-list').length ) { jq('div.error').slideUp(100).remove(); jq('#message').slideUp(100).remove(); jq('div.activity').append( '