|
31 | 31 | var removed, |
32 | 32 | nextSibling; |
33 | 33 |
|
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 | | - } |
63 | 34 |
|
64 | 35 |
|
65 | 36 | // Export |
66 | 37 | return { |
67 | 38 | restrict: 'AC', |
68 | 39 | scope: { ngSortable: "=?" }, |
69 | 40 | 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 | + |
70 | 71 | var el = $el[0], |
71 | 72 | options = angular.extend(scope.ngSortable || {}, ngSortableConfig), |
72 | 73 | source = getSource(el), |
|
0 commit comments