| 1 |
/*global $, jQuery, wpstream_integrations_vars*/ |
| 2 |
/* |
| 3 |
* WpStream integrations front-end script (BuddyPress/BuddyBoss). |
| 4 |
* |
| 5 |
* Wires up the profile "Live Video" tab: the channel-selection dropdown that |
| 6 |
* saves the chosen channel over AJAX. Timeline activities are posted |
| 7 |
* server-side from the channel lifecycle hooks, not from the browser. |
| 8 |
* Localized data (admin URL, buddyboss flag, nonce) arrives via the |
| 9 |
* wpstream_integrations_vars object. |
| 10 |
*/ |
| 11 |
jQuery(document).ready(function ($) { |
| 12 |
"use strict"; |
| 13 |
// Only bind the channel picker when the BuddyBoss integration is active. |
| 14 |
if(wpstream_integrations_vars.is_buddyboss==='yes'){ |
| 15 |
wpstream_buddy_boss_select_channel(); |
| 16 |
} |
| 17 |
}); |
| 18 |
|
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Select streaming channet on BuddyBoss |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* Bind the profile tab's channel <select> so a change persists the selection. |
| 29 |
* |
| 30 |
* On change, POSTs the chosen channel id to the select-channel AJAX action and |
| 31 |
* reloads the page when the server confirms it was saved. |
| 32 |
*/ |
| 33 |
function wpstream_buddy_boss_select_channel(){ |
| 34 |
// Listen for the user picking a different channel in the dropdown. |
| 35 |
jQuery('#wpstream_buddyboss_select_channel').on('change',function(){ |
| 36 |
|
| 37 |
// Build the admin-ajax endpoint and read the newly selected channel id. |
| 38 |
var ajaxurl = wpstream_integrations_vars.admin_url+ 'admin-ajax.php';; |
| 39 |
var show_id = jQuery('#wpstream_buddyboss_select_channel').val(); |
| 40 |
var nonce = wpstream_integrations_vars.buddy_nonce; |
| 41 |
jQuery.ajax({ |
| 42 |
type: 'POST', |
| 43 |
url: ajaxurl, |
| 44 |
dataType: 'json', |
| 45 |
timeout: 300000, |
| 46 |
|
| 47 |
// Server action, the selected channel id and the integration nonce. |
| 48 |
data: { |
| 49 |
'action' : 'wpstream_buddy_boss_select_channel_function', |
| 50 |
'show_id' : show_id, |
| 51 |
'security' : nonce |
| 52 |
}, |
| 53 |
success: function (data) { |
| 54 |
// Reload so the page reflects the newly selected channel. |
| 55 |
if(data.saved===true){ |
| 56 |
location.reload(); |
| 57 |
} |
| 58 |
|
| 59 |
}, |
| 60 |
// Swallow AJAX errors silently. |
| 61 |
error: function (jqXHR,textStatus,errorThrown) { |
| 62 |
} |
| 63 |
}); |
| 64 |
}); |
| 65 |
} |
| 66 |
|