kms 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/kms/application/controllers/pages_controller.coffee.erb +1 -2
  3. data/app/assets/javascripts/templates/assets/index.html.slim +4 -12
  4. data/app/assets/javascripts/templates/help/scopes.html.slim +74 -0
  5. data/app/assets/javascripts/templates/pages/index.html.slim +4 -3
  6. data/app/assets/javascripts/templates/snippets/index.html.slim +4 -3
  7. data/app/assets/javascripts/templates/templates/index.html.slim +4 -3
  8. data/app/assets/javascripts/templates/users/index.html.slim +3 -2
  9. data/app/assets/stylesheets/kms/custom.css.scss +3 -0
  10. data/app/controllers/kms/pages_controller.rb +2 -2
  11. data/app/models/ability.rb +0 -1
  12. data/app/models/concerns/kms/positioned.rb +18 -0
  13. data/app/models/kms/page.rb +2 -12
  14. data/app/services/kms/functions_registry.rb +11 -0
  15. data/app/uploaders/kms/asset_uploader.rb +1 -1
  16. data/config/initializers/help.rb +1 -1
  17. data/config/initializers/liquor.rb +0 -47
  18. data/config/locales/en.yml +22 -0
  19. data/config/locales/ru.yml +22 -0
  20. data/lib/generators/kms/install/install_generator.rb +2 -0
  21. data/lib/generators/kms/install/templates/carrierwave.rb +14 -0
  22. data/lib/kms/dependencies.rb +2 -0
  23. data/lib/kms/engine.rb +1 -1
  24. data/lib/kms/version.rb +1 -1
  25. data/spec/controllers/kms/snippets_controller_spec.rb +6 -6
  26. data/spec/internal/log/test.log +2439 -0
  27. data/spec/services/kms/functions_registry_spec.rb +14 -0
  28. data/spec/spec_helper.rb +1 -1
  29. data/vendor/assets/bower.json +1 -1
  30. data/vendor/assets/bower_components/angular-ui-tree/CHANGELOG.md +164 -0
  31. data/vendor/assets/bower_components/angular-ui-tree/CONTRIBUTING.md +39 -0
  32. data/vendor/assets/bower_components/angular-ui-tree/README.md +145 -37
  33. data/vendor/assets/bower_components/angular-ui-tree/bower.json +28 -18
  34. data/vendor/assets/bower_components/angular-ui-tree/{source → dist}/angular-ui-tree.css +18 -16
  35. data/vendor/assets/bower_components/angular-ui-tree/dist/angular-ui-tree.js +1408 -822
  36. data/vendor/assets/bower_components/angular-ui-tree/dist/angular-ui-tree.min.css +1 -2
  37. data/vendor/assets/bower_components/angular-ui-tree/dist/angular-ui-tree.min.js +3 -3
  38. data/vendor/assets/bower_components/angular-ui-tree/e2e/basic-example/basic-example.js +81 -0
  39. data/vendor/assets/bower_components/angular-ui-tree/e2e/basic-example/page.js +42 -0
  40. data/vendor/assets/bower_components/angular-ui-tree/e2e/table-example/page.js +31 -0
  41. data/vendor/assets/bower_components/angular-ui-tree/e2e/table-example/table-example.js +34 -0
  42. data/vendor/assets/bower_components/angular-ui-tree/index.js +2 -0
  43. data/vendor/assets/bower_components/angular-ui-tree/protractor.conf.js +19 -0
  44. data/vendor/assets/bower_components/angular/angular.js +4880 -2111
  45. data/vendor/assets/bower_components/angular/angular.min.js +320 -297
  46. data/vendor/assets/bower_components/angular/angular.min.js.gzip +0 -0
  47. data/vendor/assets/bower_components/angular/angular.min.js.map +3 -3
  48. data/vendor/assets/bower_components/angular/bower.json +1 -1
  49. data/vendor/assets/bower_components/angular/package.json +1 -1
  50. metadata +32 -40
  51. data/vendor/assets/bower_components/angular-ui-tree/Gruntfile.js +0 -229
  52. data/vendor/assets/bower_components/angular-ui-tree/build/compiler.jar +0 -0
  53. data/vendor/assets/bower_components/angular-ui-tree/demo/css/demo-horizontal.css +0 -47
  54. data/vendor/assets/bower_components/angular-ui-tree/demo/css/demo.css +0 -31
  55. data/vendor/assets/bower_components/angular-ui-tree/demo/css/tree.css +0 -25
  56. data/vendor/assets/bower_components/angular-ui-tree/demo/dist/angular-ui-tree.js +0 -1243
  57. data/vendor/assets/bower_components/angular-ui-tree/demo/dist/angular-ui-tree.min.css +0 -2
  58. data/vendor/assets/bower_components/angular-ui-tree/demo/dist/angular-ui-tree.min.js +0 -6
  59. data/vendor/assets/bower_components/angular-ui-tree/demo/filter.html +0 -64
  60. data/vendor/assets/bower_components/angular-ui-tree/demo/groups.html +0 -100
  61. data/vendor/assets/bower_components/angular-ui-tree/demo/index.html +0 -101
  62. data/vendor/assets/bower_components/angular-ui-tree/demo/js/demo.js +0 -63
  63. data/vendor/assets/bower_components/angular-ui-tree/demo/js/filter.js +0 -91
  64. data/vendor/assets/bower_components/angular-ui-tree/demo/js/groups.js +0 -143
  65. data/vendor/assets/bower_components/angular-ui-tree/demo/js/tree.js +0 -102
  66. data/vendor/assets/bower_components/angular-ui-tree/demo/js/trees.js +0 -60
  67. data/vendor/assets/bower_components/angular-ui-tree/demo/test.html +0 -60
  68. data/vendor/assets/bower_components/angular-ui-tree/demo/tree-horizontal.html +0 -66
  69. data/vendor/assets/bower_components/angular-ui-tree/demo/tree.html +0 -66
  70. data/vendor/assets/bower_components/angular-ui-tree/demo/trees.html +0 -92
  71. data/vendor/assets/bower_components/angular-ui-tree/guide/00_usage.ngdoc +0 -78
  72. data/vendor/assets/bower_components/angular-ui-tree/guide/01_development_setup.ngdoc +0 -58
  73. data/vendor/assets/bower_components/angular-ui-tree/guide/index.ngdoc +0 -33
  74. data/vendor/assets/bower_components/angular-ui-tree/karma.conf.js +0 -49
  75. data/vendor/assets/bower_components/angular-ui-tree/package.json +0 -40
  76. data/vendor/assets/bower_components/angular-ui-tree/source/angular-ui-tree.scss +0 -63
  77. data/vendor/assets/bower_components/angular-ui-tree/source/controllers/handleCtrl.js +0 -16
  78. data/vendor/assets/bower_components/angular-ui-tree/source/controllers/nodeCtrl.js +0 -141
  79. data/vendor/assets/bower_components/angular-ui-tree/source/controllers/nodesCtrl.js +0 -100
  80. data/vendor/assets/bower_components/angular-ui-tree/source/controllers/treeCtrl.js +0 -63
  81. data/vendor/assets/bower_components/angular-ui-tree/source/directives/uiTree.js +0 -115
  82. data/vendor/assets/bower_components/angular-ui-tree/source/directives/uiTreeHandle.js +0 -27
  83. data/vendor/assets/bower_components/angular-ui-tree/source/directives/uiTreeNode.js +0 -427
  84. data/vendor/assets/bower_components/angular-ui-tree/source/directives/uiTreeNodes.js +0 -59
  85. data/vendor/assets/bower_components/angular-ui-tree/source/main.js +0 -23
  86. data/vendor/assets/bower_components/angular-ui-tree/source/services/helper.js +0 -265
