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