1jQuery(document).ready(function() { 2 3 var media_selector_button = jQuery( '#media-selector-button' ); 4 var media_remove_button = jQuery( '#media-remove-button' ); 5 6 var file_frame; // variable for the wp.media file_frame 7 // attach a click event (or whatever you want) to some element on your page 8 media_selector_button.on( 'click', function( event ) { 9 10 event.preventDefault(); 11 12 // if the file_frame has already been created, just reuse it 13 if( file_frame ){ 14 file_frame.open(); 15 return; 16 } 17 18 file_frame = wp.media.frames.file_frame = wp.media({ 19 title: jQuery( this ).data( 'uploader_title' ), 20 button: { 21 text: jQuery( this ).data( 'uploader_button_text' ), 22 }, 23 multiple: false // set this to true for multiple file selection 24 }); 25 26 file_frame.on( 'select', function() { 27 attachment = file_frame.state().get('selection').first().toJSON(); 28 jQuery( '#' + media_selector_button.attr('img-holder') ).attr( 'src', attachment.url ); // display image in image placeholder 29 jQuery( '#' + media_selector_button.attr('data-holder') ).attr( 'value', attachment.id ); // assign image id value to hidden input 30 31 media_remove_button.show(); 32 }); 33 34 file_frame.open(); 35 36 }); 37 38 // on remove button click 39 media_remove_button.on( 'click', function( event ) { 40 41 event.preventDefault(); 42 43 jQuery( '#' + media_selector_button.attr('img-holder') ).attr( 'src', media_selector_button.attr('default-thumb') ); // display default image in image placeholder 44 jQuery( '#' + media_selector_button.attr('data-holder') ).attr( 'value', 0 ); // assign image id value to hidden input 45 media_remove_button.hide(); 46 47 }); 48 49});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.