if ( typeof jq == "undefined" ) var jq = jQuery; jq(document).ready( function() { jq('span#activity-visibility').prependTo('div#whats-new-submit'); jq("input#aw-whats-new-submit").off("click"); var selected_item_id = jq("select#whats-new-post-in").val(); jq("select#whats-new-post-in").data('selected', selected_item_id ); /** * Insert activity visibility dropdown next to "Post Update" button * @TODO: Migrate this code in Backbone view */ jq('#whats-new').on( 'focusin', function(e) { setTimeout(function () { var activityVisibility = document.getElementById('activity-visibility'); // Ratify that there is no activity-visibility dropdown exists on a page // before inserting one if ( ! activityVisibility ) { document.getElementById('whats-new-submit').insertAdjacentHTML( 'afterbegin', document.getElementById('buddyboss-wall-tpl-activity_visibility').innerHTML ); } }, 0 ); }); //if selected item is not 'My profile' if( 'undefined' != typeof visibility_levels && selected_item_id != undefined && selected_item_id != 0 ){ jq('select#bbwall-activity-privacy').replaceWith(visibility_levels.groups); } jq("select#whats-new-post-in").on("change", function() { var old_selected_item_id = jq(this).data('selected'); var item_id = jq("#whats-new-post-in").val(); if( 'undefined' != typeof visibility_levels ) { if(item_id == 0 && item_id != old_selected_item_id){ jq('select#bbwall-activity-privacy').replaceWith(visibility_levels.profile); }else{ if(item_id != 0 && old_selected_item_id == 0 ){ jq('select#bbwall-activity-privacy').replaceWith(visibility_levels.groups); } } } jq('select#bbwall-activity-privacy').next().remove(); jq(this).data('selected',item_id); }); /* New posts */ jq("input#aw-whats-new-submit").on('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(); var visibility = jq("select#bbwall-activity-privacy").val(); /* Set object for non-profile posts */ if ( item_id > 0 ) { object = jq("#whats-new-post-object").val(); } if (typeof bp_get_cookies == 'function') var cookie = bp_get_cookies(); else var cookie = encodeURIComponent(document.cookie); jq.post( ajaxurl, { action: 'post_update', 'cookie': cookie, '_wpnonce_post_update': jq("input#_wpnonce_post_update").val(), 'content': content, 'visibility': visibility, '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( '