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