Touch enabled selectable plugin inspired by the jQuery UI widget.

Overview

Selectable

Maintenance Code Climate maintainability npm license GitHub release npm GitHub issues GitHub issues

Inspired by the jQuery UI Selectable plugin. Functionality and options are identical to the jQuery UI version with some additions and performance enhancements.

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.

  • No dependencies
  • Lightweight
  • IE9+
  • Touch enabled

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.

Pull requests are welcome!

Demo | Documentation | Changelog | Table Plugin


Demos

Integration with other libs


Install

Bower

bower install selectable.js --save

npm

npm install selectable.js --save

Browser

Grab the file from one of the CDNs and include it in your page:

https://unpkg.com/selectable.js@latest/selectable.min.js

or

https://cdn.jsdelivr.net/npm/selectable.js@latest/selectable.min.js

You can replace latest with the required release number if needed.


Default

This will create a new instance and add any element found in the DOM with the "ui-selectable" class name and make them selectable.

const selectable = new Selectable();

Custom filter

If you don't add the "ui-selectable" class name to your items then simply tell the instance what to look for instead with the filter option:

const selectable = new Selectable({
   filter: ".my-classname"
});

// or

const selectable = new Selectable({
   filter: document.querySelectorAll(".my-classname")
});

NOTE: <a> elements will not work currently. See: #31

No items

If your document doesn't have any selectable items yet, e.g. they're added asynchronously via an ajax call, then simply create a new instance as normal, then use the add() method when they're available:

const selectable = new Selectable();

// items added to DOM ...

// then...
selectable.add(items);

Options

See Options


Public Methods

See Public Methods


Events

See Events


If this project helps you then you can grab me a coffee or beer to say thanks.

paypal


Copyright © 2017 Karl Saunders | BSD & MIT license

