From 699243dc5e7925eb41a4d585a3bd2211e130d774 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Fri, 16 Jan 2015 07:38:43 +0200 Subject: [PATCH] fix(sortable): restore support for jquery 1.10 Fixes #316 and properly fixes #313. --- src/sortable.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index 8487ad8..400ee15 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -27,6 +27,16 @@ angular.module('ui.sortable', []) return first; } + function getSortableWidgetInstance(element) { + // this is a fix to support jquery-ui prior to v1.11.x + // otherwise we should be using `element.sortable('instance')` + var data = element.data('ui-sortable'); + if (data && typeof data === 'object' && data.widgetFullName === 'ui-sortable') { + return data; + } + return null; + } + function hasSortingHelper (element, ui) { var helperOption = element.sortable('option','helper'); return helperOption === 'clone' || (typeof helperOption === 'function' && ui.item.sortable.isCustomHelperUsed()); @@ -76,7 +86,7 @@ angular.module('ui.sortable', []) $timeout(function() { // ensure that the jquery-ui-sortable widget instance // is still bound to the directive's element - if (!!element.sortable('instance')) { + if (!!getSortableWidgetInstance(element)) { element.sortable('refresh'); } }, 0, false); @@ -87,7 +97,8 @@ angular.module('ui.sortable', []) // since the drag has started, the element will be // absolutely positioned, so we check its siblings var siblings = ui.item.siblings(); - angular.element(e.target).sortable('instance').floating = isFloating(siblings); + var sortableWidgetInstance = getSortableWidgetInstance(angular.element(e.target)); + sortableWidgetInstance.floating = isFloating(siblings); } // Save the starting position of dragged item @@ -263,13 +274,14 @@ angular.module('ui.sortable', []) scope.$watch('uiSortable', function(newVal /*, oldVal*/) { // ensure that the jquery-ui-sortable widget instance // is still bound to the directive's element - if (!!element.sortable('instance')) { + var sortableWidgetInstance = getSortableWidgetInstance(element); + if (!!sortableWidgetInstance) { angular.forEach(newVal, function(value, key) { // if it's a custom option of the directive, // handle it approprietly if (key in directiveOpts) { if (key === 'ui-floating' && (value === false || value === true)) { - element.sortable('instance').floating = value; + sortableWidgetInstance.floating = value; } opts[key] = value;