Selectable
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.
Install
Bower
bower install mobius1-selectable --save
npm
npm install mobius1-selectable --save
Browser
Grab the files from one of the CDNs and include them in your page:
https://unpkg.com/mobius1-selectable@latest/selectable.min.js
//or
https://cdn.jsdelivr.net/npm/mobius1-selectable@latest/selectable.min.js
You can replace latest
with the required release number if needed.
Initialise the plugin:
const selectable = new Selectable(options);
Options
Option | Type | Default | Effect |
---|
filter | string or array | "*" | The elements that can be selected. You can pass either a CSS3 selector string or a collection of nodes. |
appendTo | string or object | document.body | The container element to append the lasso to. |
tolerance | string | touch | How far the lasso overlaps an element before it's highlighted. "fit" (lasso overlaps the item entirely) or "touch" (lasso overlaps the item by any amount). |
autoRefresh | boolean | true | Recalculate the coords of the items. Set to false if you know the selectable items won't move or change size. |
lasso | object | | Style the lasso. Must be an object of valid CSS declarations. |
Events
const selectable = new Selectable(options);
selectable.on('selectable.XXXX', function() {
});
selectable.down
fires on mousedown (within container)selectable.drag
fires when dragging the lassoselectable.up
fires on mouse up (within container)selectable.selected
fires on each element selected
selectable.on('selectable.down', function(item) {
});
selectable.on('selectable.drag', function(coords) {
});
selectable.on('selectable.up', function(selectedItems) {
});
selectable.on('selectable.selected', function(item) {
});
Note that items returned by these events are objects of the following format:
{
element: HTMLElement,
index: Numbe,r
rect: DOMRect Object,
startselected: Boolean,
selected: Boolean,
selecting: Boolean,
unselecting: Boolean
}
Copyright © 2017 Karl Saunders | BSD & MIT license