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

fix(sortable): restore support for jquery 1.10 #319

Merged
merged 1 commit into from
Jan 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down