| 1 |
var debounceTimer; |
| 2 |
|
| 3 |
jQuery(document).ready(function($) { |
| 4 |
// Save default channel options |
| 5 |
wpstream_save_default_channel_options(); |
| 6 |
|
| 7 |
// Save settings |
| 8 |
wpstream_save_settings(); |
| 9 |
|
| 10 |
wpstream_update_plugin_support_tab(); |
| 11 |
|
| 12 |
// wpstream_broadcaster_bind(); |
| 13 |
}); |
| 14 |
|
| 15 |
/** |
| 16 |
* Save the changes to the Default Channel Settings tab |
| 17 |
*/ |
| 18 |
function wpstream_save_default_channel_options() { |
| 19 |
jQuery('.theme_options_tab_wpstream .wpstream_event_option_item').on('click',function() { |
| 20 |
|
| 21 |
wpstream_adjust_settings_general(jQuery(this)); |
| 22 |
|
| 23 |
var optionarray ={}; |
| 24 |
var holder = jQuery(this).parents('.wpstream_option_wrapper'); |
| 25 |
var nonce = jQuery('#wpstream-settings-nonce').val(); |
| 26 |
|
| 27 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','visible'); |
| 28 |
var timer = setTimeout(function() { |
| 29 |
holder.find('.wpstream_event_option_item').each(function(){ |
| 30 |
optionarray[jQuery(this).attr('data-attr-ajaxname')]=jQuery(this).prop("checked") ? 1 : 0 ; |
| 31 |
}); |
| 32 |
|
| 33 |
var jsonOptions = JSON.stringify(optionarray); |
| 34 |
jQuery.ajax({ |
| 35 |
type: 'POST', |
| 36 |
url: ajaxurl, |
| 37 |
timeout: 300000, |
| 38 |
data: { |
| 39 |
'action' : 'wpstream_update_default_channel_settings', |
| 40 |
'option' : optionarray, |
| 41 |
'security' : nonce |
| 42 |
}, |
| 43 |
success: function (data) { |
| 44 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','hidden'); |
| 45 |
}, |
| 46 |
error: function (jqXHR,textStatus,errorThrown) { |
| 47 |
wpstream_show_error_message(jQuery('.theme_options_tab_wpstream .wpstream-save-settings')); |
| 48 |
} |
| 49 |
}) |
| 50 |
}, 300); |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Adjust the settings for WpStream Settings |
| 56 |
*/ |
| 57 |
function wpstream_save_settings() { |
| 58 |
var nonce = jQuery('#wpstream-settings-nonce').val(); |
| 59 |
jQuery('.wpstream_option_wrapper .wpstream_event_option_itemc').on('change',function(e){ |
| 60 |
// Get the new value (1 if checked, 0 if unchecked) |
| 61 |
var checkedState = e.target.checked ? 1 : 0; |
| 62 |
|
| 63 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','visible'); |
| 64 |
jQuery.ajax({ |
| 65 |
type: 'POST', |
| 66 |
url: ajaxurl, |
| 67 |
timeout: 300000, |
| 68 |
data: { |
| 69 |
'action' : 'wpstream_update_settings', |
| 70 |
'option_name' : jQuery(this).attr('name'), |
| 71 |
'option_type' : jQuery(this).attr('type'), |
| 72 |
'option_value' : checkedState, |
| 73 |
'security' : nonce |
| 74 |
}, |
| 75 |
success: function (data) { |
| 76 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','hidden'); |
| 77 |
}, |
| 78 |
error: function (jqXHR,textStatus,errorThrown) { |
| 79 |
wpstream_show_error_message(jQuery('.theme_options_tab_wpstream .wpstream-save-settings')); |
| 80 |
} |
| 81 |
}) |
| 82 |
}) |
| 83 |
|
| 84 |
jQuery('.wpstream_option_wrapper .wpstream-text-input-setting').on('input',function(e){ |
| 85 |
var option_name = jQuery(this).attr('id'); |
| 86 |
var option_value = jQuery(this).val(); |
| 87 |
var option_type = jQuery(this).attr('type'); |
| 88 |
|
| 89 |
clearTimeout(debounceTimer); |
| 90 |
debounceTimer = setTimeout( function() { |
| 91 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','visible'); |
| 92 |
jQuery.ajax({ |
| 93 |
type: 'POST', |
| 94 |
url: ajaxurl, |
| 95 |
timeout: 300000, |
| 96 |
data: { |
| 97 |
'action' : 'wpstream_update_settings', |
| 98 |
'option_name' : option_name, |
| 99 |
'option_type' : option_type, |
| 100 |
'option_value' : option_value, |
| 101 |
'security' : nonce |
| 102 |
}, |
| 103 |
success: function (data) { |
| 104 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','hidden'); |
| 105 |
}, |
| 106 |
error: function (jqXHR,textStatus,errorThrown) { |
| 107 |
wpstream_show_error_message(jQuery('.theme_options_tab_wpstream .wpstream-save-settings')); |
| 108 |
} |
| 109 |
}) |
| 110 |
}, 1000); // Wait for 3 seconds after the user stops typing |
| 111 |
}); |
| 112 |
|
| 113 |
jQuery('.wpstream_option_wrapper select').on('change',function(e){ |
| 114 |
var option_name = jQuery(this).siblings('label').attr('for'); |
| 115 |
var option_value = jQuery(this).val(); |
| 116 |
var option_type = jQuery(this).prop('multiple') ? 'multiple-select' : 'select'; |
| 117 |
|
| 118 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','visible'); |
| 119 |
jQuery.ajax({ |
| 120 |
type: 'POST', |
| 121 |
url: ajaxurl, |
| 122 |
timeout: 300000, |
| 123 |
data: { |
| 124 |
'action' : 'wpstream_update_settings', |
| 125 |
'option_name' : option_name, |
| 126 |
'option_type' : option_type, |
| 127 |
'option_value' : option_value, |
| 128 |
'security' : nonce |
| 129 |
}, |
| 130 |
success: function (data) { |
| 131 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','hidden'); |
| 132 |
}, |
| 133 |
error: function (jqXHR,textStatus,errorThrown) { |
| 134 |
wpstream_show_error_message(jQuery('.theme_options_tab_wpstream .wpstream-save-settings')); |
| 135 |
} |
| 136 |
}) |
| 137 |
}) |
| 138 |
|
| 139 |
jQuery('.wpstream_option_wrapper .wpstream-range-input').on('change',function(e){ |
| 140 |
var option_name = jQuery(this).attr('id'); |
| 141 |
var option_value = jQuery(this).val(); |
| 142 |
var option_type = jQuery(this).attr('type'); |
| 143 |
|
| 144 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','visible'); |
| 145 |
jQuery.ajax({ |
| 146 |
type: 'POST', |
| 147 |
url: ajaxurl, |
| 148 |
timeout: 300000, |
| 149 |
data: { |
| 150 |
'action' : 'wpstream_update_settings', |
| 151 |
'option_name' : option_name, |
| 152 |
'option_type' : option_type, |
| 153 |
'option_value' : option_value, |
| 154 |
'security' : nonce |
| 155 |
}, |
| 156 |
success: function (data) { |
| 157 |
jQuery('.theme_options_tab_wpstream .wpstream-save-settings').find('.spinner').css('visibility','hidden'); |
| 158 |
}, |
| 159 |
error: function (jqXHR,textStatus,errorThrown) { |
| 160 |
wpstream_show_error_message(jQuery('.theme_options_tab_wpstream .wpstream-save-settings')); |
| 161 |
} |
| 162 |
}) |
| 163 |
}) |
| 164 |
} |
| 165 |
|
| 166 |
/* |
| 167 |
* |
| 168 |
* Show error message when the settings are not saved |
| 169 |
* |
| 170 |
*/ |
| 171 |
function wpstream_show_error_message(container) { |
| 172 |
container.find('.spinner').css('visibility', 'hidden'); |
| 173 |
container.append('<div class="wpstream-error-message">' + wpstream_settings_vars.error_message + '</div>'); |
| 174 |
container.find('.wpstream-error-message').hide().fadeIn(400).delay(3000).fadeOut(400, function() { |
| 175 |
jQuery(this).remove(); |
| 176 |
}); |
| 177 |
} |
| 178 |
|
| 179 |
function wpstream_update_plugin_support_tab() { |
| 180 |
var nonce = jQuery('#wpstream-settings-nonce').val(); |
| 181 |
jQuery('.wpstream-update-plugin-button').on('click', function(e) { |
| 182 |
e.preventDefault(); |
| 183 |
jQuery(this).parents('.update-button-wrapper').html('Updating... <span class="spinner" style="visibility: visible;"></span>'); |
| 184 |
jQuery.ajax({ |
| 185 |
type: 'POST', |
| 186 |
url: ajaxurl, |
| 187 |
timeout: 300000, |
| 188 |
data: { |
| 189 |
'action' : 'wpstream_settings_tab_update_plugin', |
| 190 |
'security' : nonce |
| 191 |
}, |
| 192 |
success: function (data) { |
| 193 |
if (data.success) { |
| 194 |
jQuery('.update-button-wrapper').html(wpstream_settings_vars.update_successful); |
| 195 |
} else { |
| 196 |
jQuery('.update-button-wrapper').html(wpstream_settings_vars.update_failed); |
| 197 |
} |
| 198 |
}, |
| 199 |
error: function (jqXHR,textStatus,errorThrown) { |
| 200 |
jQuery('.update-button-wrapper').html(wpstream_settings_vars.update_failed); |
| 201 |
} |
| 202 |
}) |
| 203 |
}); |
| 204 |
} |
| 205 |
|
| 206 |
function wpstream_broadcaster_bind() { |
| 207 |
jQuery('.start_webcaster').on('click', function(e) { |
| 208 |
if (jQuery(this).hasClass('wpstream_inactive_icon')) { |
| 209 |
return; |
| 210 |
} |
| 211 |
e.preventDefault(); |
| 212 |
e.stopPropagation(); |
| 213 |
|
| 214 |
// Get the channel ID from the data attribute |
| 215 |
var channelId = jQuery(this).closest('.event_list_unit').data('show-id'); |
| 216 |
|
| 217 |
if (!channelId) { |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
// Open the broadcaster in a new window |
| 222 |
var broadcasterUrl = wpstream_settings_vars.broadcaster_url + channelId; |
| 223 |
window.open(broadcasterUrl, 'wpstream_broadcaster_' + channelId, 'fullscreen=yes'); |
| 224 |
}); |
| 225 |
|
| 226 |
} |