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 +397 -244 4.5.11 → 4.8.2 View file →
@@ -1,16 +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 - wpstream_handle_video_selection();
11 -
12 -
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();
13 19
14 20
15 21 function social_media_toggle(social_class){
16 22
@@ -50,101 +56,9 @@
50 56
51 57 }
52 58 });
53 59 });
54 -
55 -
56 -
57 -
58 - function generate_delete_link(){
59 - $('.wpstream_delete_media').on('click',function(){
60 -
61 -
62 - var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
63 - var video_name = $(this).attr('data-filename').trim();
64 - var acesta = $(this);
65 - var parent = $(this).parent();
66 60
67 -
68 - jQuery.ajax({
69 - type: 'POST',
70 - url: ajaxurl,
71 - dataType: 'json',
72 - data: {
73 - 'action' : 'wpstream_get_delete_file',
74 - 'video_name' : video_name
75 -
76 - },
77 - success: function (data) {
78 -
79 - if(data.success===true){
80 - parent.remove();
81 - }
82 -
83 -
84 - },
85 - error: function (errorThrown) {
86 - }
87 - });
88 - });
89 -
90 -
91 - }
92 -
93 - function generate_download_link(){
94 -
95 - $('.wpstream_get_download_link').on('click',function(){
96 - var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
97 - var video_name = $(this).attr('data-filename');
98 - var acesta = $(this);
99 - var parent = $(this).parent();
100 -
101 - jQuery(this).remove();
102 - parent.find('.wpstream_download_link').show().text('please wait...');
103 -
104 -
105 -
106 - jQuery.ajax({
107 - type: 'POST',
108 - url: ajaxurl,
109 - dataType: 'json',
110 - data: {
111 - 'action' : 'wpstream_get_download_link',
112 - 'video_name' : video_name,
113 -
114 - },
115 - success: function (data) {
116 -
117 -
118 -
119 - if(data.success===true){
120 - parent.find('.wpstream_download_link').show().text(wpstream_admin_control_vars.download_mess);
121 - parent.find('.wpstream_download_link').show().attr('href',data.url);
122 - }else{
123 - var error_message=data.error;
124 -
125 - if(data.error==='NOT_ENOUGH_TRAFFIC'){
126 - error_message = 'Not Enough data to download!';
127 -
128 - }
129 -
130 - parent.find('.wpstream_download_link').show().text(error_message);
131 - }
132 -
133 -
134 -
135 - },
136 - error: function (errorThrown) {
137 - }
138 - });
139 - });
140 -
141 - }
142 -
143 -
144 -
145 -
146 -
147 61 $( '.inputfile' ).each( function(){
148 62 var $input = $( this ),
149 63 $label = $input.next( 'label' ),
150 64 labelVal = $label.html();
@@ -179,145 +93,318 @@
179 93 */
180 94
181 95
182 96 var form = $('.direct-upload');
183 - var filesUploaded = [];
184 - var folders = [];
97 + var multipartUploadData = null;
98 + var handle = null;
99 + var currentUploadedParts = [];
185 100
186 - // var new_file_name='';
187 -
188 101 form.fileupload({
189 -
190 102 url: form.attr('action'),
191 103 type: form.attr('method'),
192 104
193 105 datatype: 'xml',
194 106 add: function (event, data) {
195 -
196 -
107 +
108 +
197 109 if( data.files[0].type!=='video/mp4' && data.files[0].type!=='video/quicktime'){
198 - 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);
199 112 return;
200 113 }
201 -
202 -
203 -
204 - var file_size = (parseInt(data.files[0].size,10))/1000000;
205 - var user_storage = jQuery('#wpstream_storage').val();
206 - var user_band = jQuery('#wpstream_band').val();
207 -
208 -
209 -
210 - 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){
211 123 jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.no_band_no_store);
212 124 return;
213 - }
214 -
215 -
216 - $('#wpstream_label_action').text(wpstream_admin_control_vars.uploading)
125 + }
217 126
218 - jQuery('#wpstream_uploaded_mes').empty().html();
219 - // 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
220 137 window.onbeforeunload = function () {
221 138 return 'You have unsaved changes.';
222 139 };
223 -
224 - var file = data.files[0];
225 140
226 -
141 + // Set content headers
227 142 form.find('input[name="Content-Type"]').val(file.type);
228 143 form.find('input[name="Content-Length"]').val(file.size);
229 144
230 - // Actually submit to form to S3.
231 - data.submit();
232 -
233 145 // Show the progress bar
234 - // Uses the file size as a unique identifier
235 146 var bar = $('<div class="progress" data-mod="'+file.size+'"><div class="bar"></div></div>');
236 147 $('.progress-bar-area').append(bar);
237 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 + }
238 160 },
239 161 progress: function (e, data) {
240 - // This is what makes everything really cool, thanks to that callback
241 - // you can now update the progress bar based on the upload progress.
242 - var percent = Math.round((data.loaded / data.total) * 100);
243 - $('.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 + }
244 167 },
245 -
246 - fail: function (e, data) {
247 -
248 - // Remove the 'unsaved changes' message.
249 - window.onbeforeunload = null;
250 - $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', '100%').addClass('red').html('');
251 - $('.bar').remove();
252 - $('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_failed);
253 - $('#wpstream_label_action').empty().html(wpstream_admin_control_vars.upload_failed2);
168 +
169 + fail: function () {
170 + handleUploadFailure();
254 171 },
255 -
256 - error: function (e, data) {
257 -
258 - // Remove the 'unsaved changes' message.
259 - window.onbeforeunload = null;
260 - $('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', '100%').addClass('red').html('');
261 - $('.bar').remove();
262 - $('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_failed);
263 - $('#wpstream_label_action').empty().html(wpstream_admin_control_vars.upload_failed2);
172 +
173 + error: function () {
174 + handleUploadFailure();
264 175 },
265 176 done: function (event, data) {
266 -
267 - window.onbeforeunload = null;
268 - $('.bar').remove();
269 - $('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_complete);
270 - $('#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 + });
271 183
272 - 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;
273 189
274 -
275 - var new_file_name_array = data.files[0].name.split(".");
276 - var temp_file_name = new_file_name_array[0].split(' ').join('_');
277 - temp_file_name = temp_file_name.replace(/\W/g, '');
278 - new_file_name = temp_file_name+'.'+new_file_name_array[new_file_name_array.length-1];
279 -
280 -
281 -
282 -
283 - 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);
284 192
285 - 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">';
286 - to_insert=to_insert+'<strong class="storage_file_name">File Name :</strong><span class="storage_file_name_real">'+new_file_name+' </span></div>';
287 - to_insert=to_insert+'<div class="wpstream_delete_media" ';
288 - to_insert=to_insert+' onclick=" return confirm('+onclick_string+') "';
289 - to_insert=to_insert+' data-filename="'+new_file_name+'" >delete file</div>';
290 - to_insert=to_insert+'<div class="wpstream_get_download_link" data-filename="'+new_file_name+'">download</div> ';
291 - to_insert=to_insert+'<a href="" class="wpstream_download_link">Click to download! The url will work for the next 20 minutes!</a></div>';
292 -
293 - $('#video_management_title').after(to_insert);
294 -
295 -
193 + jQuery('#wpstream_uploaded_mes').html(wpstream_admin_control_vars.preparing_multipart);
296 194
297 - $('.wpstream_get_download_link').unbind('click');
298 - $('.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 + }
299 218
300 - generate_download_link();
301 - generate_delete_link();
302 -
303 - setTimeout(function(){ window.location.href = window.location.href; }, 1000);
219 + multipartUploadData = {
220 + parts: response.data.parts
221 + };
222 + currentUploadedParts = [];
223 + handle = response.data.handle;
304 224
305 -
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();
306 235 }
307 - });
308 -
309 -
310 -
236 + });
237 + }
311 238
312 -
313 -
314 -
315 -
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 +
316 403 jQuery('#product-type').on('change',function(){
317 404
318 405 var product_type= jQuery('#product-type').val();
319 - 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' ){
320 407 jQuery('._sold_individually_field').show();
321 408 }
322 409
323 410 });
@@ -330,16 +417,20 @@
330 417 jQuery('#product-type').val('live_stream').trigger('change');
331 418 }
332 419
333 420 var product_type= jQuery('#product-type').val();
334 -
335 421 if ( product_type === 'video_on_demand' ) {
336 - jQuery('.show_if_video_on_demand' ).show();
337 -
338 - }
339 - else if ( product_type === 'live_stream' ) {
340 - $( '.show_if_live_stream' ).show();
341 -
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();
342 433 }
343 434
344 435
345 436
@@ -360,9 +451,9 @@
360 451
361 452
362 453 jQuery('#_subscript_live_event').change(function(){
363 454 //alert('move it'+product_type);
364 - 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' ) {
365 456
366 457 }else{
367 458 var value= jQuery(this).val();
368 459 if(value==="no"){
@@ -392,32 +483,13 @@
392 483 }
393 484 });
394 485 $('#wpstream_product_type').trigger('change');
395 486
396 -
397 -/*
398 - $('#wpstream_free_video_external_button').on( 'click', function(event) {
399 - var formfield = $('#wpstream_free_video_external').attr('name');
400 - tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
401 - window.send_to_editor = function (html) {
402 - var pathArray = html.match(/<media>(.*)<\/media>/);
403 - var mediaUrl = pathArray != null && typeof pathArray[1] != 'undefined' ? pathArray[1] : '';
404 -
405 - if(mediaUrl===''){
406 - mediaUrl = jQuery(html).attr("href");
407 - }
408 - jQuery('#wpstream_free_video_external').val(mediaUrl);
409 - tb_remove();
410 - };
411 - return false;
412 - });
413 - */
414 487
415 488
416 489
417 490
418 491
419 -
420 492 $('.close_event').click(function(event){
421 493 event.preventDefault();
422 494 var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php';
423 495 var acesta = $(this);
@@ -437,10 +509,10 @@
437 509 'action' : 'wpstream_close_event',
438 510 'security' : nonce,
439 511 'show_id' : show_id
440 512 },
441 - success: function (data) {
442 - parent.remove();
513 + success: function (data) {
514 + parent.remove();
443 515 },
444 516 error: function (errorThrown) {
445 517
446 518 }
@@ -446,33 +518,62 @@
446 518 }
447 519 });
448 520
449 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 + });
450 562
451 -
563 + mediaUploader.on("insert", function(){
564 + var image = mediaUploader.state().get("selection").first().toJSON();
565 + resolve(image);
566 + });
452 567
453 -
454 -
455 -
456 - $('.category_featured_image_button').on( 'click', function() {
457 - var parent = $(this).parent();
458 - var formfield = parent.find('#category_featured_image').attr('name');
459 - tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
460 - window.send_to_editor = function (html) {
461 - var imgurl = $('img', html).attr('src');
462 - parent.find('#category_featured_image').val(imgurl);
463 - var theid = $('img', html).attr('class');
464 - var thenum = theid.match(/\d+$/)[0];
465 - parent.find('#category_attach_id').val(thenum);
466 - tb_remove();
467 - };
468 - return false;
469 - });
470 -
568 + mediaUploader.open();
569 + });
570 +}
471 571
472 -});
473 -
474 572
573 +
574 +
575 +
475 576 /*
476 577 * handle video selection for recording
477 578 *
478 579 */
@@ -511,4 +612,56 @@
511 612 mediaUploader.open();
512 613 });
513 614 }
514 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 +}