# ffd-selector

> Provides element selection, drag and drop, drag and drop functions.

Latest version **1.0.6** (published 2018-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install ffd-selector
pnpm add ffd-selector
yarn add ffd-selector
bun add ffd-selector
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-11-10 |
| First published | 2018-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 30.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | shixia226 |
| Maintainers | shixia |
| Keywords | selector, ffd, shixia |

## Links

- npm: https://www.npmjs.com/package/ffd-selector
- Repository: https://github.com/shixia226/ffd-selector
- Homepage: https://github.com/shixia226/ffd-selector#readme
- Issues: https://github.com/shixia226/ffd-selector/issues
- npm.io page: https://npm.io/package/ffd-selector

## Dependencies (1)

- [ffd-util](https://npm.io/package/ffd-util.md) ^1.0.0

## Recent versions

- 1.0.6 (latest) — 2018-11-10
- 1.0.5 — 2018-11-02
- 1.0.4 — 2018-07-09
- 1.0.3 — 2018-07-06
- 1.0.2 — 2018-07-05
- 1.0.1 — 2018-07-04
- 1.0.0 — 2018-07-03

## README

# Selector

Provides element selection, drag and drop, drag and drop functions.

## HOW TO USE

### Install
```
npm install ffd-selector
```

### Html
```html
<span outer-draggable>ABC</span>
<div draggable></div>
<div droppable></div>
```

### Config
```javascript
Selector.config({
    onselect(evt, elems) {
        if (elems) {
            if ($(elems[0]).attr('draggable')) {
                Selector.select(elems, true);
            } else {
                Selector.select($(elems[0]).closest('[draggable]'), true);
            }
        } else {
            Selector.select($(evt.target).closest('[draggable]'), true);
        }
    },
    ondragover(target, over) {
        let dropElem = $(target).closest('[droppable]');
        if (dropElem.length) {
            if (over && dropElem[0] === over) return over;
            dropElem.addClass('droppable');
            return dropElem[0];
        }
    },
    ondragstart(target, evt) {
        let drag = $(target);
        if (drag.attr('outer-draggable')) {
            return {
                helper: target.cloneNode(true),
                cursorAt: {
                    x: 10,
                    y: 10
                }
            }
        }
    },
    ondragout(over) {
        $(over).removeClass('droppable');
    },
    ondrop(over, start) {
        $(over).append($(start.helper).text());
    }
});
```

### Regist
```javascript
$('body').on('mousedown', function(evt) {
    Selector.mousedown(evt);
}).on('mousemove', function(evt) {
    Selector.mousemove(evt);
}).on('mouseup mouseleave', function(evt) {
    Selector.mouseup(evt);
})

$('[outer-draggable]').on('mousedown', function(evt) {
    Selector.dragstart(evt);
    return false;
}) 
```

## LICENSE

MIT

---
_Source: https://npm.io/package/ffd-selector · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
