1jQuery(function($) { 2 3 var file_frame; 4 5 $(document).on('click', '#gallery-metabox a.gallery-add', function(e) { 6 7 e.preventDefault(); 8 9 if (file_frame) file_frame.close(); 10 11 file_frame = wp.media.frames.file_frame = wp.media({ 12 title: $(this).data('uploader-title'), 13 button: { 14 text: $(this).data('uploader-button-text'), 15 }, 16 multiple: true 17 }); 18 19 file_frame.on('select', function() { 20 var listIndex = $('#gallery-metabox-list li').index($('#gallery-metabox-list li:last')), 21 selection = file_frame.state().get('selection'); 22 23 selection.map(function(attachment, i) { 24 attachment = attachment.toJSON(), 25 index = listIndex + (i + 1); 26 27 $('#gallery-metabox-list').append('<li><input type="hidden" name="vdw_gallery_id[' + index + ']" value="' + attachment.id + '"><img class="image-preview" src="' + attachment.sizes.thumbnail.url + '"><a class="change-image button button-small" href="#" data-uploader-title="Change image" data-uploader-button-text="Change image">Change image</a><br><small><a class="remove-image" href="#">Remove image</a></small></li>'); 28 }); 29 }); 30 31 makeSortable(); 32 33 file_frame.open(); 34 35 }); 36 37 $(document).on('click', '#gallery-metabox a.change-image', function(e) { 38 39 e.preventDefault(); 40 41 var that = $(this); 42 43 if (file_frame) file_frame.close(); 44 45 file_frame = wp.media.frames.file_frame = wp.media({ 46 title: $(this).data('uploader-title'), 47 button: { 48 text: $(this).data('uploader-button-text'), 49 }, 50 multiple: false 51 }); 52 53 file_frame.on( 'select', function() { 54 attachment = file_frame.state().get('selection').first().toJSON(); 55 56 that.parent().find('input:hidden').attr('value', attachment.id); 57 that.parent().find('img.image-preview').attr('src', attachment.sizes.thumbnail.url); 58 }); 59 60 file_frame.open(); 61 62 }); 63 64 function resetIndex() { 65 $('#gallery-metabox-list li').each(function(i) { 66 $(this).find('input:hidden').attr('name', 'vdw_gallery_id[' + i + ']'); 67 }); 68 } 69 70 function makeSortable() { 71 $('#gallery-metabox-list').sortable({ 72 opacity: 0.6, 73 stop: function() { 74 resetIndex(); 75 } 76 }); 77 } 78 79 $(document).on('click', '#gallery-metabox a.remove-image', function(e) { 80 e.preventDefault(); 81 82 $(this).parents('li').animate({ opacity: 0 }, 200, function() { 83 $(this).remove(); 84 resetIndex(); 85 }); 86 }); 87 88 makeSortable(); 89 90});
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.