Skip to content

Commit e0220bc

Browse files
committed
Update script.js
added thumbnail preview
1 parent c6c76d9 commit e0220bc

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

js/script.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
(function ($) {
1+
jQuery( document ).ready(function($) {
22
$('.pw-gallery').each(function() {
33
var instance = this;
44

55
$('input[type=button]', instance).click(function() {
66
var gallerysc = '[gallery ids="' + $('input[type=hidden]', instance).val() + '"]';
77
wp.media.gallery.edit(gallerysc).on('update', function(g) {
88
var id_array = [];
9-
$.each(g.models, function(id, img) { id_array.push(img.id); });
10-
$('input[type=hidden]', instance).val(id_array.join(","));
9+
var fileGroup = [];
10+
11+
$( ".cmb2-media-status li" ).remove();
12+
13+
$.each(g.models, function(id, img) {
14+
15+
id_array.push(this.id);
16+
var width = this.attributes.sizes.thumbnail.width ? this.attributes.sizes.thumbnail.width : 150;
17+
var height = this.attributes.sizes.thumbnail.height ? this.attributes.sizes.thumbnail.height : 150;
18+
19+
uploadStatus = '<li class="img-status"><img width="'+width+'" height="'+height+'" src="' + this.attributes.sizes.thumbnail.url+ '" class="attachment-150x150" alt=""></li>';
20+
fileGroup.push( uploadStatus );
21+
22+
});
23+
24+
$('input[type=hidden]', instance).val(id_array.join(","));
25+
26+
$( fileGroup ).each( function() {
27+
28+
$('.cmb2-media-status').slideDown().append(this);
29+
});
1130
});
1231
});
1332
});
14-
}(jQuery));
33+
});

0 commit comments

Comments
 (0)