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