mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
sortable:
- merged back all position and scroll fixed from draggables - renamed accurate to accurateIntersection and set it to true by default - refactored intersection code (no change in logic) - added forceHelperSize option (default: false), a forced helper size is also triggered when the generated helper doesn't have any styles set for width/height, so this option won't be needed in most cases
This commit is contained in:
parent
2b92a02170
commit
91232f6ed5
@ -87,59 +87,58 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
this.refreshPositions();
|
this.refreshPositions();
|
||||||
|
|
||||||
//Create and append the visible helper
|
//Create and append the visible helper
|
||||||
this.helper = this.createHelper(event);
|
this.helper = this._createHelper(event);
|
||||||
|
|
||||||
|
//Cache the helper size
|
||||||
|
this._cacheHelperProportions();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* - Position generation -
|
* - Position generation -
|
||||||
* This block generates everything position related - it's the core of draggables.
|
* This block generates everything position related - it's the core of draggables.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.margins = { //Cache the margins
|
//Cache the margins of the original element
|
||||||
left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
|
this._cacheMargins();
|
||||||
top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
this.offset = this.currentItem.offset(); //The element's absolute position on the page
|
//Store the helper's css position
|
||||||
this.offset = { //Substract the margins from the element's absolute offset
|
this.cssPosition = this.helper.css("position");
|
||||||
|
this.scrollParent = this.helper.scrollParent();
|
||||||
|
|
||||||
|
//The element's absolute position on the page minus margins
|
||||||
|
this.offset = this.currentItem.offset();
|
||||||
|
this.offset = {
|
||||||
top: this.offset.top - this.margins.top,
|
top: this.offset.top - this.margins.top,
|
||||||
left: this.offset.left - this.margins.left
|
left: this.offset.left - this.margins.left
|
||||||
};
|
};
|
||||||
|
|
||||||
this.offset.click = { //Where the click happened, relative to the element
|
$.extend(this.offset, {
|
||||||
left: event.pageX - this.offset.left,
|
click: { //Where the click happened, relative to the element
|
||||||
top: event.pageY - this.offset.top
|
left: event.pageX - this.offset.left,
|
||||||
};
|
top: event.pageY - this.offset.top
|
||||||
|
},
|
||||||
|
parent: this._getParentOffset(),
|
||||||
|
relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
|
||||||
|
});
|
||||||
|
|
||||||
this.offsetParent = this.helper.offsetParent(); //Get the offsetParent and cache its position
|
//Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
|
||||||
var po = this.offsetParent.offset();
|
if(o.cursorAt)
|
||||||
|
this._adjustOffsetFromHelper(o.cursorAt);
|
||||||
|
|
||||||
this.offsetParentBorders = {
|
//Generate the original position
|
||||||
top: (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
|
this.originalPosition = this._generatePosition(event);
|
||||||
left: (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
this.offset.parent = { //Store its position plus border
|
//Cache the former DOM position
|
||||||
top: po.top + this.offsetParentBorders.top,
|
this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
|
||||||
left: po.left + this.offsetParentBorders.left
|
|
||||||
};
|
|
||||||
|
|
||||||
this.originalPosition = this._generatePosition(event); //Generate the original position
|
//Set a containment if given in the options
|
||||||
this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; //Cache the former DOM position
|
if(o.containment)
|
||||||
|
this._setContainment();
|
||||||
|
|
||||||
//If o.placeholder is used, create a new element at the given position with the class
|
//If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way
|
||||||
this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size
|
if(this.helper[0] != this.currentItem[0]) {
|
||||||
|
this.currentItem.hide();
|
||||||
if(o.helper == "original") {
|
|
||||||
this._storedCSS = { position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left"), clear: this.currentItem.css("clear") };
|
|
||||||
} else {
|
|
||||||
this.currentItem.hide(); //Hide the original, won't cause anything bad this way
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Position it absolutely and add a helper class
|
|
||||||
this.helper
|
|
||||||
.css({ position: 'absolute', clear: 'both' })
|
|
||||||
.addClass('ui-sortable-helper');
|
|
||||||
|
|
||||||
//Create the placeholder
|
//Create the placeholder
|
||||||
this._createPlaceholder();
|
this._createPlaceholder();
|
||||||
|
|
||||||
@ -148,42 +147,8 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
|
|
||||||
//Recache the helper size
|
//Recache the helper size
|
||||||
if(!this._preserveHelperProportions)
|
if(!this._preserveHelperProportions)
|
||||||
this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };
|
this._cacheHelperProportions();
|
||||||
|
|
||||||
if(o.cursorAt) {
|
|
||||||
if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left;
|
|
||||||
if(o.cursorAt.right != undefined) this.offset.click.left = this.helperProportions.width - o.cursorAt.right;
|
|
||||||
if(o.cursorAt.top != undefined) this.offset.click.top = o.cursorAt.top;
|
|
||||||
if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* - Position constraining -
|
|
||||||
* Here we prepare position constraining like grid and containment.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if(o.containment) {
|
|
||||||
if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
|
|
||||||
if(o.containment == 'document' || o.containment == 'window') this.containment = [
|
|
||||||
0 - this.offset.parent.left,
|
|
||||||
0 - this.offset.parent.top,
|
|
||||||
$(o.containment == 'document' ? document : window).width() - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
|
|
||||||
($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
|
|
||||||
];
|
|
||||||
|
|
||||||
if(!(/^(document|window|parent)$/).test(o.containment)) {
|
|
||||||
var ce = $(o.containment)[0];
|
|
||||||
var co = $(o.containment).offset();
|
|
||||||
var over = ($(ce).css("overflow") != 'hidden');
|
|
||||||
|
|
||||||
this.containment = [
|
|
||||||
co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.parent.left,
|
|
||||||
co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.parent.top,
|
|
||||||
co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.currentItem.css("marginRight"),10) || 0),
|
|
||||||
co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.currentItem.css("marginBottom"),10) || 0)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Post 'activate' events to possible containers
|
//Post 'activate' events to possible containers
|
||||||
if(!noActivation) {
|
if(!noActivation) {
|
||||||
@ -199,12 +164,14 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
|
|
||||||
this.dragging = true;
|
this.dragging = true;
|
||||||
|
|
||||||
|
this.helper.addClass('ui-sortable-helper');
|
||||||
this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
|
this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_mouseDrag: function(event) {
|
_mouseDrag: function(event) {
|
||||||
|
|
||||||
//Compute the helpers position
|
//Compute the helpers position
|
||||||
this.position = this._generatePosition(event);
|
this.position = this._generatePosition(event);
|
||||||
this.positionAbs = this._convertPositionTo("absolute");
|
this.positionAbs = this._convertPositionTo("absolute");
|
||||||
@ -219,32 +186,26 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
//Regenerate the absolute position used for position checks
|
//Regenerate the absolute position used for position checks
|
||||||
this.positionAbs = this._convertPositionTo("absolute");
|
this.positionAbs = this._convertPositionTo("absolute");
|
||||||
|
|
||||||
//Set the helper's position
|
//Set the helper position
|
||||||
if (this.helper) {
|
if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
|
||||||
this.helper[0].style.left = this.position.left+'px';
|
if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
|
||||||
this.helper[0].style.top = this.position.top+'px';
|
|
||||||
}
|
|
||||||
//Rearrange
|
//Rearrange
|
||||||
for (var i = this.items.length - 1; i >= 0; i--) {
|
for (var i = this.items.length - 1; i >= 0; i--) {
|
||||||
|
|
||||||
var item = this.items[i], intersection = this._intersectsWithPointer(item);
|
//Cache variables and intersection, continue if no intersection
|
||||||
|
var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
|
||||||
if (!intersection) continue;
|
if (!intersection) continue;
|
||||||
|
|
||||||
var itemChecked = this.items[i].item[0];
|
if(itemElement != this.currentItem[0] //cannot intersect with itself
|
||||||
|
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
|
||||||
if(itemChecked != this.currentItem[0] //cannot intersect with itself
|
&& !$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
|
||||||
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemChecked //no useless actions that have been done before
|
&& (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true)
|
||||||
&& !$.ui.contains(this.placeholder[0], itemChecked) //no action if the item moved is the parent of the item checked
|
|
||||||
&& (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemChecked) : true)
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.direction = intersection == 1 ? "down" : "up";
|
this.direction = intersection == 1 ? "down" : "up";
|
||||||
|
|
||||||
if (this.options.tolerance == "pointer") {
|
if (this.options.tolerance == "pointer" || (this.options.tolerance == "guess" && this._intersectsGuess(item))) {
|
||||||
this.options.sortIndicator.call(this, event, item);
|
|
||||||
}
|
|
||||||
else if (this.options.tolerance == "guess" && this._intersectsGuess(item)) {
|
|
||||||
this.options.sortIndicator.call(this, event, item);
|
this.options.sortIndicator.call(this, event, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,10 +221,9 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
|
if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
|
||||||
|
|
||||||
//Call callbacks
|
//Call callbacks
|
||||||
this.element.triggerHandler("sort", [event, this._ui()], this.options["sort"]);
|
this._trigger('sort', event, this._ui());
|
||||||
|
|
||||||
this.lastPositionAbs = this.positionAbs;
|
this.lastPositionAbs = this.positionAbs;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -365,15 +325,26 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
|
|
||||||
/* Be careful with the following core functions */
|
/* Be careful with the following core functions */
|
||||||
_intersectsWith: function(item) {
|
_intersectsWith: function(item) {
|
||||||
var x1 = this.positionAbs.left, x2 = x1 + this.helperProportions.width,
|
|
||||||
y1 = this.positionAbs.top, y2 = y1 + this.helperProportions.height;
|
|
||||||
var l = item.left, r = l + item.width,
|
|
||||||
t = item.top, b = t + item.height;
|
|
||||||
|
|
||||||
var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
|
var x1 = this.positionAbs.left,
|
||||||
|
x2 = x1 + this.helperProportions.width,
|
||||||
|
y1 = this.positionAbs.top,
|
||||||
|
y2 = y1 + this.helperProportions.height;
|
||||||
|
|
||||||
|
var l = item.left,
|
||||||
|
r = l + item.width,
|
||||||
|
t = item.top,
|
||||||
|
b = t + item.height;
|
||||||
|
|
||||||
|
var dyClick = this.offset.click.top,
|
||||||
|
dxClick = this.offset.click.left;
|
||||||
|
|
||||||
var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
|
var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
|
||||||
|
|
||||||
if(this.options.tolerance == "pointer" || this.options.forcePointerForContainers || (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])) {
|
if( this.options.tolerance == "pointer"
|
||||||
|
|| this.options.forcePointerForContainers
|
||||||
|
|| (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])
|
||||||
|
) {
|
||||||
return isOverElement;
|
return isOverElement;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -386,110 +357,45 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_intersectsWithPointer: function(item) {
|
_intersectsWithPointer: function(item) {
|
||||||
var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
|
|
||||||
var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
|
|
||||||
var itemHeight = item.height, itemWidth = item.width;
|
|
||||||
var itemTop = item.top, itemLeft = item.left;
|
|
||||||
|
|
||||||
if (this.cancelIntersection) {
|
var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
|
||||||
|
isOverElementWidth = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
|
||||||
|
isOverElement = isOverElementHeight && isOverElementWidth,
|
||||||
|
verticalDirection = this._getDragVerticalDirection(),
|
||||||
|
horizontalDirection = this._getDragHorizontalDirection();
|
||||||
|
|
||||||
|
if (!isOverElement)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
var isOverElementHeight = $.ui.isOverAxis(helperTop + dyClick, itemTop, itemHeight);
|
return this.floating ?
|
||||||
var isOverElementWidth = $.ui.isOverAxis(helperLeft + dxClick, itemLeft, itemWidth);
|
( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
|
||||||
var isOverElement = isOverElementHeight && isOverElementWidth;
|
: ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );
|
||||||
var verticalDirection = this._getDragVerticalDirection();
|
|
||||||
var horizontalDirection = this._getDragHorizontalDirection();
|
|
||||||
|
|
||||||
if (!isOverElement) return false;
|
|
||||||
|
|
||||||
if (this.floating) {
|
|
||||||
|
|
||||||
if (!horizontalDirection) {
|
|
||||||
return verticalDirection == "down" ? 2 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return horizontalDirection == "right" ? 2 : 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
if (!verticalDirection) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return verticalDirection == "down" ? 2 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_intersectsGuess: function(item) {
|
_intersectsGuess: function(item) {
|
||||||
var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
|
|
||||||
var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
|
|
||||||
var itemHeight = item.height, itemWidth = item.width;
|
|
||||||
var itemTop = item.top, itemLeft = item.left;
|
|
||||||
|
|
||||||
var isOverBottomHalf = $.ui.isOverAxis(helperTop + dyClick, itemTop + (itemHeight/2), itemHeight);
|
var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
|
||||||
var isOverTopHalf = !isOverBottomHalf;
|
isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
|
||||||
var isOverRightHalf = $.ui.isOverAxis(helperLeft + dxClick, itemLeft + (itemWidth/2), itemWidth);
|
verticalDirection = this._getDragVerticalDirection(),
|
||||||
var isOverLeftHalf = !isOverRightHalf;
|
horizontalDirection = this._getDragHorizontalDirection();
|
||||||
var verticalDirection = this._getDragVerticalDirection();
|
|
||||||
var horizontalDirection = this._getDragHorizontalDirection();
|
|
||||||
|
|
||||||
var verticalIntersection = function() {
|
if (this.floating && horizontalDirection) {
|
||||||
if (!verticalDirection) {
|
return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
|
||||||
return false;
|
} else {
|
||||||
}
|
return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf));
|
||||||
if (verticalDirection == "down" && isOverBottomHalf ||
|
|
||||||
verticalDirection == "up" && isOverTopHalf) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var horizontalIntersection = function() {
|
|
||||||
if (!horizontalDirection) {
|
|
||||||
return verticalIntersection();
|
|
||||||
}
|
|
||||||
if (horizontalDirection == "left" && isOverLeftHalf ||
|
|
||||||
horizontalDirection == "right" && isOverRightHalf) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.floating) {
|
|
||||||
return horizontalIntersection();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return verticalIntersection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_getDragVerticalDirection: function() {
|
_getDragVerticalDirection: function() {
|
||||||
var helperTop = this.positionAbs.top;
|
var delta = this.positionAbs.top - this.lastPositionAbs.top;
|
||||||
var lastTop = this.lastPositionAbs.top;
|
return delta != 0 && (delta > 0 ? "down" : "up");
|
||||||
var delta = helperTop - lastTop;
|
|
||||||
|
|
||||||
if (delta == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var direction = delta > 0 ? "down" : "up";
|
|
||||||
return direction;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_getDragHorizontalDirection: function() {
|
_getDragHorizontalDirection: function() {
|
||||||
var helperLeft = this.positionAbs.left;
|
var delta = this.positionAbs.left - this.lastPositionAbs.left;
|
||||||
var lastLeft = this.lastPositionAbs.left;
|
return delta != 0 && (delta > 0 ? "right" : "left");
|
||||||
var delta = helperLeft - lastLeft;
|
|
||||||
|
|
||||||
if (delta == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var direction = delta > 0 ? "right" : "left";
|
|
||||||
return direction;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(event) {
|
refresh: function(event) {
|
||||||
@ -586,9 +492,8 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
refreshPositions: function(fast) {
|
refreshPositions: function(fast) {
|
||||||
|
|
||||||
//This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
|
//This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
|
||||||
if(this.offsetParent) {
|
if(this.offsetParent && this.helper) {
|
||||||
var po = this.offsetParent.offset();
|
this.offset.parent = this._getParentOffset();
|
||||||
this.offset.parent = { top: po.top + this.offsetParentBorders.top, left: po.left + this.offsetParentBorders.left };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = this.items.length - 1; i >= 0; i--){
|
for (var i = this.items.length - 1; i >= 0; i--){
|
||||||
@ -601,7 +506,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
|
var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
|
||||||
|
|
||||||
if (!fast) {
|
if (!fast) {
|
||||||
if (this.options.accurate) {
|
if (this.options.accurateIntersection) {
|
||||||
item.width = t.width();
|
item.width = t.width();
|
||||||
item.height = t.height();
|
item.height = t.height();
|
||||||
}
|
}
|
||||||
@ -717,32 +622,122 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
createHelper: function(event) {
|
_createHelper: function(event) {
|
||||||
|
|
||||||
var o = this.options;
|
var o = this.options;
|
||||||
var helper = typeof o.helper == 'function' ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == "original" ? this.currentItem : this.currentItem.clone());
|
var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem);
|
||||||
|
|
||||||
if (!helper.parents('body').length)
|
if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already
|
||||||
$(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]); //Add the helper to the DOM if that didn't happen already
|
$(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
|
||||||
|
|
||||||
|
if(helper[0] == this.currentItem[0])
|
||||||
|
this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") };
|
||||||
|
|
||||||
|
if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width());
|
||||||
|
if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height());
|
||||||
|
|
||||||
|
//TODO: Still need to figure out a way to make relative sorting possible
|
||||||
|
helper.css("position", "absolute");
|
||||||
|
|
||||||
return helper;
|
return helper;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_adjustOffsetFromHelper: function(obj) {
|
||||||
|
if(obj.left != undefined) this.offset.click.left = obj.left + this.margins.left;
|
||||||
|
if(obj.right != undefined) this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
|
||||||
|
if(obj.top != undefined) this.offset.click.top = obj.top + this.margins.top;
|
||||||
|
if(obj.bottom != undefined) this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getParentOffset: function() {
|
||||||
|
|
||||||
|
//Get the offsetParent and cache its position
|
||||||
|
this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset();
|
||||||
|
|
||||||
|
if((this.offsetParent[0] == document.body && $.browser.mozilla) //Ugly FF3 fix
|
||||||
|
|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
|
||||||
|
po = { top: 0, left: 0 };
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
|
||||||
|
left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
_getRelativeOffset: function() {
|
||||||
|
|
||||||
|
if(this.cssPosition == "relative") {
|
||||||
|
var p = this.currentItem.position();
|
||||||
|
return {
|
||||||
|
top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
|
||||||
|
left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return { top: 0, left: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
_cacheMargins: function() {
|
||||||
|
this.margins = {
|
||||||
|
left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
|
||||||
|
top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
_cacheHelperProportions: function() {
|
||||||
|
this.helperProportions = {
|
||||||
|
width: this.helper.outerWidth(),
|
||||||
|
height: this.helper.outerHeight()
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
_setContainment: function() {
|
||||||
|
|
||||||
|
var o = this.options;
|
||||||
|
if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
|
||||||
|
if(o.containment == 'document' || o.containment == 'window') this.containment = [
|
||||||
|
0 - this.offset.relative.left - this.offset.parent.left,
|
||||||
|
0 - this.offset.relative.top - this.offset.parent.top,
|
||||||
|
$(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.currentItem.css("marginRight"),10) || 0),
|
||||||
|
($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.currentItem.css("marginBottom"),10) || 0)
|
||||||
|
];
|
||||||
|
|
||||||
|
if(!(/^(document|window|parent)$/).test(o.containment)) {
|
||||||
|
var ce = $(o.containment)[0];
|
||||||
|
var co = $(o.containment).offset();
|
||||||
|
var over = ($(ce).css("overflow") != 'hidden');
|
||||||
|
|
||||||
|
this.containment = [
|
||||||
|
co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left,
|
||||||
|
co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top,
|
||||||
|
co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.currentItem.css("marginRight"),10) || 0),
|
||||||
|
co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.currentItem.css("marginBottom"),10) || 0)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
_convertPositionTo: function(d, pos) {
|
_convertPositionTo: function(d, pos) {
|
||||||
|
|
||||||
if(!pos) pos = this.position;
|
if(!pos) pos = this.position;
|
||||||
var mod = d == "absolute" ? 1 : -1;
|
var mod = d == "absolute" ? 1 : -1;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
top: (
|
top: (
|
||||||
pos.top // the calculated relative position
|
pos.top // the calculated relative position
|
||||||
|
+ this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
|
||||||
+ this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
|
+ this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
|
||||||
- (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) * mod // The offsetParent's scroll position
|
+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'].scrollTop() ) * mod
|
||||||
+ this.margins.top * mod //Add the margin (you don't want the margin counting in intersection methods)
|
+ this.margins.top * mod //Add the margin (you don't want the margin counting in intersection methods)
|
||||||
),
|
),
|
||||||
left: (
|
left: (
|
||||||
pos.left // the calculated relative position
|
pos.left // the calculated relative position
|
||||||
|
+ this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
|
||||||
+ this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
|
+ this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
|
||||||
- (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft) * mod // The offsetParent's scroll position
|
+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'].scrollLeft() ) * mod
|
||||||
+ this.margins.left * mod //Add the margin (you don't want the margin counting in intersection methods)
|
+ this.margins.left * mod //Add the margin (you don't want the margin counting in intersection methods)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
@ -750,19 +745,22 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
|
|
||||||
_generatePosition: function(event) {
|
_generatePosition: function(event) {
|
||||||
|
|
||||||
var o = this.options;
|
var o = this.options, scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
|
||||||
|
|
||||||
var position = {
|
var position = {
|
||||||
top: (
|
top: (
|
||||||
event.pageY // The absolute mouse position
|
event.pageY // The absolute mouse position
|
||||||
- this.offset.click.top // Click offset (relative to the element)
|
- this.offset.click.top // Click offset (relative to the element)
|
||||||
|
- this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
|
||||||
- this.offset.parent.top // The offsetParent's offset without borders (offset + border)
|
- this.offset.parent.top // The offsetParent's offset without borders (offset + border)
|
||||||
+ (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) // The offsetParent's scroll position, not if the element is fixed
|
+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )
|
||||||
),
|
),
|
||||||
left: (
|
left: (
|
||||||
event.pageX // The absolute mouse position
|
event.pageX // The absolute mouse position
|
||||||
- this.offset.click.left // Click offset (relative to the element)
|
- this.offset.click.left // Click offset (relative to the element)
|
||||||
|
- this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
|
||||||
- this.offset.parent.left // The offsetParent's offset without borders (offset + border)
|
- this.offset.parent.left // The offsetParent's offset without borders (offset + border)
|
||||||
+ (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft) // The offsetParent's scroll position, not if the element is fixed
|
+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -816,10 +814,14 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
|
|||||||
if(!this._noFinalSort) this.placeholder.before(this.currentItem);
|
if(!this._noFinalSort) this.placeholder.before(this.currentItem);
|
||||||
this._noFinalSort = null;
|
this._noFinalSort = null;
|
||||||
|
|
||||||
if(this.options.helper == "original")
|
if(this.helper[0] == this.currentItem[0]) {
|
||||||
|
for(var i in this._storedCSS) {
|
||||||
|
if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = '';
|
||||||
|
}
|
||||||
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
|
this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
|
||||||
else
|
} else {
|
||||||
this.currentItem.show();
|
this.currentItem.show();
|
||||||
|
}
|
||||||
|
|
||||||
if(this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._propagate("update", event, null, noPropagation); //Trigger update callback if the DOM position has changed
|
if(this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._propagate("update", event, null, noPropagation); //Trigger update callback if the DOM position has changed
|
||||||
if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
|
if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
|
||||||
@ -886,13 +888,14 @@ $.extend($.ui.sortable, {
|
|||||||
getter: "serialize toArray",
|
getter: "serialize toArray",
|
||||||
version: "@VERSION",
|
version: "@VERSION",
|
||||||
defaults: {
|
defaults: {
|
||||||
accurate: false,
|
accurateIntersection: true,
|
||||||
appendTo: "parent",
|
appendTo: "parent",
|
||||||
cancel: ":input",
|
cancel: ":input",
|
||||||
delay: 0,
|
delay: 0,
|
||||||
distance: 1,
|
distance: 1,
|
||||||
dropOnEmpty: true,
|
dropOnEmpty: true,
|
||||||
forcePlaceholderSize: false,
|
forcePlaceholderSize: false,
|
||||||
|
forceHelperSize: false,
|
||||||
helper: "original",
|
helper: "original",
|
||||||
items: '> *',
|
items: '> *',
|
||||||
scope: "default",
|
scope: "default",
|
||||||
@ -909,14 +912,6 @@ $.extend($.ui.sortable, {
|
|||||||
* Sortable Extensions
|
* Sortable Extensions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.ui.plugin.add("sortable", "axis", {
|
|
||||||
sort: function(event, ui) {
|
|
||||||
var i = $(this).data('sortable'), o = i.options;
|
|
||||||
if(o.axis == "y") i.position.left = i.originalPosition.left;
|
|
||||||
if(o.axis == "x") i.position.top = i.originalPosition.top;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$.ui.plugin.add("sortable", "cursor", {
|
$.ui.plugin.add("sortable", "cursor", {
|
||||||
start: function(event, ui) {
|
start: function(event, ui) {
|
||||||
var t = $('body'), i = $(this).data('sortable');
|
var t = $('body'), i = $(this).data('sortable');
|
||||||
@ -943,47 +938,54 @@ $.ui.plugin.add("sortable", "opacity", {
|
|||||||
|
|
||||||
$.ui.plugin.add("sortable", "scroll", {
|
$.ui.plugin.add("sortable", "scroll", {
|
||||||
start: function(event, ui) {
|
start: function(event, ui) {
|
||||||
var i = $(this).data('sortable'), o = i.options;
|
var o = ui.options;
|
||||||
|
var i = $(this).data("sortable");
|
||||||
|
|
||||||
i.overflowY = function(el) {
|
if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
|
||||||
do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
|
|
||||||
return $(document);
|
|
||||||
}(i.currentItem);
|
|
||||||
i.overflowX = function(el) {
|
|
||||||
do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
|
|
||||||
return $(document);
|
|
||||||
}(i.currentItem);
|
|
||||||
|
|
||||||
if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') i.overflowYOffset = i.overflowY.offset();
|
|
||||||
if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') i.overflowXOffset = i.overflowX.offset();
|
|
||||||
|
|
||||||
},
|
},
|
||||||
sort: function(event, ui) {
|
drag: function(event, ui) {
|
||||||
|
|
||||||
var i = $(this).data('sortable'), o = i.options;
|
var o = ui.options, scrolled = false;
|
||||||
|
var i = $(this).data("sortable");
|
||||||
|
|
||||||
|
if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
|
||||||
|
|
||||||
|
if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
|
||||||
|
i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
|
||||||
|
else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity)
|
||||||
|
i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
|
||||||
|
|
||||||
|
if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
|
||||||
|
i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
|
||||||
|
else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity)
|
||||||
|
i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
|
||||||
|
|
||||||
if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
|
|
||||||
if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - event.pageY < o.scrollSensitivity)
|
|
||||||
i.overflowY[0].scrollTop = i.overflowY[0].scrollTop + o.scrollSpeed;
|
|
||||||
if(event.pageY - i.overflowYOffset.top < o.scrollSensitivity)
|
|
||||||
i.overflowY[0].scrollTop = i.overflowY[0].scrollTop - o.scrollSpeed;
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
|
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
|
||||||
$(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
|
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
|
||||||
if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
|
else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
|
||||||
$(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
|
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
|
||||||
|
|
||||||
|
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
|
||||||
|
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
|
||||||
|
else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
|
||||||
|
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
|
if(scrolled !== false && $.ui.ddmanager)
|
||||||
if((i.overflowXOffset.left + i.overflowX[0].offsetWidth) - event.pageX < o.scrollSensitivity)
|
$.ui.ddmanager.prepareOffsets(i, event);
|
||||||
i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft + o.scrollSpeed;
|
|
||||||
if(event.pageX - i.overflowXOffset.left < o.scrollSensitivity)
|
|
||||||
i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft - o.scrollSpeed;
|
|
||||||
} else {
|
//This is a special case where we need to modify a offset calculated on start, since the following happened:
|
||||||
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
|
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
|
||||||
$(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
|
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
|
||||||
if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
|
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
|
||||||
$(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
|
if(scrolled !== false && i.cssPosition == 'absolute' && i.scrollParent[0] != document && $.ui.contains(i.scrollParent[0], i.offsetParent[0])) {
|
||||||
|
i.offset.parent = i._getParentOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -997,7 +999,7 @@ $.ui.plugin.add("sortable", "zIndex", {
|
|||||||
},
|
},
|
||||||
beforeStop: function(event, ui) {
|
beforeStop: function(event, ui) {
|
||||||
var i = $(this).data('sortable');
|
var i = $(this).data('sortable');
|
||||||
if(i.options._zIndex) $(ui.helper).css('zIndex', i.options._zIndex);
|
if(i.options._zIndex) $(ui.helper).css('zIndex', i.options._zIndex == 'auto' ? '' : i.options._zIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user