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

Commit eae805d

Browse files
authored
Fixed to work with deep descendants
modifies the sortable.js file at line 198, in order for the ui-sortable directive to work on other directives that have isolated scopes.
1 parent 57c5021 commit eae805d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/sortable.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ angular.module('ui.sortable', [])
9797
}
9898
return;
9999
}
100-
100+
101101
if (!defaultOptions) {
102102
defaultOptions = angular.element.ui.sortable().options;
103103
}
@@ -195,6 +195,20 @@ angular.module('ui.sortable', [])
195195
break;
196196
}
197197
}
198+
//If result is still null it means that the draggable (ng-repeat) item isn't a direct child of
199+
//the element containing the ui.sortable directive. This may be required when using the ui.sortable
200+
//directive with other directives that have isolated scopes. This will compare x.element[0]
201+
//with the closest ancestorof element[0] that has the ui-sortable attribute to get the applicable
202+
//element scope.
203+
if (!result) {
204+
for (i = 0; i < elementScopes.length; i++) {
205+
x = elementScopes[i];
206+
if (x.element[0] === element[0].closest('[ui-sortable]')) {
207+
result = x.scope;
208+
break;
209+
}
210+
}
211+
}
198212
return result;
199213
}
200214

@@ -459,7 +473,7 @@ angular.module('ui.sortable', [])
459473
var sortableWidgetInstance = getSortableWidgetInstance(element);
460474
if (!!sortableWidgetInstance) {
461475
var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance);
462-
476+
463477
if (optsDiff) {
464478
element.sortable('option', optsDiff);
465479
}
@@ -475,7 +489,7 @@ angular.module('ui.sortable', [])
475489
} else {
476490
$log.info('ui.sortable: ngModel not provided!', element);
477491
}
478-
492+
479493
// Create sortable
480494
element.sortable(opts);
481495
}

0 commit comments

Comments
 (0)