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

use fallbackParent option instead of fallbackOnBody #2245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ var sortable = new Sortable(el, {
forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in

fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback
fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body
getFallbackParent: null, // Getter function that returns the parent for the cloned DOM Element
fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.

dragoverBubble: false,
1,210 changes: 571 additions & 639 deletions Sortable.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sortable.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -304,7 +304,7 @@ <h4 class="col-12">Grid Example</h4>

<div id="nested" class="row">
<h4 class="col-12">Nested Sortables Example</h4>
<p class="col-12">NOTE: When using nested Sortables with animation, it is recommended that the <code>fallbackOnBody</code> option is set to true. <br />It is also always recommended that either the <code>invertSwap</code> option is set to true, or the <code>swapThreshold</code> option is lower than the default value of 1 (eg <code>0.65</code>).</p>
<p class="col-12">NOTE: When using nested Sortables with animation, it is recommended that the <code>getFallbackParent</code> option is set to return document.body. (`() => (document.body)`). <br />It is also always recommended that either the <code>invertSwap</code> option is set to true, or the <code>swapThreshold</code> option is lower than the default value of 1 (eg <code>0.65</code>).</p>
<div id="nestedDemo" class="list-group col nested-sortable">
<div class="list-group-item nested-1">Item 1.1
<div class="list-group nested-sortable">
1,210 changes: 571 additions & 639 deletions modular/sortable.complete.esm.js

Large diffs are not rendered by default.

1,210 changes: 571 additions & 639 deletions modular/sortable.core.esm.js

Large diffs are not rendered by default.

1,210 changes: 571 additions & 639 deletions modular/sortable.esm.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/Sortable.js
Original file line number Diff line number Diff line change
@@ -351,7 +351,10 @@ function Sortable(el, options) {

this.el = el; // root element
this.options = options = Object.assign({}, options);

if (this.options.fallbackOnBody) {
// backwards compatibility
this.options.getFallbackParent = () => (document.body)
}

// Export instance
el[expando] = this;
@@ -389,7 +392,9 @@ function Sortable(el, options) {
touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
forceFallback: false,
fallbackClass: 'sortable-fallback',
// @obsolete use `getFallbackParent: () => (document.body)`
fallbackOnBody: false,
getFallbackParent: null,
fallbackTolerance: 0,
fallbackOffset: {x: 0, y: 0},
supportPointer: Sortable.supportPointer !== false && ('PointerEvent' in window) && !Safari,
@@ -851,7 +856,8 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
// Bug if using scale(): https://stackoverflow.com/questions/2637058
// Not being adjusted for
if (!ghostEl) {
let container = this.options.fallbackOnBody ? document.body : rootEl,
let fallbackParent = typeof this.options.getFallbackParent === 'function' ? this.options.getFallbackParent() : null
let container = fallbackParent ?? rootEl,
rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
options = this.options;

2 changes: 1 addition & 1 deletion st/app.js
Original file line number Diff line number Diff line change
@@ -202,7 +202,7 @@ for (var i = 0; i < nestedSortables.length; i++) {
new Sortable(nestedSortables[i], {
group: 'nested',
animation: 150,
fallbackOnBody: true,
getFallbackParent: () => (document.body),
swapThreshold: 0.65
});
}