Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added options.noShadow #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions dragula.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function dragula (initialContainers, options) {
if (o.direction === void 0) { o.direction = 'vertical'; }
if (o.ignoreInputTextSelection === void 0) { o.ignoreInputTextSelection = true; }
if (o.mirrorContainer === void 0) { o.mirrorContainer = doc.body; }
if (o.noShadow === void 0) { o.noShadow = false; }

var drake = emitter({
containers: o.containers,
Expand Down Expand Up @@ -242,23 +243,23 @@ function dragula (initialContainers, options) {
var elementBehindCursor = getElementBehindPoint(_mirror, clientX, clientY);
var dropTarget = findDropTarget(elementBehindCursor, clientX, clientY);
if (dropTarget && ((_copy && o.copySortSource) || (!_copy || dropTarget !== _source))) {
drop(item, dropTarget);
drop(item, dropTarget, e);
} else if (o.removeOnSpill) {
remove();
} else {
cancel();
}
}

function drop (item, target) {
function drop (item, target, event) {
var parent = getParent(item);
if (_copy && o.copySortSource && target === _source) {
parent.removeChild(_item);
}
if (isInitialPlacement(target)) {
drake.emit('cancel', item, _source, _source);
} else {
drake.emit('drop', item, target, _source, _currentSibling);
drake.emit('drop', item, target, _source, _currentSibling, event);
}
cleanup();
}
Expand Down Expand Up @@ -382,6 +383,11 @@ function dragula (initialContainers, options) {
}
return;
}

if (o.noShadow) {
return;
}

var reference;
var immediate = getImmediateChild(dropTarget, elementBehindCursor);
if (immediate !== null) {
Expand Down
9 changes: 8 additions & 1 deletion readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dragula(containers, {
removeOnSpill: false, // spilling will `.remove` the element, if this is true
mirrorContainer: document.body, // set the element that gets mirror elements appended
ignoreInputTextSelection: true // allows users to select input text, see details below
noShadow: false // no visual aid shadow is used
});
```

Expand Down Expand Up @@ -231,6 +232,12 @@ When this option is enabled, if the user clicks on an input element the drag won

This option is enabled by default. Turn it off by setting it to `false`. If its disabled your users won't be able to select text in inputs within `dragula` containers with their mouse.

#### `options.noShadow`

When this option is enabled, no visual aid shadow is used, and the dragged element (the copy if `options.copy = true` or the original element otherwise) is **not automatically dropped** in the target. This is useful if you want to customize the element insertion in elements such `svg` or `canvas`.

This option speeds things up because the DOM operations decrease significantly.

## API

The `dragula` method returns a tiny object with a concise API. We'll refer to the API returned by `dragula` as `drake`.
Expand Down Expand Up @@ -272,7 +279,7 @@ Event Name | Listener Arguments | Event Description
-----------|----------------------------------|-------------------------------------------------------------------------------------
`drag` | `el, source` | `el` was lifted from `source`
`dragend` | `el` | Dragging event for `el` ended with either `cancel`, `remove`, or `drop`
`drop` | `el, target, source, sibling` | `el` was dropped into `target` before a `sibling` element, and originally came from `source`
`drop` | `el, target, source, sibling, event` | `el` was dropped into `target` before a `sibling` element at position given by `event`, and originally came from `source`
`cancel` | `el, container, source` | `el` was being dragged but it got nowhere and went back into `container`, its last stable parent; `el` originally came from `source`
`remove` | `el, container, source` | `el` was being dragged but it got nowhere and it was removed from the DOM. Its last stable parent was `container`, and originally came from `source`
`shadow` | `el, container, source` | `el`, _the visual aid shadow_, was moved into `container`. May trigger many times as the position of `el` changes, even within the same `container`; `el` originally came from `source`
Expand Down