我创建了一个自定义meta_box,我希望能够为图库选择图像。问题是,当我选择图像时,我需要按住Ctrl / Cmd来选择更多。
我怎么能这样做呢?
我试过改变"倍数"假,并删除它,但没有任何反应。
jQuery(document).ready(function() {
var galleryFrame;
var gallerySelection = [];
var galleryImages = [];
galleryImages = jQuery.parseJSON(jQuery('#mysite-gallery-array').val());
// Frame
galleryFrame = wp.media.frames.mysite_gallery_frame = wp.media({
title: 'Select Image',
button: {
text: 'Insert Image'
},
library: {
type: 'image'
},
multiple: true
});
// Add
jQuery('#mysite-gallery-add').click(function(e) {
e.preventDefault();
galleryFrame.open();
});
// Open
galleryFrame.on('open', function() {
gallerySelection = galleryFrame.state().get('selection');
if(galleryImages){
galleryImages.forEach(function(i) {
var attachment = wp.media.attachment(i);
gallerySelection.add(attachment ? [attachment] : []);
});
}
});
// Select
galleryFrame.on('select', function() {
gallerySelection = galleryFrame.state().get('selection');
jQuery("#mysite-gallery-main").empty();
galleryImages = [];
gallerySelection.map(function(attachment) {
var id = attachment.id;
var url = attachment.attributes.sizes.thumbnail.url;
galleryImages.push(id);
jQuery("#mysite-gallery-main").append('<div class="mysite-gallery-image"><input name="article_gallery[]" value="'+id+'" type="hidden"><img src="'+url+'"><div class="mysite-gallery-remove"></div></div>');
});
});
// Remove
jQuery('#mysite-gallery-main').on('click', '.mysite-gallery-remove', function() {
var imageWrapper = jQuery(this).parents('.mysite-gallery-image')
var imageId = imageWrapper.find('input').val();
galleryImages.splice(jQuery.inArray(imageId, galleryImages), 1);
imageWrapper.remove();
});
// Sortable
jQuery('#mysite-gallery-main').sortable();
jQuery('#mysite-gallery-main').disableSelection();
});
答案 0 :(得分:2)
尝试将multiple: true
更改为multiple:'add'