From eae805dc0afa5ac3bc6f41fc5013722c342db583 Mon Sep 17 00:00:00 2001 From: yenoh2 Date: Tue, 29 Nov 2016 15:24:36 +0100 Subject: [PATCH 1/2] 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. --- src/sortable.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index bfed173..607adb7 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; } @@ -459,7 +473,7 @@ angular.module('ui.sortable', []) var sortableWidgetInstance = getSortableWidgetInstance(element); if (!!sortableWidgetInstance) { var optsDiff = patchUISortableOptions(newVal, oldVal, sortableWidgetInstance); - + if (optsDiff) { element.sortable('option', optsDiff); } @@ -475,7 +489,7 @@ angular.module('ui.sortable', []) } else { $log.info('ui.sortable: ngModel not provided!', element); } - + // Create sortable element.sortable(opts); } From 37d04d3597898c73481889beb279c5cdd206952b Mon Sep 17 00:00:00 2001 From: yenoh2 Date: Wed, 30 Nov 2016 07:21:25 +0100 Subject: [PATCH 2/2] Correcting linter errors --- src/sortable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sortable.js b/src/sortable.js index 607adb7..311ca8b 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -188,8 +188,10 @@ angular.module('ui.sortable', []) function getElementScope(elementScopes, element) { var result = null; - for (var i = 0; i < elementScopes.length; i++) { - var x = elementScopes[i]; + var x = null; + var i = null; + for (i = 0; i < elementScopes.length; i++) { + x = elementScopes[i]; if (x.element[0] === element[0]) { result = x.scope; break;