-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.selection.min.js
executable file
·1 lines (1 loc) · 1.77 KB
/
jquery.selection.min.js
1
(function(e){function i(){}function s(t){var r=e(t).closest(".selection"),i=r.find(n.filter);return i.index(t)}function o(r,i,s,o){var u=i<s?i:s,a=s>i?s:i;t=[];r.each(function(){var r=n.value(this),i=n.group(this),s=r>=u&&r<=a&&(!o||o===i),f=e(this);if(!f.hasClass("selection-selected")&&s){n.select(this)}if(f.hasClass("selection-selected")&&!s){n.unselect(this)}f.toggleClass("selection-selected",s).toggleClass("selection-first",r===u).toggleClass("selection-last",r===a);if(s)t.push(this)})}var t=[],n,r;r={selectedValues:function(){var r=[];e(t).each(function(){r.push(n.value(this))});return r},isSelecting:function(){return this.data("selection-selecting")===true},clear:function(){return this.each(function(){var t=e(this),r=t.find(n.filter);o(r)})},init:function(u){n=e.extend({filter:"*",start:i,stop:i,select:i,unselect:i,value:s,group:i},u);return this.each(function(){var i=e(this),s=i.find(n.filter),u,a;i.addClass("selection");s.addClass("selection-selectable");i.on("mouseenter",n.filter,function(){if(i.data("selection-selecting")===true){o(s,u,n.value(this),a)}e(this).addClass("selection-over")});i.on("mouseleave",n.filter,function(){e(this).removeClass("selection-over")});i.on("mousedown",n.filter,function(t){if(t.which!==1){return}n.start(this);i.data("selection-selecting",true);u=n.value(this);a=n.group(this);o(s,u,u,a);e(this).addClass("selection-over")});e(document).on("mouseup",function(){if(i.data("selection-selecting")===true){try{n.stop(this,{elements:t,values:r.selectedValues()})}finally{i.data("selection-selecting",false)}}})})}};e.fn.selection=function(t){if(r[t]){return r[t].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof t==="object"||!t){return r.init.apply(this,arguments)}else{e.error("Method "+t+" does not exist on jQuery.selection")}}})(jQuery)