// source --> https://www.spcreative.eu/wp-content/themes/kleo/kleo/buddypress/js/buddypress.js?ver=5.1.2 /* jshint undef: false, unused:false */ // 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; 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(); var objects = [ 'members', 'groups', 'blogs', 'forums', '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').animate({ height:'40px' }); $whats_new.animate({ height:'70px' }); jq.scrollTo( $whats_new, 500, { offset:-125, easing:'swing' } ); /* Kleo added */ jq(".rtmedia-container").css('height', 'auto'); jq(".rtmedia-container").css('visibility', 'visible'); $whats_new.val('').focus().val( $member_nicename ); } /**** Activity Posting ********************************************************/ /* Textarea focus */ $whats_new.focus( function(){ jq('#whats-new-options').animate({ height:'40px' }); jq('#whats-new-form textarea').animate({ height:'70px' }); jq('#aw-whats-new-submit').prop('disabled', false); 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' ); } } /* Kleo added */ jq(".rtmedia-container").css('height', 'auto'); jq(".rtmedia-container").css('visibility', 'visible'); }); /* On blur, shrink if it's empty */ $whats_new.blur( function(){ if ( document.activeElement !== this ) { if (!this.value.match(/\S+/)) { this.value = ''; jq('#whats-new-options').animate({ height:'40px' }); jq('form#whats-new-form textarea').animate({ height:'50px' }); jq('#aw-whats-new-submit').prop('disabled', true); } /* Kleo added */ jq(".rtmedia-container").css('height', 'auto'); jq(".rtmedia-container").css('visibility', 'visible'); } }); /* 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'); 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 */ 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(); } jq.post( ajaxurl, { 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() || '' }, 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.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( '