1/** 2 * Admin front page image widget 3 * Derived from: https://hughlashbrooke.com/2015/12/18/create-a-custom-featured-image-box/ 4 */ 5function frontPageImageWidgetAdmin_media(parentSelector) { 6 7 var parent = jQuery(parentSelector), 8 button = parent.find('.frontPageImageWidgetAdmin_button'), 9 input = parent.find('.frontPageImageWidgetAdmin_input'), 10 image = parent.find('img'); 11 12 if( button.hasClass('frontPageImageWidgetAdmin_button-add') ) { 13 14 // Create the media frame. 15 var file_frame = wp.media.frames.file_frame = wp.media({ 16 title: 'Choose an image', 17 button: { text: 'Set image' }, 18 multiple: false, 19 }); 20 21 // When an image is selected, run a callback. 22 file_frame.on('select', function() { 23 var attachment = file_frame.state().get('selection').first().toJSON(); 24 25 input.val(attachment.id); 26 image.attr('src',attachment.sizes.thumbnail.url).show(); 27 button.text('Remove image') 28 .removeClass('frontPageImageWidgetAdmin_button-add') 29 .addClass('frontPageImageWidgetAdmin_button-remove'); 30 }); 31 32 // Open the modal. 33 file_frame.open(); 34 35 } else { 36 input.val(''); 37 image.hide(); 38 button.text('Set image') 39 .removeClass('frontPageImageWidgetAdmin_button-remove') 40 .addClass('frontPageImageWidgetAdmin_button-add'); 41 } 42}
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.