0.1.8 • Published 2 years ago

dragorder v0.1.8

Weekly downloads
18
License
MIT
Repository
github
Last release
2 years ago

DragOrder

A javascript class for managing the order of elements via drag and drop

Inspired by https://archive.codeplex.com/?p=dragsort, this javascript class has no dependencies and is importable via npm.

FAQ

What about the Drag and Drop API?

Unfortunately, the Drag and Drop API quite limited in what it can do when trying to customize things like the placeholder and the dragging element. This class uses mouse events to mimic similar behavior.

Usage

npm install dragorder
import DragOrder from 'dragorder';

new DragOrder({
    el: document.getElementById('example')
})

Options

OptionTypeDescriptionDefault
elElementThe element that contains the itemsrequired
dropFunctionCallback when element is dropped and items are reordereditems => {}
dragStartFunctionCallback when element drag is initiateditems => {}
dragEndFunctionCallback when element drag is ended. This is always called, even if drag is canceled (i.e. escape key)items => {}
placeholderHTML or Element or FunctionWhat to render as a placeholder for dragged itemitem => item.cloneNode(true)
dragholderFunctionWhat to render as the element that is dragged by the mouseitem => item.cloneNode(true)
handleSelectorStringSelector to scope what element is clickable to initiate dragitem
itemSelectorStringSelector to scope what elements are draggablethis.el.children

Development

Demo

Load demo.html in browser

Release

npm publish
0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago