PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.8.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.8.2
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
← All changes | admin/js/admin_control.js +441 -240 4.4.94.8.2 View file →
@@ -1,15 +1,22 @@
1 1 /*global $, jQuery, */
2 2 var counters={};
3 -
3 +
4 +const CHUNK_SIZE = 128 * 1024 * 1024; // 128MB in bytes
5 +const MAX_STANDARD_UPLOAD_SIZE = 5 * 1000000000; // 5GB in bytes
6 +const MAX_RETRIES = 3;
7 +const RETRY_DELAY = 5000;
8 +
4 9 jQuery(document).ready(function ($) {
5 10 "use strict";
6 11
7 12
8 - generate_download_link();
9 - generate_delete_link();
10 -
11 -
13 + WpStreamUtils.generate_download_link();
14 + WpStreamUtils.generate_delete_link();
15 + wpstream_handle_video_selection();
16 + wpstream_upload_images_in_wpadmin();
17 +
18 + wpstream_upload_player_logo();
12 19
13 20
14 21 function social_media_toggle(social_class){
15 22
@@ -49,101 +56,9 @@
49 56
50 57 }
51 58 });
52 59 });
53 -
54 -
55 -
56 -
57 - function generate_delete_link(){
58 - $('.wpstream_delete_media').on('click',function(){
59 -
60 -
61 - var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
62 - var video_name = $(this).attr('data-filename').trim();
63 - var acesta = $(this);
64 - var parent = $(this).parent();
65 60
66 -
67 - jQuery.ajax({
68 - type: 'POST',
69 - url: ajaxurl,
70 - dataType: 'json',
71 - data: {
72 - 'action' : 'wpstream_get_delete_file',
73 - 'video_name' : video_name
74 -
75 - },
76 - success: function (data) {
77 -
78 - if(data.success===true){
79 - parent.remove();
80 - }
81 -
82 -
83 - },
84 - error: function (errorThrown) {
85 - }
86 - });
87 - });
88 -
89 -
90 - }
91 -
92 - function generate_download_link(){
93 -
94 - $('.wpstream_get_download_link').on('click',function(){
95 - var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
96 - var video_name = $(this).attr('data-filename');
97 - var acesta = $(this);
98 - var parent = $(this).parent();
99 -
100 - jQuery(this).remove();
101 - parent.find('.wpstream_download_link').show().text('please wait...');
102 -
103 -
104 -
105 - jQuery.ajax({
106 - type: 'POST',
107 - url: ajaxurl,
108 - dataType: 'json',
109 - data: {
110 - 'action' : 'wpstream_get_download_link',
111 - 'video_name' : video_name,
112 -
113 - },
114 - success: function (data) {
115 -
116 -
117 -
118 - if(data.success===true){
119 - parent.find('.wpstream_download_link').show().text(wpstream_admin_control_vars.download_mess);
120 - parent.find('.wpstream_download_link').show().attr('href',data.url);
121 - }else{
122 - var error_message=data.error;
123 -
124 - if(data.error==='NOT_ENOUGH_TRAFFIC'){
125 - error_message = 'Not Enough data to download!';
126 -
127 - }
128 -
129 - parent.find('.wpstream_download_link').show().text(error_message);
130 - }
131 -
132 -
133 -
134 - },
135 - error: function (errorThrown) {
136 - }
137 - });
138 - });
139 -
140 - }
141 -
142 -
143 -
144 -
145 -
146 61 $( '.inputfile' ).each( function(){
147 62 var $input = $( this ),
148 63 $label = $input.next( 'label' ),
149 64 labelVal = $label.html();
@@ -178,145 +93,318 @@
178 93 */
179 94
180 95
181 96 var form = $('.direct-upload');
182 - var filesUploaded = [];
183 - var folders = [];
97 + var multipartUploadData = null;
98 + var handle = null;
99 + var currentUploadedParts = [];
184 100
185 - // var new_file_name='';
186 -
187 101 form.fileupload({
188 -
189 102 url: form.attr('action'),
190 103 type: form.attr('method'),
191 104
192 105 datatype: 'xml',
193 106 add: function (event, data) {
194 -
195 -
107 +
108 +
196 109 if( data.files[0].type!=='video/mp4' && data.files[0].type!=='video/quicktime'){
197 - jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.not_accepted);
110 + jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.not_accepted);
111 + jQuery('#wpstream_label_action').text(wpstream_admin_control_vars.choose_a_file);
198 112 return;
199 113 }
200 -
201 -
202 -
203 - var file_size = (parseInt(data.files[0].size,10))/1000000;
204 - var user_storage = jQuery('#wpstream_storage').val();
205 - var user_band = jQuery('#wpstream_band').val();
206 -
207 -
208 -
209 - if(file_size > user_storage || file_size>user_band){
114 +
115 + // Get file info
116 + var file = data.files[0];
117 + var fileSizeInBytes = file.size;
118 + var file_size = (parseInt(fileSizeInBytes, 10))/1000000;
119 + var user_storage = jQuery('#wpstream_storage').val();
120 + var user_band = jQuery('#wpstream_band').val();
121 +
122 + if(file_size > user_storage || file_size > user_band){
210 123 jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.no_band_no_store);
211 124 return;
212 - }
213 -
214 -
215 - $('#wpstream_label_action').text(wpstream_admin_control_vars.uploading)
125 + }
216 126
217 - jQuery('#wpstream_uploaded_mes').empty().html();
218 - // Show warning message if your leaving the page during an upload.
127 + // Update UI
128 + $('#wpstream_label_action').text(wpstream_admin_control_vars.uploading);
129 + $('#wpstream_upload').prop('disabled', true);
130 + $('label[for="wpstream_upload"]')
131 + .css('cursor','not-allowed')
132 + .css('background-color','#8c8f94');
133 +
134 + jQuery('#wpstream_uploaded_mes').empty();
135 +
136 + // Show warning message if leaving page during upload
219 137 window.onbeforeunload = function () {
220 138 return 'You have unsaved changes.';
221 139 };
222 -
223 - var file = data.files[0];
224 140
225 -
141 + // Set content headers
226 142 form.find('input[name="Content-Type"]').val(file.type);
227 143 form.find('input[name="Content-Length"]').val(file.size);
228 144
229 - // Actually submit to form to S3.
230 - data.submit();
231 -
232 145 // Show the progress bar
233 - // Uses the file size as a unique identifier
234 146 var bar = $('<div class="progress" data-mod="'+file.size+'"><div class="bar"></div></div>');
235 147 $('.progress-bar-area').append(bar);
236 148 bar.slideDown('fast');
149 +
150 + // Check if file size exceeds 5GB and requires multipart upload
151 + if (fileSizeInBytes > MAX_STANDARD_UPLOAD_SIZE) {
152 + // Show multipart upload message
153 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.exceeding_limit);
154 + // Initiate multipart upload
155 + initiateMultipartUpload(file, data);
156 + } else {
157 + // Standard upload for files under 5GB
158 + data.submit();
159 + }
237 160 },
238 161 progress: function (e, data) {
239 - // This is what makes everything really cool, thanks to that callback
240 - // you can now update the progress bar based on the upload progress.
241 - var percent = Math.round((data.loaded / data.total) * 100);
242 - $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', percent + '%').html(percent+'%');
162 + // Standard upload progress
163 + if (!multipartUploadData) {
164 + var percent = Math.round((data.loaded / data.total) * 100);
165 + $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', percent + '%').html(percent+'%');
166 + }
243 167 },
244 -
245 - fail: function (e, data) {
246 -
247 - // Remove the 'unsaved changes' message.
248 - window.onbeforeunload = null;
249 - $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', '100%').addClass('red').html('');
250 - $('.bar').remove();
251 - $('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_failed);
252 - $('#wpstream_label_action').empty().html(wpstream_admin_control_vars.upload_failed2);
168 +
169 + fail: function () {
170 + handleUploadFailure();
253 171 },
254 -
255 - error: function (e, data) {
256 -
257 - // Remove the 'unsaved changes' message.
258 - window.onbeforeunload = null;
259 - $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', '100%').addClass('red').html('');
260 - $('.bar').remove();
261 - $('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_failed);
262 - $('#wpstream_label_action').empty().html(wpstream_admin_control_vars.upload_failed2);
172 +
173 + error: function () {
174 + handleUploadFailure();
263 175 },
264 176 done: function (event, data) {
265 -
266 - window.onbeforeunload = null;
267 - $('.bar').remove();
268 - $('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_complete);
269 - $('#wpstream_label_action').text(wpstream_admin_control_vars.upload_complete2);
177 + if (!multipartUploadData) {
178 + // Handle standard upload completion
179 + handleUploadSuccess(data.files[0]);
180 + }
181 + }
182 + });
270 183
271 - var new_file_name=data.files[0].name;
184 + // Function to initiate multipart upload
185 + function initiateMultipartUpload(file, data) {
186 + var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
187 + var fileName = file.name;
188 + var fileSize = file.size;
272 189
273 -
274 - var new_file_name_array = data.files[0].name.split(".");
275 - var temp_file_name = new_file_name_array[0].split(' ').join('_');
276 - temp_file_name = temp_file_name.replace(/\W/g, '');
277 - new_file_name = temp_file_name+'.'+new_file_name_array[new_file_name_array.length-1];
278 -
279 -
280 -
281 -
282 - var onclick_string=' Are you sure you wish to delete '+new_file_name+' ? ';
190 + // Calculate number of parts needed
191 + var numParts = Math.ceil(fileSize / CHUNK_SIZE);
283 192
284 - var to_insert='<div class="wpstream_video_wrapper"><div class="wpstream_video_title"><div class="wpstream_video_notice"></div></div><div class="wpstream_video_title">';
285 - to_insert=to_insert+'<strong class="storage_file_name">File Name :</strong><span class="storage_file_name_real">'+new_file_name+' </span></div>';
286 - to_insert=to_insert+'<div class="wpstream_delete_media" ';
287 - to_insert=to_insert+' onclick=" return confirm('+onclick_string+') "';
288 - to_insert=to_insert+' data-filename="'+new_file_name+'" >delete file</div>';
289 - to_insert=to_insert+'<div class="wpstream_get_download_link" data-filename="'+new_file_name+'">download</div> ';
290 - to_insert=to_insert+'<a href="" class="wpstream_download_link">Click to download! The url will work for the next 20 minutes!</a></div>';
291 -
292 - $('#video_management_title').after(to_insert);
293 -
294 -
193 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.preparing_multipart);
295 194
296 - $('.wpstream_get_download_link').unbind('click');
297 - $('.wpstream_delete_media').unbind('click');
195 + jQuery.ajax({
196 + type: 'POST',
197 + url: ajaxurl,
198 + dataType: 'json',
199 + data: {
200 + 'action': 'wpstream_initiate_multipart_upload',
201 + 'file_name': fileName,
202 + 'file_size': fileSize,
203 + 'content_type': file.type,
204 + 'parts': numParts
205 + },
206 + success: function(response) {
207 + if (response.success) {
208 + // Validate required data exists in response
209 + if (!response.data ||
210 + !response.data.multipart ||
211 + !response.data.parts ||
212 + !response.data.handle
213 + ) {
214 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.invalid_response);
215 + handleUploadFailure();
216 + return;
217 + }
298 218
299 - generate_download_link();
300 - generate_delete_link();
301 -
302 - setTimeout(function(){ window.location.href = window.location.href; }, 1000);
219 + multipartUploadData = {
220 + parts: response.data.parts
221 + };
222 + currentUploadedParts = [];
223 + handle = response.data.handle;
303 224
304 -
225 + // Start uploading chunks
226 + uploadNextChunk(file, 0, numParts);
227 + } else {
228 + jQuery('#wpstream_uploaded_mes').html(response.error || wpstream_admin_control_vars.upload_failed);
229 + handleUploadFailure();
230 + }
231 + },
232 + error: function() {
233 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed);
234 + handleUploadFailure();
305 235 }
306 - });
307 -
308 -
309 -
236 + });
237 + }
310 238
311 -
312 -
313 -
314 -
239 + // Function to upload a chunk of the file
240 + function uploadNextChunk(
241 + file,
242 + partIndex,
243 + totalParts,
244 + retryCount = 0
245 + ) {
246 + if (partIndex >= totalParts) {
247 + // All parts uploaded, complete the multipart upload
248 + completeMultipartUpload(file, totalParts);
249 + return;
250 + }
251 +
252 + var start = partIndex * CHUNK_SIZE;
253 + var end = Math.min((partIndex + 1) * CHUNK_SIZE, file.size);
254 + var chunk = file.slice(start, end);
255 + var partNumber = partIndex + 1;
256 +
257 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.uploading_part.replace('{part}', partNumber).replace('{total}', totalParts));
258 +
259 + // Update progress bar to show overall progress
260 + var overallProgress = Math.round((partIndex / totalParts) * 100);
261 + jQuery('.progress[data-mod="'+file.size+'"] .bar').css('width', overallProgress + '%').html(overallProgress+'%');
262 +
263 + // Upload the chunk
264 + var xhr = new XMLHttpRequest();
265 + // xhr.open('POST', 'https://s3.amazonaws.com/' + partData.bucket, true);
266 + xhr.open('PUT', multipartUploadData.parts[partIndex], true);
267 +
268 + xhr.onload = function() {
269 + if (xhr.status === 204 || xhr.status === 200) {
270 + currentUploadedParts.push({
271 + PartNumber: partNumber,
272 + });
273 +
274 + // Upload next chunk
275 + uploadNextChunk(file, partIndex + 1, totalParts);
276 + } else {
277 + var errorInfo = {
278 + status: xhr.status,
279 + statusText: xhr.statusText,
280 + response: xhr.responseText,
281 + headers: xhr.getAllResponseHeaders()
282 + };
283 + console.error('Part Upload Failed:', errorInfo);
284 +
285 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed_part.replace('{part}', partNumber));
286 + handleUploadFailure();
287 + }
288 + };
289 +
290 + xhr.onerror = function() {
291 + handleChunkError(file, partIndex, totalParts, retryCount, xhr);
292 + // jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed_part.replace('{part}', partNumber));
293 + // handleUploadFailure();
294 + };
295 +
296 + xhr.upload.onprogress = function(e) {
297 + if (e.lengthComputable) {
298 + // Calculate chunk progress and overall progress
299 + var chunkProgress = (e.loaded / e.total) * 100;
300 + var overallProgress = Math.round((partIndex / totalParts * 100) + (chunkProgress / totalParts));
301 + jQuery('.progress[data-mod="'+file.size+'"] .bar').css('width', overallProgress + '%').html(overallProgress+'%');
302 + }
303 + };
304 +
305 + xhr.send(chunk);
306 + }
307 +
308 + // Function to retry uploading when failing
309 + // Adding a delay of RETRY_DELAY seconds before retrying
310 + function handleChunkError(file, partIndex, totalParts, retryCount, xhr) {
311 + var partNumber = partIndex + 1;
312 +
313 + if ( retryCount < MAX_RETRIES ) {
314 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed_part_retry.replace('{part}', partNumber).replace('{times}', retryCount + 1));
315 + setTimeout(function() {
316 + uploadNextChunk(file, partIndex, totalParts, retryCount + 1);
317 + }, RETRY_DELAY);
318 + } else {
319 + handleUploadFailure();
320 + }
321 +
322 + }
323 +
324 + // Function to complete multipart upload
325 + function completeMultipartUpload(file, totalParts) {
326 + var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
327 +
328 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.completing_upload);
329 + jQuery.ajax({
330 + type: 'POST',
331 + url: ajaxurl,
332 + dataType: 'json',
333 + data: {
334 + 'action': 'wpstream_complete_multipart_upload',
335 + 'parts': totalParts,
336 + 'file_name': file.name,
337 + 'handle': handle,
338 + },
339 + success: function(response) {
340 + if (response.success) {
341 + // Reset multipart data
342 + multipartUploadData = null;
343 + currentUploadedParts = [];
344 +
345 + // Handle success
346 + handleUploadSuccess(file);
347 + } else {
348 + jQuery('#wpstream_uploaded_mes').html(response.error || wpstream_admin_control_vars.upload_failed);
349 + handleUploadFailure();
350 + }
351 + },
352 + error: function(e) {
353 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.upload_failed);
354 + handleUploadFailure();
355 + }
356 + });
357 + }
358 +
359 + // Handle upload failure
360 + function handleUploadFailure() {
361 + window.onbeforeunload = null;
362 + jQuery('.bar').remove();
363 + jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_failed);
364 + jQuery('#wpstream_label_action').empty().html(wpstream_admin_control_vars.upload_failed2);
365 + jQuery('#wpstream_upload').prop('disabled', false);
366 + jQuery('label[for="wpstream_upload"]')
367 + .css('cursor','')
368 + .css('background-color','');
369 +
370 + // Reset multipart upload data
371 + multipartUploadData = null;
372 + currentUploadedParts = [];
373 + }
374 +
375 + // Handle upload success
376 + function handleUploadSuccess(file) {
377 + window.onbeforeunload = null;
378 + jQuery('.bar').remove();
379 + jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_complete);
380 + jQuery('#wpstream_label_action').text(wpstream_admin_control_vars.upload_complete2);
381 + jQuery('#wpstream_upload').prop('disabled', false);
382 + jQuery('label[for="wpstream_upload"]')
383 + .css('cursor','')
384 + .css('background-color','');
385 +
386 + var new_file_name = file.name;
387 + var new_file_size = Math.floor(file.size / 1048576);
388 +
389 + var new_file_name_array = new_file_name.split(".");
390 + var temp_file_name = new_file_name_array[0].split(' ').join('_');
391 + temp_file_name = temp_file_name.replace(/\W/g, '');
392 + new_file_name = temp_file_name+'.'+new_file_name_array[new_file_name_array.length-1];
393 +
394 + var to_insert='<div class="wpstream_video_wrapper"><div class="wpstream_video_title"><div class="wpstream_video_notice"></div></div>';
395 + to_insert += `<div class="wpstream_video_title"><strong class="storage_file_name">${wpstream_admin_control_vars.file_name_text}</strong><span class="storage_file_name_real">`+new_file_name+`</span><span class="storage_file_size">` + new_file_size + ` MB</span></div>`;
396 + to_insert += `<div class="wpstream_video_pending">${wpstream_admin_control_vars.video_processing}</div>`;
397 +
398 + jQuery('#video_management_title').after(to_insert);
399 +
400 + WpStreamUtils.checkPendingVideos();
401 + }
402 +
315 403 jQuery('#product-type').on('change',function(){
316 404
317 405 var product_type= jQuery('#product-type').val();
318 - if(product_type==='live_stream' || product_type==='video_on_demand'){
406 + if(product_type==='live_stream' || product_type==='video_on_demand' || product_type==='wpstream_bundle' ){
319 407 jQuery('._sold_individually_field').show();
320 408 }
321 409
322 410 });
@@ -329,16 +417,20 @@
329 417 jQuery('#product-type').val('live_stream').trigger('change');
330 418 }
331 419
332 420 var product_type= jQuery('#product-type').val();
333 -
334 421 if ( product_type === 'video_on_demand' ) {
335 - jQuery('.show_if_video_on_demand' ).show();
336 -
337 - }
338 - else if ( product_type === 'live_stream' ) {
339 - $( '.show_if_live_stream' ).show();
340 -
422 + jQuery('.show_if_video_on_demand' ).show();
423 + }else if ( product_type === 'live_stream' ) {
424 + jQuery( '.show_if_live_stream' ).show();
425 + } else if ( product_type === 'wpstream_bundle' ) {
426 + jQuery( '.show_if_wpstream_bundle' ).show();
427 + console.log ('we do click');
428 + var element= jQuery('.general_tab');
429 + console.log(element);
430 + jQuery('.general_tab').trigger('click');
431 + $('a[href="#general_product_data"]').click();
432 + $('.product_data_tabs .tab.general_tab').click();
341 433 }
342 434
343 435
344 436
@@ -359,9 +451,9 @@
359 451
360 452
361 453 jQuery('#_subscript_live_event').change(function(){
362 454 //alert('move it'+product_type);
363 - if ( product_type === 'video_on_demand' || product_type === 'live_stream' ) {
455 + if ( product_type === 'video_on_demand' || product_type === 'live_stream' || product_type === 'wpstream_bundle' ) {
364 456
365 457 }else{
366 458 var value= jQuery(this).val();
367 459 if(value==="no"){
@@ -391,26 +483,13 @@
391 483 }
392 484 });
393 485 $('#wpstream_product_type').trigger('change');
394 486
395 -
396 487
397 - $('#wpstream_free_video_external_button').on( 'click', function(event) {
398 - var formfield = $('#wpstream_free_video_external').attr('name');
399 - tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
400 - window.send_to_editor = function (html) {
401 - var pathArray = html.match(/<media>(.*)<\/media>/);
402 - var mediaUrl = pathArray != null && typeof pathArray[1] != 'undefined' ? pathArray[1] : '';
403 -
404 - if(mediaUrl===''){
405 - mediaUrl = jQuery(html).attr("href");
406 - }
407 - jQuery('#wpstream_free_video_external').val(mediaUrl);
408 - tb_remove();
409 - };
410 - return false;
411 - });
412 -
488 +
489 +
490 +
491 +
413 492 $('.close_event').click(function(event){
414 493 event.preventDefault();
415 494 var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
416 495 var acesta = $(this);
@@ -430,10 +509,10 @@
430 509 'action' : 'wpstream_close_event',
431 510 'security' : nonce,
432 511 'show_id' : show_id
433 512 },
434 - success: function (data) {
435 - parent.remove();
513 + success: function (data) {
514 + parent.remove();
436 515 },
437 516 error: function (errorThrown) {
438 517
439 518 }
@@ -439,28 +518,150 @@
439 518 }
440 519 });
441 520
442 521 });
522 +});
523 +
524 +
525 +
526 +/*
527 +* Upload images in admin
528 +*
529 +*/
530 +function wpstream_upload_images_in_wpadmin(){
531 + console.log('wpstream_upload_images_in_wpadmin');
532 + var idList = ["category_featured_image_button"];
533 +
534 + for (var i = 0; i < idList.length; i++) {
535 + var currentId = idList[i];
536 + jQuery('#'+currentId).on( 'click', function(event) {
537 + var parent=jQuery(this).parent();
538 + wpstream_admin_return_uploaded_image().then(function(image) {
539 + parent.find('.wpestate_landing_upload').val(image.url);
540 + parent.find('.wpestate_landing_upload_id').val(image.id);
541 +
542 + });
543 +
544 + });
545 +
546 + }
547 +}
548 +
549 +
550 +/*
551 +* return uploaded image
552 +*
553 +*/
554 +function wpstream_admin_return_uploaded_image(){
555 +
556 + return new Promise(function(resolve, reject) {
557 + var mediaUploader = wp.media({
558 + frame: "post",
559 + state: "insert",
560 + multiple: false
561 + });
443 562
444 -
563 + mediaUploader.on("insert", function(){
564 + var image = mediaUploader.state().get("selection").first().toJSON();
565 + resolve(image);
566 + });
445 567
446 -
447 -
448 -
449 - $('.category_featured_image_button').on( 'click', function() {
450 - var parent = $(this).parent();
451 - var formfield = parent.find('#category_featured_image').attr('name');
452 - tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
453 - window.send_to_editor = function (html) {
454 - var imgurl = $('img', html).attr('src');
455 - parent.find('#category_featured_image').val(imgurl);
456 - var theid = $('img', html).attr('class');
457 - var thenum = theid.match(/\d+$/)[0];
458 - parent.find('#category_attach_id').val(thenum);
459 - tb_remove();
460 - };
461 - return false;
568 + mediaUploader.open();
569 + });
570 +}
571 +
572 +
573 +
574 +
575 +
576 +/*
577 +* handle video selection for recording
578 +*
579 +*/
580 +
581 +function wpstream_handle_video_selection(){
582 +
583 + jQuery('#wpstream_free_video_external_button').on( 'click', function(event) {
584 + var parent=jQuery(this).parent();
585 + wpstream_admin_return_uploaded_image().then(function(image) {
586 + parent.find('#wpstream_free_video_external').val(image.url);
587 + });
462 588 });
463 -
589 +}
464 590
465 -});
466 -
591 +
592 +
593 +/*
594 +* return uploaded image
595 +*
596 +*/
597 +function wpstream_admin_return_uploaded_image(){
598 +
599 +
600 + return new Promise(function(resolve, reject) {
601 + var mediaUploader = wp.media({
602 + frame: "post",
603 + state: "insert",
604 + multiple: false
605 + });
606 +
607 + mediaUploader.on("insert", function(){
608 + var image = mediaUploader.state().get("selection").first().toJSON();
609 + resolve(image);
610 + });
611 +
612 + mediaUploader.open();
613 + });
614 +}
615 +
616 +function wpstream_upload_player_logo(){
617 + var mediaUploader;
618 +
619 + // Handle upload button click
620 + jQuery('.wpstream-upload-image').on('click', function(e) {
621 + e.preventDefault();
622 +
623 + var button = jQuery(this);
624 + var wrapper = button.closest('.wpstream-image-upload-wrapper');
625 + var inputField = wrapper.find('input[type="hidden"]');
626 + var previewArea = wrapper.find('.wpstream-image-preview');
627 + var removeButton = wrapper.find('.wpstream-remove-image');
628 +
629 + // Create media uploader instance if not already created
630 + if (!mediaUploader) {
631 + mediaUploader = wp.media({
632 + title: wpstream_settings_vars.choose_image_text || 'Choose Image',
633 + button: {
634 + text: wpstream_settings_vars.select_image_text || 'Select Image'
635 + },
636 + multiple: false
637 + });
638 +
639 + // When image is selected in the media uploader
640 + mediaUploader.on('select', function() {
641 + var attachment = mediaUploader.state().get('selection').first().toJSON();
642 + inputField.val(attachment.url);
643 +
644 + previewArea.find('img').attr('src', attachment.url);
645 + previewArea.show();
646 + removeButton.show();
647 + });
648 + }
649 +
650 + // Open the media uploader
651 + mediaUploader.open();
652 + });
653 +
654 + // Handle remove button click
655 + jQuery('.wpstream-remove-image').on('click', function(e) {
656 + e.preventDefault();
657 +
658 + var button = jQuery(this);
659 + var wrapper = button.closest('.wpstream-image-upload-wrapper');
660 + var inputField = wrapper.find('input[type="hidden"]');
661 + var previewArea = wrapper.find('.wpstream-image-preview');
662 +
663 + inputField.val('');
664 + previewArea.hide();
665 + button.hide();
666 + });
667 +}