ansible/angular-drag-and-drop-lists

Name: angular-drag-and-drop-lists

Owner: Ansible

Description: Angular directives for sorting nested lists using the HTML5 Drag & Drop API

Forked from: leigh-johnson/angular-drag-and-drop-lists

Created: 2016-12-05 15:46:31.0

Updated: 2017-12-19 13:11:58.0

Pushed: 2017-11-27 15:50:24.0

Homepage: null

Size: 225

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

angular-drag-and-drop-lists

Angular directives that allow you to build sortable lists with the native HTML5 drag & drop API. The directives can also be nested to bring drag & drop to your WYSIWYG editor, your tree, or whatever fancy structure you are building.

Demo
Supported browsers

Touch devices are not supported, because they do not implement the HTML5 drag & drop standard. However, you can use a shim to make it work on touch devices as well.

Internet Explorer 8 or lower is not supported, but all modern browsers are (see changelog for list of tested browsers).

Download & Installation
dnd-draggable directive

Use the dnd-draggable directive to make your element draggable

Attributes

Callbacks

CSS classes

dnd-list directive

Use the dnd-list attribute to make your list element a dropzone. Usually you will add a single li element as child with the ng-repeat directive. If you don't do that, we will not be able to position the dropped element correctly. If you want your list to be sortable, also add the dnd-draggable directive to your li element(s). Both the dnd-list and it's direct children must have position: relative CSS style, otherwise the positioning algorithm will not be able to determine the correct placeholder position in all browsers.

Attributes

Callbacks

CSS classes

dnd-nodrag directive

Use the dnd-nodrag attribute inside of dnd-draggable elements to prevent them from starting drag operations. This is especially useful if you want to use input elements inside of dnd-draggable elements or create specific handle elements.

Note: This directive does not work in Internet Explorer 9.

Demo

dnd-handle directive

Use the dnd-handle directive within a dnd-nodrag element in order to allow dragging of that element after all. Therefore, by combining dnd-nodrag and dnd-handle you can allow dnd-draggable elements to only be dragged via specific handle elements.

Note: Internet Explorer will show the handle element as drag image instead of the dnd-draggable element. You can work around this by styling the handle element differently when it is being dragged. Use the CSS selector .dndDragging:not(.dndDraggingSource) [dnd-handle] for that.

Demo

Required CSS styles

Both the dnd-list and it's children require relative positioning, so that the directive can determine the mouse position relative to the list and thus calculate the correct drop position.

ul[dnd-list], ul[dnd-list] > li {
    position: relative;
}
Why another drag & drop library?

There are tons of other drag & drop libraries out there, but none of them met my three requirements:

If this doesn't fit your requirements, check out one of the other awesome drag & drop libraries:

License

Copyright (c) 2014 Marcel Juenemann

Copyright (c) 2014-2016 Google Inc.

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

MIT License


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.