Skip to content

Commit 61e06a0

Browse files
committed
Sortable: Support hash, array, string for cursorAt option. Partial fix for #2525 - Standardised way to pass coordinates to plugins.
1 parent ec4d469 commit 61e06a0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

ui/ui.sortable.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
132132
this.originalPageY = event.pageY;
133133

134134
//Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
135-
if(o.cursorAt)
136-
this._adjustOffsetFromHelper(o.cursorAt);
135+
(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
137136

138137
//Cache the former DOM position
139138
this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
@@ -724,10 +723,24 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
724723
},
725724

726725
_adjustOffsetFromHelper: function(obj) {
727-
if(obj.left != undefined) this.offset.click.left = obj.left + this.margins.left;
728-
if(obj.right != undefined) this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
729-
if(obj.top != undefined) this.offset.click.top = obj.top + this.margins.top;
730-
if(obj.bottom != undefined) this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
726+
if (typeof obj == 'string') {
727+
obj = obj.split(' ');
728+
}
729+
if ($.isArray(obj)) {
730+
obj = {left: +obj[0], top: +obj[1] || 0};
731+
}
732+
if ('left' in obj) {
733+
this.offset.click.left = obj.left + this.margins.left;
734+
}
735+
if ('right' in obj) {
736+
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
737+
}
738+
if ('top' in obj) {
739+
this.offset.click.top = obj.top + this.margins.top;
740+
}
741+
if ('bottom' in obj) {
742+
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
743+
}
731744
},
732745

733746
_getParentOffset: function() {

0 commit comments

Comments
 (0)