@@ -1,31 +0,0 @@
1
-
2
- .btn {
3
- margin-right: 8px;
4
- }
5
-
6
- .angular-ui-tree-handle {
7
- background: #f8faff;
8
- border: 1px solid #dae2ea;
9
- color: #7c9eb2;
10
- padding: 10px 10px;
11
- }
12
-
13
- .angular-ui-tree-handle:hover {
14
- color: #438eb9;
15
- background: #f4f6f7;
16
- border-color: #dce2e8;
17
- }
18
-
19
- .angular-ui-tree-placeholder {
20
- background: #f0f9ff;
21
- border: 2px dashed #bed2db;
22
- -webkit-box-sizing: border-box;
23
- -moz-box-sizing: border-box;
24
- box-sizing: border-box;
25
- }
26
-
27
-
28
- .group-title {
29
- background-color: #687074 !important;
30
- color: #FFF !important;
31
- }
@@ -1,25 +0,0 @@
1
- .tree-node {
2
- border: 1px solid #dae2ea;
3
- background: #f8faff;
4
- color: #7c9eb2;
5
- }
6
- .tree-node-content {
7
- margin: 10px;
8
- }
9
- .tree-handle {
10
- padding: 10px;
11
- background: #428bca;
12
- color: #FFF;
13
- margin-right: 10px;
14
- }
15
-
16
- .angular-ui-tree-handle:hover {
17
- }
18
-
19
- .angular-ui-tree-placeholder {
20
- background: #f0f9ff;
21
- border: 2px dashed #bed2db;
22
- -webkit-box-sizing: border-box;
23
- -moz-box-sizing: border-box;
24
- box-sizing: border-box;
25
- }
@@ -1,1243 +0,0 @@
1
- /**
2
- * @license Angular UI Tree v2.1.5
3
- * (c) 2010-2014. https://github.com/JimLiu/angular-ui-tree
4
- * License: MIT
5
- */
6
- (function () {
7
- 'use strict';
8
-
9
- angular.module('ui.tree', [])
10
- .constant('treeConfig', {
11
- treeClass: 'angular-ui-tree',
12
- emptyTreeClass: 'angular-ui-tree-empty',
13
- hiddenClass: 'angular-ui-tree-hidden',
14
- nodesClass: 'angular-ui-tree-nodes',
15
- nodeClass: 'angular-ui-tree-node',
16
- handleClass: 'angular-ui-tree-handle',
17
- placeHolderClass: 'angular-ui-tree-placeholder',
18
- dragClass: 'angular-ui-tree-drag',
19
- dragThreshold: 3,
20
- levelThreshold: 30
21
- });
22
-
23
- })();
24
-
25
- (function () {
26
- 'use strict';
27
-
28
- angular.module('ui.tree')
29
-
30
- /**
31
- * @ngdoc service
32
- * @name ui.tree.service:$helper
33
- * @requires ng.$document
34
- * @requires ng.$window
35
- *
36
- * @description
37
- * angular-ui-tree.
38
- */
39
- .factory('$uiTreeHelper', ['$document', '$window',
40
- function ($document, $window) {
41
- return {
42
-
43
- /**
44
- * A hashtable used to storage data of nodes
45
- * @type {Object}
46
- */
47
- nodesData: {
48
- },
49
-
50
- setNodeAttribute: function(scope, attrName, val) {
51
- var data = this.nodesData[scope.$modelValue.$$hashKey];
52
- if (!data) {
53
- data = {};
54
- this.nodesData[scope.$modelValue.$$hashKey] = data;
55
- }
56
- data[attrName] = val;
57
- },
58
-
59
- getNodeAttribute: function(scope, attrName) {
60
- var data = this.nodesData[scope.$modelValue.$$hashKey];
61
- if (data) {
62
- return data[attrName];
63
- }
64
- return null;
65
- },
66
-
67
- /**
68
- * @ngdoc method
69
- * @methodOf ui.tree.service:$nodrag
70
- * @param {Object} targetElm angular element
71
- * @return {Bool} check if the node can be dragged.
72
- */
73
- nodrag: function (targetElm) {
74
- return (typeof targetElm.attr('data-nodrag')) != "undefined";
75
- },
76
-
77
- /**
78
- * get the event object for touchs
79
- * @param {[type]} e [description]
80
- * @return {[type]} [description]
81
- */
82
- eventObj: function(e) {
83
- var obj = e;
84
- if (e.targetTouches !== undefined) {
85
- obj = e.targetTouches.item(0);
86
- } else if (e.originalEvent !== undefined && e.originalEvent.targetTouches !== undefined) {
87
- obj = e.originalEvent.targetTouches.item(0);
88
- }
89
- return obj;
90
- },
91
-
92
- dragInfo: function(node) {
93
- return {
94
- source: node,
95
- sourceInfo: {
96
- nodeScope: node,
97
- index: node.index(),
98
- nodesScope: node.$parentNodesScope
99
- },
100
- index: node.index(),
101
- siblings: node.siblings().slice(0),
102
- parent: node.$parentNodesScope,
103
-
104
- moveTo: function(parent, siblings, index) { // Move the node to a new position
105
- this.parent = parent;
106
- this.siblings = siblings.slice(0);
107
- var i = this.siblings.indexOf(this.source); // If source node is in the target nodes
108
- if (i > -1) {
109
- this.siblings.splice(i, 1);
110
- if (this.source.index() < index) {
111
- index--;
112
- }
113
- }
114
- this.siblings.splice(index, 0, this.source);
115
- this.index = index;
116
- },
117
-
118
- parentNode: function() {
119
- return this.parent.$nodeScope;
120
- },
121
-
122
- prev: function() {
123
- if (this.index > 0) {
124
- return this.siblings[this.index - 1];
125
- }
126
- return null;
127
- },
128
-
129
- next: function() {
130
- if (this.index < this.siblings.length - 1) {
131
- return this.siblings[this.index + 1];
132
- }
133
- return null;
134
- },
135
-
136
- isDirty: function() {
137
- return this.source.$parentNodesScope != this.parent ||
138
- this.source.index() != this.index;
139
- },
140
-
141
- eventArgs: function(elements, pos) {
142
- return {
143
- source: this.sourceInfo,
144
- dest: {
145
- index: this.index,
146
- nodesScope: this.parent
147
- },
148
- elements: elements,
149
- pos: pos
150
- };
151
- },
152
-
153
- apply: function() {
154
- var nodeData = this.source.$modelValue;
155
- this.source.remove();
156
- this.parent.insertNode(this.index, nodeData);
157
- }
158
- };
159
- },
160
-
161
- /**
162
- * @ngdoc method
163
- * @name hippo.theme#height
164
- * @methodOf ui.tree.service:$helper
165
- *
166
- * @description
167
- * Get the height of an element.
168
- *
169
- * @param {Object} element Angular element.
170
- * @returns {String} Height
171
- */
172
- height: function (element) {
173
- return element.prop('scrollHeight');
174
- },
175
-
176
- /**
177
- * @ngdoc method
178
- * @name hippo.theme#width
179
- * @methodOf ui.tree.service:$helper
180
- *
181
- * @description
182
- * Get the width of an element.
183
- *
184
- * @param {Object} element Angular element.
185
- * @returns {String} Width
186
- */
187
- width: function (element) {
188
- return element.prop('scrollWidth');
189
- },
190
-
191
- /**
192
- * @ngdoc method
193
- * @name hippo.theme#offset
194
- * @methodOf ui.nestedSortable.service:$helper
195
- *
196
- * @description
197
- * Get the offset values of an element.
198
- *
199
- * @param {Object} element Angular element.
200
- * @returns {Object} Object with properties width, height, top and left
201
- */
202
- offset: function (element) {
203
- var boundingClientRect = element[0].getBoundingClientRect();
204
-
205
- return {
206
- width: element.prop('offsetWidth'),
207
- height: element.prop('offsetHeight'),
208
- top: boundingClientRect.top + ($window.pageYOffset || $document[0].body.scrollTop || $document[0].documentElement.scrollTop),
209
- left: boundingClientRect.left + ($window.pageXOffset || $document[0].body.scrollLeft || $document[0].documentElement.scrollLeft)
210
- };
211
- },
212
-
213
- /**
214
- * @ngdoc method
215
- * @name hippo.theme#positionStarted
216
- * @methodOf ui.tree.service:$helper
217
- *
218
- * @description
219
- * Get the start position of the target element according to the provided event properties.
220
- *
221
- * @param {Object} e Event
222
- * @param {Object} target Target element
223
- * @returns {Object} Object with properties offsetX, offsetY, startX, startY, nowX and dirX.
224
- */
225
- positionStarted: function (e, target) {
226
- var pos = {};
227
- pos.offsetX = e.pageX - this.offset(target).left;
228
- pos.offsetY = e.pageY - this.offset(target).top;
229
- pos.startX = pos.lastX = e.pageX;
230
- pos.startY = pos.lastY = e.pageY;
231
- pos.nowX = pos.nowY = pos.distX = pos.distY = pos.dirAx = 0;
232
- pos.dirX = pos.dirY = pos.lastDirX = pos.lastDirY = pos.distAxX = pos.distAxY = 0;
233
- return pos;
234
- },
235
-
236
- positionMoved: function (e, pos, firstMoving) {
237
- // mouse position last events
238
- pos.lastX = pos.nowX;
239
- pos.lastY = pos.nowY;
240
-
241
- // mouse position this events
242
- pos.nowX = e.pageX;
243
- pos.nowY = e.pageY;
244
-
245
- // distance mouse moved between events
246
- pos.distX = pos.nowX - pos.lastX;
247
- pos.distY = pos.nowY - pos.lastY;
248
-
249
- // direction mouse was moving
250
- pos.lastDirX = pos.dirX;
251
- pos.lastDirY = pos.dirY;
252
-
253
- // direction mouse is now moving (on both axis)
254
- pos.dirX = pos.distX === 0 ? 0 : pos.distX > 0 ? 1 : -1;
255
- pos.dirY = pos.distY === 0 ? 0 : pos.distY > 0 ? 1 : -1;
256
-
257
- // axis mouse is now moving on
258
- var newAx = Math.abs(pos.distX) > Math.abs(pos.distY) ? 1 : 0;
259
-
260
- // do nothing on first move
261
- if (firstMoving) {
262
- pos.dirAx = newAx;
263
- pos.moving = true;
264
- return;
265
- }
266
-
267
- // calc distance moved on this axis (and direction)
268
- if (pos.dirAx !== newAx) {
269
- pos.distAxX = 0;
270
- pos.distAxY = 0;
271
- } else {
272
- pos.distAxX += Math.abs(pos.distX);
273
- if (pos.dirX !== 0 && pos.dirX !== pos.lastDirX) {
274
- pos.distAxX = 0;
275
- }
276
-
277
- pos.distAxY += Math.abs(pos.distY);
278
- if (pos.dirY !== 0 && pos.dirY !== pos.lastDirY) {
279
- pos.distAxY = 0;
280
- }
281
- }
282
-
283
- pos.dirAx = newAx;
284
- }
285
- };
286
- }
287
- ]);
288
-
289
- })();
290
- (function () {
291
- 'use strict';
292
-
293
- angular.module('ui.tree')
294
-
295
- .controller('TreeController', ['$scope', '$element', '$attrs', 'treeConfig',
296
- function ($scope, $element, $attrs, treeConfig) {
297
- this.scope = $scope;
298
-
299
- $scope.$element = $element;
300
- $scope.$nodesScope = null; // root nodes
301
- $scope.$type = 'uiTree';
302
- $scope.$emptyElm = null;
303
- $scope.$callbacks = null;
304
-
305
- $scope.dragEnabled = true;
306
- $scope.emptyPlaceHolderEnabled = true;
307
- $scope.maxDepth = 0;
308
- $scope.dragDelay = 0;
309
-
310
- // Check if it's a empty tree
311
- $scope.isEmpty = function() {
312
- return ($scope.$nodesScope && $scope.$nodesScope.$modelValue
313
- && $scope.$nodesScope.$modelValue.length === 0);
314
- };
315
-
316
- // add placeholder to empty tree
317
- $scope.place = function(placeElm) {
318
- $scope.$nodesScope.$element.append(placeElm);
319
- $scope.$emptyElm.remove();
320
- };
321
-
322
- $scope.resetEmptyElement = function() {
323
- if ($scope.$nodesScope.$modelValue.length === 0 &&
324
- $scope.emptyPlaceHolderEnabled) {
325
- $element.append($scope.$emptyElm);
326
- } else {
327
- $scope.$emptyElm.remove();
328
- }
329
- };
330
-
331
- var collapseOrExpand = function(scope, collapsed) {
332
- var nodes = scope.childNodes();
333
- for (var i = 0; i < nodes.length; i++) {
334
- collapsed ? nodes[i].collapse() : nodes[i].expand();
335
- var subScope = nodes[i].$childNodesScope;
336
- if (subScope) {
337
- collapseOrExpand(subScope, collapsed);
338
- }
339
- }
340
- };
341
-
342
- $scope.collapseAll = function() {
343
- collapseOrExpand($scope.$nodesScope, true);
344
- };
345
-
346
- $scope.expandAll = function() {
347
- collapseOrExpand($scope.$nodesScope, false);
348
- };
349
-
350
- }
351
- ]);
352
- })();
353
-
354
- (function () {
355
- 'use strict';
356
-
357
- angular.module('ui.tree')
358
-
359
- .controller('TreeNodesController', ['$scope', '$element', 'treeConfig',
360
- function ($scope, $element, treeConfig) {
361
- this.scope = $scope;
362
-
363
- $scope.$element = $element;
364
- $scope.$modelValue = null;
365
- $scope.$nodeScope = null; // the scope of node which the nodes belongs to
366
- $scope.$treeScope = null;
367
- $scope.$type = 'uiTreeNodes';
368
- $scope.$nodesMap = {};
369
-
370
- $scope.nodrop = false;
371
- $scope.maxDepth = 0;
372
-
373
- $scope.initSubNode = function(subNode) {
374
- $scope.$nodesMap[subNode.$modelValue.$$hashKey] = subNode;
375
- };
376
-
377
- $scope.destroySubNode = function(subNode) {
378
- $scope.$nodesMap[subNode.$modelValue.$$hashKey] = null;
379
- };
380
-
381
- $scope.accept = function(sourceNode, destIndex) {
382
- return $scope.$treeScope.$callbacks.accept(sourceNode, $scope, destIndex);
383
- };
384
-
385
- $scope.beforeDrag = function(sourceNode) {
386
- return $scope.$treeScope.$callbacks.beforeDrag(sourceNode);
387
- };
388
-
389
- $scope.isParent = function(node) {
390
- return node.$parentNodesScope == $scope;
391
- };
392
-
393
- $scope.hasChild = function() {
394
- return $scope.$modelValue.length > 0;
395
- };
396
-
397
- $scope.safeApply = function(fn) {
398
- var phase = this.$root.$$phase;
399
- if(phase == '$apply' || phase == '$digest') {
400
- if(fn && (typeof(fn) === 'function')) {
401
- fn();
402
- }
403
- } else {
404
- this.$apply(fn);
405
- }
406
- };
407
-
408
- $scope.removeNode = function(node) {
409
- var index = $scope.$modelValue.indexOf(node.$modelValue);
410
- if (index > -1) {
411
- $scope.safeApply(function() {
412
- $scope.$modelValue.splice(index, 1)[0];
413
- });
414
- return node;
415
- }
416
- return null;
417
- };
418
-
419
- $scope.insertNode = function(index, nodeData) {
420
- $scope.safeApply(function() {
421
- $scope.$modelValue.splice(index, 0, nodeData);
422
- });
423
- };
424
-
425
- $scope.childNodes = function() {
426
- var nodes = [];
427
- if ($scope.$modelValue) {
428
- for (var i = 0; i < $scope.$modelValue.length; i++) {
429
- nodes.push($scope.$nodesMap[$scope.$modelValue[i].$$hashKey]);
430
- }
431
- }
432
- return nodes;
433
- };
434
-
435
- $scope.depth = function() {
436
- if ($scope.$nodeScope) {
437
- return $scope.$nodeScope.depth();
438
- }
439
- return 0; // if it has no $nodeScope, it's root
440
- };
441
-
442
- // check if depth limit has reached
443
- $scope.outOfDepth = function(sourceNode) {
444
- var maxDepth = $scope.maxDepth || $scope.$treeScope.maxDepth;
445
- if (maxDepth > 0) {
446
- return $scope.depth() + sourceNode.maxSubDepth() + 1 > maxDepth;
447
- }
448
- return false;
449
- };
450
-
451
- }
452
- ]);
453
- })();
454
- (function () {
455
- 'use strict';
456
-
457
- angular.module('ui.tree')
458
-
459
- .controller('TreeNodeController', ['$scope', '$element', '$attrs', 'treeConfig',
460
- function ($scope, $element, $attrs, treeConfig) {
461
- this.scope = $scope;
462
-
463
- $scope.$element = $element;
464
- $scope.$modelValue = null; // Model value for node;
465
- $scope.$parentNodeScope = null; // uiTreeNode Scope of parent node;
466
- $scope.$childNodesScope = null; // uiTreeNodes Scope of child nodes.
467
- $scope.$parentNodesScope = null; // uiTreeNodes Scope of parent nodes.
468
- $scope.$treeScope = null; // uiTree scope
469
- $scope.$handleScope = null; // it's handle scope
470
- $scope.$type = 'uiTreeNode';
471
- $scope.$$apply = false; //
472
-
473
- $scope.collapsed = false;
474
-
475
- $scope.init = function(controllersArr) {
476
- var treeNodesCtrl = controllersArr[0];
477
- $scope.$treeScope = controllersArr[1] ? controllersArr[1].scope : null;
478
-
479
- // find the scope of it's parent node
480
- $scope.$parentNodeScope = treeNodesCtrl.scope.$nodeScope;
481
- // modelValue for current node
482
- $scope.$modelValue = treeNodesCtrl.scope.$modelValue[$scope.$index];
483
- $scope.$parentNodesScope = treeNodesCtrl.scope;
484
- treeNodesCtrl.scope.initSubNode($scope); // init sub nodes
485
-
486
- $element.on('$destroy', function() {
487
- treeNodesCtrl.scope.destroySubNode($scope); // destroy sub nodes
488
- });
489
- };
490
-
491
- $scope.index = function() {
492
- return $scope.$parentNodesScope.$modelValue.indexOf($scope.$modelValue);
493
- };
494
-
495
- $scope.dragEnabled = function() {
496
- return !($scope.$treeScope && !$scope.$treeScope.dragEnabled);
497
- };
498
-
499
- $scope.isSibling = function(targetNode) {
500
- return $scope.$parentNodesScope == targetNode.$parentNodesScope;
501
- };
502
-
503
- $scope.isChild = function(targetNode) {
504
- var nodes = $scope.childNodes();
505
- return nodes && nodes.indexOf(targetNode) > -1;
506
- };
507
-
508
- $scope.prev = function() {
509
- var index = $scope.index();
510
- if (index > 0) {
511
- return $scope.siblings()[index - 1];
512
- }
513
- return null;
514
- };
515
-
516
- $scope.siblings = function() {
517
- return $scope.$parentNodesScope.childNodes();
518
- };
519
-
520
- $scope.childNodesCount = function() {
521
- return $scope.childNodes() ? $scope.childNodes().length : 0;
522
- };
523
-
524
- $scope.hasChild = function() {
525
- return $scope.childNodesCount() > 0;
526
- };
527
-
528
- $scope.childNodes = function() {
529
- return $scope.$childNodesScope && $scope.$childNodesScope.$modelValue ?
530
- $scope.$childNodesScope.childNodes() :
531
- null;
532
- };
533
-
534
- $scope.accept = function(sourceNode, destIndex) {
535
- return $scope.$childNodesScope &&
536
- $scope.$childNodesScope.$modelValue &&
537
- $scope.$childNodesScope.accept(sourceNode, destIndex);
538
- };
539
-
540
- $scope.removeNode = function(){
541
- var node = $scope.remove();
542
- $scope.$callbacks.removed(node);
543
- return node;
544
- };
545
-
546
- $scope.remove = function() {
547
- return $scope.$parentNodesScope.removeNode($scope);
548
- };
549
-
550
- $scope.toggle = function() {
551
- $scope.collapsed = !$scope.collapsed;
552
- };
553
-
554
- $scope.collapse = function() {
555
- $scope.collapsed = true;
556
- };
557
-
558
- $scope.expand = function() {
559
- $scope.collapsed = false;
560
- };
561
-
562
- $scope.depth = function() {
563
- var parentNode = $scope.$parentNodeScope;
564
- if (parentNode) {
565
- return parentNode.depth() + 1;
566
- }
567
- return 1;
568
- };
569
-
570
- var subDepth = 0;
571
- var countSubDepth = function(scope) {
572
- var count = 0;
573
- var nodes = scope.childNodes();
574
- for (var i = 0; i < nodes.length; i++) {
575
- var childNodes = nodes[i].$childNodesScope;
576
- if (childNodes) {
577
- count = 1;
578
- countSubDepth(childNodes);
579
- }
580
- }
581
- subDepth += count;
582
- };
583
-
584
- $scope.maxSubDepth = function() {
585
- subDepth = 0;
586
- if ($scope.$childNodesScope) {
587
- countSubDepth($scope.$childNodesScope);
588
- }
589
- return subDepth;
590
- };
591
-
592
- }
593
- ]);
594
- })();
595
-
596
- (function () {
597
- 'use strict';
598
-
599
- angular.module('ui.tree')
600
-
601
- .controller('TreeHandleController', ['$scope', '$element', '$attrs', 'treeConfig',
602
- function ($scope, $element, $attrs, treeConfig) {
603
- this.scope = $scope;
604
-
605
- $scope.$element = $element;
606
- $scope.$nodeScope = null;
607
- $scope.$type = 'uiTreeHandle';
608
-
609
- }
610
- ]);
611
- })();
612
-
613
- (function () {
614
- 'use strict';
615
-
616
- angular.module('ui.tree')
617
- .directive('uiTree', [ 'treeConfig', '$window',
618
- function(treeConfig, $window) {
619
- return {
620
- restrict: 'A',
621
- scope: true,
622
- controller: 'TreeController',
623
- link: function(scope, element, attrs) {
624
- var callbacks = {
625
- accept: null,
626
- beforeDrag: null
627
- };
628
-
629
- var config = {};
630
- angular.extend(config, treeConfig);
631
- if (config.treeClass) {
632
- element.addClass(config.treeClass);
633
- }
634
-
635
- scope.$emptyElm = angular.element($window.document.createElement('div'));
636
- if (config.emptyTreeClass) {
637
- scope.$emptyElm.addClass(config.emptyTreeClass);
638
- }
639
-
640
- scope.$watch('$nodesScope.$modelValue.length', function() {
641
- if (scope.$nodesScope.$modelValue) {
642
- scope.resetEmptyElement();
643
- }
644
- }, true);
645
-
646
- scope.$watch(attrs.dragEnabled, function(val) {
647
- if((typeof val) == "boolean") {
648
- scope.dragEnabled = val;
649
- }
650
- });
651
-
652
- scope.$watch(attrs.emptyPlaceHolderEnabled, function(val) {
653
- if((typeof val) == "boolean") {
654
- scope.emptyPlaceHolderEnabled = val;
655
- }
656
- });
657
-
658
- scope.$watch(attrs.maxDepth, function(val) {
659
- if((typeof val) == "number") {
660
- scope.maxDepth = val;
661
- }
662
- });
663
-
664
- scope.$watch(attrs.dragDelay, function(val) {
665
- if((typeof val) == "number") {
666
- scope.dragDelay = val;
667
- }
668
- });
669
-
670
- // check if the dest node can accept the dragging node
671
- // by default, we check the 'data-nodrop' attribute in `ui-tree-nodes`
672
- // and the 'max-depth' attribute in `ui-tree` or `ui-tree-nodes`.
673
- // the method can be overrided
674
- callbacks.accept = function(sourceNodeScope, destNodesScope, destIndex) {
675
- if (destNodesScope.nodrop || destNodesScope.outOfDepth(sourceNodeScope)) {
676
- return false;
677
- }
678
- return true;
679
- };
680
-
681
- callbacks.beforeDrag = function(sourceNodeScope) {
682
- return true;
683
- };
684
-
685
- callbacks.removed = function(node){
686
-
687
- };
688
-
689
- callbacks.dropped = function(event) {
690
-
691
- };
692
-
693
- //
694
- callbacks.dragStart = function(event) {
695
-
696
- };
697
-
698
- callbacks.dragMove = function(event) {
699
-
700
- };
701
-
702
- callbacks.dragStop = function(event) {
703
-
704
- };
705
-
706
- callbacks.beforeDrop = function(event) {
707
-
708
- };
709
-
710
- scope.$watch(attrs.uiTree, function(newVal, oldVal){
711
- angular.forEach(newVal, function(value, key){
712
- if (callbacks[key]) {
713
- if (typeof value === "function") {
714
- callbacks[key] = value;
715
- }
716
- }
717
- });
718
-
719
- scope.$callbacks = callbacks;
720
- }, true);
721
-
722
-
723
- }
724
- };
725
- }
726
- ]);
727
- })();
728
-
729
- (function () {
730
- 'use strict';
731
-
732
- angular.module('ui.tree')
733
- .directive('uiTreeNodes', [ 'treeConfig', '$window',
734
- function(treeConfig) {
735
- return {
736
- require: ['ngModel', '?^uiTreeNode', '^uiTree'],
737
- restrict: 'A',
738
- scope: true,
739
- controller: 'TreeNodesController',
740
- link: function(scope, element, attrs, controllersArr) {
741
-
742
- var config = {};
743
- angular.extend(config, treeConfig);
744
- if (config.nodesClass) {
745
- element.addClass(config.nodesClass);
746
- }
747
-
748
- var ngModel = controllersArr[0];
749
- var treeNodeCtrl = controllersArr[1];
750
- var treeCtrl = controllersArr[2];
751
- if (treeNodeCtrl) {
752
- treeNodeCtrl.scope.$childNodesScope = scope;
753
- scope.$nodeScope = treeNodeCtrl.scope;
754
- }
755
- else { // find the root nodes if there is no parent node and have a parent ui-tree
756
- treeCtrl.scope.$nodesScope = scope;
757
- }
758
- scope.$treeScope = treeCtrl.scope;
759
-
760
- if (ngModel) {
761
- ngModel.$render = function() {
762
- if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) {
763
- scope.$modelValue = [];
764
- }
765
- scope.$modelValue = ngModel.$modelValue;
766
- };
767
- }
768
-
769
- scope.$watch(attrs.maxDepth, function(val) {
770
- if((typeof val) == "number") {
771
- scope.maxDepth = val;
772
- }
773
- });
774
-
775
- attrs.$observe('nodrop', function(val) {
776
- scope.nodrop = ((typeof val) != "undefined");
777
- });
778
-
779
- attrs.$observe('horizontal', function(val) {
780
- scope.horizontal = ((typeof val) != "undefined");
781
- });
782
-
783
- }
784
- };
785
- }
786
- ]);
787
- })();
788
-
789
- (function () {
790
- 'use strict';
791
-
792
- angular.module('ui.tree')
793
-
794
- .directive('uiTreeNode', ['treeConfig', '$uiTreeHelper', '$window', '$document','$timeout',
795
- function (treeConfig, $uiTreeHelper, $window, $document, $timeout) {
796
- return {
797
- require: ['^uiTreeNodes', '^uiTree'],
798
- restrict: 'A',
799
- controller: 'TreeNodeController',
800
- link: function(scope, element, attrs, controllersArr) {
801
- var config = {};
802
- angular.extend(config, treeConfig);
803
- if (config.nodeClass) {
804
- element.addClass(config.nodeClass);
805
- }
806
- scope.init(controllersArr);
807
-
808
- scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
809
-
810
- scope.$watch(attrs.collapsed, function(val) {
811
- if((typeof val) == "boolean") {
812
- scope.collapsed = val;
813
- }
814
- });
815
-
816
- scope.$watch('collapsed', function(val) {
817
- $uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
818
- attrs.$set('collapsed', val);
819
- });
820
-
821
- var hasTouch = 'ontouchstart' in window;
822
- // todo startPos is unused
823
- var startPos, firstMoving, dragInfo, pos;
824
- var placeElm, hiddenPlaceElm, dragElm;
825
- var treeScope = null;
826
- var elements; // As a parameter for callbacks
827
- var dragDelaying = true;
828
- var dragStarted = false;
829
- var dragTimer = null;
830
- var body = document.body,
831
- html = document.documentElement,
832
- document_height,
833
- document_width;
834
-
835
- var dragStart = function(e) {
836
- if (!hasTouch && (e.button == 2 || e.which == 3)) {
837
- // disable right click
838
- return;
839
- }
840
- if (e.uiTreeDragging || (e.originalEvent && e.originalEvent.uiTreeDragging)) { // event has already fired in other scope.
841
- return;
842
- }
843
-
844
- // the element which is clicked.
845
- var eventElm = angular.element(e.target);
846
- var eventScope = eventElm.scope();
847
- if (!eventScope || !eventScope.$type) {
848
- return;
849
- }
850
- if (eventScope.$type != 'uiTreeNode'
851
- && eventScope.$type != 'uiTreeHandle') { // Check if it is a node or a handle
852
- return;
853
- }
854
- if (eventScope.$type == 'uiTreeNode'
855
- && eventScope.$handleScope) { // If the node has a handle, then it should be clicked by the handle
856
- return;
857
- }
858
-
859
- var eventElmTagName = eventElm.prop('tagName').toLowerCase();
860
- if (eventElmTagName == 'input' ||
861
- eventElmTagName == 'textarea' ||
862
- eventElmTagName == 'button' ||
863
- eventElmTagName == 'select') { // if it's a input or button, ignore it
864
- return;
865
- }
866
-
867
- // check if it or it's parents has a 'data-nodrag' attribute
868
- while (eventElm && eventElm[0] && eventElm[0] != element) {
869
- if ($uiTreeHelper.nodrag(eventElm)) { // if the node mark as `nodrag`, DONOT drag it.
870
- return;
871
- }
872
- eventElm = eventElm.parent();
873
- }
874
-
875
- if (!scope.beforeDrag(scope)){
876
- return;
877
- }
878
-
879
- e.uiTreeDragging = true; // stop event bubbling
880
- if (e.originalEvent) {
881
- e.originalEvent.uiTreeDragging = true;
882
- }
883
- e.preventDefault();
884
- var eventObj = $uiTreeHelper.eventObj(e);
885
-
886
- firstMoving = true;
887
- dragInfo = $uiTreeHelper.dragInfo(scope);
888
-
889
- var tagName = scope.$element.prop('tagName');
890
- if (tagName.toLowerCase() === 'tr') {
891
- placeElm = angular.element($window.document.createElement(tagName));
892
- var tdElm = angular.element($window.document.createElement('td'))
893
- .addClass(config.placeHolderClass);
894
- placeElm.append(tdElm);
895
- } else {
896
- placeElm = angular.element($window.document.createElement(tagName))
897
- .addClass(config.placeHolderClass);
898
- }
899
- hiddenPlaceElm = angular.element($window.document.createElement(tagName));
900
- if (config.hiddenClass) {
901
- hiddenPlaceElm.addClass(config.hiddenClass);
902
- }
903
- pos = $uiTreeHelper.positionStarted(eventObj, scope.$element);
904
- placeElm.css('height', $uiTreeHelper.height(scope.$element) + 'px');
905
- placeElm.css('width', $uiTreeHelper.width(scope.$element) + 'px');
906
- dragElm = angular.element($window.document.createElement(scope.$parentNodesScope.$element.prop('tagName')))
907
- .addClass(scope.$parentNodesScope.$element.attr('class')).addClass(config.dragClass);
908
- dragElm.css('width', $uiTreeHelper.width(scope.$element) + 'px');
909
- dragElm.css('z-index', 9999);
910
-
911
- // Prevents cursor to change rapidly in Opera 12.16 and IE when dragging an element
912
- var hStyle = (scope.$element[0].querySelector('.angular-ui-tree-handle') || scope.$element[0]).currentStyle;
913
- if (hStyle) {
914
- document.body.setAttribute('ui-tree-cursor', $document.find('body').css('cursor') || '');
915
- $document.find('body').css({'cursor': hStyle.cursor + '!important'});
916
- }
917
-
918
- scope.$element.after(placeElm);
919
- scope.$element.after(hiddenPlaceElm);
920
- dragElm.append(scope.$element);
921
- $document.find('body').append(dragElm);
922
- dragElm.css({
923
- 'left' : eventObj.pageX - pos.offsetX + 'px',
924
- 'top' : eventObj.pageY - pos.offsetY + 'px'
925
- });
926
- elements = {
927
- placeholder: placeElm,
928
- dragging: dragElm
929
- };
930
-
931
- angular.element($document).bind('touchend', dragEndEvent);
932
- angular.element($document).bind('touchcancel', dragEndEvent);
933
- angular.element($document).bind('touchmove', dragMoveEvent);
934
- angular.element($document).bind('mouseup', dragEndEvent);
935
- angular.element($document).bind('mousemove', dragMoveEvent);
936
- angular.element($document).bind('mouseleave', dragCancelEvent);
937
-
938
- document_height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
939
- document_width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
940
- };
941
-
942
- var dragMove = function(e) {
943
- if (!dragStarted) {
944
- if (!dragDelaying) {
945
- dragStarted = true;
946
- scope.$apply(function() {
947
- scope.$callbacks.dragStart(dragInfo.eventArgs(elements, pos));
948
- });
949
- }
950
- return;
951
- }
952
-
953
- var eventObj = $uiTreeHelper.eventObj(e);
954
- var prev, leftElmPos, topElmPos;
955
-
956
- if (dragElm) {
957
- e.preventDefault();
958
-
959
- if ($window.getSelection) {
960
- $window.getSelection().removeAllRanges();
961
- } else if ($window.document.selection) {
962
- $window.document.selection.empty();
963
- }
964
-
965
- leftElmPos = eventObj.pageX - pos.offsetX;
966
- topElmPos = eventObj.pageY - pos.offsetY;
967
-
968
- //dragElm can't leave the screen on the left
969
- if(leftElmPos < 0){
970
- leftElmPos = 0;
971
- }
972
-
973
- //dragElm can't leave the screen on the top
974
- if(topElmPos < 0){
975
- topElmPos = 0;
976
- }
977
-
978
- //dragElm can't leave the screen on the bottom
979
- if ((topElmPos + 10) > document_height){
980
- topElmPos = document_height - 10;
981
- }
982
-
983
- //dragElm can't leave the screen on the right
984
- if((leftElmPos + 10) > document_width) {
985
- leftElmPos = document_width - 10;
986
- }
987
-
988
- dragElm.css({
989
- 'left': leftElmPos + 'px',
990
- 'top': topElmPos + 'px'
991
- });
992
-
993
- var top_scroll = window.pageYOffset || $window.document.documentElement.scrollTop;
994
- var bottom_scroll = top_scroll + (window.innerHeight || $window.document.clientHeight || $window.document.clientHeight);
995
-
996
- // to scroll down if cursor y-position is greater than the bottom position the vertical scroll
997
- if (bottom_scroll < eventObj.pageY && bottom_scroll <= document_height) {
998
- window.scrollBy(0, 10);
999
- }
1000
-
1001
- // to scroll top if cursor y-position is less than the top position the vertical scroll
1002
- if (top_scroll > eventObj.pageY) {
1003
- window.scrollBy(0, -10);
1004
- }
1005
-
1006
- $uiTreeHelper.positionMoved(e, pos, firstMoving);
1007
- if (firstMoving) {
1008
- firstMoving = false;
1009
- return;
1010
- }
1011
-
1012
- // move horizontal
1013
- if (pos.dirAx && pos.distAxX >= config.levelThreshold) {
1014
- pos.distAxX = 0;
1015
-
1016
- // increase horizontal level if previous sibling exists and is not collapsed
1017
- if (pos.distX > 0) {
1018
- prev = dragInfo.prev();
1019
- if (prev && !prev.collapsed
1020
- && prev.accept(scope, prev.childNodesCount())) {
1021
- prev.$childNodesScope.$element.append(placeElm);
1022
- dragInfo.moveTo(prev.$childNodesScope, prev.childNodes(), prev.childNodesCount());
1023
- }
1024
- }
1025
-
1026
- // decrease horizontal level
1027
- if (pos.distX < 0) {
1028
- // we can't decrease a level if an item preceeds the current one
1029
- var next = dragInfo.next();
1030
- if (!next) {
1031
- var target = dragInfo.parentNode(); // As a sibling of it's parent node
1032
- if (target
1033
- && target.$parentNodesScope.accept(scope, target.index() + 1)) {
1034
- target.$element.after(placeElm);
1035
- dragInfo.moveTo(target.$parentNodesScope, target.siblings(), target.index() + 1);
1036
- }
1037
- }
1038
- }
1039
- }
1040
-
1041
- // check if add it as a child node first
1042
- // todo decrease is unused
1043
- var decrease = ($uiTreeHelper.offset(dragElm).left - $uiTreeHelper.offset(placeElm).left) >= config.threshold;
1044
- var targetX = eventObj.pageX - $window.document.body.scrollLeft;
1045
- var targetY = eventObj.pageY - (window.pageYOffset || $window.document.documentElement.scrollTop);
1046
-
1047
- // Select the drag target. Because IE does not support CSS 'pointer-events: none', it will always
1048
- // pick the drag element itself as the target. To prevent this, we hide the drag element while
1049
- // selecting the target.
1050
- var displayElm;
1051
- if (angular.isFunction(dragElm.hide)) {
1052
- dragElm.hide();
1053
- }else{
1054
- displayElm = dragElm[0].style.display;
1055
- dragElm[0].style.display = "none";
1056
- }
1057
-
1058
- // when using elementFromPoint() inside an iframe, you have to call
1059
- // elementFromPoint() twice to make sure IE8 returns the correct value
1060
- $window.document.elementFromPoint(targetX, targetY);
1061
-
1062
- var targetElm = angular.element($window.document.elementFromPoint(targetX, targetY));
1063
- if (angular.isFunction(dragElm.show)) {
1064
- dragElm.show();
1065
- }else{
1066
- dragElm[0].style.display = displayElm;
1067
- }
1068
-
1069
- // move vertical
1070
- if (!pos.dirAx) {
1071
- var targetBefore, targetNode;
1072
- // check it's new position
1073
- targetNode = targetElm.scope();
1074
- var isEmpty = false;
1075
- if (!targetNode) {
1076
- return;
1077
- }
1078
- if (targetNode.$type == 'uiTree' && targetNode.dragEnabled) {
1079
- isEmpty = targetNode.isEmpty(); // Check if it's empty tree
1080
- }
1081
- if (targetNode.$type == 'uiTreeHandle') {
1082
- targetNode = targetNode.$nodeScope;
1083
- }
1084
- if (targetNode.$type != 'uiTreeNode'
1085
- && !isEmpty) { // Check if it is a uiTreeNode or it's an empty tree
1086
- return;
1087
- }
1088
-
1089
- // if placeholder move from empty tree, reset it.
1090
- if (treeScope && placeElm.parent()[0] != treeScope.$element[0]) {
1091
- treeScope.resetEmptyElement();
1092
- treeScope = null;
1093
- }
1094
-
1095
- if (isEmpty) { // it's an empty tree
1096
- treeScope = targetNode;
1097
- if (targetNode.$nodesScope.accept(scope, 0)) {
1098
- targetNode.place(placeElm);
1099
- dragInfo.moveTo(targetNode.$nodesScope, targetNode.$nodesScope.childNodes(), 0);
1100
- }
1101
- } else if (targetNode.dragEnabled()){ // drag enabled
1102
- targetElm = targetNode.$element; // Get the element of ui-tree-node
1103
- var targetOffset = $uiTreeHelper.offset(targetElm);
1104
- targetBefore = targetNode.horizontal ? eventObj.pageX < (targetOffset.left + $uiTreeHelper.width(targetElm) / 2)
1105
- : eventObj.pageY < (targetOffset.top + $uiTreeHelper.height(targetElm) / 2);
1106
-
1107
- if (targetNode.$parentNodesScope.accept(scope, targetNode.index())) {
1108
- if (targetBefore) {
1109
- targetElm[0].parentNode.insertBefore(placeElm[0], targetElm[0]);
1110
- dragInfo.moveTo(targetNode.$parentNodesScope, targetNode.siblings(), targetNode.index());
1111
- } else {
1112
- targetElm.after(placeElm);
1113
- dragInfo.moveTo(targetNode.$parentNodesScope, targetNode.siblings(), targetNode.index() + 1);
1114
- }
1115
- }
1116
- else if (!targetBefore && targetNode.accept(scope, targetNode.childNodesCount())) { // we have to check if it can add the dragging node as a child
1117
- targetNode.$childNodesScope.$element.append(placeElm);
1118
- dragInfo.moveTo(targetNode.$childNodesScope, targetNode.childNodes(), targetNode.childNodesCount());
1119
- }
1120
- }
1121
-
1122
- }
1123
-
1124
- scope.$apply(function() {
1125
- scope.$callbacks.dragMove(dragInfo.eventArgs(elements, pos));
1126
- });
1127
- }
1128
- };
1129
-
1130
- var dragEnd = function(e) {
1131
- e.preventDefault();
1132
-
1133
- if (dragElm) {
1134
- scope.$treeScope.$apply(function() {
1135
- scope.$callbacks.beforeDrop(dragInfo.eventArgs(elements, pos));
1136
- });
1137
- // roll back elements changed
1138
- hiddenPlaceElm.replaceWith(scope.$element);
1139
- placeElm.remove();
1140
-
1141
- dragElm.remove();
1142
- dragElm = null;
1143
- if (scope.$$apply) {
1144
- dragInfo.apply();
1145
- scope.$treeScope.$apply(function() {
1146
- scope.$callbacks.dropped(dragInfo.eventArgs(elements, pos));
1147
- });
1148
- } else {
1149
- bindDrag();
1150
- }
1151
- scope.$treeScope.$apply(function() {
1152
- scope.$callbacks.dragStop(dragInfo.eventArgs(elements, pos));
1153
- });
1154
- scope.$$apply = false;
1155
- dragInfo = null;
1156
-
1157
- }
1158
-
1159
- // Restore cursor in Opera 12.16 and IE
1160
- var oldCur = document.body.getAttribute('ui-tree-cursor');
1161
- if (oldCur !== null) {
1162
- $document.find('body').css({'cursor': oldCur});
1163
- document.body.removeAttribute('ui-tree-cursor');
1164
- }
1165
-
1166
- angular.element($document).unbind('touchend', dragEndEvent); // Mobile
1167
- angular.element($document).unbind('touchcancel', dragEndEvent); // Mobile
1168
- angular.element($document).unbind('touchmove', dragMoveEvent); // Mobile
1169
- angular.element($document).unbind('mouseup', dragEndEvent);
1170
- angular.element($document).unbind('mousemove', dragMoveEvent);
1171
- angular.element($window.document.body).unbind('mouseleave', dragCancelEvent);
1172
- };
1173
-
1174
- var dragStartEvent = function(e) {
1175
- if (scope.dragEnabled()) {
1176
- dragStart(e);
1177
- }
1178
- };
1179
-
1180
- var dragMoveEvent = function(e) {
1181
- dragMove(e);
1182
- };
1183
-
1184
- var dragEndEvent = function(e) {
1185
- scope.$$apply = true;
1186
- dragEnd(e);
1187
- };
1188
-
1189
- var dragCancelEvent = function(e) {
1190
- dragEnd(e);
1191
- };
1192
-
1193
- var bindDrag = function() {
1194
- element.bind('touchstart mousedown', function (e) {
1195
- dragDelaying = true;
1196
- dragStarted = false;
1197
- dragStartEvent(e);
1198
- dragTimer = $timeout(function(){dragDelaying = false;}, scope.dragDelay);
1199
- });
1200
- element.bind('touchend touchcancel mouseup',function(){$timeout.cancel(dragTimer);});
1201
- };
1202
- bindDrag();
1203
-
1204
- angular.element($window.document.body).bind("keydown", function(e) {
1205
- if (e.keyCode == 27) {
1206
- scope.$$apply = false;
1207
- dragEnd(e);
1208
- }
1209
- });
1210
- }
1211
- };
1212
- }
1213
- ]);
1214
-
1215
- })();
1216
-
1217
- (function () {
1218
- 'use strict';
1219
-
1220
- angular.module('ui.tree')
1221
- .directive('uiTreeHandle', [ 'treeConfig', '$window',
1222
- function(treeConfig) {
1223
- return {
1224
- require: '^uiTreeNode',
1225
- restrict: 'A',
1226
- scope: true,
1227
- controller: 'TreeHandleController',
1228
- link: function(scope, element, attrs, treeNodeCtrl) {
1229
- var config = {};
1230
- angular.extend(config, treeConfig);
1231
- if (config.handleClass) {
1232
- element.addClass(config.handleClass);
1233
- }
1234
- // connect with the tree node.
1235
- if (scope != treeNodeCtrl.scope) {
1236
- scope.$nodeScope = treeNodeCtrl.scope;
1237
- treeNodeCtrl.scope.$handleScope = scope;
1238
- }
1239
- }
1240
- };
1241
- }
1242
- ]);
1243
- })();