Comments
  • Can sequential selection be improved?

    Can sequential selection be improved?

    Thank you for this great library. We use it to allow users to select text and add highlights to PDFs in a web browser. The issue is that when a user starts the lasso outside of the first element, all previous elements are added to the selection. This can be reproduced in your demo page for 'lassoSelect` option. We work around the issue like this:

    let selectable = new Selectable({
        lassoSelect: 'sequential'
    });
    
    selectable.on('start', function (e, item) {
        if(typeof item === 'object') {
            // User started the lasso inside an item. Allow selecting.
            This.selectable.off('end');
            This.selectable.on('end', method);
        } else {
            // User started the lasso outside an item. Disallow selecting.
            This.selectable.off('end');
        }
    });
    

    Just thought I would let you know of this.

    bug 
    opened by mkucej 5
  • Destroying instance doesn’t remove all event handlers

    Destroying instance doesn’t remove all event handlers

    When destroying instance with destroy() method, touchstart event handlers are still there.

    selectable.min.js:11 Uncaught TypeError: Cannot read property 'start' of undefined
        at a.touchstart (selectable.min.js:11)
    

    I’ve pinpointed issue to these lines of code.

    Am I doing something wrong?

    bug 
    opened by niksy 5
  • After Chrome update plugin doesn't work on touch devices.

    After Chrome update plugin doesn't work on touch devices.

    Chrome v: 64.0.3282.140 On touch plugin throws an error Uncaught TypeError: Failed to execute 'elementFromPoint' on 'Document': The provided double value is non-finite. at Selectable.end (selectable.js:705) 2018-02-02_1801

    bug 
    opened by AlexandrTuniev 4
  • Events firing regardless of Selectable instance?

    Events firing regardless of Selectable instance?

    I am slightly confused by the firing of events across multiple selectable instances. As a result it's not clear to me if what am experiencing is a bug or expected behaviour.

    I have two selectable instances on a page:

                const selectable = new Selectable({
                    toggle: true
                });
    
                const groupSelectable = new Selectable({
                    filter: ".team-row"
                });
    

    Listening to the end event for one of the instances (selectable.on("selectable.end", function(e, selected, unselected) {...), the code seems to be firing also for selection changes in the second (groupSelectable) instance. This is in itself something that I could have worked around had it not been for the fact that at the point of execution, the groupSelectable.getSelectedItems() returns empty.

    If I create a separate groupSelectable.on("selectable.end", function(e, selected, unselected) {... event listener, groupSelectable.getSelectedItems() contain the expected items. However, I am looking to perform an action once all the selections have "settled down" (across multiple instances), and I don't know how I would go about that.

    Apologies if there's something I'm not understanding.

    opened by nmeirik 3
  • [BUGFIX] Match OS behaviour when holding cmd/ctrl key

    [BUGFIX] Match OS behaviour when holding cmd/ctrl key

    currently when holding the metaKey you cannot unselect an item that you selected by accident, this PR added tests to prove they don't and then fixes those

    opened by esserj 3
  • Get selectable instance

    Get selectable instance

    1. How can i get the Selectable instance using class/filter (whatever was added during initiation) So as we can get it even if it is defined in Function ?

    2. And also if i call a function whenever i click a refresh button , the instances are getting generated constantly and cause the system to lag.There should be an option so that along with creating new instance each time the previous should be destroyed OR one instance option and it refreshes only.

    function selectableInit(element,getInstance){
    	const selectable = new Selectable({
    		appendTo: '.fm-data',
    		autoRefresh: true,
     		autoScroll: {
    			threshold: 0,
    			increment: 20,
    		}, 
    		classes: {
    			lasso: "ui-lasso",
    			selected: "ui-selected",
    			container: "ui-container",
    			selecting: "ui-selecting",
    			selectable: "ui-selectable",
    			unselecting: "ui-unselecting"
    		},		
    		filter: element,
    		lasso:{
    			border: '1px solid inherit',
    			backgroundColor: 'rgba(52, 152, 219, 0.2)',
    			zIndex: '1',
    		},
    		tolerance: 'touch'
    	});
    	
    	if(getInstance == 'get'){
    		return selectable.getSelectedNodes();
    	}
    };
    
    

    3. The plugin should work for updating(dynamic) elements It should look for the class of how many elements so we have to initiate it only one time and it looks for elements , since there is an auto refresh option this should serve the purpose of re initiating/refreshing.

    Thanks for the beautiful plugin

    opened by MR-AMDEV 2
  • It works with AngularJS?

    It works with AngularJS?

    Hi, i'm i really insterested into in use this gadget on a project but i need that it works on angular, when i try to do a ng-repeat Selectable stops to work. here an example:

    whit ng-repeat: https://codepen.io/dev15/pen/MBQobQ?editors=1111

    whitout: https://codepen.io/anon/pen/ejrBrJ?editors=1111

    opened by dev15seucondominio 2
  • Selected area is wrong

    Selected area is wrong

    When i try to select the rows in Selectable with Tables demo, the area i selected with dashed line border area is different from the selected area. You can see this from the image below. I'm using chrome browser version 64.

    image

    bug 
    opened by Gaslan 2
  • Temporary stop when selector starts from inside previously selected elem

    Temporary stop when selector starts from inside previously selected elem

    Hello. First, sorry for bad english I need drag selected elements that selected via Selectable instance. But when drag, it's drawing new rectangle. So, when elements are selected, is it possible temporary stop the instance? I tried enable disable method but when disabled the instance, i lost selected items and listeners.

    opened by Tumur1117 1
  • License problems

    License problems

    Unfortunately, there are several licenses within the repository.

    In the readme.md under Copyright at the bottom is BSD & MIT, in the file LICENCE is MIT and in the source code in selectable.js is Dual Licence MIT and GPL.

    What is the license under which the project may be used?

    I suppose it is MIT and the others may be old remnants. I would be very grateful if it was clear under which license I am allowed to use the project!

    opened by WWWuschel 1
  • Allowed to control the plugin on touch devices

    Allowed to control the plugin on touch devices

    Finally! You all requested this feature! This pull request allows users to manipulate their plugin on touch devices!

    How to use?

    Standart usage:

    const selectable = new Selectable({
      appendTo: '#content',
    });
    

    New usage:

    const selectable = new Selectable({
      touch: false, // Set to false if you want to disable "lasso" toggling items still work!
      toggleTouch: true, // Set to true if you want to toggle or false if not
      appendTo: '#content',
    });
    

    Note! By default plugin works as a previous version! But now you can manipulate it better 👍

    #34

    opened by mafftor 1
  • Selecting in a calendar

    Selecting in a calendar

    Hi, first of all great work! Let's assume I have a calendar which displays each month side-by-side. I have the following config to enable selectable:

    const selectable = new Selectable({
            lassoSelect: "sequential",
            appendTo: "#calendar",
            filter: ".day"
    });
    

    When I start selecting in one month and move to the second month like in the following image (Start 23.07 End 30.08): grafik Please note that the mouse was moved from top left to bottom right (see lasso). The example above works as expected. However, when I want to do the following: Start 23.07 End 10.08 (mouse is moved from bottom left to top right now!), it's not selecting any field: grafik

    The expected behaviour should be that everything between 23.07. and 10.08. is selected now.

    Therefore I'm wondering how to achieve the behaviour with your selectable?

    All the best

    opened by developeregrem 0
  • General Question: How to improve the scrolling behavior on Mobile devices (iOS & Android)

    General Question: How to improve the scrolling behavior on Mobile devices (iOS & Android)

    Hello, my basic setup is like this but its a bit slow on mobile. It's hard to deselect and the scrolling is way too slow.

    const selectable = new Selectable({
        appendTo: ".files-list",
        ignore: ["img", "ion-icon"],
        autoScroll: {
        threshold: 0,
        increment: 100,
        }
    });
    

    Any tips or additional JS command to make it more responsive and fluid? Otherwise, I can use the builtin features to select all, invert and so on... While I find a better way to work this out.

    Regards

    opened by inglesuniversal 0
  • Help finding the IDs of elements selected ...

    Help finding the IDs of elements selected ...

    Hello, my code looks as follows and even though I am able to select the items properly, I am trying to create an array of the IDs of the items selected, but all I get is a blank {} curly brackets.

    Here is the code I'm using:

    <div id="row_P6CtxjdhyiEPOPxilMHf" class="files-item ui-selectable ui-selected">
    </div>
    
    var ids = $('div#showFiles.file-list.ui-selected').map(function() {
    return $(this).attr('id');
    });
    
    alert(ids.length);
    alert(ids[0]);
    

    I get zero and then undefined in the output function

    Best regards

    enhancement 
    opened by inglesuniversal 3
  • lasso position when transform zoom

    lasso position when transform zoom

    Is it possible to adjust lasso position when set css transform zoom to parent div of objects ? Now selected items are ok, but lasso was draw on wrong position

    opened by cescocesco 1
Releases(0.18.0)
Owner
Karl
Mad man.
Karl
Omnichannel Live Chat Widget UI Components offers a re-usable component-based library to help create a custom chat widget that can be connected to the Dynamics 365 Customer Service experience.

Omnichannel Live Chat Widget UI Components @microsoft/omnichannel-chat-widget is a React-based UI component library which allows you to build your own

Microsoft 14 Dec 15, 2022
TikTokLive-Widget: A socket client/server program that exposes a widget with alerts (such as gifts, followers ...) for a specific user streaming on Tik Tok Live platform

TikTokLive-Widget: A socket client/server program that exposes a widget with alerts (such as gifts, followers ...) for a specific user streaming on Tik Tok Live platform

null 3 Dec 3, 2022
Super tiny size multi-touch gestures library for the web.    You can touch this →

Preview You can touch this → http://alloyteam.github.io/AlloyFinger/ Install You can install it via npm: npm install alloyfinger Usage var af = new Al

腾讯 AlloyTeam 3.3k Dec 12, 2022
Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web

Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled under one library with a simple API that makes working with them painless.

Stuart Yamartino 2.9k Dec 29, 2022
infiniteScrollWithTemplate - JQuery plugin for ajax-enabled infinite page scroll / auto paging with template

jQuery Infinite With Template Plugin JQuery plugin for ajax-enabled infinite page scroll with template. If you like jQuery until now, this little libr

이삼구 2 Mar 19, 2021
Several custom made and legacy icons, and icons collected all over the internet in 1 set, UI selectable.

Custom icon library Several custom made and legacy icons, and icons collected all over the internet in 1 set, UI selectable. Upon each Material Design

Marius 12 Dec 12, 2022
A JavaScript library that creates a small dropdown list of selectable Emojis.

Welcome to EmojiButtonList.js: This is a JavaScript library that creates a small dropdown list of selectable Emojis. To get started, download the sour

William Troup 2 Mar 27, 2021
JqTree - Tree widget for jQuery

jqTree JqTree is a tree widget. Read more in the documentation. Features Create a tree from JSON data Drag and drop Works on ie9+, firefox, chrome and

Marco Braak 1k Dec 22, 2022
jQuery UI widget for structured queries like "Contacts where Firstname starts with A and Birthday before 1/1/2000 and State in (CA, NY, FL)"...

Structured-Filter · Structured-Filter is a generic Web UI for building structured search or filter queries. With it you can build structured search co

Olivier Giulieri 238 Jan 6, 2023
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).

evol-colorpicker · evol-colorpicker is a web color picker which looks like the one in Microsoft Office 2010. It can be used inline or as a popup bound

Olivier Giulieri 285 Dec 14, 2022
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.

Sortable Sortable is a JavaScript library for reorderable drag-and-drop lists. Demo: http://sortablejs.github.io/Sortable/ Features Supports touch dev

SortableJS 26.1k Jan 5, 2023
Spiner bot to buy and sell tokens on ETH and ERC compatible chains as soon as liquidity is added and trade is enabled.

An open-source defi sniper. open-sniper is free to download. Premium Services Now Available While open-sniper is free and open-source, if you want the

spacemonk 4 Apr 21, 2022
On-chain query batcher for CosmWasm-enabled chains

multiquery On-chain query batcher for CosmWasm. Similar to SCB 10X's multicall contract, but supports any serializable query request, not limited to W

null 7 Dec 6, 2022
Ethereum chain sniperbot for tokens. This bot sniffs the mempool for pending transactions for trading enabled and also liquidity add functions.

Ethereum chain sniperbot for tokens. This bot sniffs the mempool for pending transactions for trading enabled and also liquidity add functions.

null 12 Dec 5, 2022
Digitally enabled cafe for students to order drinks, socialize, and study hard.

Coffee Shop Full Stack Full Stack Nano - IAM Final Project Udacity has decided to open a new digitally enabled cafe for students to order drinks, soci

Samuel Nzubechi Chukwuma 25 Nov 20, 2022
A framework for building blockchain-enabled web services

NOTE: Not ready for public use. Please reach out via twitter dm or email with any questions. Ponder A framework for building blockchain-enabled web se

Olias 23 Dec 19, 2022
Responsive navigation plugin without library dependencies and with fast touch screen support.

Responsive Nav Responsive navigation plugin without library dependencies and with fast touch screen support. Responsive Nav is a tiny JavaScript plugi

Viljami Salminen 4.1k Dec 29, 2022
Fintoc.js ES Module - Use the Fintoc widget as an ES module

Fintoc.js ES Module Use the Fintoc widget as an ES module. Installation Install using npm! (or your favourite package manager) # Using npm npm install

Fintoc 6 May 13, 2022