Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobius1-selectable

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobius1-selectable - npm Package Compare versions

Comparing version 0.8.5 to 0.8.6

2

bower.json
{
"name": "mobius1-selectable",
"version": "0.8.5",
"version": "0.8.6",
"ignore": [

@@ -5,0 +5,0 @@ ".gitattributes",

{
"name": "mobius1-selectable",
"version": "0.8.5",
"version": "0.8.6",
"description": "UI Selectable plugin without the bloat of jQuery and jQuery UI.",

@@ -13,3 +13,3 @@ "main": "selectable.min.js",

},
"keywords": [],
"keywords": ["selectable", "select", "drag"],
"author": "Karl Saunders",

@@ -16,0 +16,0 @@ "license": "MIT",

@@ -8,3 +8,6 @@ # Selectable

Works in most modern deskop and mobile browsers including IE9+ as well a touchscreen devices.
* No dependencies
* 3kb gzipped
* IE9+
* Touch enabled

@@ -11,0 +14,0 @@ **Selectable is still in active development and therefore the API is in constant flux until `v1.0.0`. Check back regularly for any changes and make sure you have the latest version installed.**

@@ -8,3 +8,3 @@ /*!

*
* Version: 0.8.5
* Version: 0.8.6
*

@@ -25,3 +25,3 @@ */

var _version = "0.8.5";
var _version = "0.8.6";

@@ -201,3 +201,3 @@ var _touch = (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);

*/
var debounce = function(n, t, u) {
var throttle = function(n, t, u) {
var e;

@@ -267,27 +267,3 @@ return function() {

/* EMITTER */
var Emitter = function() {};
Emitter.prototype = {
on: function(a, b) {
this._events = this._events || {}, this._events[a] = this._events[a] || [], this._events[a].push(b)
},
off: function(a, b) {
this._events = this._events || {}, a in this._events != !1 && this._events[a].splice(this._events[a].indexOf(b), 1)
},
emit: function(a) {
if (this._events = this._events || {}, a in this._events != !1) {
for (var b = 0; b < this._events[a].length; b++) {
this._events[a][b].apply(this, Array.prototype.slice.call(arguments, 1))
}
}
}
};
Emitter.mixin = function(a) {
var b = ["on", "off", "emit"],
c = b.length;
for (; c--;) "function" == typeof a ? a.prototype[b[c]] = Emitter.prototype[b[c]] : a[b[c]] = Emitter.prototype[b[c]];
return a
};
/* SELECTABLE */

@@ -308,5 +284,2 @@ function Selectable(options) {

/* Enable emitter */
Emitter.mixin(this);
/* lasso */

@@ -326,3 +299,3 @@ this.lasso = document.createElement('div');

keydown: this.keydown.bind(this),
recalculate: debounce(this.recalculate, 50).bind(this)
recalculate: throttle(this.recalculate, 50).bind(this)
}

@@ -957,2 +930,39 @@

/**
* Add custom event listener
* @param {String} event
* @param {Function} callback
* @return {Void}
*/
Selectable.prototype.on = function (event, callback) {
this.events = this.events || {};
this.events[event] = this.events[event] || [];
this.events[event].push(callback);
};
/**
* Remove custom event listener
* @param {String} event
* @param {Function} callback
* @return {Void}
*/
Selectable.prototype.off = function (event, callback) {
this.events = this.events || {};
if (event in this.events === false) return;
this.events[event].splice(this.events[event].indexOf(callback), 1);
};
/**
* Fire custom event
* @param {String} event
* @return {Void}
*/
Selectable.prototype.emit = function (event) {
this.events = this.events || {};
if (event in this.events === false) return;
for (var i = 0; i < this.events[event].length; i++) {
this.events[event][i].apply(this, Array.prototype.slice.call(arguments, 1));
}
};
/**
* Enable instance

@@ -959,0 +969,0 @@ * @return {Boolean}

@@ -8,5 +8,5 @@ /*!

*
* Version: 0.8.5
* Version: 0.8.6
*
*/
!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,i,s){e.addEventListener(t,i,!1)}function t(e,t,i){e.removeEventListener(t,i)}function i(e){this.version=s,this.config=h(c,e),this.init()}var s="0.8.5",n="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,o="classList"in document.documentElement,c={multiple:!0,autoRefresh:!0,appendTo:document.body,filter:".ui-selectable",tolerance:"touch",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 HTMLCollection||e instanceof NodeList},h=function(e,t){for(var i in t)if(t.hasOwnProperty(i)){var s=t[i];s&&r(s)?(e[i]=e[i]||{},h(e[i],s)):e[i]=s}return e},u=function(e,t,i){var s;if(r(e))for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(i,e[s],s);else for(s=0;s<e.length;s++)t.call(i,e[s],s)},d=function(e,t,i){var s=e&&e.style,n=r(t);if(s){if(void 0===i&&!n)return i=window.getComputedStyle(e,""),void 0===t?i:i[t];n?u(t,function(e,t){t in s||(t="-webkit-"+t),s[t]=e+("string"==typeof e?"":"opacity"===t?"":"px")}):(t in s||(t="-webkit-"+t),s[t]=i+("string"==typeof i?"":"opacity"===t?"":"px"))}},f=function(e){var t=window,i=e.getBoundingClientRect(),s=document.documentElement||document.body.parentNode||document.body,n=void 0!==t.pageXOffset?t.pageXOffset:s.scrollLeft,o=void 0!==t.pageYOffset?t.pageYOffset:s.scrollTop;return{x1:i.left+n,x2:i.left+i.width+n,y1:i.top+o,y2:i.top+i.height+o,height:i.height,width:i.width}},p=function(e,t,i){var s;return function(){var n=this,o=arguments,c=i&&!s;clearTimeout(s),s=setTimeout(function(){s=null,i||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"],i=t.length;i--;)"function"==typeof e?e.prototype[t[i]]=v.prototype[t[i]]:e[t[i]]=v.prototype[t[i]];return e},i.prototype.init=function(){var e=this,t=this.config;v.mixin(this),this.lasso=document.createElement("div"),this.lasso.className=t.classes.lasso,d(this.lasso,h({position:"fixed",opacity:0},t.lasso)),this.events={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)},this.setContainer(),this.update(),this.enable(),setTimeout(function(){e.emit("selectable.init")},10)},i.prototype.update=function(){var e=this;this.config.classes;this.setItems(),e.emit("selectable.update",e.items)},i.prototype.bind=function(){var t=this.events;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)},i.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)},i.prototype.start=function(e){if(e.preventDefault(),this.container.contains(e.target)){var t,i=this,s=this.config,o=l(e.target,function(e){return e===i.container||m.contains(e,s.classes.selectable)});if(!o||s.disabled)return!1;if(s.multiple){var c="touchstart"===e.type;if(this.dragging=!0,this.origin={x:c?e.touches[0].clientX:e.pageX,y:c?e.touches[0].clientY:e.pageY},this.container.appendChild(this.lasso),o!==this.container&&m.add(o,s.classes.selecting),s.autoRefresh&&this.update(),n){var r=this.get(o);if(r.selected)return this.dragging=!1,void this.unselect(r)}if(y(e)){var a=this.items,h=!1,d=this.items.length,f=function(e){return a[e].node===o&&(h=!0),!(!h||!a[e].selected)||(h&&(a[e].selecting=!0),!1)};if("normal"!==s.shiftDirection)for(var p=0;p<d&&!f(p);p++);else for(;d--&&!f(d););}}else this.select(o);u(this.items,function(i){var c=i.node;i.selected&&(i.startselected=!0,c!==o&&(s.multiple&&(n||g(e)||y(e))||(m.remove(c,s.classes.selected),i.selected=!1,m.add(c,s.classes.unselecting),i.unselecting=!0))),c===o&&(t=i)}),this.emit("selectable.start",t)}},i.prototype.drag=function(e){if(this.dragging&&!y(e)){var t=this.config;if(!t.disabled){var i,s=m,n=t.classes,o="touchstart"===e.type,c={x1:this.origin.x,y1:this.origin.y,x2:o?e.touches[0].clientX:e.pageX,y2:o?e.touches[0].clientY:e.pageY};c.x1>c.x2&&(i=c.x2,c.x2=c.x1,c.x1=i),c.y1>c.y2&&(i=c.y2,c.y2=c.y1,c.y1=i),d(this.lasso,{opacity:1,left:c.x1,width:c.x2-c.x1,top:c.y1,height:c.y2-c.y1}),u(this.items,function(i){var o=i.node,l=i.rect,r=!1;"touch"==t.tolerance?r=!(l.x1>c.x2||l.x2<c.x1||l.y1>c.y2||l.y2<c.y1):"fit"==t.tolerance&&(r=l.x1>c.x1&&l.x2<c.x2&&l.y1>c.y1&&l.y2<c.y2),r?(i.selected&&(s.remove(o,n.selected),i.selected=!1),i.unselecting&&(s.remove(o,n.unselecting),i.unselecting=!1),i.selecting||(s.add(o,n.selecting),i.selecting=!0)):(i.selecting&&(g(e)&&i.startselected?(s.remove(o,n.selecting),i.selecting=!1,s.add(o,n.selected),i.selected=!0):(s.remove(o,n.selecting),i.selecting=!1,i.startselected&&(s.add(o,n.unselecting),i.unselecting=!0))),o.selected&&(g(e)||i.startselected||(s.remove(o,n.selected),i.selected=!1,s.add(o,n.unselecting),i.unselecting=!0)))}),this.emit("selectable.drag",c)}}},i.prototype.end=function(e){if(this.dragging||!this.config.multiple){this.dragging=!1,d(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)}},i.prototype.keydown=function(e){g(e)&&(65!=e.keyCode&&97!=e.keyCode||(e.preventDefault(),this.selectAll()))},i.prototype.setContainer=function(e){var t,i=this.config;this.container&&(t=this.container),"string"==typeof(e=e||i.appendTo)?this.container=document.querySelector(e):e instanceof Element&&e.nodeName&&(this.container=e),m.add(this.container,this.config.classes.container),this.config.multiple&&m.add(this.container,this.config.classes.multiple),t&&(m.remove(t,this.config.classes.container),this.config.multiple&&m.remove(t,this.config.classes.multiple),this.unbind()),a(i.filter)?this.nodes=[].slice.call(i.filter):"string"==typeof i.filter&&(this.nodes=[].slice.call(this.container.querySelectorAll(i.filter))),this.bind()},i.prototype.setItems=function(){var e=this.config.classes;this.items=[],u(this.nodes,function(t,i){m.add(t,e.selectable),this.items[i]={node:t,rect:f(t),startselected:!1,selected:m.contains(t,e.selected),selecting:m.contains(t,e.selecting),unselecting:m.contains(t,e.unselecting)}},this)},i.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,i=this.config.classes;return m.remove(t,i.selecting),m.add(t,i.selected),e.selecting=!1,e.selected=!0,e.startselected=!0,this.emit("selectable.select",e),e}return!1},i.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,i=this.config.classes;return e.selecting=!1,e.selected=!1,e.unselecting=!1,e.startselected=!1,m.remove(t,i.unselecting),m.remove(t,i.selecting),m.remove(t,i.selected),this.emit("selectable.unselect",e),e}return!1},i.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()},i.prototype.remove=function(e,t){if(e=this.get(e)){if(a(e))for(var i=e.length-1;i>=0;i--)this.remove(e[i],i>0);else{var s=e.node,n=this.config.classes;m.remove(s,n.selectable),m.remove(s,n.unselecting),m.remove(s,n.selecting),m.remove(s,n.selected),this.nodes.splice(this.nodes.indexOf(e.node),1)}return t||this.update(),!0}return!1},i.prototype.recalculate=function(){u(this.nodes,function(e,t){this.items[t].rect=f(e)},this),this.emit("selectable.recalculate")},i.prototype.selectAll=function(){u(this.items,function(e){this.select(e)},this)},i.prototype.clear=function(){for(var e=this.items.length-1;e>=0;e--)this.unselect(this.items[e])},i.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},i.prototype.getItems=function(){return this.items},i.prototype.getNodes=function(){return this.nodes},i.prototype.getSelectedItems=function(){return this.getItems().filter(function(e){return e.selected})},i.prototype.getSelectedNodes=function(){return this.getSelectedItems().map(function(e){return e.node})},i.prototype.enable=function(){return this.enabled||(this.enabled=!0,this.bind(),m.add(this.container,this.config.classes.container),this.config.multiple&&m.add(this.container,this.config.classes.multiple),this.emit("selectable.enable")),this.enabled},i.prototype.disable=function(){return this.enabled&&(this.enabled=!1,this.unbind(),m.remove(this.container,this.config.classes.container),this.config.multiple&&m.remove(this.container,this.config.classes.multiple),this.emit("selectable.disable")),this.enabled},i.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)},i});
!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,i,s){e.addEventListener(t,i,!1)}function t(e,t,i){e.removeEventListener(t,i)}function i(e){this.version=s,this.config=h(c,e),this.init()}var s="0.8.6",n="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,o="classList"in document.documentElement,c={multiple:!0,autoRefresh:!0,appendTo:document.body,filter:".ui-selectable",tolerance:"touch",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 HTMLCollection||e instanceof NodeList},h=function(e,t){for(var i in t)if(t.hasOwnProperty(i)){var s=t[i];s&&r(s)?(e[i]=e[i]||{},h(e[i],s)):e[i]=s}return e},d=function(e,t,i){var s;if(r(e))for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(i,e[s],s);else for(s=0;s<e.length;s++)t.call(i,e[s],s)},u=function(e,t,i){var s=e&&e.style,n=r(t);if(s){if(void 0===i&&!n)return i=window.getComputedStyle(e,""),void 0===t?i:i[t];n?d(t,function(e,t){t in s||(t="-webkit-"+t),s[t]=e+("string"==typeof e?"":"opacity"===t?"":"px")}):(t in s||(t="-webkit-"+t),s[t]=i+("string"==typeof i?"":"opacity"===t?"":"px"))}},f=function(e){var t=window,i=e.getBoundingClientRect(),s=document.documentElement||document.body.parentNode||document.body,n=void 0!==t.pageXOffset?t.pageXOffset:s.scrollLeft,o=void 0!==t.pageYOffset?t.pageYOffset:s.scrollTop;return{x1:i.left+n,x2:i.left+i.width+n,y1:i.top+o,y2:i.top+i.height+o,height:i.height,width:i.width}},p=function(e,t,i){var s;return function(){var n=this,o=arguments,c=i&&!s;clearTimeout(s),s=setTimeout(function(){s=null,i||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};return i.prototype.init=function(){var e=this,t=this.config;this.lasso=document.createElement("div"),this.lasso.className=t.classes.lasso,u(this.lasso,h({position:"fixed",opacity:0},t.lasso)),this.events={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)},this.setContainer(),this.update(),this.enable(),setTimeout(function(){e.emit("selectable.init")},10)},i.prototype.update=function(){var e=this;this.config.classes;this.setItems(),e.emit("selectable.update",e.items)},i.prototype.bind=function(){var t=this.events;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)},i.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)},i.prototype.start=function(e){if(e.preventDefault(),this.container.contains(e.target)){var t,i=this,s=this.config,o=l(e.target,function(e){return e===i.container||g.contains(e,s.classes.selectable)});if(!o||s.disabled)return!1;if(s.multiple){var c="touchstart"===e.type;if(this.dragging=!0,this.origin={x:c?e.touches[0].clientX:e.pageX,y:c?e.touches[0].clientY:e.pageY},this.container.appendChild(this.lasso),o!==this.container&&g.add(o,s.classes.selecting),s.autoRefresh&&this.update(),n){var r=this.get(o);if(r.selected)return this.dragging=!1,void this.unselect(r)}if(y(e)){var a=this.items,h=!1,u=this.items.length,f=function(e){return a[e].node===o&&(h=!0),!(!h||!a[e].selected)||(h&&(a[e].selecting=!0),!1)};if("normal"!==s.shiftDirection)for(var p=0;p<u&&!f(p);p++);else for(;u--&&!f(u););}}else this.select(o);d(this.items,function(i){var c=i.node;i.selected&&(i.startselected=!0,c!==o&&(s.multiple&&(n||m(e)||y(e))||(g.remove(c,s.classes.selected),i.selected=!1,g.add(c,s.classes.unselecting),i.unselecting=!0))),c===o&&(t=i)}),this.emit("selectable.start",t)}},i.prototype.drag=function(e){if(this.dragging&&!y(e)){var t=this.config;if(!t.disabled){var i,s=g,n=t.classes,o="touchstart"===e.type,c={x1:this.origin.x,y1:this.origin.y,x2:o?e.touches[0].clientX:e.pageX,y2:o?e.touches[0].clientY:e.pageY};c.x1>c.x2&&(i=c.x2,c.x2=c.x1,c.x1=i),c.y1>c.y2&&(i=c.y2,c.y2=c.y1,c.y1=i),u(this.lasso,{opacity:1,left:c.x1,width:c.x2-c.x1,top:c.y1,height:c.y2-c.y1}),d(this.items,function(i){var o=i.node,l=i.rect,r=!1;"touch"==t.tolerance?r=!(l.x1>c.x2||l.x2<c.x1||l.y1>c.y2||l.y2<c.y1):"fit"==t.tolerance&&(r=l.x1>c.x1&&l.x2<c.x2&&l.y1>c.y1&&l.y2<c.y2),r?(i.selected&&(s.remove(o,n.selected),i.selected=!1),i.unselecting&&(s.remove(o,n.unselecting),i.unselecting=!1),i.selecting||(s.add(o,n.selecting),i.selecting=!0)):(i.selecting&&(m(e)&&i.startselected?(s.remove(o,n.selecting),i.selecting=!1,s.add(o,n.selected),i.selected=!0):(s.remove(o,n.selecting),i.selecting=!1,i.startselected&&(s.add(o,n.unselecting),i.unselecting=!0))),o.selected&&(m(e)||i.startselected||(s.remove(o,n.selected),i.selected=!1,s.add(o,n.unselecting),i.unselecting=!0)))}),this.emit("selectable.drag",c)}}},i.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=[];d(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)}},i.prototype.keydown=function(e){m(e)&&(65!=e.keyCode&&97!=e.keyCode||(e.preventDefault(),this.selectAll()))},i.prototype.setContainer=function(e){var t,i=this.config;this.container&&(t=this.container),"string"==typeof(e=e||i.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.remove(t,this.config.classes.multiple),this.unbind()),a(i.filter)?this.nodes=[].slice.call(i.filter):"string"==typeof i.filter&&(this.nodes=[].slice.call(this.container.querySelectorAll(i.filter))),this.bind()},i.prototype.setItems=function(){var e=this.config.classes;this.items=[],d(this.nodes,function(t,i){g.add(t,e.selectable),this.items[i]={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)},i.prototype.select=function(e){if(a(e))return d(e,function(e){this.select(e)},this),this.getSelectedItems();if(e=this.get(e)){var t=e.node,i=this.config.classes;return g.remove(t,i.selecting),g.add(t,i.selected),e.selecting=!1,e.selected=!0,e.startselected=!0,this.emit("selectable.select",e),e}return!1},i.prototype.unselect=function(e){if(a(e))return d(e,function(e){this.unselect(e)},this),this.getSelectedItems();if(e=this.get(e)){var t=e.node,i=this.config.classes;return e.selecting=!1,e.selected=!1,e.unselecting=!1,e.startselected=!1,g.remove(t,i.unselecting),g.remove(t,i.selecting),g.remove(t,i.selected),this.emit("selectable.unselect",e),e}return!1},i.prototype.add=function(e){this.config;a(e)?d(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()},i.prototype.remove=function(e,t){if(e=this.get(e)){if(a(e))for(var i=e.length-1;i>=0;i--)this.remove(e[i],i>0);else{var s=e.node,n=this.config.classes;g.remove(s,n.selectable),g.remove(s,n.unselecting),g.remove(s,n.selecting),g.remove(s,n.selected),this.nodes.splice(this.nodes.indexOf(e.node),1)}return t||this.update(),!0}return!1},i.prototype.recalculate=function(){d(this.nodes,function(e,t){this.items[t].rect=f(e)},this),this.emit("selectable.recalculate")},i.prototype.selectAll=function(){d(this.items,function(e){this.select(e)},this)},i.prototype.clear=function(){for(var e=this.items.length-1;e>=0;e--)this.unselect(this.items[e])},i.prototype.get=function(e){var t=!1;return a(e)?(t=[],d(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},i.prototype.getItems=function(){return this.items},i.prototype.getNodes=function(){return this.nodes},i.prototype.getSelectedItems=function(){return this.getItems().filter(function(e){return e.selected})},i.prototype.getSelectedNodes=function(){return this.getSelectedItems().map(function(e){return e.node})},i.prototype.on=function(e,t){this.events=this.events||{},this.events[e]=this.events[e]||[],this.events[e].push(t)},i.prototype.off=function(e,t){this.events=this.events||{},e in this.events!=!1&&this.events[e].splice(this.events[e].indexOf(t),1)},i.prototype.emit=function(e){if(this.events=this.events||{},e in this.events!=!1)for(var t=0;t<this.events[e].length;t++)this.events[e][t].apply(this,Array.prototype.slice.call(arguments,1))},i.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},i.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},i.prototype.destroy=function(){this.config.classes;this.disable(),this.remove(this.items),d(this,function(e,t){"version"!==t&&"config"!==t&&delete this[t]},this)},i});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc