jQuery(function(jQuery) { //UPLOAD SINGLE IMAGE if ( ! jQuery('.custom_upload_image').val() ) { jQuery('.itls_logo_showcase_remove_image_button').hide(); } // Uploading files var file_frame; jQuery(document).on( 'click', '.itls_logo_showcase_upload_image_button', function( event ){ event.preventDefault(); formfield = jQuery(this).siblings('.custom_upload_image'); preview = jQuery(this).siblings('.custom_preview_video'); // If the media frame already exists, reopen it. if ( file_frame ) { file_frame.open(); return; } // Create the media frame. file_frame = wp.media.frames.downloadable_file = wp.media({ title: 'Choose Video', button: { text: 'Use Video' }, multiple: false }); file_frame.on('open', function() { var selection = file_frame_gallery.state().get('selection'); ids = formfield.val().split(','); ids.forEach(function(id) { attachment = wp.media.attachment(id); attachment.fetch(); selection.add( attachment ? [ attachment ] : [] ); }); //} }); // When an image is selected, run a callback. file_frame.on( 'select', function() { attachment = file_frame.state().get('selection').first().toJSON(); formfield.val( attachment.id ); preview.html(attachment.name); jQuery('.itls_logo_showcase_remove_image_button').show(); }); // Finally, open the modal. file_frame.open(); }); jQuery(document).on( 'click', '.itls_logo_showcase_remove_image_button', function( event ){ formfield = jQuery(this).siblings('.custom_upload_image'); preview = jQuery(this).siblings('.custom_preview_video'); formfield.val(''); preview.html(''); jQuery(this).hide(); return false; }); ///IMAGE GALLERY if ( ! jQuery('.custom_upload_imagegallery').val() ) { jQuery('.itls_logo_showcase_remove_imagegallery_button').hide(); } // Uploading files var file_frame_gallery; jQuery(document).on( 'click', '.itls_logo_showcase_upload_imagegallery_button', function( event ){ event.preventDefault(); formfield = jQuery(this).siblings('.custom_upload_imagegallery'); preview = jQuery(this).siblings('.custom_preview_imagegallery'); // If the media frame already exists, reopen it. if ( file_frame_gallery ) { file_frame_gallery.open(); return; } // Create the media frame. file_frame_gallery = wp.media.frames.downloadable_file = wp.media({ title: 'Add Image to Gallery', button: { text: 'Insert to Gallery' }, multiple : true }); file_frame_gallery.on('open', function() { var selection = file_frame_gallery.state().get('selection'); ids = formfield.val().split(','); ids.forEach(function(id) { attachment = wp.media.attachment(id); attachment.fetch(); selection.add( attachment ? [ attachment ] : [] ); }); }); // When an image is selected, run a callback. file_frame_gallery.on( 'select', function() { var selection_image=Array(); var selection_items_dom=''; var i=0; var selection = file_frame_gallery.state().get('selection'); selection.map( function( attachment ) { if(attachment.id!='' && attachment.id!=null && attachment.url!='' && attachment.url!=null ) { attachment = attachment.toJSON(); //selection_image[i++]=attachment.id+"@"+attachment.url; selection_image[i++]=attachment.id; selection_items_dom+="