(function(e){"function"===typeof define&&define.amd?define(["jquery","./core","./mouse","./widget"],e):e(jQuery)})(function(e){return e.widget("ui.selectable",e.ui.mouse,{version:"1.11.4",options:{appendTo:"body",autoRefresh:!0,distance:0,filter:"*",tolerance:"touch",selected:null,selecting:null,start:null,stop:null,unselected:null,unselecting:null},_create:function(){var a,f=this;this.element.addClass("ui-selectable");this.dragged=!1;this.refresh=function(){a=e(f.options.filter,f.element[0]);a.addClass("ui-selectee");
a.each(function(){var a=e(this),d=a.offset();e.data(this,"selectable-item",{element:this,$element:a,left:d.left,top:d.top,right:d.left+a.outerWidth(),bottom:d.top+a.outerHeight(),startselected:!1,selected:a.hasClass("ui-selected"),selecting:a.hasClass("ui-selecting"),unselecting:a.hasClass("ui-unselecting")})})};this.refresh();this.selectees=a.addClass("ui-selectee");this._mouseInit();this.helper=e("<div class='ui-selectable-helper'></div>")},_destroy:function(){this.selectees.removeClass("ui-selectee").removeData("selectable-item");
this.element.removeClass("ui-selectable ui-selectable-disabled");this._mouseDestroy()},_mouseStart:function(a){var f=this,c=this.options;this.opos=[a.pageX,a.pageY];this.options.disabled||(this.selectees=e(c.filter,this.element[0]),this._trigger("start",a),e(c.appendTo).append(this.helper),this.helper.css({left:a.pageX,top:a.pageY,width:0,height:0}),c.autoRefresh&&this.refresh(),this.selectees.filter(".ui-selected").each(function(){var d=e.data(this,"selectable-item");d.startselected=!0;a.metaKey||
a.ctrlKey||(d.$element.removeClass("ui-selected"),d.selected=!1,d.$element.addClass("ui-unselecting"),d.unselecting=!0,f._trigger("unselecting",a,{unselecting:d.element}))}),e(a.target).parents().addBack().each(function(){var d,c=e.data(this,"selectable-item");if(c)return d=!a.metaKey&&!a.ctrlKey||!c.$element.hasClass("ui-selected"),c.$element.removeClass(d?"ui-unselecting":"ui-selected").addClass(d?"ui-selecting":"ui-unselecting"),c.unselecting=!d,c.selecting=d,(c.selected=d)?f._trigger("selecting",
a,{selecting:c.element}):f._trigger("unselecting",a,{unselecting:c.element}),!1}))},_mouseDrag:function(a){this.dragged=!0;if(!this.options.disabled){var f,c=this,d=this.options,g=this.opos[0],h=this.opos[1],k=a.pageX,l=a.pageY;g>k&&(f=k,k=g,g=f);h>l&&(f=l,l=h,h=f);this.helper.css({left:g,top:h,width:k-g,height:l-h});this.selectees.each(function(){var b=e.data(this,"selectable-item"),f=!1;b&&b.element!==c.element[0]&&("touch"===d.tolerance?f=!(b.left>k||b.right<g||b.top>l||b.bottom<h):"fit"===d.tolerance&&
(f=b.left>g&&b.right<k&&b.top>h&&b.bottom<l),f?(b.selected&&(b.$element.removeClass("ui-selected"),b.selected=!1),b.unselecting&&(b.$element.removeClass("ui-unselecting"),b.unselecting=!1),b.selecting||(b.$element.addClass("ui-selecting"),b.selecting=!0,c._trigger("selecting",a,{selecting:b.element}))):(b.selecting&&((a.metaKey||a.ctrlKey)&&b.startselected?(b.$element.removeClass("ui-selecting"),b.selecting=!1,b.$element.addClass("ui-selected"),b.selected=!0):(b.$element.removeClass("ui-selecting"),
b.selecting=!1,b.startselected&&(b.$element.addClass("ui-unselecting"),b.unselecting=!0),c._trigger("unselecting",a,{unselecting:b.element}))),!b.selected||a.metaKey||a.ctrlKey||b.startselected||(b.$element.removeClass("ui-selected"),b.selected=!1,b.$element.addClass("ui-unselecting"),b.unselecting=!0,c._trigger("unselecting",a,{unselecting:b.element}))))});return!1}},_mouseStop:function(a){var f=this;this.dragged=!1;e(".ui-unselecting",this.element[0]).each(function(){var c=e.data(this,"selectable-item");
c.$element.removeClass("ui-unselecting");c.unselecting=!1;c.startselected=!1;f._trigger("unselected",a,{unselected:c.element})});e(".ui-selecting",this.element[0]).each(function(){var c=e.data(this,"selectable-item");c.$element.removeClass("ui-selecting").addClass("ui-selected");c.selecting=!1;c.selected=!0;c.startselected=!0;f._trigger("selected",a,{selected:c.element})});this._trigger("stop",a);this.helper.remove();return!1}})});