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

Commit c023e32

Browse files
committed
feat(sortable): add support for the case that debugInfo is disabled
1 parent 3dcefe9 commit c023e32

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
@@ -47,6 +47,16 @@ angular.module('ui.sortable', [])
4747
return (/left|right/).test(item.css('float')) || (/inline|table-cell/).test(item.css('display'));
4848
}
4949

50+
function getElementScope(elementScopes, element) {
51+
for (var i = 0; i < elementScopes.length; i++) {
52+
var x = elementScopes[i];
53+
if (x.element[0] === element[0]) {
54+
return x.scope;
55+
}
56+
}
57+
return null;
58+
}
59+
5060
function afterStop(e, ui) {
5161
ui.item.sortable._destroy();
5262
}
@@ -126,7 +136,7 @@ angular.module('ui.sortable', [])
126136
};
127137
};
128138

129-
callbacks.activate = function(/*e, ui*/) {
139+
callbacks.activate = function(e, ui) {
130140
// We need to make a copy of the current element's contents so
131141
// we can restore it after sortable has messed it up.
132142
// This is inside activate (instead of start) in order to save
@@ -151,10 +161,20 @@ angular.module('ui.sortable', [])
151161
// exact match with the placeholder's class attribute to handle
152162
// the case that multiple connected sortables exist and
153163
// the placehoilder option equals the class of sortable items
154-
var excludes = element.find('[class="' + phElement.attr('class') + '"]');
164+
var excludes = element.find('[class="' + phElement.attr('class') + '"]:not([ng-repeat], [data-ng-repeat])');
155165

156166
savedNodes = savedNodes.not(excludes);
157167
}
168+
169+
// save the directive's scope so that it is accessible from ui.item.sortable
170+
var connectedSortables = ui.item.sortable._connectedSortables || [];
171+
172+
connectedSortables.push({
173+
element: element,
174+
scope: scope
175+
});
176+
177+
ui.item.sortable._connectedSortables = connectedSortables;
158178
};
159179

160180
callbacks.update = function(e, ui) {
@@ -165,8 +185,9 @@ angular.module('ui.sortable', [])
165185
ui.item.sortable.dropindex = ui.item.index();
166186
var droptarget = ui.item.parent();
167187
ui.item.sortable.droptarget = droptarget;
168-
var attr = droptarget.attr('ng-model') || droptarget.attr('data-ng-model');
169-
ui.item.sortable.droptargetModel = droptarget.scope().$eval(attr);
188+
189+
var droptargetScope = getElementScope(ui.item.sortable._connectedSortables, droptarget);
190+
ui.item.sortable.droptargetModel = droptargetScope.ngModel;
170191

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

0 commit comments

Comments
 (0)