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(i){initValue={}}return $.extend({emptyImage:"/assets/lib/img/none.png"},initValue)},init:function(){if(!init&&(init=!0,"callback"in window&&"imageWidgetSelectImage"in window.callback)){$(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(){return new i(this)}}),$(function(){$("[data-image-widget]").imageWidget().init()})}}};module.exports=ImageWidget;