kms 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,100 +0,0 @@
1
- (function () {
2
- 'use strict';
3
-
4
- angular.module('ui.tree')
5
-
6
- .controller('TreeNodesController', ['$scope', '$element', 'treeConfig',
7
- function ($scope, $element, treeConfig) {
8
- this.scope = $scope;
9
-
10
- $scope.$element = $element;
11
- $scope.$modelValue = null;
12
- $scope.$nodeScope = null; // the scope of node which the nodes belongs to
13
- $scope.$treeScope = null;
14
- $scope.$type = 'uiTreeNodes';
15
- $scope.$nodesMap = {};
16
-
17
- $scope.nodrop = false;
18
- $scope.maxDepth = 0;
19
-
20
- $scope.initSubNode = function(subNode) {
21
- $scope.$nodesMap[subNode.$modelValue.$$hashKey] = subNode;
22
- };
23
-
24
- $scope.destroySubNode = function(subNode) {
25
- $scope.$nodesMap[subNode.$modelValue.$$hashKey] = null;
26
- };
27
-
28
- $scope.accept = function(sourceNode, destIndex) {
29
- return $scope.$treeScope.$callbacks.accept(sourceNode, $scope, destIndex);
30
- };
31
-
32
- $scope.beforeDrag = function(sourceNode) {
33
- return $scope.$treeScope.$callbacks.beforeDrag(sourceNode);
34
- };
35
-
36
- $scope.isParent = function(node) {
37
- return node.$parentNodesScope == $scope;
38
- };
39
-
40
- $scope.hasChild = function() {
41
- return $scope.$modelValue.length > 0;
42
- };
43
-
44
- $scope.safeApply = function(fn) {
45
- var phase = this.$root.$$phase;
46
- if(phase == '$apply' || phase == '$digest') {
47
- if(fn && (typeof(fn) === 'function')) {
48
- fn();
49
- }
50
- } else {
51
- this.$apply(fn);
52
- }
53
- };
54
-
55
- $scope.removeNode = function(node) {
56
- var index = $scope.$modelValue.indexOf(node.$modelValue);
57
- if (index > -1) {
58
- $scope.safeApply(function() {
59
- $scope.$modelValue.splice(index, 1)[0];
60
- });
61
- return node;
62
- }
63
- return null;
64
- };
65
-
66
- $scope.insertNode = function(index, nodeData) {
67
- $scope.safeApply(function() {
68
- $scope.$modelValue.splice(index, 0, nodeData);
69
- });
70
- };
71
-
72
- $scope.childNodes = function() {
73
- var nodes = [];
74
- if ($scope.$modelValue) {
75
- for (var i = 0; i < $scope.$modelValue.length; i++) {
76
- nodes.push($scope.$nodesMap[$scope.$modelValue[i].$$hashKey]);
77
- }
78
- }
79
- return nodes;
80
- };
81
-
82
- $scope.depth = function() {
83
- if ($scope.$nodeScope) {
84
- return $scope.$nodeScope.depth();
85
- }
86
- return 0; // if it has no $nodeScope, it's root
87
- };
88
-
89
- // check if depth limit has reached
90
- $scope.outOfDepth = function(sourceNode) {
91
- var maxDepth = $scope.maxDepth || $scope.$treeScope.maxDepth;
92
- if (maxDepth > 0) {
93
- return $scope.depth() + sourceNode.maxSubDepth() + 1 > maxDepth;
94
- }
95
- return false;
96
- };
97
-
98
- }
99
- ]);
100
- })();
@@ -1,63 +0,0 @@
1
- (function () {
2
- 'use strict';
3
-
4
- angular.module('ui.tree')
5
-
6
- .controller('TreeController', ['$scope', '$element', '$attrs', 'treeConfig',
7
- function ($scope, $element, $attrs, treeConfig) {
8
- this.scope = $scope;
9
-
10
- $scope.$element = $element;
11
- $scope.$nodesScope = null; // root nodes
12
- $scope.$type = 'uiTree';
13
- $scope.$emptyElm = null;
14
- $scope.$callbacks = null;
15
-
16
- $scope.dragEnabled = true;
17
- $scope.emptyPlaceHolderEnabled = true;
18
- $scope.maxDepth = 0;
19
- $scope.dragDelay = 0;
20
-
21
- // Check if it's a empty tree
22
- $scope.isEmpty = function() {
23
- return ($scope.$nodesScope && $scope.$nodesScope.$modelValue
24
- && $scope.$nodesScope.$modelValue.length === 0);
25
- };
26
-
27
- // add placeholder to empty tree
28
- $scope.place = function(placeElm) {
29
- $scope.$nodesScope.$element.append(placeElm);
30
- $scope.$emptyElm.remove();
31
- };
32
-
33
- $scope.resetEmptyElement = function() {
34
- if ($scope.$nodesScope.$modelValue.length === 0 &&
35
- $scope.emptyPlaceHolderEnabled) {
36
- $element.append($scope.$emptyElm);
37
- } else {
38
- $scope.$emptyElm.remove();
39
- }
40
- };
41
-
42
- var collapseOrExpand = function(scope, collapsed) {
43
- var nodes = scope.childNodes();
44
- for (var i = 0; i < nodes.length; i++) {
45
- collapsed ? nodes[i].collapse() : nodes[i].expand();
46
- var subScope = nodes[i].$childNodesScope;
47
- if (subScope) {
48
- collapseOrExpand(subScope, collapsed);
49
- }
50
- }
51
- };
52
-
53
- $scope.collapseAll = function() {
54
- collapseOrExpand($scope.$nodesScope, true);
55
- };
56
-
57
- $scope.expandAll = function() {
58
- collapseOrExpand($scope.$nodesScope, false);
59
- };
60
-
61
- }
62
- ]);
63
- })();
@@ -1,115 +0,0 @@
1
- (function () {
2
- 'use strict';
3
-
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();
31
- }
32
- }, true);
33
-
34
- scope.$watch(attrs.dragEnabled, function(val) {
35
- if((typeof val) == "boolean") {
36
- scope.dragEnabled = val;
37
- }
38
- });
39
-
40
- scope.$watch(attrs.emptyPlaceHolderEnabled, function(val) {
41
- if((typeof val) == "boolean") {
42
- scope.emptyPlaceHolderEnabled = val;
43
- }
44
- });
45
-
46
- scope.$watch(attrs.maxDepth, function(val) {
47
- if((typeof val) == "number") {
48
- scope.maxDepth = val;
49
- }
50
- });
51
-
52
- scope.$watch(attrs.dragDelay, function(val) {
53
- if((typeof val) == "number") {
54
- scope.dragDelay = val;
55
- }
56
- });
57
-
58
- // check if the dest node can accept the dragging node
59
- // by default, we check the 'data-nodrop' attribute in `ui-tree-nodes`
60
- // and the 'max-depth' attribute in `ui-tree` or `ui-tree-nodes`.
61
- // the method can be overrided
62
- callbacks.accept = function(sourceNodeScope, destNodesScope, destIndex) {
63
- if (destNodesScope.nodrop || destNodesScope.outOfDepth(sourceNodeScope)) {
64
- return false;
65
- }
66
- return true;
67
- };
68
-
69
- callbacks.beforeDrag = function(sourceNodeScope) {
70
- return true;
71
- };
72
-
73
- callbacks.removed = function(node){
74
-
75
- };
76
-
77
- callbacks.dropped = function(event) {
78
-
79
- };
80
-
81
- //
82
- callbacks.dragStart = function(event) {
83
-
84
- };
85
-
86
- callbacks.dragMove = function(event) {
87
-
88
- };
89
-
90
- callbacks.dragStop = function(event) {
91
-
92
- };
93
-
94
- callbacks.beforeDrop = function(event) {
95
-
96
- };
97
-
98
- scope.$watch(attrs.uiTree, function(newVal, oldVal){
99
- angular.forEach(newVal, function(value, key){
100
- if (callbacks[key]) {
101
- if (typeof value === "function") {
102
- callbacks[key] = value;
103
- }
104
- }
105
- });
106
-
107
- scope.$callbacks = callbacks;
108
- }, true);
109
-
110
-
111
- }
112
- };
113
- }
114
- ]);
115
- })();
@@ -1,27 +0,0 @@
1
- (function () {
2
- 'use strict';
3
-
4
- angular.module('ui.tree')
5
- .directive('uiTreeHandle', [ 'treeConfig', '$window',
6
- function(treeConfig) {
7
- return {
8
- require: '^uiTreeNode',
9
- restrict: 'A',
10
- scope: true,
11
- controller: 'TreeHandleController',
12
- link: function(scope, element, attrs, treeNodeCtrl) {
13
- var config = {};
14
- angular.extend(config, treeConfig);
15
- if (config.handleClass) {
16
- element.addClass(config.handleClass);
17
- }
18
- // connect with the tree node.
19
- if (scope != treeNodeCtrl.scope) {
20
- scope.$nodeScope = treeNodeCtrl.scope;
21
- treeNodeCtrl.scope.$handleScope = scope;
22
- }
23
- }
24
- };
25
- }
26
- ]);
27
- })();
@@ -1,427 +0,0 @@
1
- (function () {
2
- 'use strict';
3
-
4
- angular.module('ui.tree')
5
-
6
- .directive('uiTreeNode', ['treeConfig', '$uiTreeHelper', '$window', '$document','$timeout',
7
- function (treeConfig, $uiTreeHelper, $window, $document, $timeout) {
8
- return {
9
- require: ['^uiTreeNodes', '^uiTree'],
10
- restrict: 'A',
11
- controller: 'TreeNodeController',
12
- link: function(scope, element, attrs, controllersArr) {
13
- var config = {};
14
- angular.extend(config, treeConfig);
15
- if (config.nodeClass) {
16
- element.addClass(config.nodeClass);
17
- }
18
- scope.init(controllersArr);
19
-
20
- scope.collapsed = !!$uiTreeHelper.getNodeAttribute(scope, 'collapsed');
21
-
22
- scope.$watch(attrs.collapsed, function(val) {
23
- if((typeof val) == "boolean") {
24
- scope.collapsed = val;
25
- }
26
- });
27
-
28
- scope.$watch('collapsed', function(val) {
29
- $uiTreeHelper.setNodeAttribute(scope, 'collapsed', val);
30
- attrs.$set('collapsed', val);
31
- });
32
-
33
- var hasTouch = 'ontouchstart' in window;
34
- // todo startPos is unused
35
- var startPos, firstMoving, dragInfo, pos;
36
- var placeElm, hiddenPlaceElm, dragElm;
37
- var treeScope = null;
38
- var elements; // As a parameter for callbacks
39
- var dragDelaying = true;
40
- var dragStarted = false;
41
- var dragTimer = null;
42
- var body = document.body,
43
- html = document.documentElement,
44
- document_height,
45
- document_width;
46
-
47
- var dragStart = function(e) {
48
- if (!hasTouch && (e.button == 2 || e.which == 3)) {
49
- // disable right click
50
- return;
51
- }
52
- if (e.uiTreeDragging || (e.originalEvent && e.originalEvent.uiTreeDragging)) { // event has already fired in other scope.
53
- return;
54
- }
55
-
56
- // the element which is clicked.
57
- var eventElm = angular.element(e.target);
58
- var eventScope = eventElm.scope();
59
- if (!eventScope || !eventScope.$type) {
60
- return;
61
- }
62
- if (eventScope.$type != 'uiTreeNode'
63
- && eventScope.$type != 'uiTreeHandle') { // Check if it is a node or a handle
64
- return;
65
- }
66
- if (eventScope.$type == 'uiTreeNode'
67
- && eventScope.$handleScope) { // If the node has a handle, then it should be clicked by the handle
68
- return;
69
- }
70
-
71
- var eventElmTagName = eventElm.prop('tagName').toLowerCase();
72
- if (eventElmTagName == 'input' ||
73
- eventElmTagName == 'textarea' ||
74
- eventElmTagName == 'button' ||
75
- eventElmTagName == 'select') { // if it's a input or button, ignore it
76
- return;
77
- }
78
-
79
- // check if it or it's parents has a 'data-nodrag' attribute
80
- while (eventElm && eventElm[0] && eventElm[0] != element) {
81
- if ($uiTreeHelper.nodrag(eventElm)) { // if the node mark as `nodrag`, DONOT drag it.
82
- return;
83
- }
84
- eventElm = eventElm.parent();
85
- }
86
-
87
- if (!scope.beforeDrag(scope)){
88
- return;
89
- }
90
-
91
- e.uiTreeDragging = true; // stop event bubbling
92
- if (e.originalEvent) {
93
- e.originalEvent.uiTreeDragging = true;
94
- }
95
- e.preventDefault();
96
- var eventObj = $uiTreeHelper.eventObj(e);
97
-
98
- firstMoving = true;
99
- dragInfo = $uiTreeHelper.dragInfo(scope);
100
-
101
- var tagName = scope.$element.prop('tagName');
102
- if (tagName.toLowerCase() === 'tr') {
103
- placeElm = angular.element($window.document.createElement(tagName));
104
- var tdElm = angular.element($window.document.createElement('td'))
105
- .addClass(config.placeHolderClass);
106
- placeElm.append(tdElm);
107
- } else {
108
- placeElm = angular.element($window.document.createElement(tagName))
109
- .addClass(config.placeHolderClass);
110
- }
111
- hiddenPlaceElm = angular.element($window.document.createElement(tagName));
112
- if (config.hiddenClass) {
113
- hiddenPlaceElm.addClass(config.hiddenClass);
114
- }
115
- pos = $uiTreeHelper.positionStarted(eventObj, scope.$element);
116
- placeElm.css('height', $uiTreeHelper.height(scope.$element) + 'px');
117
- placeElm.css('width', $uiTreeHelper.width(scope.$element) + 'px');
118
- dragElm = angular.element($window.document.createElement(scope.$parentNodesScope.$element.prop('tagName')))
119
- .addClass(scope.$parentNodesScope.$element.attr('class')).addClass(config.dragClass);
120
- dragElm.css('width', $uiTreeHelper.width(scope.$element) + 'px');
121
- dragElm.css('z-index', 9999);
122
-
123
- // Prevents cursor to change rapidly in Opera 12.16 and IE when dragging an element
124
- var hStyle = (scope.$element[0].querySelector('.angular-ui-tree-handle') || scope.$element[0]).currentStyle;
125
- if (hStyle) {
126
- document.body.setAttribute('ui-tree-cursor', $document.find('body').css('cursor') || '');
127
- $document.find('body').css({'cursor': hStyle.cursor + '!important'});
128
- }
129
-
130
- scope.$element.after(placeElm);
131
- scope.$element.after(hiddenPlaceElm);
132
- dragElm.append(scope.$element);
133
- $document.find('body').append(dragElm);
134
- dragElm.css({
135
- 'left' : eventObj.pageX - pos.offsetX + 'px',
136
- 'top' : eventObj.pageY - pos.offsetY + 'px'
137
- });
138
- elements = {
139
- placeholder: placeElm,
140
- dragging: dragElm
141
- };
142
-
143
- angular.element($document).bind('touchend', dragEndEvent);
144
- angular.element($document).bind('touchcancel', dragEndEvent);
145
- angular.element($document).bind('touchmove', dragMoveEvent);
146
- angular.element($document).bind('mouseup', dragEndEvent);
147
- angular.element($document).bind('mousemove', dragMoveEvent);
148
- angular.element($document).bind('mouseleave', dragCancelEvent);
149
-
150
- document_height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
151
- document_width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
152
- };
153
-
154
- var dragMove = function(e) {
155
- if (!dragStarted) {
156
- if (!dragDelaying) {
157
- dragStarted = true;
158
- scope.$apply(function() {
159
- scope.$callbacks.dragStart(dragInfo.eventArgs(elements, pos));
160
- });
161
- }
162
- return;
163
- }
164
-
165
- var eventObj = $uiTreeHelper.eventObj(e);
166
- var prev, leftElmPos, topElmPos;
167
-
168
- if (dragElm) {
169
- e.preventDefault();
170
-
171
- if ($window.getSelection) {
172
- $window.getSelection().removeAllRanges();
173
- } else if ($window.document.selection) {
174
- $window.document.selection.empty();
175
- }
176
-
177
- leftElmPos = eventObj.pageX - pos.offsetX;
178
- topElmPos = eventObj.pageY - pos.offsetY;
179
-
180
- //dragElm can't leave the screen on the left
181
- if(leftElmPos < 0){
182
- leftElmPos = 0;
183
- }
184
-
185
- //dragElm can't leave the screen on the top
186
- if(topElmPos < 0){
187
- topElmPos = 0;
188
- }
189
-
190
- //dragElm can't leave the screen on the bottom
191
- if ((topElmPos + 10) > document_height){
192
- topElmPos = document_height - 10;
193
- }
194
-
195
- //dragElm can't leave the screen on the right
196
- if((leftElmPos + 10) > document_width) {
197
- leftElmPos = document_width - 10;
198
- }
199
-
200
- dragElm.css({
201
- 'left': leftElmPos + 'px',
202
- 'top': topElmPos + 'px'
203
- });
204
-
205
- var top_scroll = window.pageYOffset || $window.document.documentElement.scrollTop;
206
- var bottom_scroll = top_scroll + (window.innerHeight || $window.document.clientHeight || $window.document.clientHeight);
207
-
208
- // to scroll down if cursor y-position is greater than the bottom position the vertical scroll
209
- if (bottom_scroll < eventObj.pageY && bottom_scroll <= document_height) {
210
- window.scrollBy(0, 10);
211
- }
212
-
213
- // to scroll top if cursor y-position is less than the top position the vertical scroll
214
- if (top_scroll > eventObj.pageY) {
215
- window.scrollBy(0, -10);
216
- }
217
-
218
- $uiTreeHelper.positionMoved(e, pos, firstMoving);
219
- if (firstMoving) {
220
- firstMoving = false;
221
- return;
222
- }
223
-
224
- // move horizontal
225
- if (pos.dirAx && pos.distAxX >= config.levelThreshold) {
226
- pos.distAxX = 0;
227
-
228
- // increase horizontal level if previous sibling exists and is not collapsed
229
- if (pos.distX > 0) {
230
- prev = dragInfo.prev();
231
- if (prev && !prev.collapsed
232
- && prev.accept(scope, prev.childNodesCount())) {
233
- prev.$childNodesScope.$element.append(placeElm);
234
- dragInfo.moveTo(prev.$childNodesScope, prev.childNodes(), prev.childNodesCount());
235
- }
236
- }
237
-
238
- // decrease horizontal level
239
- if (pos.distX < 0) {
240
- // we can't decrease a level if an item preceeds the current one
241
- var next = dragInfo.next();
242
- if (!next) {
243
- var target = dragInfo.parentNode(); // As a sibling of it's parent node
244
- if (target
245
- && target.$parentNodesScope.accept(scope, target.index() + 1)) {
246
- target.$element.after(placeElm);
247
- dragInfo.moveTo(target.$parentNodesScope, target.siblings(), target.index() + 1);
248
- }
249
- }
250
- }
251
- }
252
-
253
- // check if add it as a child node first
254
- // todo decrease is unused
255
- var decrease = ($uiTreeHelper.offset(dragElm).left - $uiTreeHelper.offset(placeElm).left) >= config.threshold;
256
- var targetX = eventObj.pageX - $window.document.body.scrollLeft;
257
- var targetY = eventObj.pageY - (window.pageYOffset || $window.document.documentElement.scrollTop);
258
-
259
- // Select the drag target. Because IE does not support CSS 'pointer-events: none', it will always
260
- // pick the drag element itself as the target. To prevent this, we hide the drag element while
261
- // selecting the target.
262
- var displayElm;
263
- if (angular.isFunction(dragElm.hide)) {
264
- dragElm.hide();
265
- }else{
266
- displayElm = dragElm[0].style.display;
267
- dragElm[0].style.display = "none";
268
- }
269
-
270
- // when using elementFromPoint() inside an iframe, you have to call
271
- // elementFromPoint() twice to make sure IE8 returns the correct value
272
- $window.document.elementFromPoint(targetX, targetY);
273
-
274
- var targetElm = angular.element($window.document.elementFromPoint(targetX, targetY));
275
- if (angular.isFunction(dragElm.show)) {
276
- dragElm.show();
277
- }else{
278
- dragElm[0].style.display = displayElm;
279
- }
280
-
281
- // move vertical
282
- if (!pos.dirAx) {
283
- var targetBefore, targetNode;
284
- // check it's new position
285
- targetNode = targetElm.scope();
286
- var isEmpty = false;
287
- if (!targetNode) {
288
- return;
289
- }
290
- if (targetNode.$type == 'uiTree' && targetNode.dragEnabled) {
291
- isEmpty = targetNode.isEmpty(); // Check if it's empty tree
292
- }
293
- if (targetNode.$type == 'uiTreeHandle') {
294
- targetNode = targetNode.$nodeScope;
295
- }
296
- if (targetNode.$type != 'uiTreeNode'
297
- && !isEmpty) { // Check if it is a uiTreeNode or it's an empty tree
298
- return;
299
- }
300
-
301
- // if placeholder move from empty tree, reset it.
302
- if (treeScope && placeElm.parent()[0] != treeScope.$element[0]) {
303
- treeScope.resetEmptyElement();
304
- treeScope = null;
305
- }
306
-
307
- if (isEmpty) { // it's an empty tree
308
- treeScope = targetNode;
309
- if (targetNode.$nodesScope.accept(scope, 0)) {
310
- targetNode.place(placeElm);
311
- dragInfo.moveTo(targetNode.$nodesScope, targetNode.$nodesScope.childNodes(), 0);
312
- }
313
- } else if (targetNode.dragEnabled()){ // drag enabled
314
- targetElm = targetNode.$element; // Get the element of ui-tree-node
315
- var targetOffset = $uiTreeHelper.offset(targetElm);
316
- targetBefore = targetNode.horizontal ? eventObj.pageX < (targetOffset.left + $uiTreeHelper.width(targetElm) / 2)
317
- : eventObj.pageY < (targetOffset.top + $uiTreeHelper.height(targetElm) / 2);
318
-
319
- if (targetNode.$parentNodesScope.accept(scope, targetNode.index())) {
320
- if (targetBefore) {
321
- targetElm[0].parentNode.insertBefore(placeElm[0], targetElm[0]);
322
- dragInfo.moveTo(targetNode.$parentNodesScope, targetNode.siblings(), targetNode.index());
323
- } else {
324
- targetElm.after(placeElm);
325
- dragInfo.moveTo(targetNode.$parentNodesScope, targetNode.siblings(), targetNode.index() + 1);
326
- }
327
- }
328
- else if (!targetBefore && targetNode.accept(scope, targetNode.childNodesCount())) { // we have to check if it can add the dragging node as a child
329
- targetNode.$childNodesScope.$element.append(placeElm);
330
- dragInfo.moveTo(targetNode.$childNodesScope, targetNode.childNodes(), targetNode.childNodesCount());
331
- }
332
- }
333
-
334
- }
335
-
336
- scope.$apply(function() {
337
- scope.$callbacks.dragMove(dragInfo.eventArgs(elements, pos));
338
- });
339
- }
340
- };
341
-
342
- var dragEnd = function(e) {
343
- e.preventDefault();
344
-
345
- if (dragElm) {
346
- scope.$treeScope.$apply(function() {
347
- scope.$callbacks.beforeDrop(dragInfo.eventArgs(elements, pos));
348
- });
349
- // roll back elements changed
350
- hiddenPlaceElm.replaceWith(scope.$element);
351
- placeElm.remove();
352
-
353
- dragElm.remove();
354
- dragElm = null;
355
- if (scope.$$apply) {
356
- dragInfo.apply();
357
- scope.$treeScope.$apply(function() {
358
- scope.$callbacks.dropped(dragInfo.eventArgs(elements, pos));
359
- });
360
- } else {
361
- bindDrag();
362
- }
363
- scope.$treeScope.$apply(function() {
364
- scope.$callbacks.dragStop(dragInfo.eventArgs(elements, pos));
365
- });
366
- scope.$$apply = false;
367
- dragInfo = null;
368
-
369
- }
370
-
371
- // Restore cursor in Opera 12.16 and IE
372
- var oldCur = document.body.getAttribute('ui-tree-cursor');
373
- if (oldCur !== null) {
374
- $document.find('body').css({'cursor': oldCur});
375
- document.body.removeAttribute('ui-tree-cursor');
376
- }
377
-
378
- angular.element($document).unbind('touchend', dragEndEvent); // Mobile
379
- angular.element($document).unbind('touchcancel', dragEndEvent); // Mobile
380
- angular.element($document).unbind('touchmove', dragMoveEvent); // Mobile
381
- angular.element($document).unbind('mouseup', dragEndEvent);
382
- angular.element($document).unbind('mousemove', dragMoveEvent);
383
- angular.element($window.document.body).unbind('mouseleave', dragCancelEvent);
384
- };
385
-
386
- var dragStartEvent = function(e) {
387
- if (scope.dragEnabled()) {
388
- dragStart(e);
389
- }
390
- };
391
-
392
- var dragMoveEvent = function(e) {
393
- dragMove(e);
394
- };
395
-
396
- var dragEndEvent = function(e) {
397
- scope.$$apply = true;
398
- dragEnd(e);
399
- };
400
-
401
- var dragCancelEvent = function(e) {
402
- dragEnd(e);
403
- };
404
-
405
- var bindDrag = function() {
406
- element.bind('touchstart mousedown', function (e) {
407
- dragDelaying = true;
408
- dragStarted = false;
409
- dragStartEvent(e);
410
- dragTimer = $timeout(function(){dragDelaying = false;}, scope.dragDelay);
411
- });
412
- element.bind('touchend touchcancel mouseup',function(){$timeout.cancel(dragTimer);});
413
- };
414
- bindDrag();
415
-
416
- angular.element($window.document.body).bind("keydown", function(e) {
417
- if (e.keyCode == 27) {
418
- scope.$$apply = false;
419
- dragEnd(e);
420
- }
421
- });
422
- }
423
- };
424
- }
425
- ]);
426
-
427
- })();