aboutsummaryrefslogtreecommitdiffstats
path: root/ui/ui.sortable.js
diff options
context:
space:
mode:
authorPaul Bakaus <paul.bakaus@googlemail.com>2009-07-28 05:50:23 +0000
committerPaul Bakaus <paul.bakaus@googlemail.com>2009-07-28 05:50:23 +0000
commit0bbf9260154ff3a0721b736b3487f1ee57b5a552 (patch)
tree6964018eeccb4c593173003efc0072ae3859c8d2 /ui/ui.sortable.js
parentde827dd8df1d9a839258901b83c73869c153f3cb (diff)
downloadjquery-ui-0bbf9260154ff3a0721b736b3487f1ee57b5a552.tar.gz
jquery-ui-0bbf9260154ff3a0721b736b3487f1ee57b5a552.zip
sortable: fixed issues with nested containers (fixes #4703,#4611, thanks kae!)
Diffstat (limited to 'ui/ui.sortable.js')
-rw-r--r--ui/ui.sortable.js80
1 files changed, 51 insertions, 29 deletions
diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js
index f2d5dc4ed..36e13ae75 100644
--- a/ui/ui.sortable.js
+++ b/ui/ui.sortable.js
@@ -258,6 +258,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
&& !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
&& (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true)
+ //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
) {
this.direction = intersection == 1 ? "down" : "up";
@@ -640,47 +641,68 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
},
_contactContainers: function(event) {
+
+ // get innermost container that intersects with item
+ var innermostContainer = null, innermostIndex = null;
+
+
for (var i = this.containers.length - 1; i >= 0; i--){
- if(this._intersectsWith(this.containers[i].containerCache)) {
- if(!this.containers[i].containerCache.over) {
-
- if(this.currentContainer != this.containers[i]) {
-
- //When entering a new container, we will find the item with the least distance and append our item near it
- var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[i].floating ? 'left' : 'top'];
- for (var j = this.items.length - 1; j >= 0; j--) {
- if(!$.ui.contains(this.containers[i].element[0], this.items[j].item[0])) continue;
- var cur = this.items[j][this.containers[i].floating ? 'left' : 'top'];
- if(Math.abs(cur - base) < dist) {
- dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
- }
- }
+ // never consider a container that's located within the item itself
+ if($.ui.contains(this.currentItem[0], this.containers[i].element[0]))
+ continue;
- if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
- continue;
-
- this.currentContainer = this.containers[i];
- itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[i].element, true);
- this._trigger("change", event, this._uiHash());
- this.containers[i]._trigger("change", event, this._uiHash(this));
+ if(this._intersectsWith(this.containers[i].containerCache)) {
- //Update the placeholder
- this.options.placeholder.update(this.currentContainer, this.placeholder);
+ // if we've already found a container and it's more "inner" than this, then continue
+ if(innermostContainer && $.ui.contains(this.containers[i].element[0], innermostContainer.element[0]))
+ continue;
- }
-
- this.containers[i]._trigger("over", event, this._uiHash(this));
- this.containers[i].containerCache.over = 1;
- }
+ innermostContainer = this.containers[i];
+ innermostIndex = i;
+
} else {
+ // container doesn't intersect. trigger "out" event if necessary
if(this.containers[i].containerCache.over) {
this.containers[i]._trigger("out", event, this._uiHash(this));
this.containers[i].containerCache.over = 0;
}
}
- };
+ }
+
+ // if no intersecting containers found, return
+ if(!innermostContainer) return;
+
+ // move the item into the container if it's not there already
+ if(this.currentContainer != this.containers[innermostIndex]) {
+
+ //When entering a new container, we will find the item with the least distance and append our item near it
+ var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top'];
+ for (var j = this.items.length - 1; j >= 0; j--) {
+ if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue;
+ var cur = this.items[j][this.containers[innermostIndex].floating ? 'left' : 'top'];
+ if(Math.abs(cur - base) < dist) {
+ dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
+ }
+ }
+
+ if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
+ return;
+
+ this.currentContainer = this.containers[innermostIndex];
+ itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
+ this._trigger("change", event, this._uiHash());
+ this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
+
+ //Update the placeholder
+ this.options.placeholder.update(this.currentContainer, this.placeholder);
+
+ }
+
+ this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
+ this.containers[innermostIndex].containerCache.over = 1;
+
},
_createHelper: function(event) {