var init=!1,ImageTemplateWidget={getOption:function($container){var initValue;try{try{initValue=JSON.parse($container.attr("data-image-template-widget"))}catch(e){eval("initValue = "+$container.attr("data-image-template-widget"))}}catch(e){initValue={}}return $.extend({},initValue)},init:function(){if(!init&&(init=!0,"callback"in window&&"imageTemplateWidgetSelectImage"in window.callback)){$(document).on("click","[data-image-template-widget] .item",function(){var e,a=$(this).closest("[data-image-template-widget]"),t=$(this);return $(this).is(".custom")?window.callback.imageTemplateWidgetSelectImage(function(i){e=i[0],a.find(".list .item").removeClass("active"),t.addClass("active"),t.find(".image").css({backgroundImage:'url("'+e+'")'}),t.attr("data-value",e),a.find("[data-image]").val(e),a.trigger("image-template-widget.change",[e])}):(a.find(".list .item").removeClass("active"),t.addClass("active"),e=t.attr("data-value"),a.find("[data-image]").val(e),a.trigger("image-template-widget.change",[e])),!1});var e=function(e){var a=$(e);this.val=function(e){if(void 0==e)return a.find("[data-image]").val();if(e){a.find("[data-image]").val(e),a.find(".item").removeClass("active");var t=!1;a.find(".item").each(function(a,i){if(!$(i).is(".custom")){$(i).attr("data-value")==e&&($(i).addClass("active"),t=!0)}}),t||a.find(".item.custom .image").css({backgroundImage:"url("+e+")"}),a.trigger("image-template-widget.change",[e])}else a.find("[data-image]").val(""),a.find(".item").removeClass("active"),a.trigger("image-template-widget.change",[null])}};$.fn.extend({imageTemplateWidget:function(){return new e(this)}})}}};module.exports=ImageTemplateWidget;