diff --git a/src/sortable.js b/src/sortable.js index 7c799d1..3671a15 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -97,7 +97,7 @@ angular.module('ui.sortable', []) } return; } - + if (!defaultOptions) { defaultOptions = angular.element.ui.sortable().options; } @@ -195,6 +195,20 @@ angular.module('ui.sortable', []) break; } } + //If result is still null it means that the draggable (ng-repeat) item isn't a direct child of + //the element containing the ui.sortable directive. This may be required when using the ui.sortable + //directive with other directives that have isolated scopes. This will compare x.element[0] + //with the closest ancestorof element[0] that has the ui-sortable attribute to get the applicable + //element scope. + if (!result) { + for (i = 0; i < elementScopes.length; i++) { + x = elementScopes[i]; + if (x.element[0] === element[0].closest('[ui-sortable]')) { + result = x.scope; + break; + } + } + } return result; } @@ -372,7 +386,6 @@ angular.module('ui.sortable', []) if(!ui.item.sortable.received && ('dropindex' in ui.item.sortable) && !ui.item.sortable.isCanceled()) { - scope.$apply(function () { ngModel.$modelValue.splice( ui.item.sortable.dropindex, 0, @@ -458,7 +471,7 @@ angular.module('ui.sortable', []) var sortableWidgetInstance = getSortableWidgetInstance(element); if (!!sortableWidgetInstance) { var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance); - + if (optsDiff) { element.sortable('option', optsDiff); } @@ -474,7 +487,7 @@ angular.module('ui.sortable', []) } else { $log.info('ui.sortable: ngModel not provided!', element); } - + // Create sortable element.sortable(opts); }