Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 4ccc37a

Browse files
committed
Merge pull request #319 from thgreasi/master
fix(sortable): restore support for jquery 1.10
2 parents a723311 + 699243d commit 4ccc37a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/sortable.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ angular.module('ui.sortable', [])
2727
return first;
2828
}
2929

30+
function getSortableWidgetInstance(element) {
31+
// this is a fix to support jquery-ui prior to v1.11.x
32+
// otherwise we should be using `element.sortable('instance')`
33+
var data = element.data('ui-sortable');
34+
if (data && typeof data === 'object' && data.widgetFullName === 'ui-sortable') {
35+
return data;
36+
}
37+
return null;
38+
}
39+
3040
function hasSortingHelper (element, ui) {
3141
var helperOption = element.sortable('option','helper');
3242
return helperOption === 'clone' || (typeof helperOption === 'function' && ui.item.sortable.isCustomHelperUsed());
@@ -76,7 +86,7 @@ angular.module('ui.sortable', [])
7686
$timeout(function() {
7787
// ensure that the jquery-ui-sortable widget instance
7888
// is still bound to the directive's element
79-
if (!!element.sortable('instance')) {
89+
if (!!getSortableWidgetInstance(element)) {
8090
element.sortable('refresh');
8191
}
8292
}, 0, false);
@@ -87,7 +97,8 @@ angular.module('ui.sortable', [])
8797
// since the drag has started, the element will be
8898
// absolutely positioned, so we check its siblings
8999
var siblings = ui.item.siblings();
90-
angular.element(e.target).sortable('instance').floating = isFloating(siblings);
100+
var sortableWidgetInstance = getSortableWidgetInstance(angular.element(e.target));
101+
sortableWidgetInstance.floating = isFloating(siblings);
91102
}
92103

93104
// Save the starting position of dragged item
@@ -263,13 +274,14 @@ angular.module('ui.sortable', [])
263274
scope.$watch('uiSortable', function(newVal /*, oldVal*/) {
264275
// ensure that the jquery-ui-sortable widget instance
265276
// is still bound to the directive's element
266-
if (!!element.sortable('instance')) {
277+
var sortableWidgetInstance = getSortableWidgetInstance(element);
278+
if (!!sortableWidgetInstance) {
267279
angular.forEach(newVal, function(value, key) {
268280
// if it's a custom option of the directive,
269281
// handle it approprietly
270282
if (key in directiveOpts) {
271283
if (key === 'ui-floating' && (value === false || value === true)) {
272-
element.sortable('instance').floating = value;
284+
sortableWidgetInstance.floating = value;
273285
}
274286

275287
opts[key] = value;

0 commit comments

Comments
 (0)