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

Commit c4eae05

Browse files
committed
feat(sortable): add support for the case that debugInfo is disabled
1 parent 162c45d commit c4eae05

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/sortable.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ angular.module('ui.sortable', [])
3737
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
3838
}
3939

40+
function getElementScope(elementScopes, element) {
41+
for (var i = 0; i < elementScopes.length; i++) {
42+
var x = elementScopes[i];
43+
if (x.element[0] === element[0]) {
44+
return x.scope;
45+
}
46+
}
47+
return null;
48+
}
49+
4050
function afterStop(e, ui) {
4151
ui.item.sortable._destroy();
4252
}
@@ -115,7 +125,7 @@ angular.module('ui.sortable', [])
115125
};
116126
};
117127

118-
callbacks.activate = function(/*e, ui*/) {
128+
callbacks.activate = function(e, ui) {
119129
// We need to make a copy of the current element's contents so
120130
// we can restore it after sortable has messed it up.
121131
// This is inside activate (instead of start) in order to save
@@ -140,10 +150,20 @@ angular.module('ui.sortable', [])
140150
// exact match with the placeholder's class attribute to handle
141151
// the case that multiple connected sortables exist and
142152
// the placehoilder option equals the class of sortable items
143-
var excludes = element.find('[class="' + phElement.attr('class') + '"]');
153+
var excludes = element.find('[class="' + phElement.attr('class') + '"]:not([ng-repeat], [data-ng-repeat])');
144154

145155
savedNodes = savedNodes.not(excludes);
146156
}
157+
158+
// save the directive's scope so that it is accessible from ui.item.sortable
159+
var connectedSortables = ui.item.sortable._connectedSortables || [];
160+
161+
connectedSortables.push({
162+
element: element,
163+
scope: scope
164+
});
165+
166+
ui.item.sortable._connectedSortables = connectedSortables;
147167
};
148168

149169
callbacks.update = function(e, ui) {
@@ -154,8 +174,9 @@ angular.module('ui.sortable', [])
154174
ui.item.sortable.dropindex = ui.item.index();
155175
var droptarget = ui.item.parent();
156176
ui.item.sortable.droptarget = droptarget;
157-
var attr = droptarget.attr('ng-model') || droptarget.attr('data-ng-model');
158-
ui.item.sortable.droptargetModel = droptarget.scope().$eval(attr);
177+
178+
var droptargetScope = getElementScope(ui.item.sortable._connectedSortables, droptarget);
179+
ui.item.sortable.droptargetModel = droptargetScope.ngModel;
159180

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

0 commit comments

Comments
 (0)