var init=!1,ImagesWidget={getOption:function($container){var initValue;try{try{initValue=JSON.parse($container.attr("data-images-widget"))}catch(e){eval("initValue = "+$container.attr("data-images-widget"))}}catch(e){initValue={}}return $.extend({},initValue)},init:function(){if(!init&&(init=!0,"callback"in window&&"imagesWidgetSelectImage"in window.callback)){$(document).on("click","[data-images-widget] .add",function(){var e=$(this).closest("[data-images-widget]");ImagesWidget.getOption(e);return window.callback.imagesWidgetSelectImage(function(a){var t=e.imagesWidget().val();t=t.concat(a),e.imagesWidget().val(t)}),!1}),$(document).on("click","[data-images-widget] .delete",function(){var e=$(this).closest(".item"),a=e.closest("[data-images-widget]"),t=parseInt(e.attr("data-item-index")),i=a.imagesWidget().val();return i.splice(t,1),a.imagesWidget().val(i),!1});var ImagesWidgetForJquery=function(obj){var $container=$(obj);this.init=function(){var currentValue=[];try{currentValue=JSON.parse($container.find("[data-images]").val())}catch(e){try{eval("currentValue = "+$container.find("[data-images]").val())}catch(e){currentValue=[]}}this.val(currentValue)},this.val=function(value){var currentValue=[];try{currentValue=JSON.parse($container.find("[data-images]").val())}catch(e){try{eval("value = "+$container.find("[data-images]").val())}catch(e){currentValue=[]}}if(void 0===value)return currentValue;$container.find(".list").find(".item").remove();for(var $html,i=value.length-1;i>=0;i--)$html=$(['<div class="item" data-item-index="',i,'">','   <a href="javascript:;" class="delete">x</a>','   <div class="cover"></div>',"</div>"].join("")),$html.find(".cover").css({backgroundImage:"url("+value[i]+")"}),$container.find(".list").prepend($html);$container.find("[data-images]").val(JSON.stringify(value)),$container.trigger("images-widget.change",[value])}};$.fn.extend({imagesWidget:function(){if($(this).length>1)return alert("ImagesWidget only accept one dom"),null;var e=$(this).data("widget");return e||(e=new ImagesWidgetForJquery(this),$(this).data("widget",e),e)}}),$(function(){$("[data-images-widget]").each(function(e,a){$(a).imagesWidget().init()})})}}};module.exports=ImagesWidget;