mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Sortable: Moved helper methods into the widget prototype.
This commit is contained in:
parent
b7e3e4636f
commit
604e0949e3
31
ui/jquery.ui.sortable.js
vendored
31
ui/jquery.ui.sortable.js
vendored
@ -15,14 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
(function( $, undefined ) {
|
(function( $, undefined ) {
|
||||||
|
|
||||||
function isOverAxis( 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",
|
||||||
@ -65,6 +57,15 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
stop: null,
|
stop: null,
|
||||||
update: null
|
update: null
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_isOverAxis: function( x, reference, size ) {
|
||||||
|
return ( x >= reference ) && ( x < ( reference + size ) );
|
||||||
|
},
|
||||||
|
|
||||||
|
_isFloating: function( item ) {
|
||||||
|
return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
|
||||||
|
},
|
||||||
|
|
||||||
_create: function() {
|
_create: function() {
|
||||||
|
|
||||||
var o = this.options;
|
var o = this.options;
|
||||||
@ -75,7 +76,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" || isFloating(this.items[0].item) : false;
|
this.floating = this.items.length ? o.axis === "x" || this._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();
|
||||||
@ -554,8 +555,8 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
_intersectsWithPointer: function(item) {
|
_intersectsWithPointer: function(item) {
|
||||||
|
|
||||||
var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
|
var isOverElementHeight = (this.options.axis === "x") || this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
|
||||||
isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
|
isOverElementWidth = (this.options.axis === "y") || this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
|
||||||
isOverElement = isOverElementHeight && isOverElementWidth,
|
isOverElement = isOverElementHeight && isOverElementWidth,
|
||||||
verticalDirection = this._getDragVerticalDirection(),
|
verticalDirection = this._getDragVerticalDirection(),
|
||||||
horizontalDirection = this._getDragHorizontalDirection();
|
horizontalDirection = this._getDragHorizontalDirection();
|
||||||
@ -572,8 +573,8 @@ $.widget("ui.sortable", $.ui.mouse, {
|
|||||||
|
|
||||||
_intersectsWithSides: function(item) {
|
_intersectsWithSides: function(item) {
|
||||||
|
|
||||||
var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
|
var isOverBottomHalf = this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
|
||||||
isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
|
isOverRightHalf = this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
|
||||||
verticalDirection = this._getDragVerticalDirection(),
|
verticalDirection = this._getDragVerticalDirection(),
|
||||||
horizontalDirection = this._getDragHorizontalDirection();
|
horizontalDirection = this._getDragHorizontalDirection();
|
||||||
|
|
||||||
@ -846,7 +847,7 @@ $.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;
|
||||||
floating = innermostContainer.floating || isFloating(this.currentItem);
|
floating = innermostContainer.floating || this._isFloating(this.currentItem);
|
||||||
posProperty = floating ? "left" : "top";
|
posProperty = floating ? "left" : "top";
|
||||||
sizeProperty = floating ? "width" : "height";
|
sizeProperty = floating ? "width" : "height";
|
||||||
base = this.positionAbs[posProperty] + this.offset.click[posProperty];
|
base = this.positionAbs[posProperty] + this.offset.click[posProperty];
|
||||||
@ -857,7 +858,7 @@ $.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)) {
|
if (floating && !this._isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cur = this.items[j].item.offset()[posProperty];
|
cur = this.items[j].item.offset()[posProperty];
|
||||||
|
Loading…
Reference in New Issue
Block a user