mobius1-selectable
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"name": "mobius1-selectable", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"ignore": [ | ||
@@ -5,0 +5,0 @@ ".gitattributes", |
{ | ||
"name": "mobius1-selectable", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "UI Selectable plugin without the bloat of jQuery and jQuery UI.", | ||
@@ -5,0 +5,0 @@ "main": "selectable.min.js", |
# Selectable [![npm version](https://badge.fury.io/js/mobius1-selectable.svg)](https://badge.fury.io/js/mobius1-selectable) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/Mobius1/Selectable/blob/master/LICENSE) | ||
This is a conversion of the jQuery UI Selectable plugin with all dependencies removed. Functionality and options are identical to the jQuery UI version with some additions. | ||
Selectable mimics the Windows file / directory behaviour, i.e. click and / or drag to select items, hold CTRL to select multiple or hold SHIFT to select consecutive groups of items. | ||
[Demo](http://codepen.io/Mobius1/full/qRxaqQ/) | ||
@@ -35,3 +37,3 @@ | ||
filter: ".some-class", | ||
/** | ||
@@ -49,3 +51,3 @@ * The container element to append the lasso to | ||
tolerance: "touch", | ||
/** | ||
@@ -56,11 +58,11 @@ * Recalculate coords of the items. Disable if you have a shit-ton of items. | ||
autoRefresh: true, | ||
/** | ||
* Style the lasso. | ||
* @type {object} | ||
*/ | ||
*/ | ||
lasso: { | ||
border: '1px solid #3498db', | ||
backgroundColor: 'rgba(52, 152, 219, 0.2)', | ||
} | ||
} | ||
}); | ||
@@ -90,3 +92,3 @@ ``` | ||
* @return {object} | ||
*/ | ||
*/ | ||
selectable.on('selectable.down', function(item) { | ||
@@ -97,5 +99,5 @@ // Do something when selectable.down fires | ||
/** | ||
* @param coords - lasso coords (x1, x2, y1, y2) | ||
* @param coords - lasso coords (x1, x2, y1, y2) | ||
* @return {object} | ||
*/ | ||
*/ | ||
selectable.on('selectable.drag', function(coords) { | ||
@@ -108,3 +110,3 @@ // Do something when selectable.drag fires | ||
* @return {array} | ||
*/ | ||
*/ | ||
selectable.on('selectable.up', function(selectedItems) { | ||
@@ -117,3 +119,3 @@ // Do something when selectable.up fires | ||
* @return {object} | ||
*/ | ||
*/ | ||
selectable.on('selectable.selected', function(item) { | ||
@@ -124,3 +126,3 @@ // Do something when selectable.selected fires | ||
Note that items returned by these events are objects of the following format: | ||
Note that items returned by these events are objects of the following format: | ||
@@ -127,0 +129,0 @@ ```javascript |
@@ -8,3 +8,3 @@ /*! | ||
* | ||
* Version: 0.0.5 | ||
* Version: 0.0.6 | ||
* | ||
@@ -327,3 +327,3 @@ */ | ||
item.startselected = true; | ||
if (!isCmdKey(e)) { | ||
if (!isCmdKey(e) && !isShiftKey(e)) { | ||
el.classList.remove("ui-selected"); | ||
@@ -330,0 +330,0 @@ |
@@ -8,5 +8,5 @@ /*! | ||
* | ||
* Version: 0.0.5 | ||
* Version: 0.0.6 | ||
* | ||
*/ | ||
!function(e,t){var s="Selectable";"object"==typeof exports?module.exports=t(s):"function"==typeof define&&define.amd?define([],t(s)):e[s]=t(s)}("undefined"!=typeof global?global:this.window||this.global,function(e){"use strict";function t(e,t,s,i){e.addEventListener(t,s,!1)}function s(e,t,s){e.removeEventListener(t,s)}function i(e){this.options=c(n,e),p.mixin(this),this.init()}var n={appendTo:"body",autoRefresh:!0,filter:"*",tolerance:"touch",lasso:{border:"1px solid #3498db",backgroundColor:"rgba(52, 152, 219, 0.2)"}},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,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)}},u=function(e){return e=e||window.event,e.preventDefault?e.preventDefault():e.returnValue=!1},d=function(e){return!!e.ctrlKey||!!e.metaKey},h=function(e){return!!e.shiftKey},p=function(){};return p.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))}},p.mixin=function(e){for(var t=["on","off","emit"],s=t.length;s--;)"function"==typeof e?e.prototype[t[s]]=p.prototype[t[s]]:e[t[s]]=p.prototype[t[s]];return e},i.prototype.init=function(){var e=document.createElement("div");e.className="ui-lasso",e.style.position="fixed",l(this.options.lasso,function(t,s){e.style[s]=t}),this.lasso=e,"string"==typeof this.options.appendTo||this.options.appendTo instanceof String?this.container=document.querySelector(this.options.appendTo):this.options.appendTo.nodeName?this.container=this.options.appendTo:this.container=document.body,this.refresh(),this.events={mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this),update:a(this.update,50).bind(this)},t(this.container,"mousedown",this.events.mousedown),t(document,"mousemove",this.events.mousemove),t(document,"mouseup",this.events.mouseup),t(window,"resize",this.events.update),t(window,"scroll",this.events.update)},i.prototype.refresh=function(){var e=this;this.nodes=this.container.querySelectorAll(this.options.selector),this.items=[],l(this.nodes,function(t,s){e.items[s]={index:s,element:t,rect:t.getBoundingClientRect(),startselected:!1,selected:t.classList.contains("ui-selected"),selecting:t.classList.contains("ui-selecting"),unselecting:t.classList.contains("ui-unselecting")},t.ondragstart=function(e){u(e)}})},i.prototype.mousedown=function(e){u(e);var t,s=this.options,i=e.target,n=i.classList.contains(s.selector.replace(".",""));if(this.container.appendChild(this.lasso),this.origin={x:e.pageX,y:e.pageY},!s.disabled){if(n&&i.classList.add("ui-selecting"),s.autoRefresh&&this.refresh(),h(e)){for(var o=!1,c=0;c<this.items.length;c++)if(this.items[c].element===e.target){o=this.items[c];break}for(var r=!1,c=o.index;c>=0&&(this.items[c].selected&&(r=!0),!r||this.items[c].selected);c--)this.items[c].selecting=!0}l(this.items,function(s){var n=s.element;s.selected&&(s.startselected=!0,d(e)||(n.classList.remove("ui-selected"),s.selected=!1,n.classList.add("ui-unselecting"),s.unselecting=!0)),n===i&&(t=s)}),this.dragging=!0,n&&this.emit("selectable.down",t)}},i.prototype.mousemove=function(e){if(this.dragging){var t=this.options;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,{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.left>i.x2||s.rect.right<i.x1||s.rect.top>i.y2||s.rect.bottom<i.y1):"fit"==t.tolerance&&(o=s.rect.left>i.x1&&s.rect.right<i.x2&&s.rect.top>i.y1&&s.rect.bottom<i.y2),o?(s.selected&&(n.classList.remove("ui-selected"),s.selected=!1),s.unselecting&&(n.classList.remove("ui-unselecting"),s.unselecting=!1),s.selecting||(n.classList.add("ui-selecting"),s.selecting=!0)):(s.selecting&&(d(e)&&s.startselected?(n.classList.remove("ui-selecting"),s.selecting=!1,n.classList.add("ui-selected"),s.selected=!0):(n.classList.remove("ui-selecting"),s.selecting=!1,s.startselected&&(n.classList.add("ui-unselecting"),s.unselecting=!0))),n.selected&&(d(e)||s.startselected||(n.classList.remove("ui-selected"),s.selected=!1,n.classList.add("ui-unselecting"),s.unselecting=!0)))}),this.emit("selectable.drag",i)}}},i.prototype.mouseup=function(e){if(this.dragging&&(this.dragging=!1),this.container.contains(e.target)){var t=this;this.selectedItems=[],r(this.lasso,{left:0,width:0,top:0,height:0}),l(this.items,function(e){var s=e.element;e.unselecting&&(s.classList.remove("ui-unselecting"),e.unselecting=!1,e.startselected=!1),e.selecting&&t.selectItem(e),e.selected&&(t.selectedItems.push(e),t.emit("selectable.selected",e))}),this.container.removeChild(this.lasso),this.emit("selectable.up",this.selectedItems)}},i.prototype.selectItem=function(e){e.element.classList.remove("ui-selecting"),e.element.classList.add("ui-selected"),e.selecting=!1,e.selected=e.startselected=!0},i.prototype.update=function(){l(this.nodes,function(e,t){this.items[t].rect=e.getBoundingClientRect()},this)},i.prototype.destroy=function(){l(this.items,function(e){var t=e.element;t.classList.remove("ui-unselecting"),t.classList.remove("ui-selecting"),t.classList.remove("ui-selected")}),s(this.container,"mousedown",this.events.mousedown),s(document,"mousemove",this.events.mousemove),s(document,"mouseup",this.events.mouseup),s(window,"resize",this.events.update),s(window,"scroll",this.events.update)},i}); | ||
!function(e,t){var s="Selectable";"object"==typeof exports?module.exports=t(s):"function"==typeof define&&define.amd?define([],t(s)):e[s]=t(s)}("undefined"!=typeof global?global:this.window||this.global,function(e){"use strict";function t(e,t,s,i){e.addEventListener(t,s,!1)}function s(e,t,s){e.removeEventListener(t,s)}function i(e){this.options=c(n,e),p.mixin(this),this.init()}var n={appendTo:"body",autoRefresh:!0,filter:"*",tolerance:"touch",lasso:{border:"1px solid #3498db",backgroundColor:"rgba(52, 152, 219, 0.2)"}},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,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)}},u=function(e){return e=e||window.event,e.preventDefault?e.preventDefault():e.returnValue=!1},d=function(e){return!!e.ctrlKey||!!e.metaKey},h=function(e){return!!e.shiftKey},p=function(){};return p.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))}},p.mixin=function(e){for(var t=["on","off","emit"],s=t.length;s--;)"function"==typeof e?e.prototype[t[s]]=p.prototype[t[s]]:e[t[s]]=p.prototype[t[s]];return e},i.prototype.init=function(){var e=document.createElement("div");e.className="ui-lasso",e.style.position="fixed",l(this.options.lasso,function(t,s){e.style[s]=t}),this.lasso=e,"string"==typeof this.options.appendTo||this.options.appendTo instanceof String?this.container=document.querySelector(this.options.appendTo):this.options.appendTo.nodeName?this.container=this.options.appendTo:this.container=document.body,this.refresh(),this.events={mousedown:this.mousedown.bind(this),mousemove:this.mousemove.bind(this),mouseup:this.mouseup.bind(this),update:a(this.update,50).bind(this)},t(this.container,"mousedown",this.events.mousedown),t(document,"mousemove",this.events.mousemove),t(document,"mouseup",this.events.mouseup),t(window,"resize",this.events.update),t(window,"scroll",this.events.update)},i.prototype.refresh=function(){var e=this;this.nodes=this.container.querySelectorAll(this.options.selector),this.items=[],l(this.nodes,function(t,s){e.items[s]={index:s,element:t,rect:t.getBoundingClientRect(),startselected:!1,selected:t.classList.contains("ui-selected"),selecting:t.classList.contains("ui-selecting"),unselecting:t.classList.contains("ui-unselecting")},t.ondragstart=function(e){u(e)}})},i.prototype.mousedown=function(e){u(e);var t,s=this.options,i=e.target,n=i.classList.contains(s.selector.replace(".",""));if(this.container.appendChild(this.lasso),this.origin={x:e.pageX,y:e.pageY},!s.disabled){if(n&&i.classList.add("ui-selecting"),s.autoRefresh&&this.refresh(),h(e)){for(var o=!1,c=0;c<this.items.length;c++)if(this.items[c].element===e.target){o=this.items[c];break}for(var r=!1,c=o.index;c>=0&&(this.items[c].selected&&(r=!0),!r||this.items[c].selected);c--)this.items[c].selecting=!0}l(this.items,function(s){var n=s.element;s.selected&&(s.startselected=!0,d(e)||h(e)||(n.classList.remove("ui-selected"),s.selected=!1,n.classList.add("ui-unselecting"),s.unselecting=!0)),n===i&&(t=s)}),this.dragging=!0,n&&this.emit("selectable.down",t)}},i.prototype.mousemove=function(e){if(this.dragging){var t=this.options;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,{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.left>i.x2||s.rect.right<i.x1||s.rect.top>i.y2||s.rect.bottom<i.y1):"fit"==t.tolerance&&(o=s.rect.left>i.x1&&s.rect.right<i.x2&&s.rect.top>i.y1&&s.rect.bottom<i.y2),o?(s.selected&&(n.classList.remove("ui-selected"),s.selected=!1),s.unselecting&&(n.classList.remove("ui-unselecting"),s.unselecting=!1),s.selecting||(n.classList.add("ui-selecting"),s.selecting=!0)):(s.selecting&&(d(e)&&s.startselected?(n.classList.remove("ui-selecting"),s.selecting=!1,n.classList.add("ui-selected"),s.selected=!0):(n.classList.remove("ui-selecting"),s.selecting=!1,s.startselected&&(n.classList.add("ui-unselecting"),s.unselecting=!0))),n.selected&&(d(e)||s.startselected||(n.classList.remove("ui-selected"),s.selected=!1,n.classList.add("ui-unselecting"),s.unselecting=!0)))}),this.emit("selectable.drag",i)}}},i.prototype.mouseup=function(e){if(this.dragging&&(this.dragging=!1),this.container.contains(e.target)){var t=this;this.selectedItems=[],r(this.lasso,{left:0,width:0,top:0,height:0}),l(this.items,function(e){var s=e.element;e.unselecting&&(s.classList.remove("ui-unselecting"),e.unselecting=!1,e.startselected=!1),e.selecting&&t.selectItem(e),e.selected&&(t.selectedItems.push(e),t.emit("selectable.selected",e))}),this.container.removeChild(this.lasso),this.emit("selectable.up",this.selectedItems)}},i.prototype.selectItem=function(e){e.element.classList.remove("ui-selecting"),e.element.classList.add("ui-selected"),e.selecting=!1,e.selected=e.startselected=!0},i.prototype.update=function(){l(this.nodes,function(e,t){this.items[t].rect=e.getBoundingClientRect()},this)},i.prototype.destroy=function(){l(this.items,function(e){var t=e.element;t.classList.remove("ui-unselecting"),t.classList.remove("ui-selecting"),t.classList.remove("ui-selected")}),s(this.container,"mousedown",this.events.mousedown),s(document,"mousemove",this.events.mousemove),s(document,"mouseup",this.events.mouseup),s(window,"resize",this.events.update),s(window,"scroll",this.events.update)},i}); |
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
28269
133