jQuery(document).ready(function($) { "use strict"; var last = 0; $('.add_feature').click(function(event) { event.preventDefault(); var uploader = wp.media( { title : 'Add feature icon file with feature box', button : { text : 'Add', }, multiple : true }) .on('select', function() { var selection = uploader.state().get('selection'); var attachements = []; selection.map(function(attachement) { attachement = attachement.toJSON(); attachements.push([attachement.id, attachement.url, attachement.caption]); }) get_all_images_data(attachements); }) .open(); }); function get_all_images_data(attachments) { var attachs = []; $.each(attachments, function(i,v){ attachs[i] = v[0]; }); var attach_alts = []; var url = ajaxurl; var nonce = $('#img_alt_query_nonce').html(); $.post( url, { action:"bluesquirrel_get_image_alt_info_ajax", alt_save_ajax: true, nonce: nonce, attachments:attachs }) .done(function( nfo ) { var res = $.parseJSON(nfo); $.each(res, function(i,v){ var sdiv = ''; attach_alts[i] = v; }); $.each(attachments, function(i,v){ var sdiv = ''; (last==0) ? last = parseInt($('input[name="lastf"]').val(), 10)+1 : last++; var html = "

"+feature_parameters[0]+" #"+last+"

"+ ""+ ""+ ""+ "

"+feature_parameters[1]+"

"+feature_parameters[2]+"
"+feature_parameters[6]+"
"+feature_parameters[3]+"
"+feature_parameters[4]+"

"; $('#accordion_invitation').append(html); $('button[name="remove"]').bind('click', function(event){ $(this).parent().parent().prev().remove(); $(this).parent().parent().remove(); }); }); $('#accordion_invitation').accordion('destroy').accordion({heightStyle: "content"}); }); } });