var init=!1,ImageWidget={getOption:function($container){var initValue;try{try{initValue=JSON.parse($container.attr("data-image-widget"))}catch(e){initValue=eval("initValue = "+$container.attr("data-image-widget"))}}catch(i){initValue={}}return $.extend({emptyImage:"/assets/lib/img/none.png"},initValue)},init:function(){if(!init){if(init=!0,!("callback"in window&&"imageWidgetSelectImage"in window.callback))return void alert("window.callback.imageWidgetSelectImage not defined");$(document).on("click","[data-image-widget] .add",function(){var i=$(this).closest("[data-image-widget]");ImageWidget.getOption(i);return window.callback.imageWidgetSelectImage(function(e){i.find("[data-image]").val(e[0]),i.find(".image").css({backgroundImage:'url("'+e[0]+'")'}),i.trigger("image-widget.change",[e[0]])}),!1}),$(document).on("click","[data-image-widget] .delete",function(){var i=$(this).closest("[data-image-widget]"),e=ImageWidget.getOption(i);return i.find("[data-image]").val(""),i.find(".image").css({backgroundImage:"url("+e.emptyImage+")"}),i.trigger("image-widget.change",[null]),!1});var i=function(i){var e=$(i);this.init=function(){this.val(e.find("[data-image]").val())},this.val=function(i){if(void 0==i)return e.find("[data-image]").val();if(i)e.find("[data-image]").val(i),e.find(".image").css({backgroundImage:"url("+i+")"}),e.trigger("image-widget.change",[i]);else{var a=ImageWidget.getOption(e);e.find("[data-image]").val(""),e.find(".image").css({backgroundImage:"url("+a.emptyImage+")"}),e.trigger("image-widget.change",[null])}}};$.fn.extend({imageWidget:function(){if($(this).length>1)return alert("ImagesWidget only accept one dom"),null;var e=$(this).data("widget");return e||(e=new i(this),$(this).data("widget",e),e)}}),$(function(){$("[data-image-widget]").each(function(i,e){$(e).imageWidget().init()})})}}};module.exports=ImageWidget;