Skip to content

Commit 604e094

Browse files
committed
Sortable: Moved helper methods into the widget prototype.
1 parent b7e3e46 commit 604e094

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

ui/jquery.ui.sortable.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@
1515
*/
1616
(function( $, undefined ) {
1717

18-
function isOverAxis( x, reference, size ) {
19-
return ( x >= reference ) && ( x < ( reference + size ) );
20-
}
21-
22-
function isFloating(item) {
23-
return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
24-
}
25-
2618
$.widget("ui.sortable", $.ui.mouse, {
2719
version: "@VERSION",
2820
widgetEventPrefix: "sort",
@@ -65,6 +57,15 @@ $.widget("ui.sortable", $.ui.mouse, {
6557
stop: null,
6658
update: null
6759
},
60+
61+
_isOverAxis: function( x, reference, size ) {
62+
return ( x >= reference ) && ( x < ( reference + size ) );
63+
},
64+
65+
_isFloating: function( item ) {
66+
return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
67+
},
68+
6869
_create: function() {
6970

7071
var o = this.options;
@@ -75,7 +76,7 @@ $.widget("ui.sortable", $.ui.mouse, {
7576
this.refresh();
7677

7778
//Let's determine if the items are being displayed horizontally
78-
this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
79+
this.floating = this.items.length ? o.axis === "x" || this._isFloating(this.items[0].item) : false;
7980

8081
//Let's determine the parent's offset
8182
this.offset = this.element.offset();
@@ -554,8 +555,8 @@ $.widget("ui.sortable", $.ui.mouse, {
554555

555556
_intersectsWithPointer: function(item) {
556557

557-
var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
558-
isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
558+
var isOverElementHeight = (this.options.axis === "x") || this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
559+
isOverElementWidth = (this.options.axis === "y") || this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
559560
isOverElement = isOverElementHeight && isOverElementWidth,
560561
verticalDirection = this._getDragVerticalDirection(),
561562
horizontalDirection = this._getDragHorizontalDirection();
@@ -572,8 +573,8 @@ $.widget("ui.sortable", $.ui.mouse, {
572573

573574
_intersectsWithSides: function(item) {
574575

575-
var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
576-
isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
576+
var isOverBottomHalf = this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
577+
isOverRightHalf = this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
577578
verticalDirection = this._getDragVerticalDirection(),
578579
horizontalDirection = this._getDragHorizontalDirection();
579580

@@ -846,7 +847,7 @@ $.widget("ui.sortable", $.ui.mouse, {
846847
//When entering a new container, we will find the item with the least distance and append our item near it
847848
dist = 10000;
848849
itemWithLeastDistance = null;
849-
floating = innermostContainer.floating || isFloating(this.currentItem);
850+
floating = innermostContainer.floating || this._isFloating(this.currentItem);
850851
posProperty = floating ? "left" : "top";
851852
sizeProperty = floating ? "width" : "height";
852853
base = this.positionAbs[posProperty] + this.offset.click[posProperty];
@@ -857,7 +858,7 @@ $.widget("ui.sortable", $.ui.mouse, {
857858
if(this.items[j].item[0] === this.currentItem[0]) {
858859
continue;
859860
}
860-
if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
861+
if (floating && !this._isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
861862
continue;
862863
}
863864
cur = this.items[j].item.offset()[posProperty];

0 commit comments

Comments
 (0)