PluginProbe
Embed Privacy / 1.10.0
Embed Privacy v1.10.0
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / assets / js / admin / image-upload.js

image-upload.js in Embed Privacy 1.10.0, at assets/js/admin/image-upload.js

53 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Add support for image uploads.
3 *
4 * @author Epiphyt
5 * @license GPL2
6 * @package epiphyt\Embed_Privacy
7 */
8 jQuery( document ).ready( function( $ ) {
9 // remove image
10 $( document ).on( 'click', '.embed-privacy-remove-image', function( event ) {
11 event.preventDefault();
12
13 var image_item = $( this ).closest( '.embed-privacy-image-item' );
14
15 image_item.find( '.embed-privacy-image-input-container, .embed-privacy-image-set-input-container' ).removeClass( 'embed-privacy-hidden' );
16 image_item.find( '.embed-privacy-image-container, .embed-privacy-image-set-container' ).addClass( 'embed-privacy-hidden' );
17
18 // reset value
19 image_item.find( '.embed-privacy-image-input' ).val( '' );
20 image_item.find( '.embed-privacy-upload-input' ).val( '' );
21 // reset type
22 image_item.find( '.embed-privacy-upload-input' ).attr( 'type', 'file' );
23 } );
24
25 // upload functionality single image
26 $( document ).on( 'click', '.embed-privacy-image-upload', function( event ) {
27 event.preventDefault();
28
29 var container = $( this ).closest( '.embed-privacy-image-item' ).find( '.embed-privacy-image-container' );
30 var id_field = $( this ).closest( '.embed-privacy-image-item' ).find( '.embed-privacy-image-input' );
31 var meta_image_frame = wp.media.frames.meta_image_frame = wp.media();
32 var upload_field = $( this );
33
34 meta_image_frame.on( 'select', function() {
35 var media_attachment = meta_image_frame.state().get('selection').first().toJSON();
36
37 // clear the image container
38 container.find( 'img' ).remove();
39 // add uploaded/selected image
40 container.prepend( '<img src="' + ( typeof media_attachment.sizes !== 'undefined' ? typeof media_attachment.sizes.thumbnail !== 'undefined' ? media_attachment.sizes.thumbnail.url : media_attachment.sizes.full.url : media_attachment.url ) + '" alt="">' );
41 // don't hide the container anymore
42 container.removeClass( 'embed-privacy-hidden' );
43 // store attachment ID
44 id_field.val( media_attachment.id );
45
46 // hide upload field
47 upload_field.parent().addClass( 'embed-privacy-hidden' );
48 } );
49
50 meta_image_frame.open();
51 } );
52 } );
53