var Widget=function(e){var c=$(e),t=this;this.value=null,this._sync=function(){var e=[];c.find("input[type=checkbox]").each(function(c,t){$(t).is(":checked")?(e.push($(t).val()),$(this).parent().addClass("select")):$(this).parent().removeClass("select")}),t.value=e},this.val=function(e){if(void 0===e)return t.value;c.find("input[type=checkbox]:checked").each(function(c,t){var i=$(t).val();e.indexOf(i)>=0?$(t).prop("checked",!0):$(t).prop("checked",!1)}),t._sync(),c.trigger("checkbox-widget.change",[t.value])},c.on("click","label",function(){var e=$(this).find("input[type=checkbox]");return e.prop("checked",!e.is(":checked")),t._sync(),!1}),this._sync()},CheckboxWidget={init:function(){$("[data-checkbox-widget]").each(function(e,c){var t=$(c).data("widget");t||(t=new Widget(c),$(c).data("widget",t))})}};module.exports=CheckboxWidget;