|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 | 4 | angular.module('ui.tree')
|
5 |
| - .directive('uiTree', [ 'treeConfig', '$window', |
6 |
| - function(treeConfig, $window) { |
7 |
| - return { |
8 |
| - restrict: 'A', |
9 |
| - scope: true, |
10 |
| - controller: 'TreeController', |
11 |
| - link: function(scope, element, attrs) { |
12 |
| - var callbacks = { |
13 |
| - accept: null, |
14 |
| - beforeDrag: null |
15 |
| - }; |
16 |
| - |
17 |
| - var config = {}; |
18 |
| - angular.extend(config, treeConfig); |
19 |
| - if (config.treeClass) { |
20 |
| - element.addClass(config.treeClass); |
21 |
| - } |
22 |
| - |
23 |
| - scope.$emptyElm = angular.element($window.document.createElement('div')); |
24 |
| - if (config.emptyTreeClass) { |
25 |
| - scope.$emptyElm.addClass(config.emptyTreeClass); |
26 |
| - } |
27 |
| - |
28 |
| - scope.$watch('$nodesScope.$modelValue.length', function() { |
29 |
| - if (scope.$nodesScope.$modelValue) { |
30 |
| - scope.resetEmptyElement(); |
| 5 | + .directive('uiTree', ['treeConfig', '$window', |
| 6 | + function (treeConfig, $window) { |
| 7 | + return { |
| 8 | + restrict: 'A', |
| 9 | + scope: true, |
| 10 | + controller: 'TreeController', |
| 11 | + link: function (scope, element, attrs) { |
| 12 | + var callbacks = { |
| 13 | + accept: null, |
| 14 | + beforeDrag: null |
| 15 | + }; |
| 16 | + |
| 17 | + var config = {}; |
| 18 | + angular.extend(config, treeConfig); |
| 19 | + if (config.treeClass) { |
| 20 | + element.addClass(config.treeClass); |
31 | 21 | }
|
32 |
| - }, true); |
33 | 22 |
|
34 |
| - scope.$watch(attrs.dragEnabled, function(val) { |
35 |
| - if((typeof val) == "boolean") { |
36 |
| - scope.dragEnabled = val; |
| 23 | + scope.$emptyElm = angular.element($window.document.createElement('div')); |
| 24 | + if (config.emptyTreeClass) { |
| 25 | + scope.$emptyElm.addClass(config.emptyTreeClass); |
37 | 26 | }
|
38 |
| - }); |
39 | 27 |
|
40 |
| - scope.$watch(attrs.emptyPlaceHolderEnabled, function(val) { |
41 |
| - if((typeof val) == "boolean") { |
42 |
| - scope.emptyPlaceHolderEnabled = val; |
43 |
| - } |
44 |
| - }); |
| 28 | + scope.$watch('$nodesScope.$modelValue.length', function () { |
| 29 | + if (scope.$nodesScope.$modelValue) { |
| 30 | + scope.resetEmptyElement(); |
| 31 | + } |
| 32 | + }, true); |
45 | 33 |
|
46 |
| - scope.$watch(attrs.nodropEnabled, function(val) { |
47 |
| - if((typeof val) == "boolean") { |
48 |
| - scope.nodropEnabled = val; |
49 |
| - } |
50 |
| - }); |
| 34 | + scope.$watch(attrs.dragEnabled, function (val) { |
| 35 | + if ((typeof val) == "boolean") { |
| 36 | + scope.dragEnabled = val; |
| 37 | + } |
| 38 | + }); |
51 | 39 |
|
52 |
| - scope.$watch(attrs.cloneEnabled, function(val) { |
53 |
| - if((typeof val) == "boolean") { |
54 |
| - scope.cloneEnabled = val; |
55 |
| - } |
56 |
| - }); |
| 40 | + scope.$watch(attrs.emptyPlaceHolderEnabled, function (val) { |
| 41 | + if ((typeof val) == "boolean") { |
| 42 | + scope.emptyPlaceHolderEnabled = val; |
| 43 | + } |
| 44 | + }); |
57 | 45 |
|
58 |
| - scope.$watch(attrs.maxDepth, function(val) { |
59 |
| - if((typeof val) == "number") { |
60 |
| - scope.maxDepth = val; |
61 |
| - } |
62 |
| - }); |
| 46 | + scope.$watch(attrs.nodropEnabled, function (val) { |
| 47 | + if ((typeof val) == "boolean") { |
| 48 | + scope.nodropEnabled = val; |
| 49 | + } |
| 50 | + }); |
63 | 51 |
|
64 |
| - scope.$watch(attrs.dragDelay, function(val) { |
65 |
| - if((typeof val) == "number") { |
66 |
| - scope.dragDelay = val; |
67 |
| - } |
68 |
| - }); |
69 |
| - |
70 |
| - // check if the dest node can accept the dragging node |
71 |
| - // by default, we check the 'data-nodrop-enabled' attribute in `ui-tree-nodes` |
72 |
| - // and the 'max-depth' attribute in `ui-tree` or `ui-tree-nodes`. |
73 |
| - // the method can be overrided |
74 |
| - callbacks.accept = function(sourceNodeScope, destNodesScope, destIndex) { |
75 |
| - if (destNodesScope.nodropEnabled || destNodesScope.outOfDepth(sourceNodeScope)) { |
76 |
| - return false; |
77 |
| - } |
78 |
| - return true; |
79 |
| - }; |
| 52 | + scope.$watch(attrs.cloneEnabled, function (val) { |
| 53 | + if ((typeof val) == "boolean") { |
| 54 | + scope.cloneEnabled = val; |
| 55 | + } |
| 56 | + }); |
80 | 57 |
|
81 |
| - callbacks.beforeDrag = function(sourceNodeScope) { |
82 |
| - return true; |
83 |
| - }; |
| 58 | + scope.$watch(attrs.maxDepth, function (val) { |
| 59 | + if ((typeof val) == "number") { |
| 60 | + scope.maxDepth = val; |
| 61 | + } |
| 62 | + }); |
84 | 63 |
|
85 |
| - callbacks.removed = function(node){ |
86 |
| - |
87 |
| - }; |
| 64 | + scope.$watch(attrs.dragDelay, function (val) { |
| 65 | + if ((typeof val) == "number") { |
| 66 | + scope.dragDelay = val; |
| 67 | + } |
| 68 | + }); |
88 | 69 |
|
89 |
| - callbacks.dropped = function(event) { |
| 70 | + // check if the dest node can accept the dragging node |
| 71 | + // by default, we check the 'data-nodrop-enabled' attribute in `ui-tree-nodes` |
| 72 | + // and the 'max-depth' attribute in `ui-tree` or `ui-tree-nodes`. |
| 73 | + // the method can be overrided |
| 74 | + callbacks.accept = function (sourceNodeScope, destNodesScope, destIndex) { |
| 75 | + if (destNodesScope.nodropEnabled || destNodesScope.outOfDepth(sourceNodeScope)) { |
| 76 | + return false; |
| 77 | + } |
| 78 | + return true; |
| 79 | + }; |
90 | 80 |
|
91 |
| - }; |
| 81 | + callbacks.beforeDrag = function (sourceNodeScope) { |
| 82 | + return true; |
| 83 | + }; |
92 | 84 |
|
93 |
| - // |
94 |
| - callbacks.dragStart = function(event) { |
| 85 | + callbacks.removed = function (node) { |
95 | 86 |
|
96 |
| - }; |
| 87 | + }; |
97 | 88 |
|
98 |
| - callbacks.dragMove = function(event) { |
| 89 | + callbacks.dropped = function (event) { |
99 | 90 |
|
100 |
| - }; |
| 91 | + }; |
101 | 92 |
|
102 |
| - callbacks.dragStop = function(event) { |
| 93 | + callbacks.dragStart = function (event) { |
103 | 94 |
|
104 |
| - }; |
| 95 | + }; |
105 | 96 |
|
106 |
| - callbacks.beforeDrop = function(event) { |
| 97 | + callbacks.dragMove = function (event) { |
107 | 98 |
|
108 |
| - }; |
| 99 | + }; |
109 | 100 |
|
110 |
| - scope.$watch(attrs.uiTree, function(newVal, oldVal){ |
111 |
| - angular.forEach(newVal, function(value, key){ |
112 |
| - if (callbacks[key]) { |
113 |
| - if (typeof value === "function") { |
114 |
| - callbacks[key] = value; |
| 101 | + callbacks.dragStop = function (event) { |
| 102 | + |
| 103 | + }; |
| 104 | + |
| 105 | + callbacks.beforeDrop = function (event) { |
| 106 | + |
| 107 | + }; |
| 108 | + |
| 109 | + scope.$watch(attrs.uiTree, function (newVal, oldVal) { |
| 110 | + angular.forEach(newVal, function (value, key) { |
| 111 | + if (callbacks[key]) { |
| 112 | + if (typeof value === "function") { |
| 113 | + callbacks[key] = value; |
| 114 | + } |
115 | 115 | }
|
116 |
| - } |
117 |
| - }); |
| 116 | + }); |
118 | 117 |
|
119 |
| - scope.$callbacks = callbacks; |
120 |
| - }, true); |
| 118 | + scope.$callbacks = callbacks; |
| 119 | + }, true); |
121 | 120 |
|
122 | 121 |
|
123 |
| - } |
124 |
| - }; |
125 |
| - } |
126 |
| - ]); |
| 122 | + } |
| 123 | + }; |
| 124 | + } |
| 125 | + ]); |
127 | 126 | })();
|
0 commit comments