!function($){$(".wpzinc-media-library-selector").each((function(){var t=$(this).data("multiple");void 0===t&&(t=!1),t&&$("ul",$(this)).sortable()})),$("#wpbody").on("click",".wpzinc-media-library-insert",(function(t){t.preventDefault();var e=$(this).closest(".wpzinc-media-library-selector"),a=$(e).data("input-name"),i=$(e).data("output-size"),n=$(e).data("file-type"),l=$(e).data("multiple"),o=$(e).data("limit");void 0===i&&(i="thumbnail"),void 0===n&&(n="image"),void 0===l&&(l=!1),void 0===o&&(o=99999);var r=[];if($("input[type=hidden]",$(e)).each((function(){r.push($(this).val())})),c)c.open();else{var c=wp.media({title:"Choose Item",button:{text:"Select"},library:{type:n},multiple:!!l&&"add"});c.on("open",(function(){var t=c.state().get("selection");r.forEach((function(e){attachment=wp.media.attachment(e),attachment.fetch(),t.add(attachment?[attachment]:[])}))})),c.off("select"),c.off("selection:toggle"),c.on("selection:toggle",(function(){var t=c.state().get("selection");t.length>o&&t.remove(t.last())})),c.on("select",(function(){var t=c.state().get("selection").map((function(t){return t.toJSON(),t}));$("ul",$(e)).html("");for(var n=t.length,l=0;l<n;l++){var o=t[l],r=o.get("id"),s=o.get("url"),u='<li class="wpzinc-media-library-attachment">';switch(u+='<a href="#" class="wpzinc-media-library-insert">',u+='<input type="hidden" name="'+a+'" value="'+r+'" />',o.attributes.type){case"image":void 0!==o.attributes.sizes[i]&&(console.log(o.attributes.sizes[i]),s=o.attributes.sizes[i].url),u+='<img src="'+s+'" />';break;default:u+=o.attributes.filename;break}u+='<a href="#" class="wpzinc-media-library-remove">Remove</a>',u+="</li>",$("ul",$(e)).append(u)}})),c.open()}})),$("#wpbody").on("click",".wpzinc-media-library-remove",(function(t){t.preventDefault(),$(this).closest(".wpzinc-media-library-attachment").remove()}))}(jQuery);