2 * Adapted from: http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/
4 jQuery(document
).ready(function($){
8 $('#dnxasi_uploadimage').on('click', function( event
){
10 event
.preventDefault();
12 // If the media frame already exists, reopen it.
18 // Create the media frame.
19 file_frame
= wp
.media
.frames
.file_frame
= wp
.media({
20 title
: data
.frameTitle
,
22 text
: data
.buttonText
,
24 multiple
: false // Set to true to allow multiple files to be selected
27 // When an image is selected, run a callback.
28 file_frame
.on( 'select', function() {
29 // We set multiple to false so only get one image from the uploader
30 attachment
= file_frame
.state().get('selection').first().toJSON();
32 // Do something with attachment.id and/or attachment.url here
33 $('#dnxasi_meta_signature').attr('value', attachment
.url
);
34 $('#dnxasi_signature_preview').attr('src', attachment
.url
);
37 // Finally, open the modal
41 $('#dnxasi_deleteimage').on( 'click', function(event
) {
42 event
.preventDefault();
44 $('#dnxasi_meta_signature').attr('value', '');
45 $('#dnxasi_signature_preview').attr('src', data
.placeholder
);