Skip to content

Commit 5b4737f

Browse files
committed
Update ng-sortable.js
1 parent e912d00 commit 5b4737f

1 file changed

Lines changed: 30 additions & 29 deletions

File tree

ng-sortable.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,43 @@
3131
var removed,
3232
nextSibling;
3333

34-
function getSource(el) {
35-
var scope = angular.element(el).scope();
36-
var ngRepeat = [].filter.call(el.childNodes, function (node) {
37-
return (
38-
(node.nodeType === 8) &&
39-
(node.nodeValue.indexOf('ngRepeat:') !== -1)
40-
);
41-
})[0];
42-
43-
if (!ngRepeat) {
44-
// Without ng-repeat
45-
return null;
46-
}
47-
48-
// tests: http://jsbin.com/kosubutilo/1/edit?js,output
49-
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/);
50-
51-
var itemExpr = $parse(ngRepeat[1]);
52-
var itemsExpr = $parse(ngRepeat[2]);
53-
54-
return {
55-
item: function (el) {
56-
return itemExpr(angular.element(el).scope());
57-
},
58-
items: function () {
59-
return itemsExpr(scope);
60-
}
61-
};
62-
}
6334

6435

6536
// Export
6637
return {
6738
restrict: 'AC',
6839
scope: { ngSortable: "=?" },
6940
link: function (scope, $el, attrs) {
41+
42+
function getSource(el) {
43+
var ngRepeat = [].filter.call(el.childNodes, function (node) {
44+
return (
45+
(node.nodeType === 8) &&
46+
(node.nodeValue.indexOf('ngRepeat:') !== -1)
47+
);
48+
})[0];
49+
50+
if (!ngRepeat) {
51+
// Without ng-repeat
52+
return null;
53+
}
54+
55+
// tests: http://jsbin.com/kosubutilo/1/edit?js,output
56+
ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/);
57+
58+
var itemExpr = $parse(ngRepeat[1]);
59+
var itemsExpr = $parse(ngRepeat[2]);
60+
61+
return {
62+
item: function (el) {
63+
return itemExpr(angular.element(el).scope());
64+
},
65+
items: function () {
66+
return itemsExpr(scope);
67+
}
68+
};
69+
}
70+
7071
var el = $el[0],
7172
options = angular.extend(scope.ngSortable || {}, ngSortableConfig),
7273
source = getSource(el),

0 commit comments

Comments
 (0)