| 1 | /* |
| 2 | * Adapted from: http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/ |
| 3 | */ |
| 4 | jQuery(document).ready(function($){ |
| 5 | // Uploading files |
| 6 | var file_frame; |
| 7 | |
| 8 | $('#dnxasi_uploadimage').on('click', function( event ){ |
| 9 | |
| 10 | event.preventDefault(); |
| 11 | |
| 12 | // If the media frame already exists, reopen it. |
| 13 | if ( file_frame ) { |
| 14 | file_frame.open(); |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | // Create the media frame. |
| 19 | file_frame = wp.media.frames.file_frame = wp.media({ |
| 20 | title: data.frameTitle, |
| 21 | button: { |
| 22 | text: data.buttonText, |
| 23 | }, |
| 24 | multiple: false // Set to true to allow multiple files to be selected |
| 25 | }); |
| 26 | |
| 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(); |
| 31 | |
| 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); |
| 35 | }); |
| 36 | |
| 37 | // Finally, open the modal |
| 38 | file_frame.open(); |
| 39 | }); |
| 40 | |
| 41 | $('#dnxasi_deleteimage').on( 'click', function(event) { |
| 42 | event.preventDefault(); |
| 43 | |
| 44 | $('#dnxasi_meta_signature').attr('value', ''); |
| 45 | $('#dnxasi_signature_preview').attr('src', data.placeholder); |
| 46 | }); |
| 47 | |
| 48 | }); |