Sortable - accurate option added, If you prefer better accuracy and low performance set accurate: true.

This commit is contained in:
Eduardo Lundgren 2008-10-30 06:57:32 +00:00
parent b0772dc3d8
commit be7db1369d

View File

@ -116,10 +116,12 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
var itemHeight = item.height, itemWidth = item.width;
var itemTop = item.top, itemLeft = item.left;
var isOverElementHeight = ((helperTop + dyClick) > itemTop) &&
var isOverElementHeight =
((helperTop + dyClick) > itemTop) &&
((helperTop + dyClick) < (itemTop + itemHeight));
var isOverElementWidth = ((helperLeft + dxClick) > itemLeft) &&
var isOverElementWidth =
((helperLeft + dxClick) > itemLeft) &&
((helperLeft + dxClick) < (itemLeft + itemWidth));
var isOverElement = isOverElementHeight && isOverElementWidth;
@ -129,7 +131,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
if (this.floating) {
if (isOverElement) {
if (horizontalDirection == false) {
if (!horizontalDirection) {
return false;
}
@ -140,7 +142,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
else {
if (isOverElement) {
if (verticalDirection == false) {
if (!verticalDirection) {
return false;
}
@ -287,9 +289,15 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
if (!fast) {
if (this.options.accurate) {
item.width = t.width();
item.height = t.height();
}
else {
item.width = t[0].offsetWidth;
item.height = t[0].offsetHeight;
}
}
var p = t.offset();
item.left = p.left;
@ -300,7 +308,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
this.options.custom.refreshContainers.call(this);
} else {
for (var i = this.containers.length - 1; i >= 0; i--){
var p =this.containers[i].element.offset();
var p = this.containers[i].element.offset();
this.containers[i].containerCache.left = p.left;
this.containers[i].containerCache.top = p.top;
this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
@ -497,7 +505,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
left: po.left + this.offsetParentBorders.left
};
this.updateOriginalPosition = this.originalPosition = this._generatePosition(e); //Generate the original position
this.originalPosition = this._generatePosition(e); //Generate the original position
this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; //Cache the former DOM position
//If o.placeholder is used, create a new element at the given position with the class
@ -667,13 +675,13 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
if(!intersection) continue;
if(this.items[i].item[0] != this.currentItem[0] //cannot intersect with itself
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != this.items[i].item[0] //no useless actions that have been done before
&& !contains(this.placeholder[0], this.items[i].item[0]) //no action if the item moved is the parent of the item checked
&& (this.options.type == 'semi-dynamic' ? !contains(this.element[0], this.items[i].item[0]) : true)
) {
var item = this.items[i].item[0];
this.updateOriginalPosition = this._generatePosition(e);
if(item != this.currentItem[0] //cannot intersect with itself
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != item //no useless actions that have been done before
&& !contains(this.placeholder[0], item) //no action if the item moved is the parent of the item checked
&& (this.options.type == 'semi-dynamic' ? !contains(this.element[0], item) : true)
) {
this.direction = intersection == 1 ? "down" : "up";
this.options.sortIndicator.call(this, e, this.items[i]);
@ -810,7 +818,8 @@ $.extend($.ui.sortable, {
appendTo: "parent",
sortIndicator: $.ui.sortable.prototype._rearrange,
scope: "default",
forcePlaceholderSize: false
forcePlaceholderSize: false,
accurate: false
}
});