mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Sortable: Skip items that are not at the same line as the cursor when floating. Fixes #8792: Issue with floated items in connected lists.
This commit is contained in:
parent
e0b2644d91
commit
89473f6557
22
ui/jquery.ui.sortable.js
vendored
22
ui/jquery.ui.sortable.js
vendored
@ -21,6 +21,10 @@ function isOverAxis( x, reference, size ) {
|
|||||||
return ( x > reference ) && ( x < ( reference + size ) );
|
return ( x > reference ) && ( x < ( reference + size ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isFloating(item) {
|
||||||
|
return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
|
||||||
|
}
|
||||||
|
|
||||||
$.widget("ui.sortable", $.ui.mouse, {
|
$.widget("ui.sortable", $.ui.mouse, {
|
||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
widgetEventPrefix: "sort",
|
widgetEventPrefix: "sort",
|
||||||
@ -73,7 +77,7 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
this.refresh();
|
this.refresh();
|
||||||
|
|
||||||
//Let's determine if the items are being displayed horizontally
|
//Let's determine if the items are being displayed horizontally
|
||||||
this.floating = this.items.length ? o.axis === "x" || (/left|right/).test(this.items[0].item.css("float")) || (/inline|table-cell/).test(this.items[0].item.css("display")) : false;
|
this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
|
||||||
|
|
||||||
//Let's determine the parent's offset
|
//Let's determine the parent's offset
|
||||||
this.offset = this.element.offset();
|
this.offset = this.element.offset();
|
||||||
@ -799,7 +803,7 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_contactContainers: function(event) {
|
_contactContainers: function(event) {
|
||||||
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom,
|
var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
|
||||||
innermostContainer = null,
|
innermostContainer = null,
|
||||||
innermostIndex = null;
|
innermostIndex = null;
|
||||||
|
|
||||||
@ -845,8 +849,9 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
//When entering a new container, we will find the item with the least distance and append our item near it
|
//When entering a new container, we will find the item with the least distance and append our item near it
|
||||||
dist = 10000;
|
dist = 10000;
|
||||||
itemWithLeastDistance = null;
|
itemWithLeastDistance = null;
|
||||||
posProperty = this.containers[innermostIndex].floating ? "left" : "top";
|
floating = innermostContainer.floating || isFloating(this.currentItem);
|
||||||
sizeProperty = this.containers[innermostIndex].floating ? "width" : "height";
|
posProperty = floating ? "left" : "top";
|
||||||
|
sizeProperty = floating ? "width" : "height";
|
||||||
base = this.positionAbs[posProperty] + this.offset.click[posProperty];
|
base = this.positionAbs[posProperty] + this.offset.click[posProperty];
|
||||||
for (j = this.items.length - 1; j >= 0; j--) {
|
for (j = this.items.length - 1; j >= 0; j--) {
|
||||||
if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
|
if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
|
||||||
@ -855,6 +860,9 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
if(this.items[j].item[0] === this.currentItem[0]) {
|
if(this.items[j].item[0] === this.currentItem[0]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
cur = this.items[j].item.offset()[posProperty];
|
cur = this.items[j].item.offset()[posProperty];
|
||||||
nearBottom = false;
|
nearBottom = false;
|
||||||
if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
|
if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
|
||||||
@ -873,10 +881,14 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentContainer = this.containers[innermostIndex];
|
if(this.currentContainer === this.containers[innermostIndex]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
|
itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
|
||||||
this._trigger("change", event, this._uiHash());
|
this._trigger("change", event, this._uiHash());
|
||||||
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
|
this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
|
||||||
|
this.currentContainer = this.containers[innermostIndex];
|
||||||
|
|
||||||
//Update the placeholder
|
//Update the placeholder
|
||||||
this.options.placeholder.update(this.currentContainer, this.placeholder);
|
this.options.placeholder.update(this.currentContainer, this.placeholder);
|
||||||
|
Loading…
Reference in New Issue
Block a user