mobius1-selectable
Advanced tools
Comparing version 0.8.2 to 0.8.3
{ | ||
"name": "mobius1-selectable", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"ignore": [ | ||
@@ -5,0 +5,0 @@ ".gitattributes", |
{ | ||
"name": "mobius1-selectable", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "UI Selectable plugin without the bloat of jQuery and jQuery UI.", | ||
@@ -5,0 +5,0 @@ "main": "selectable.min.js", |
@@ -8,3 +8,3 @@ /*! | ||
* | ||
* Version: 0.8.2 | ||
* Version: 0.8.3 | ||
* | ||
@@ -25,3 +25,3 @@ */ | ||
var _version = "0.8.2"; | ||
var _version = "0.8.3"; | ||
@@ -316,14 +316,4 @@ var _touch = (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch); | ||
if (typeof o.appendTo === 'string') { | ||
this.container = document.querySelector(o.appendTo); | ||
} else if (o.appendTo instanceof Element && o.appendTo.nodeName) { | ||
this.container = o.appendTo; | ||
} | ||
this.setContainer(); | ||
if (isCollection(o.filter)) { | ||
this.nodes = [].slice.call(o.filter); | ||
} else if (typeof o.filter === "string") { | ||
this.nodes = [].slice.call(this.container.querySelectorAll(o.filter)); | ||
} | ||
this.update(); | ||
@@ -364,2 +354,47 @@ | ||
Selectable.prototype.bind = function() { | ||
var e = { | ||
start: this.start.bind(this), | ||
drag: this.drag.bind(this), | ||
end: this.end.bind(this), | ||
keydown: this.keydown.bind(this), | ||
recalculate: debounce(this.recalculate, 50).bind(this) | ||
}; | ||
// Attach event listeners | ||
on(this.container, 'mousedown', e.start); | ||
on(document, 'mousemove', e.drag); | ||
on(document, 'mouseup', e.end); | ||
on(document, 'keydown', e.keydown); | ||
// Mobile | ||
on(this.container, "touchstart", e.start); | ||
on(document, "touchend", e.end); | ||
on(document, "touchcancel", e.end); | ||
on(document, "touchmove", e.drag); | ||
on(window, 'resize', e.recalculate); | ||
on(window, 'scroll', e.recalculate); | ||
this.events = e; | ||
}; | ||
Selectable.prototype.unbind = function() { | ||
var e = this.events; | ||
off(this.container, 'mousedown', e.start); | ||
off(document, 'mousemove', e.drag); | ||
off(document, 'mouseup', e.end); | ||
off(document, 'keydown', e.keydown); | ||
// Mobile | ||
off(this.container, "touchstart", e.start); | ||
off(document, "touchend", e.end); | ||
off(document, "touchcancel", e.end); | ||
off(document, "touchmove", e.drag); | ||
off(window, 'resize', e.recalculate); | ||
off(window, 'scroll', e.recalculate); | ||
}; | ||
/** | ||
@@ -636,2 +671,63 @@ * mousedown / touchstart event listener | ||
Selectable.prototype.setContainer = function(container) { | ||
var o = this.config, | ||
old; | ||
if (this.container) { | ||
old = this.container; | ||
} | ||
container = container || o.appendTo; | ||
if (typeof container === 'string') { | ||
this.container = document.querySelector(container); | ||
} else if (container instanceof Element && container.nodeName) { | ||
this.container = container; | ||
} | ||
classList.add(this.container, this.config.classes.container); | ||
if ( this.config.multiple ) { | ||
classList.add(this.container, this.config.classes.multiple); | ||
} | ||
if (old) { | ||
classList.remove(old, this.config.classes.container); | ||
if ( this.config.multiple ) { | ||
classList.add(old, this.config.classes.multiple); | ||
} | ||
this.unbind(); | ||
} | ||
if (isCollection(o.filter)) { | ||
this.nodes = [].slice.call(o.filter); | ||
} else if (typeof o.filter === "string") { | ||
this.nodes = [].slice.call(this.container.querySelectorAll(o.filter)); | ||
} | ||
this.bind(); | ||
}; | ||
Selectable.prototype.setItems = function() { | ||
var o = this.config.classes; | ||
this.items = []; | ||
each(this.nodes, function(el, i) { | ||
classList.add(el, o.selectable); | ||
this.items[i] = { | ||
node: el, | ||
rect: rect(el), | ||
startselected: false, | ||
selected: classList.contains(el, o.selected), | ||
selecting: classList.contains(el, o.selecting), | ||
unselecting: classList.contains(el, o.unselecting) | ||
}; | ||
}, this); | ||
}; | ||
/** | ||
@@ -876,28 +972,4 @@ * Select an item | ||
// Bind events | ||
var e = { | ||
start: this.start.bind(this), | ||
drag: this.drag.bind(this), | ||
end: this.end.bind(this), | ||
keydown: this.keydown.bind(this), | ||
recalculate: debounce(this.recalculate, 50).bind(this) | ||
}; | ||
this.bind(); | ||
// Attach event listeners | ||
on(this.container, 'mousedown', e.start); | ||
on(document, 'mousemove', e.drag); | ||
on(document, 'mouseup', e.end); | ||
on(document, 'keydown', e.keydown); | ||
// Mobile | ||
on(this.container, "touchstart", e.start); | ||
on(document, "touchend", e.end); | ||
on(document, "touchcancel", e.end); | ||
on(document, "touchmove", e.drag); | ||
on(window, 'resize', e.recalculate); | ||
on(window, 'scroll', e.recalculate); | ||
this.events = e; | ||
classList.add(this.container, this.config.classes.container); | ||
@@ -921,22 +993,12 @@ | ||
if (this.enabled) { | ||
var e = this.events; | ||
this.enabled = false; | ||
off(this.container, 'mousedown', e.start); | ||
off(document, 'mousemove', e.drag); | ||
off(document, 'mouseup', e.end); | ||
off(document, 'keydown', e.keydown); | ||
this.unbind(); | ||
// Mobile | ||
off(this.container, "touchstart", e.start); | ||
off(document, "touchend", e.end); | ||
off(document, "touchcancel", e.end); | ||
off(document, "touchmove", e.drag); | ||
classList.remove(this.container, this.config.classes.container); | ||
off(window, 'resize', e.recalculate); | ||
off(window, 'scroll', e.recalculate); | ||
if ( this.config.multiple ) { | ||
classList.remove(this.container, this.config.classes.multiple); | ||
} | ||
classList.remove(this.container, this.config.classes.multiple); | ||
classList.remove(this.container, this.config.classes.container); | ||
this.emit('selectable.disable'); | ||
@@ -943,0 +1005,0 @@ } |
@@ -8,5 +8,5 @@ /*! | ||
* | ||
* Version: 0.8.2 | ||
* Version: 0.8.3 | ||
* | ||
*/ | ||
!function(e,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define([],t):e.Selectable=t()}("undefined"!=typeof global?global:this.window||this.global,function(){"use strict";function e(e,t,s,i){e.addEventListener(t,s,!1)}function t(e,t,s){e.removeEventListener(t,s)}function s(e){this.version=i,this.config=d(c,e),this.init()}var i="0.8.2",n="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,o="classList"in document.documentElement,c={appendTo:document.body,autoRefresh:!0,filter:".ui-selectable",tolerance:"touch",multiple:!0,shiftDirection:"normal",lasso:{border:"1px dotted #3498db",backgroundColor:"rgba(52, 152, 219, 0.2)"},classes:{lasso:"ui-lasso",multiple:"ui-multiple",selected:"ui-selected",container:"ui-container",selecting:"ui-selecting",selectable:"ui-selectable",unselecting:"ui-unselecting"}},l=function(e,t){return e&&(t(e)?e:l(e.parentNode,t))},r=function(e){return"[object Object]"===Object.prototype.toString.call(e)},a=function(e){return Array.isArray(e)||e instanceof NodeList||e instanceof HTMLCollection},d=function(e,t){for(var s in t)if(t.hasOwnProperty(s)){var i=t[s];i&&r(i)?(e[s]=e[s]||{},d(e[s],i)):e[s]=i}return e},u=function(e,t,s){var i;if(r(e))for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.call(s,e[i],i);else for(i=0;i<e.length;i++)t.call(s,e[i],i)},h=function(e,t,s){var i=e&&e.style,n=r(t);if(i){if(void 0===s&&!n)return s=window.getComputedStyle(e,""),void 0===t?s:s[t];n?u(t,function(e,t){t in i||(t="-webkit-"+t),i[t]=e+("string"==typeof e?"":"opacity"===t?"":"px")}):(t in i||(t="-webkit-"+t),i[t]=s+("string"==typeof s?"":"opacity"===t?"":"px"))}},f=function(e){var t=window,s=e.getBoundingClientRect(),i=document.documentElement||document.body.parentNode||document.body,n=void 0!==t.pageXOffset?t.pageXOffset:i.scrollLeft,o=void 0!==t.pageYOffset?t.pageYOffset:i.scrollTop;return{x1:s.left+n,x2:s.left+s.width+n,y1:s.top+o,y2:s.top+s.height+o,height:s.height,width:s.width}},p=function(e,t,s){var i;return function(){var n=this,o=arguments,c=s&&!i;clearTimeout(i),i=setTimeout(function(){i=null,s||e.apply(n,o)},t),c&&e.apply(n,o)}},m={add:function(e,t){o?e.classList.add(t):m.contains(e,t)||(e.className=e.className.trim()+" "+t)},remove:function(e,t){o?e.classList.remove(t):m.contains(e,t)&&(e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},contains:function(e,t){if(e)return o?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},g=function(e){return!!e.ctrlKey||!!e.metaKey},y=function(e){return!!e.shiftKey},v=function(){};return v.prototype={on:function(e,t){this._events=this._events||{},this._events[e]=this._events[e]||[],this._events[e].push(t)},off:function(e,t){this._events=this._events||{},e in this._events!=0&&this._events[e].splice(this._events[e].indexOf(t),1)},emit:function(e){if(this._events=this._events||{},e in this._events!=0)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}},v.mixin=function(e){for(var t=["on","off","emit"],s=t.length;s--;)"function"==typeof e?e.prototype[t[s]]=v.prototype[t[s]]:e[t[s]]=v.prototype[t[s]];return e},s.prototype.init=function(){var e=this,t=this.config;v.mixin(this),this.lasso=document.createElement("div"),this.lasso.className=t.classes.lasso,h(this.lasso,d({position:"fixed",opacity:0},t.lasso)),"string"==typeof t.appendTo?this.container=document.querySelector(t.appendTo):t.appendTo instanceof Element&&t.appendTo.nodeName&&(this.container=t.appendTo),a(t.filter)?this.nodes=[].slice.call(t.filter):"string"==typeof t.filter&&(this.nodes=[].slice.call(this.container.querySelectorAll(t.filter))),this.update(),this.enable(),setTimeout(function(){e.emit("selectable.init")},10)},s.prototype.update=function(){var e=this,t=this.config;this.items=[],u(this.nodes,function(s,i){m.add(s,t.classes.selectable),e.items[i]={node:s,rect:f(s),startselected:!1,selected:m.contains(s,t.classes.selected),selecting:m.contains(s,t.classes.selecting),unselecting:m.contains(s,t.classes.unselecting)}}),e.emit("selectable.update",e.items)},s.prototype.start=function(e){if(e.preventDefault(),this.container.contains(e.target)){var t,s=this,i=this.config,o=l(e.target,function(e){return e===s.container||m.contains(e,i.classes.selectable)});if(!o||i.disabled)return!1;if(i.multiple){if(this.dragging=!0,this.origin={x:n&&"touchstart"===e.type?e.touches[0].clientX:e.pageX,y:n&&"touchstart"===e.type?e.touches[0].clientY:e.pageY},this.container.appendChild(this.lasso),o!==this.container&&m.add(o,i.classes.selecting),i.autoRefresh&&this.update(),n){var c=this.get(o);if(c.selected)return this.dragging=!1,void this.unselect(c)}if(y(e)){var r=this.items,a=!1,d=this.items.length,h=function(e){return r[e].node===o&&(a=!0),!(!a||!r[e].selected)||(a&&(r[e].selecting=!0),!1)};if("normal"!==i.shiftDirection)for(var f=0;f<d&&!h(f);f++);else for(;d--&&!h(d););}}else this.select(o);u(this.items,function(s){var c=s.node;s.selected&&(s.startselected=!0,c!==o&&(i.multiple&&(n||g(e)||y(e))||(m.remove(c,i.classes.selected),s.selected=!1,m.add(c,i.classes.unselecting),s.unselecting=!0))),c===o&&(t=s)}),this.emit("selectable.start",t)}},s.prototype.drag=function(e){if(this.dragging&&!y(e)){var t=this.config;if(!t.disabled){var s,i={x1:this.origin.x,y1:this.origin.y,x2:n&&"touchmove"===e.type?e.touches[0].clientX:e.pageX,y2:n&&"touchmove"===e.type?e.touches[0].clientY:e.pageY};i.x1>i.x2&&(s=i.x2,i.x2=i.x1,i.x1=s),i.y1>i.y2&&(s=i.y2,i.y2=i.y1,i.y1=s),h(this.lasso,{opacity:1,left:i.x1,width:i.x2-i.x1,top:i.y1,height:i.y2-i.y1}),u(this.items,function(s){var n=s.node,o=!1;"touch"==t.tolerance?o=!(s.rect.x1>i.x2||s.rect.x2<i.x1||s.rect.y1>i.y2||s.rect.y2<i.y1):"fit"==t.tolerance&&(o=s.rect.x1>i.x1&&s.rect.x2<i.x2&&s.rect.y1>i.y1&&s.rect.y2<i.y2),o?(s.selected&&(m.remove(n,t.classes.selected),s.selected=!1),s.unselecting&&(m.remove(n,t.classes.unselecting),s.unselecting=!1),s.selecting||(m.add(n,t.classes.selecting),s.selecting=!0)):(s.selecting&&(g(e)&&s.startselected?(m.remove(n,t.classes.selecting),s.selecting=!1,m.add(n,t.classes.selected),s.selected=!0):(m.remove(n,t.classes.selecting),s.selecting=!1,s.startselected&&(m.add(n,t.classes.unselecting),s.unselecting=!0))),n.selected&&(g(e)||s.startselected||(m.remove(n,t.classes.selected),s.selected=!1,m.add(n,t.classes.unselecting),s.unselecting=!0)))}),this.emit("selectable.drag",i)}}},s.prototype.end=function(e){if(this.dragging||!this.config.multiple){this.dragging=!1,h(this.lasso,{opacity:0,left:0,width:0,top:0,height:0});var t=[];u(this.items,function(e){e.node;e.unselecting&&this.unselect(e),e.selecting&&(t.push(e),this.select(e))},this),this.container.contains(this.lasso)&&this.container.removeChild(this.lasso),this.emit("selectable.end",t)}},s.prototype.keydown=function(e){g(e)&&(65!=e.keyCode&&97!=e.keyCode||(e.preventDefault(),this.selectAll()))},s.prototype.select=function(e){if(a(e))return u(e,function(e){this.select(e)},this),this.getSelectedItems();if(e=this.get(e)){var t=e.node,s=this.config.classes;return m.remove(t,s.selecting),m.add(t,s.selected),e.selecting=!1,e.selected=!0,e.startselected=!0,this.emit("selectable.select",e),e}return!1},s.prototype.unselect=function(e){if(a(e))return u(e,function(e){this.unselect(e)},this),this.getSelectedItems();if(e=this.get(e)){var t=e.node,s=this.config.classes;return e.selecting=!1,e.selected=!1,e.unselecting=!1,e.startselected=!1,m.remove(t,s.unselecting),m.remove(t,s.selecting),m.remove(t,s.selected),this.emit("selectable.unselect",e),e}return!1},s.prototype.add=function(e){this.config;a(e)?u(e,function(e){this.nodes.indexOf(e)<0&&e instanceof Element&&this.nodes.push(e)},this):this.nodes.indexOf(e)<0&&e instanceof Element&&this.nodes.push(e),this.update()},s.prototype.remove=function(e,t){if(e=this.get(e)){if(a(e))for(var s=e.length-1;s>=0;s--)this.remove(e[s],s>0);else{var i=e.node,n=this.config.classes;m.remove(i,n.selectable),m.remove(i,n.unselecting),m.remove(i,n.selecting),m.remove(i,n.selected),this.nodes.splice(this.nodes.indexOf(e.node),1)}return t||this.update(),!0}return!1},s.prototype.recalculate=function(){u(this.nodes,function(e,t){this.items[t].rect=f(e)},this),this.emit("selectable.recalculate")},s.prototype.selectAll=function(){u(this.items,function(e){this.select(e)},this)},s.prototype.clear=function(){for(var e=this.items.length-1;e>=0;e--)this.unselect(this.items[e])},s.prototype.get=function(e){var t=!1;return a(e)?(t=[],u(e,function(e){(e=this.get(e))&&t.push(e)},this)):isNaN(e)?e instanceof Element?t=this.items[this.nodes.indexOf(e)]:r(e)&&this.items.indexOf(e)>=0&&(t=e):this.items.indexOf(this.items[e])>=0&&(t=this.items[e]),t},s.prototype.getItems=function(){return this.items},s.prototype.getNodes=function(){return this.nodes},s.prototype.getSelectedItems=function(){return this.getItems().filter(function(e){return e.selected})},s.prototype.getSelectedNodes=function(){return this.getSelectedItems().map(function(e){return e.node})},s.prototype.enable=function(){if(!this.enabled){this.enabled=!0;var t={start:this.start.bind(this),drag:this.drag.bind(this),end:this.end.bind(this),keydown:this.keydown.bind(this),recalculate:p(this.recalculate,50).bind(this)};e(this.container,"mousedown",t.start),e(document,"mousemove",t.drag),e(document,"mouseup",t.end),e(document,"keydown",t.keydown),e(this.container,"touchstart",t.start),e(document,"touchend",t.end),e(document,"touchcancel",t.end),e(document,"touchmove",t.drag),e(window,"resize",t.recalculate),e(window,"scroll",t.recalculate),this.events=t,m.add(this.container,this.config.classes.container),this.config.multiple&&m.add(this.container,this.config.classes.multiple),this.emit("selectable.enable")}return this.enabled},s.prototype.disable=function(){if(this.enabled){var e=this.events;this.enabled=!1,t(this.container,"mousedown",e.start),t(document,"mousemove",e.drag),t(document,"mouseup",e.end),t(document,"keydown",e.keydown),t(this.container,"touchstart",e.start),t(document,"touchend",e.end),t(document,"touchcancel",e.end),t(document,"touchmove",e.drag),t(window,"resize",e.recalculate),t(window,"scroll",e.recalculate),m.remove(this.container,this.config.classes.multiple),m.remove(this.container,this.config.classes.container),this.emit("selectable.disable")}return this.enabled},s.prototype.destroy=function(){this.config.classes;this.disable(),this.remove(this.items),u(this,function(e,t){"version"!==t&&"config"!==t&&delete this[t]},this)},s}); | ||
!function(e,t){"object"==typeof exports?module.exports=t():"function"==typeof define&&define.amd?define([],t):e.Selectable=t()}("undefined"!=typeof global?global:this.window||this.global,function(){"use strict";function e(e,t,s,i){e.addEventListener(t,s,!1)}function t(e,t,s){e.removeEventListener(t,s)}function s(e){this.version=i,this.config=d(c,e),this.init()}var i="0.8.3",n="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,o="classList"in document.documentElement,c={appendTo:document.body,autoRefresh:!0,filter:".ui-selectable",tolerance:"touch",multiple:!0,shiftDirection:"normal",lasso:{border:"1px dotted #3498db",backgroundColor:"rgba(52, 152, 219, 0.2)"},classes:{lasso:"ui-lasso",multiple:"ui-multiple",selected:"ui-selected",container:"ui-container",selecting:"ui-selecting",selectable:"ui-selectable",unselecting:"ui-unselecting"}},l=function(e,t){return e&&(t(e)?e:l(e.parentNode,t))},r=function(e){return"[object Object]"===Object.prototype.toString.call(e)},a=function(e){return Array.isArray(e)||e instanceof NodeList||e instanceof HTMLCollection},d=function(e,t){for(var s in t)if(t.hasOwnProperty(s)){var i=t[s];i&&r(i)?(e[s]=e[s]||{},d(e[s],i)):e[s]=i}return e},h=function(e,t,s){var i;if(r(e))for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.call(s,e[i],i);else for(i=0;i<e.length;i++)t.call(s,e[i],i)},u=function(e,t,s){var i=e&&e.style,n=r(t);if(i){if(void 0===s&&!n)return s=window.getComputedStyle(e,""),void 0===t?s:s[t];n?h(t,function(e,t){t in i||(t="-webkit-"+t),i[t]=e+("string"==typeof e?"":"opacity"===t?"":"px")}):(t in i||(t="-webkit-"+t),i[t]=s+("string"==typeof s?"":"opacity"===t?"":"px"))}},f=function(e){var t=window,s=e.getBoundingClientRect(),i=document.documentElement||document.body.parentNode||document.body,n=void 0!==t.pageXOffset?t.pageXOffset:i.scrollLeft,o=void 0!==t.pageYOffset?t.pageYOffset:i.scrollTop;return{x1:s.left+n,x2:s.left+s.width+n,y1:s.top+o,y2:s.top+s.height+o,height:s.height,width:s.width}},p=function(e,t,s){var i;return function(){var n=this,o=arguments,c=s&&!i;clearTimeout(i),i=setTimeout(function(){i=null,s||e.apply(n,o)},t),c&&e.apply(n,o)}},g={add:function(e,t){o?e.classList.add(t):g.contains(e,t)||(e.className=e.className.trim()+" "+t)},remove:function(e,t){o?e.classList.remove(t):g.contains(e,t)&&(e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},contains:function(e,t){if(e)return o?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},m=function(e){return!!e.ctrlKey||!!e.metaKey},y=function(e){return!!e.shiftKey},v=function(){};return v.prototype={on:function(e,t){this._events=this._events||{},this._events[e]=this._events[e]||[],this._events[e].push(t)},off:function(e,t){this._events=this._events||{},e in this._events!=0&&this._events[e].splice(this._events[e].indexOf(t),1)},emit:function(e){if(this._events=this._events||{},e in this._events!=0)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}},v.mixin=function(e){for(var t=["on","off","emit"],s=t.length;s--;)"function"==typeof e?e.prototype[t[s]]=v.prototype[t[s]]:e[t[s]]=v.prototype[t[s]];return e},s.prototype.init=function(){var e=this,t=this.config;v.mixin(this),this.lasso=document.createElement("div"),this.lasso.className=t.classes.lasso,u(this.lasso,d({position:"fixed",opacity:0},t.lasso)),this.setContainer(),this.update(),this.enable(),setTimeout(function(){e.emit("selectable.init")},10)},s.prototype.update=function(){var e=this,t=this.config;this.items=[],h(this.nodes,function(s,i){g.add(s,t.classes.selectable),e.items[i]={node:s,rect:f(s),startselected:!1,selected:g.contains(s,t.classes.selected),selecting:g.contains(s,t.classes.selecting),unselecting:g.contains(s,t.classes.unselecting)}}),e.emit("selectable.update",e.items)},s.prototype.bind=function(){var t={start:this.start.bind(this),drag:this.drag.bind(this),end:this.end.bind(this),keydown:this.keydown.bind(this),recalculate:p(this.recalculate,50).bind(this)};e(this.container,"mousedown",t.start),e(document,"mousemove",t.drag),e(document,"mouseup",t.end),e(document,"keydown",t.keydown),e(this.container,"touchstart",t.start),e(document,"touchend",t.end),e(document,"touchcancel",t.end),e(document,"touchmove",t.drag),e(window,"resize",t.recalculate),e(window,"scroll",t.recalculate),this.events=t},s.prototype.unbind=function(){var e=this.events;t(this.container,"mousedown",e.start),t(document,"mousemove",e.drag),t(document,"mouseup",e.end),t(document,"keydown",e.keydown),t(this.container,"touchstart",e.start),t(document,"touchend",e.end),t(document,"touchcancel",e.end),t(document,"touchmove",e.drag),t(window,"resize",e.recalculate),t(window,"scroll",e.recalculate)},s.prototype.start=function(e){if(e.preventDefault(),this.container.contains(e.target)){var t,s=this,i=this.config,o=l(e.target,function(e){return e===s.container||g.contains(e,i.classes.selectable)});if(!o||i.disabled)return!1;if(i.multiple){if(this.dragging=!0,this.origin={x:n&&"touchstart"===e.type?e.touches[0].clientX:e.pageX,y:n&&"touchstart"===e.type?e.touches[0].clientY:e.pageY},this.container.appendChild(this.lasso),o!==this.container&&g.add(o,i.classes.selecting),i.autoRefresh&&this.update(),n){var c=this.get(o);if(c.selected)return this.dragging=!1,void this.unselect(c)}if(y(e)){var r=this.items,a=!1,d=this.items.length,u=function(e){return r[e].node===o&&(a=!0),!(!a||!r[e].selected)||(a&&(r[e].selecting=!0),!1)};if("normal"!==i.shiftDirection)for(var f=0;f<d&&!u(f);f++);else for(;d--&&!u(d););}}else this.select(o);h(this.items,function(s){var c=s.node;s.selected&&(s.startselected=!0,c!==o&&(i.multiple&&(n||m(e)||y(e))||(g.remove(c,i.classes.selected),s.selected=!1,g.add(c,i.classes.unselecting),s.unselecting=!0))),c===o&&(t=s)}),this.emit("selectable.start",t)}},s.prototype.drag=function(e){if(this.dragging&&!y(e)){var t=this.config;if(!t.disabled){var s,i={x1:this.origin.x,y1:this.origin.y,x2:n&&"touchmove"===e.type?e.touches[0].clientX:e.pageX,y2:n&&"touchmove"===e.type?e.touches[0].clientY:e.pageY};i.x1>i.x2&&(s=i.x2,i.x2=i.x1,i.x1=s),i.y1>i.y2&&(s=i.y2,i.y2=i.y1,i.y1=s),u(this.lasso,{opacity:1,left:i.x1,width:i.x2-i.x1,top:i.y1,height:i.y2-i.y1}),h(this.items,function(s){var n=s.node,o=!1;"touch"==t.tolerance?o=!(s.rect.x1>i.x2||s.rect.x2<i.x1||s.rect.y1>i.y2||s.rect.y2<i.y1):"fit"==t.tolerance&&(o=s.rect.x1>i.x1&&s.rect.x2<i.x2&&s.rect.y1>i.y1&&s.rect.y2<i.y2),o?(s.selected&&(g.remove(n,t.classes.selected),s.selected=!1),s.unselecting&&(g.remove(n,t.classes.unselecting),s.unselecting=!1),s.selecting||(g.add(n,t.classes.selecting),s.selecting=!0)):(s.selecting&&(m(e)&&s.startselected?(g.remove(n,t.classes.selecting),s.selecting=!1,g.add(n,t.classes.selected),s.selected=!0):(g.remove(n,t.classes.selecting),s.selecting=!1,s.startselected&&(g.add(n,t.classes.unselecting),s.unselecting=!0))),n.selected&&(m(e)||s.startselected||(g.remove(n,t.classes.selected),s.selected=!1,g.add(n,t.classes.unselecting),s.unselecting=!0)))}),this.emit("selectable.drag",i)}}},s.prototype.end=function(e){if(this.dragging||!this.config.multiple){this.dragging=!1,u(this.lasso,{opacity:0,left:0,width:0,top:0,height:0});var t=[];h(this.items,function(e){e.node;e.unselecting&&this.unselect(e),e.selecting&&(t.push(e),this.select(e))},this),this.container.contains(this.lasso)&&this.container.removeChild(this.lasso),this.emit("selectable.end",t)}},s.prototype.keydown=function(e){m(e)&&(65!=e.keyCode&&97!=e.keyCode||(e.preventDefault(),this.selectAll()))},s.prototype.setContainer=function(e){var t,s=this.config;this.container&&(t=this.container),"string"==typeof(e=e||s.appendTo)?this.container=document.querySelector(e):e instanceof Element&&e.nodeName&&(this.container=e),g.add(this.container,this.config.classes.container),this.config.multiple&&g.add(this.container,this.config.classes.multiple),t&&(g.remove(t,this.config.classes.container),this.config.multiple&&g.add(t,this.config.classes.multiple),this.unbind()),a(s.filter)?this.nodes=[].slice.call(s.filter):"string"==typeof s.filter&&(this.nodes=[].slice.call(this.container.querySelectorAll(s.filter))),this.bind()},s.prototype.setItems=function(){var e=this.config.classes;this.items=[],h(this.nodes,function(t,s){g.add(t,e.selectable),this.items[s]={node:t,rect:f(t),startselected:!1,selected:g.contains(t,e.selected),selecting:g.contains(t,e.selecting),unselecting:g.contains(t,e.unselecting)}},this)},s.prototype.select=function(e){if(a(e))return h(e,function(e){this.select(e)},this),this.getSelectedItems();if(e=this.get(e)){var t=e.node,s=this.config.classes;return g.remove(t,s.selecting),g.add(t,s.selected),e.selecting=!1,e.selected=!0,e.startselected=!0,this.emit("selectable.select",e),e}return!1},s.prototype.unselect=function(e){if(a(e))return h(e,function(e){this.unselect(e)},this),this.getSelectedItems();if(e=this.get(e)){var t=e.node,s=this.config.classes;return e.selecting=!1,e.selected=!1,e.unselecting=!1,e.startselected=!1,g.remove(t,s.unselecting),g.remove(t,s.selecting),g.remove(t,s.selected),this.emit("selectable.unselect",e),e}return!1},s.prototype.add=function(e){this.config;a(e)?h(e,function(e){this.nodes.indexOf(e)<0&&e instanceof Element&&this.nodes.push(e)},this):this.nodes.indexOf(e)<0&&e instanceof Element&&this.nodes.push(e),this.update()},s.prototype.remove=function(e,t){if(e=this.get(e)){if(a(e))for(var s=e.length-1;s>=0;s--)this.remove(e[s],s>0);else{var i=e.node,n=this.config.classes;g.remove(i,n.selectable),g.remove(i,n.unselecting),g.remove(i,n.selecting),g.remove(i,n.selected),this.nodes.splice(this.nodes.indexOf(e.node),1)}return t||this.update(),!0}return!1},s.prototype.recalculate=function(){h(this.nodes,function(e,t){this.items[t].rect=f(e)},this),this.emit("selectable.recalculate")},s.prototype.selectAll=function(){h(this.items,function(e){this.select(e)},this)},s.prototype.clear=function(){for(var e=this.items.length-1;e>=0;e--)this.unselect(this.items[e])},s.prototype.get=function(e){var t=!1;return a(e)?(t=[],h(e,function(e){(e=this.get(e))&&t.push(e)},this)):isNaN(e)?e instanceof Element?t=this.items[this.nodes.indexOf(e)]:r(e)&&this.items.indexOf(e)>=0&&(t=e):this.items.indexOf(this.items[e])>=0&&(t=this.items[e]),t},s.prototype.getItems=function(){return this.items},s.prototype.getNodes=function(){return this.nodes},s.prototype.getSelectedItems=function(){return this.getItems().filter(function(e){return e.selected})},s.prototype.getSelectedNodes=function(){return this.getSelectedItems().map(function(e){return e.node})},s.prototype.enable=function(){return this.enabled||(this.enabled=!0,this.bind(),g.add(this.container,this.config.classes.container),this.config.multiple&&g.add(this.container,this.config.classes.multiple),this.emit("selectable.enable")),this.enabled},s.prototype.disable=function(){return this.enabled&&(this.enabled=!1,this.unbind(),g.remove(this.container,this.config.classes.container),this.config.multiple&&g.remove(this.container,this.config.classes.multiple),this.emit("selectable.disable")),this.enabled},s.prototype.destroy=function(){this.config.classes;this.disable(),this.remove(this.items),h(this,function(e,t){"version"!==t&&"config"!==t&&delete this[t]},this)},s}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46420
880