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

Commit fd8238f

Browse files
committed
refactor: change getElementScope to retireve the whole context
1 parent c3232eb commit fd8238f

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

src/sortable.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,13 @@ angular.module('ui.sortable', [])
186186
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
187187
}
188188

189-
function getElementScope(elementScopes, element) {
190-
var result = null;
191-
var x = null;
192-
var i = null;
193-
for (i = 0; i < elementScopes.length; i++) {
194-
x = elementScopes[i];
195-
if (x.element[0] === element[0]) {
196-
result = x.scope;
197-
break;
189+
function getElementContext(elementScopes, element) {
190+
for (var i = 0; i < elementScopes.length; i++) {
191+
var c = elementScopes[i];
192+
if (c.element[0] === element[0]) {
193+
return c;
198194
}
199195
}
200-
//If result is still null it means that the draggable (ng-repeat) item isn't a direct child of
201-
//the element containing the ui.sortable directive. This may be required when using the ui.sortable
202-
//directive with other directives that have isolated scopes. This will compare x.element[0]
203-
//with the closest ancestorof element[0] that has the ui-sortable attribute to get the applicable
204-
//element scope.
205-
if (!result) {
206-
for (i = 0; i < elementScopes.length; i++) {
207-
x = elementScopes[i];
208-
if (x.element[0] === element[0].closest('[ui-sortable]')) {
209-
result = x.scope;
210-
break;
211-
}
212-
}
213-
}
214-
return result;
215196
}
216197

217198
function afterStop(e, ui) {
@@ -338,8 +319,8 @@ angular.module('ui.sortable', [])
338319
var droptarget = ui.item.closest('[ui-sortable]');
339320
ui.item.sortable.droptarget = droptarget;
340321

341-
var droptargetScope = getElementScope(ui.item.sortable._connectedSortables, droptarget);
342-
ui.item.sortable.droptargetModel = droptargetScope.ngModel;
322+
var droptargetContext = getElementContext(ui.item.sortable._connectedSortables, droptarget);
323+
ui.item.sortable.droptargetModel = droptargetContext.scope.ngModel;
343324

344325
// Cancel the sort (let ng-repeat do the sort for us)
345326
// Don't cancel if this is the received list because it has

0 commit comments

Comments
 (0)