You can do it using something like this
$(document).on('change','input[type="checkbox"][name^="gal-item"]',function(){
var checkedIds = $('input[type="checkbox"][name^="gal-item"]:checked')
.map(function(){
return parseInt($(this).prop('name').replace(/gal-item-/,''));
}).get();
$('#shortcode').val('include="'+checkedIds.join(',')+'"');
});
You can replace it documentwith any closer static containerthat you need to find by looking at the markup for adding media. And you find the item you want to add an input field to, add it as
$('<span>[gallery</span><input type="text" id="shortcode" /><span>]</span>')
.appendTo(TARGETIDORCLASS);
Working demo
-
jQuery(document).ready( function($) {
$('<span>[gallery</span><input type="text" id="shortcode" /><span>]</span>')
.appendTo(TARGETIDORCLASS);
$(document).on('change','input[type="checkbox"][name^="gal-item"]',function(){
var checkedIds = $('input[type="checkbox"][name^="gal-item"]:checked').map(function(){
return parseInt($(this).prop('name').replace(/gal-item-/,''));
}).get();
$('#shortcode').val('include="'+checkedIds.join(',')+'"');
});
$('.filename.new').each(function(i,e){
var id = $(this).next('.slidetoggle')
.find('thead')
.attr('id')
.replace(/media-head-/, '');
var filename = $('<label>Add to gallery list <input type="checkbox" name="gal-item-'+id+'" id="gal-item-'+id+'" value="" /></label>')
.insertBefore($(this));
filename.css('float','right').css('margin-right','40px');
});
});
. , , , - , .