| 1 |
/*global $, jQuery, */ |
| 2 |
var counters={}; |
| 3 |
|
| 4 |
jQuery(document).ready(function ($) { |
| 5 |
"use strict"; |
| 6 |
|
| 7 |
|
| 8 |
generate_download_link(); |
| 9 |
generate_delete_link(); |
| 10 |
social_media_toggle('wpstream_on_facebook'); |
| 11 |
social_media_toggle('wpstream_on_youtube'); |
| 12 |
social_media_toggle('wpstream_on_twich'); |
| 13 |
|
| 14 |
|
| 15 |
function social_media_toggle(social_class){ |
| 16 |
|
| 17 |
jQuery('.'+social_class).on('change',function(){ |
| 18 |
|
| 19 |
if( $(this).prop('checked') ){ |
| 20 |
jQuery($(this).parent().parent().find( '.'+social_class+'_container' )).slideDown('100'); |
| 21 |
}else{ |
| 22 |
jQuery($(this).parent().parent().find( '.'+social_class+'_container' )).slideUp('100'); |
| 23 |
} |
| 24 |
|
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
jQuery('.wpestate_notices .notice-dismiss').on('click',function(){ |
| 31 |
|
| 32 |
var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php'; |
| 33 |
var notice_type = $(this).parent().attr('data-notice-type'); |
| 34 |
var nonce = $('#wpstream_notice_nonce').val(); |
| 35 |
|
| 36 |
|
| 37 |
jQuery.ajax({ |
| 38 |
type: 'POST', |
| 39 |
url: ajaxurl, |
| 40 |
data: { |
| 41 |
'action' : 'wpstream_update_cache_notice', |
| 42 |
'notice_type' : notice_type, |
| 43 |
'security' : nonce |
| 44 |
}, |
| 45 |
success: function (data) { |
| 46 |
|
| 47 |
|
| 48 |
}, |
| 49 |
error: function (errorThrown) { |
| 50 |
|
| 51 |
} |
| 52 |
}); |
| 53 |
}); |
| 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 |
|
| 67 |
|
| 68 |
jQuery.ajax({ |
| 69 |
type: 'POST', |
| 70 |
url: ajaxurl, |
| 71 |
|
| 72 |
data: { |
| 73 |
'action' : 'wpstream_get_delete_file', |
| 74 |
'video_name' : video_name |
| 75 |
|
| 76 |
}, |
| 77 |
success: function (data) { |
| 78 |
parent.remove(); |
| 79 |
|
| 80 |
|
| 81 |
}, |
| 82 |
error: function (errorThrown) { |
| 83 |
} |
| 84 |
}); |
| 85 |
}); |
| 86 |
|
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
function generate_download_link(){ |
| 91 |
|
| 92 |
$('.wpstream_get_download_link').on('click',function(){ |
| 93 |
var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php'; |
| 94 |
var video_name = $(this).attr('data-filename'); |
| 95 |
var acesta = $(this); |
| 96 |
var parent = $(this).parent(); |
| 97 |
|
| 98 |
jQuery(this).remove(); |
| 99 |
parent.find('.wpstream_download_link').show().text('please wait...'); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
jQuery.ajax({ |
| 104 |
type: 'POST', |
| 105 |
url: ajaxurl, |
| 106 |
|
| 107 |
data: { |
| 108 |
'action' : 'wpstream_get_download_link', |
| 109 |
'video_name' : video_name, |
| 110 |
|
| 111 |
}, |
| 112 |
success: function (data) { |
| 113 |
|
| 114 |
if(String(data)==='toolarge'){ |
| 115 |
parent.find('.wpstream_download_link').show().text(wpstream_admin_control_vars.no_band); |
| 116 |
}else{ |
| 117 |
parent.find('.wpstream_download_link').show().text(wpstream_admin_control_vars.download_mess); |
| 118 |
parent.find('.wpstream_download_link').show().attr('href',data); |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
}, |
| 123 |
error: function (errorThrown) { |
| 124 |
} |
| 125 |
}); |
| 126 |
}); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
$( '.inputfile' ).each( function(){ |
| 135 |
var $input = $( this ), |
| 136 |
$label = $input.next( 'label' ), |
| 137 |
labelVal = $label.html(); |
| 138 |
|
| 139 |
$input.on( 'change', function( e ) |
| 140 |
{ |
| 141 |
var fileName = ''; |
| 142 |
|
| 143 |
if( this.files && this.files.length > 1 ) |
| 144 |
fileName = ( this.getAttribute( 'data-multiple-caption' ) || '' ).replace( '{count}', this.files.length ); |
| 145 |
else if( e.target.value ) |
| 146 |
fileName = e.target.value.split( '\\' ).pop(); |
| 147 |
|
| 148 |
if( fileName ) |
| 149 |
$label.find( 'span' ).html( fileName ); |
| 150 |
else |
| 151 |
$label.html( labelVal ); |
| 152 |
}); |
| 153 |
|
| 154 |
// Firefox bug fix |
| 155 |
$input |
| 156 |
.on( 'focus', function(){ $input.addClass( 'has-focus' ); }) |
| 157 |
.on( 'blur', function(){ $input.removeClass( 'has-focus' ); }); |
| 158 |
}); |
| 159 |
|
| 160 |
var form = $('.direct-upload'); |
| 161 |
var filesUploaded = []; |
| 162 |
var folders = []; |
| 163 |
|
| 164 |
// var new_file_name=''; |
| 165 |
|
| 166 |
form.fileupload({ |
| 167 |
url: form.attr('action'), |
| 168 |
type: form.attr('method'), |
| 169 |
datatype: 'xml', |
| 170 |
add: function (event, data) { |
| 171 |
|
| 172 |
|
| 173 |
if( data.files[0].type!=='video/mp4' && data.files[0].type!=='video/quicktime'){ |
| 174 |
jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.not_accepted); |
| 175 |
return; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
var file_size=(parseInt(data.files[0].size,10))/1000000; |
| 181 |
var user_storage = jQuery('#wpstream_storage').val(); |
| 182 |
var user_band = jQuery('#wpstream_band').val(); |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
if(file_size > user_storage || file_size>user_band){ |
| 187 |
jQuery('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.no_band_no_store); |
| 188 |
return; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
$('#wpstream_label_action').text(wpstream_admin_control_vars.uploading) |
| 193 |
|
| 194 |
jQuery('#wpstream_uploaded_mes').empty().html(); |
| 195 |
// Show warning message if your leaving the page during an upload. |
| 196 |
window.onbeforeunload = function () { |
| 197 |
return 'You have unsaved changes.'; |
| 198 |
}; |
| 199 |
|
| 200 |
var file = data.files[0]; |
| 201 |
|
| 202 |
//console.log('file'+JSON.stringify(file)); |
| 203 |
form.find('input[name="Content-Type"]').val(file.type); |
| 204 |
form.find('input[name="Content-Length"]').val(file.size); |
| 205 |
|
| 206 |
// Actually submit to form to S3. |
| 207 |
data.submit(); |
| 208 |
|
| 209 |
// Show the progress bar |
| 210 |
// Uses the file size as a unique identifier |
| 211 |
var bar = $('<div class="progress" data-mod="'+file.size+'"><div class="bar"></div></div>'); |
| 212 |
$('.progress-bar-area').append(bar); |
| 213 |
bar.slideDown('fast'); |
| 214 |
}, |
| 215 |
progress: function (e, data) { |
| 216 |
// This is what makes everything really cool, thanks to that callback |
| 217 |
// you can now update the progress bar based on the upload progress. |
| 218 |
var percent = Math.round((data.loaded / data.total) * 100); |
| 219 |
$('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', percent + '%').html(percent+'%'); |
| 220 |
}, |
| 221 |
|
| 222 |
fail: function (e, data) { |
| 223 |
// Remove the 'unsaved changes' message. |
| 224 |
window.onbeforeunload = null; |
| 225 |
$('.progress[data-mod="'+data.files[0].size+'"] .bar').css('width', '100%').addClass('red').html(''); |
| 226 |
}, |
| 227 |
done: function (event, data) { |
| 228 |
|
| 229 |
window.onbeforeunload = null; |
| 230 |
$('.bar').remove(); |
| 231 |
$('#wpstream_uploaded_mes').empty().html(wpstream_admin_control_vars.upload_complete); |
| 232 |
$('#wpstream_label_action').text(wpstream_admin_control_vars.upload_complete2); |
| 233 |
|
| 234 |
var new_file_name=data.files[0].name; |
| 235 |
|
| 236 |
|
| 237 |
var new_file_name_array= data.files[0].name.split("."); |
| 238 |
var temp_file_name= new_file_name_array[0].split(' ').join('_'); |
| 239 |
temp_file_name= temp_file_name.replace(/\W/g, ''); |
| 240 |
new_file_name=temp_file_name+'.'+new_file_name_array[new_file_name_array.length-1]; |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
var onclick_string=' Are you sure you wish to delete '+new_file_name+' ? '; |
| 246 |
|
| 247 |
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">'; |
| 248 |
to_insert=to_insert+'<strong class="storage_file_name">File Name :</strong><span class="storage_file_name_real">'+new_file_name+' </span></div>'; |
| 249 |
to_insert=to_insert+'<div class="wpstream_delete_media" '; |
| 250 |
to_insert=to_insert+' onclick=" return confirm('+onclick_string+') "'; |
| 251 |
to_insert=to_insert+' data-filename="'+new_file_name+'" >delete file</div>'; |
| 252 |
to_insert=to_insert+'<div class="wpstream_get_download_link" data-filename="'+new_file_name+'">get download link</div> '; |
| 253 |
to_insert=to_insert+'<a href="" class="wpstream_download_link">Click to download! The url will work for the next 20 minutes!</a></div>'; |
| 254 |
|
| 255 |
$('#video_management_title').after(to_insert); |
| 256 |
|
| 257 |
$('.wpstream_get_download_link').unbind('click'); |
| 258 |
$('.wpstream_delete_media').unbind('click'); |
| 259 |
|
| 260 |
generate_download_link(); |
| 261 |
generate_delete_link(); |
| 262 |
|
| 263 |
|
| 264 |
} |
| 265 |
}); |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
jQuery('#product-type').on('change',function(){ |
| 275 |
|
| 276 |
var product_type= jQuery('#product-type').val(); |
| 277 |
if(product_type==='live_stream' || product_type==='video_on_demand'){ |
| 278 |
jQuery('._sold_individually_field').show(); |
| 279 |
} |
| 280 |
|
| 281 |
}); |
| 282 |
|
| 283 |
if(wpstream_findGetParameter('new_video_name')!=='' && wpstream_findGetParameter('new_video_name')!=null ){ |
| 284 |
jQuery('#product-type').val('video_on_demand').trigger('change'); |
| 285 |
} |
| 286 |
|
| 287 |
if(wpstream_findGetParameter('new_stream')!=='' && wpstream_findGetParameter('new_stream')!=null ){ |
| 288 |
jQuery('#product-type').val('live_stream').trigger('change'); |
| 289 |
} |
| 290 |
|
| 291 |
var product_type= jQuery('#product-type').val(); |
| 292 |
|
| 293 |
if ( product_type === 'video_on_demand' ) { |
| 294 |
jQuery('.show_if_video_on_demand' ).show(); |
| 295 |
|
| 296 |
} |
| 297 |
else if ( product_type === 'live_stream' ) { |
| 298 |
$( '.show_if_live_stream' ).show(); |
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
function wpstream_findGetParameter(parameterName) { |
| 307 |
var result = null, |
| 308 |
tmp = []; |
| 309 |
location.search |
| 310 |
.substr(1) |
| 311 |
.split("&") |
| 312 |
.forEach(function (item) { |
| 313 |
tmp = item.split("="); |
| 314 |
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); |
| 315 |
}); |
| 316 |
return result; |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
jQuery('#_subscript_live_event').change(function(){ |
| 321 |
//alert('move it'+product_type); |
| 322 |
if ( product_type === 'video_on_demand' || product_type === 'live_stream' ) { |
| 323 |
|
| 324 |
}else{ |
| 325 |
var value= jQuery(this).val(); |
| 326 |
if(value==="no"){ |
| 327 |
jQuery("._movie_url_field").parent().removeClass("hide_if_subscription").show(); |
| 328 |
}else{ |
| 329 |
jQuery("._movie_url_field").parent().addClass("hide_if_subscription").hide(); |
| 330 |
} |
| 331 |
} |
| 332 |
}); |
| 333 |
|
| 334 |
jQuery('#_subscript_live_event').trigger('change'); |
| 335 |
|
| 336 |
|
| 337 |
$('#wpstream_product_type').change(function(){ |
| 338 |
$('.video_free').hide(); |
| 339 |
$('.video_free_external').hide(); |
| 340 |
|
| 341 |
if( $('#wpstream_product_type').val()=== "2"){ |
| 342 |
$('.video_free').show(); |
| 343 |
} |
| 344 |
if( $('#wpstream_product_type').val()=== "3"){ |
| 345 |
$('.video_free_external').show(); |
| 346 |
} |
| 347 |
}); |
| 348 |
$('#wpstream_product_type').trigger('change'); |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
$('#wpstream_free_video_external_button').on( 'click', function(event) { |
| 353 |
var formfield = $('#wpstream_free_video_external').attr('name'); |
| 354 |
tb_show('', 'media-upload.php?type=image&TB_iframe=true'); |
| 355 |
window.send_to_editor = function (html) { |
| 356 |
var pathArray = html.match(/<media>(.*)<\/media>/); |
| 357 |
var mediaUrl = pathArray != null && typeof pathArray[1] != 'undefined' ? pathArray[1] : ''; |
| 358 |
|
| 359 |
if(mediaUrl===''){ |
| 360 |
mediaUrl = jQuery(html).attr("href"); |
| 361 |
} |
| 362 |
jQuery('#wpstream_free_video_external').val(mediaUrl); |
| 363 |
tb_remove(); |
| 364 |
}; |
| 365 |
return false; |
| 366 |
}); |
| 367 |
|
| 368 |
$('.close_event').click(function(event){ |
| 369 |
event.preventDefault(); |
| 370 |
var ajaxurl = wpstream_admin_control_vars.admin_url + 'admin-ajax.php'; |
| 371 |
var acesta = $(this); |
| 372 |
var parent = $(this).parent().parent(); |
| 373 |
var notification_area = $(this).parent().find('.event_list_unit_notificationx'); |
| 374 |
var show_id = parseFloat( $(this).attr('data-show-id') ); |
| 375 |
var nonce = $('#wpstream_start_event_nonce').val(); |
| 376 |
//$(this).unbind(); |
| 377 |
notification_area.text('Closing Event'); |
| 378 |
|
| 379 |
|
| 380 |
jQuery.ajax({ |
| 381 |
type: 'POST', |
| 382 |
url: ajaxurl, |
| 383 |
dataType: 'json', |
| 384 |
data: { |
| 385 |
'action' : 'wpstream_close_event', |
| 386 |
'security' : nonce, |
| 387 |
'show_id' : show_id |
| 388 |
}, |
| 389 |
success: function (data) { |
| 390 |
parent.remove(); |
| 391 |
}, |
| 392 |
error: function (errorThrown) { |
| 393 |
|
| 394 |
} |
| 395 |
}); |
| 396 |
|
| 397 |
}); |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
$('.category_featured_image_button').on( 'click', function() { |
| 405 |
var parent = $(this).parent(); |
| 406 |
var formfield = parent.find('#category_featured_image').attr('name'); |
| 407 |
tb_show('', 'media-upload.php?type=image&TB_iframe=true'); |
| 408 |
window.send_to_editor = function (html) { |
| 409 |
var imgurl = $('img', html).attr('src'); |
| 410 |
parent.find('#category_featured_image').val(imgurl); |
| 411 |
var theid = $('img', html).attr('class'); |
| 412 |
var thenum = theid.match(/\d+$/)[0]; |
| 413 |
parent.find('#category_attach_id').val(thenum); |
| 414 |
tb_remove(); |
| 415 |
}; |
| 416 |
return false; |
| 417 |
}); |
| 418 |
|
| 419 |
|
| 420 |
}); |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|