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.2.5 to 0.3.0

2

bower.json
{
"name": "mobius1-selectable",
"version": "0.2.5",
"version": "0.3.0",
"ignore": [

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

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

@@ -5,0 +5,0 @@ "main": "selectable.min.js",

@@ -102,2 +102,8 @@ # Selectable

### getItems()
Returns an `Array` of all items.
### getNodes()
Returns an `Array` of all `HTMLElement` nodes.
### getSelectedItems()

@@ -104,0 +110,0 @@ Returns an `Array` of selected items.

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

*
* Version: 0.2.5
* Version: 0.3.0
*

@@ -279,2 +279,3 @@ */

Selectable.prototype.init = function() {
var o = this.config;
/* lasso */

@@ -286,9 +287,9 @@ this.lasso = document.createElement('div');

position: "fixed",
opacity: 0, // border will show event at zero width / height
}, this.config.lasso));
opacity: 0, // border will show even at zero width / height
}, o.lasso));
if (typeof this.config.appendTo === 'string' || this.config.appendTo instanceof String) {
this.container = document.querySelector(this.config.appendTo);
} else if (this.config.appendTo.nodeName) {
this.container = this.config.appendTo;
if (typeof o.appendTo === 'string' || o.appendTo instanceof String) {
this.container = document.querySelector(o.appendTo);
} else if (o.appendTo.nodeName) {
this.container = o.appendTo;
}

@@ -308,2 +309,3 @@

o = this.config;
this.nodes = this.container.querySelectorAll(o.filter);

@@ -313,3 +315,3 @@ this.items = [];

each(this.nodes, function(el, i) {
classList.add(el, that.config.classes.selectable);
classList.add(el, o.classes.selectable);
that.items[i] = {

@@ -334,7 +336,7 @@ index: i,

e.preventDefault();
var o = this.config,
originalEl;
var node = closest(e.target, function(el) {
return classList.contains(el, o.filter.replace('.', ''));
return classList.contains(el, o.filter.replace(".", ""));
});

@@ -622,2 +624,20 @@

/**
* Get all items
* @return {Array}
*/
Selectable.prototype.getItems = function() {
return this.items;
};
/**
* Get all nodes
* @return {Array}
*/
Selectable.prototype.getNodes = function() {
return this.items.map(function(item) {
return item.element;
});
};
/**
* Get all selected items

@@ -627,3 +647,3 @@ * @return {Array}

Selectable.prototype.getSelectedItems = function() {
return this.items.filter(function(item) {
return this.getItems().filter(function(item) {
return item.selected;

@@ -652,3 +672,3 @@ });

// Bind events
this.events = {
var e = {
mousedown: this.mousedown.bind(this),

@@ -661,9 +681,11 @@ mousemove: this.mousemove.bind(this),

// Attach event listeners
on(this.container, 'mousedown', this.events.mousedown);
on(document, 'mousemove', this.events.mousemove);
on(document, 'mouseup', this.events.mouseup);
on(this.container, 'mousedown', e.mousedown);
on(document, 'mousemove', e.mousemove);
on(document, 'mouseup', e.mouseup);
on(window, 'resize', this.events.recalculate);
on(window, 'scroll', this.events.recalculate);
on(window, 'resize', e.recalculate);
on(window, 'scroll', e.recalculate);
this.events = e;
classList.add(this.container, this.config.classes.container);

@@ -681,10 +703,11 @@ }

if (this.enabled) {
var e = this.events;
this.enabled = false;
off(this.container, 'mousedown', this.events.mousedown);
off(document, 'mousemove', this.events.mousemove);
off(document, 'mouseup', this.events.mouseup);
off(this.container, 'mousedown', e.mousedown);
off(document, 'mousemove', e.mousemove);
off(document, 'mouseup', e.mouseup);
off(window, 'resize', this.events.recalculate);
off(window, 'scroll', this.events.recalculate);
off(window, 'resize', e.recalculate);
off(window, 'scroll', e.recalculate);

@@ -691,0 +714,0 @@ classList.remove(this.container, this.config.classes.container);

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

*
* Version: 0.2.5
* Version: 0.3.0
*
*/
!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.config=c(i,e),m.mixin(this),this.init()}var i={appendTo:document.body,autoRefresh:!0,filter:".ui-selectable",tolerance:"touch",lasso:{border:"1px dotted #3498db",backgroundColor:"rgba(52, 152, 219, 0.2)"},classes:{container:"ui-container",selectable:"ui-selectable",selecting:"ui-selecting",unselecting:"ui-unselecting",selected:"ui-selected"}},n=function(e,t){return e&&e!==document.body&&(t(e)?e:n(e.parentNode,t))},o=function(e){return"[object Object]"===Object.prototype.toString.call(e)},c=function(e,t){for(var s in t)if(t.hasOwnProperty(s)){var i=t[s];i&&o(i)?(e[s]=e[s]||{},c(e[s],i)):e[s]=i}return e},l=function(e,t,s){var i;if(o(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)},a=function(e,t,s){var i=e&&e.style,n=o(t);if(i){if(void 0===s&&!n)return s=window.getComputedStyle(e,""),void 0===t?s:s[t];n?l(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"))}},r=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}},u=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)}},d={add:function(e,t){e.classList?e.classList.add(t):d.contains(e,t)||(e.className=e.className.trim()+" "+t)},remove:function(e,t){e.classList?e.classList.remove(t):d.contains(e,t)&&(e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},contains:function(e,t){if(e)return e.classList?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},h=function(e){return!!e.ctrlKey||!!e.metaKey},f=function(e){return!!e.shiftKey},m=function(){};return m.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))}},m.mixin=function(e){for(var t=["on","off","emit"],s=t.length;s--;)"function"==typeof e?e.prototype[t[s]]=m.prototype[t[s]]:e[t[s]]=m.prototype[t[s]];return e},s.prototype.init=function(){this.lasso=document.createElement("div"),this.lasso.className="ui-lasso",a(this.lasso,c({position:"fixed",opacity:0},this.config.lasso)),"string"==typeof this.config.appendTo||this.config.appendTo instanceof String?this.container=document.querySelector(this.config.appendTo):this.config.appendTo.nodeName&&(this.container=this.config.appendTo),this.update(),this.enable()},s.prototype.update=function(){var e=this,t=this.config;this.nodes=this.container.querySelectorAll(t.filter),this.items=[],l(this.nodes,function(s,i){d.add(s,e.config.classes.selectable),e.items[i]={index:i,element:s,rect:r(s),startselected:!1,selected:d.contains(s,t.classes.selected),selecting:d.contains(s,t.classes.selecting),unselecting:d.contains(s,t.classes.unselecting)}})},s.prototype.mousedown=function(e){e.preventDefault();var t,s=this.config,i=n(e.target,function(e){return d.contains(e,s.filter.replace(".",""))});if(this.container.appendChild(this.lasso),this.origin={x:e.pageX,y:e.pageY},!s.disabled){if(i&&d.add(i,s.classes.selecting),s.autoRefresh&&this.update(),f(e))for(var o=!1,c=this.items.length-1;c>=0&&(this.items[c].element===i&&(o=!0),!o||!this.items[c].selected);c--)o&&(this.items[c].selecting=!0);l(this.items,function(n){var o=n.element;n.selected&&o!==i&&(n.startselected=!0,h(e)||f(e)||(d.remove(o,s.classes.selected),n.selected=!1,d.add(o,s.classes.unselecting),n.unselecting=!0)),o===i&&(t=n)}),this.dragging=!0,i&&this.emit("selectable.down",t)}},s.prototype.mousemove=function(e){if(this.dragging){var t=this.config;if(!t.disabled){var s,i={x1:this.origin.x,y1:this.origin.y,x2:e.pageX,y2: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),a(this.lasso,{opacity:1,left:i.x1,width:i.x2-i.x1,top:i.y1,height:i.y2-i.y1}),l(this.items,function(s){var n=s.element,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&&(d.remove(n,t.classes.selected),s.selected=!1),s.unselecting&&(d.remove(n,t.classes.unselecting),s.unselecting=!1),s.selecting||(d.add(n,t.classes.selecting),s.selecting=!0)):(s.selecting&&(h(e)&&s.startselected?(d.remove(n,t.classes.selecting),s.selecting=!1,d.add(n,t.classes.selected),s.selected=!0):(d.remove(n,t.classes.selecting),s.selecting=!1,s.startselected&&(d.add(n,t.classes.unselecting),s.unselecting=!0))),n.selected&&(h(e)||s.startselected||(d.remove(n,t.classes.selected),s.selected=!1,d.add(n,t.classes.unselecting),s.unselecting=!0)))}),this.emit("selectable.drag",i)}}},s.prototype.mouseup=function(e){if(this.dragging&&(this.dragging=!1),this.container.contains(e.target)){var t=this;a(this.lasso,{opacity:0,left:0,width:0,top:0,height:0}),l(this.items,function(e){e.element;e.unselecting&&t.deselectItem(e),e.selecting&&t.selectItem(e)}),this.container.removeChild(this.lasso),this.emit("selectable.up",this.getSelectedItems())}},s.prototype.selectItem=function(e){if(this.items.indexOf(e)>=0){var t=e.element,s=this.config.classes;return d.remove(t,s.selecting),d.add(t,s.selected),e.selecting=!1,e.selected=!0,e.startselected=!0,this.emit("selectable.selected",e)}return!1},s.prototype.deselectItem=function(e){if(this.items.indexOf(e)>=0){var t=e.element,s=this.config.classes;return e.selecting=!1,e.selected=!1,e.unselecting=!1,e.startselected=!1,d.remove(t,s.unselecting),d.remove(t,s.selecting),d.remove(t,s.selected),this.emit("selectable.deselected",e)}return!1},s.prototype.recalculate=function(){l(this.nodes,function(e,t){this.items[t].rect=r(e)},this)},s.prototype.selectAll=function(){l(this.items,function(e){this.selectItem(e)},this)},s.prototype.clear=function(){for(var e=this.items.length-1;e>=0;e--)this.deselectItem(this.items[e])},s.prototype.getSelectedItems=function(){return this.items.filter(function(e){return e.selected})},s.prototype.getSelectedNodes=function(){return this.getSelectedItems().map(function(e){return e.element})},s.prototype.enable=function(){return this.enabled||(this.enabled=!0,this.events={mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this),recalculate:u(this.recalculate,50).bind(this)},e(this.container,"mousedown",this.events.mousedown),e(document,"mousemove",this.events.mousemove),e(document,"mouseup",this.events.mouseup),e(window,"resize",this.events.recalculate),e(window,"scroll",this.events.recalculate),d.add(this.container,this.config.classes.container)),this.enabled},s.prototype.disable=function(){return this.enabled&&(this.enabled=!1,t(this.container,"mousedown",this.events.mousedown),t(document,"mousemove",this.events.mousemove),t(document,"mouseup",this.events.mouseup),t(window,"resize",this.events.recalculate),t(window,"scroll",this.events.recalculate),d.remove(this.container,this.config.classes.container)),this.enabled},s.prototype.destroy=function(){var e=this.config.classes;l(this.items,function(t){var s=t.element;d.remove(s,e.unselecting),d.remove(s,e.selecting),d.remove(s,e.selected)}),this.disable()},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.config=c(i,e),m.mixin(this),this.init()}var i={appendTo:document.body,autoRefresh:!0,filter:".ui-selectable",tolerance:"touch",lasso:{border:"1px dotted #3498db",backgroundColor:"rgba(52, 152, 219, 0.2)"},classes:{container:"ui-container",selectable:"ui-selectable",selecting:"ui-selecting",unselecting:"ui-unselecting",selected:"ui-selected"}},n=function(e,t){return e&&e!==document.body&&(t(e)?e:n(e.parentNode,t))},o=function(e){return"[object Object]"===Object.prototype.toString.call(e)},c=function(e,t){for(var s in t)if(t.hasOwnProperty(s)){var i=t[s];i&&o(i)?(e[s]=e[s]||{},c(e[s],i)):e[s]=i}return e},l=function(e,t,s){var i;if(o(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)},r=function(e,t,s){var i=e&&e.style,n=o(t);if(i){if(void 0===s&&!n)return s=window.getComputedStyle(e,""),void 0===t?s:s[t];n?l(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"))}},a=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}},u=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)}},d={add:function(e,t){e.classList?e.classList.add(t):d.contains(e,t)||(e.className=e.className.trim()+" "+t)},remove:function(e,t){e.classList?e.classList.remove(t):d.contains(e,t)&&(e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},contains:function(e,t){if(e)return e.classList?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},h=function(e){return!!e.ctrlKey||!!e.metaKey},f=function(e){return!!e.shiftKey},m=function(){};return m.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))}},m.mixin=function(e){for(var t=["on","off","emit"],s=t.length;s--;)"function"==typeof e?e.prototype[t[s]]=m.prototype[t[s]]:e[t[s]]=m.prototype[t[s]];return e},s.prototype.init=function(){var e=this.config;this.lasso=document.createElement("div"),this.lasso.className="ui-lasso",r(this.lasso,c({position:"fixed",opacity:0},e.lasso)),"string"==typeof e.appendTo||e.appendTo instanceof String?this.container=document.querySelector(e.appendTo):e.appendTo.nodeName&&(this.container=e.appendTo),this.update(),this.enable()},s.prototype.update=function(){var e=this,t=this.config;this.nodes=this.container.querySelectorAll(t.filter),this.items=[],l(this.nodes,function(s,i){d.add(s,t.classes.selectable),e.items[i]={index:i,element:s,rect:a(s),startselected:!1,selected:d.contains(s,t.classes.selected),selecting:d.contains(s,t.classes.selecting),unselecting:d.contains(s,t.classes.unselecting)}})},s.prototype.mousedown=function(e){e.preventDefault();var t,s=this.config,i=n(e.target,function(e){return d.contains(e,s.filter.replace(".",""))});if(this.container.appendChild(this.lasso),this.origin={x:e.pageX,y:e.pageY},!s.disabled){if(i&&d.add(i,s.classes.selecting),s.autoRefresh&&this.update(),f(e))for(var o=!1,c=this.items.length-1;c>=0&&(this.items[c].element===i&&(o=!0),!o||!this.items[c].selected);c--)o&&(this.items[c].selecting=!0);l(this.items,function(n){var o=n.element;n.selected&&o!==i&&(n.startselected=!0,h(e)||f(e)||(d.remove(o,s.classes.selected),n.selected=!1,d.add(o,s.classes.unselecting),n.unselecting=!0)),o===i&&(t=n)}),this.dragging=!0,i&&this.emit("selectable.down",t)}},s.prototype.mousemove=function(e){if(this.dragging){var t=this.config;if(!t.disabled){var s,i={x1:this.origin.x,y1:this.origin.y,x2:e.pageX,y2: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),r(this.lasso,{opacity:1,left:i.x1,width:i.x2-i.x1,top:i.y1,height:i.y2-i.y1}),l(this.items,function(s){var n=s.element,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&&(d.remove(n,t.classes.selected),s.selected=!1),s.unselecting&&(d.remove(n,t.classes.unselecting),s.unselecting=!1),s.selecting||(d.add(n,t.classes.selecting),s.selecting=!0)):(s.selecting&&(h(e)&&s.startselected?(d.remove(n,t.classes.selecting),s.selecting=!1,d.add(n,t.classes.selected),s.selected=!0):(d.remove(n,t.classes.selecting),s.selecting=!1,s.startselected&&(d.add(n,t.classes.unselecting),s.unselecting=!0))),n.selected&&(h(e)||s.startselected||(d.remove(n,t.classes.selected),s.selected=!1,d.add(n,t.classes.unselecting),s.unselecting=!0)))}),this.emit("selectable.drag",i)}}},s.prototype.mouseup=function(e){if(this.dragging&&(this.dragging=!1),this.container.contains(e.target)){var t=this;r(this.lasso,{opacity:0,left:0,width:0,top:0,height:0}),l(this.items,function(e){e.element;e.unselecting&&t.deselectItem(e),e.selecting&&t.selectItem(e)}),this.container.removeChild(this.lasso),this.emit("selectable.up",this.getSelectedItems())}},s.prototype.selectItem=function(e){if(this.items.indexOf(e)>=0){var t=e.element,s=this.config.classes;return d.remove(t,s.selecting),d.add(t,s.selected),e.selecting=!1,e.selected=!0,e.startselected=!0,this.emit("selectable.selected",e)}return!1},s.prototype.deselectItem=function(e){if(this.items.indexOf(e)>=0){var t=e.element,s=this.config.classes;return e.selecting=!1,e.selected=!1,e.unselecting=!1,e.startselected=!1,d.remove(t,s.unselecting),d.remove(t,s.selecting),d.remove(t,s.selected),this.emit("selectable.deselected",e)}return!1},s.prototype.recalculate=function(){l(this.nodes,function(e,t){this.items[t].rect=a(e)},this)},s.prototype.selectAll=function(){l(this.items,function(e){this.selectItem(e)},this)},s.prototype.clear=function(){for(var e=this.items.length-1;e>=0;e--)this.deselectItem(this.items[e])},s.prototype.getItems=function(){return this.items},s.prototype.getNodes=function(){return this.items.map(function(e){return e.element})},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.element})},s.prototype.enable=function(){if(!this.enabled){this.enabled=!0;var t={mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this),recalculate:u(this.recalculate,50).bind(this)};e(this.container,"mousedown",t.mousedown),e(document,"mousemove",t.mousemove),e(document,"mouseup",t.mouseup),e(window,"resize",t.recalculate),e(window,"scroll",t.recalculate),this.events=t,d.add(this.container,this.config.classes.container)}return this.enabled},s.prototype.disable=function(){if(this.enabled){var e=this.events;this.enabled=!1,t(this.container,"mousedown",e.mousedown),t(document,"mousemove",e.mousemove),t(document,"mouseup",e.mouseup),t(window,"resize",e.recalculate),t(window,"scroll",e.recalculate),d.remove(this.container,this.config.classes.container)}return this.enabled},s.prototype.destroy=function(){var e=this.config.classes;l(this.items,function(t){var s=t.element;d.remove(s,e.unselecting),d.remove(s,e.selecting),d.remove(s,e.selected)}),this.disable()},s});
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