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)return void alert("ImagesWidget already init");if(init=!0,!("callback"in window&&"imagesWidgetSelectImage"in window.callback))return void alert("miss window.callback.imagesWidgetSelectImage");$(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 i=e.imagesWidget().val();i=i.concat(a),e.imagesWidget().val(i)}),!1}),$(document).on("click","[data-images-widget] .delete",function(){var e=$(this).closest(".item"),a=e.closest("[data-images-widget]"),i=parseInt(e.attr("data-item-index")),t=a.imagesWidget().val();return t.splice(i,1),a.imagesWidget().val(t),!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("value = "+$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(){return new ImagesWidgetForJquery(this)}}),$(function(){$("[data-images-widget]").imagesWidget().init()})}};module.exports=ImagesWidget;