| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 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 |
dropzoneClass: 'angular-ui-tree-dropzone', |
| 14 |
hiddenClass: 'angular-ui-tree-hidden', |
| 15 |
nodesClass: 'angular-ui-tree-nodes', |
| 16 |
nodeClass: 'angular-ui-tree-node', |
| 17 |
handleClass: 'angular-ui-tree-handle', |
| 18 |
placeholderClass: 'angular-ui-tree-placeholder', |
| 19 |
dragClass: 'angular-ui-tree-drag', |
| 20 |
dragThreshold: 3, |
| 21 |
defaultCollapsed: false, |
| 22 |
appendChildOnHover: true |
| 23 |
}); |
| 24 |
|
| 25 |
})(); |
| 26 |
|
| 27 |
(function () { |
| 28 |
'use strict'; |
| 29 |
|
| 30 |
angular.module('ui.tree') |
| 31 |
|
| 32 |
.controller('TreeHandleController', ['$scope', '$element', |
| 33 |
function ($scope, $element) { |
| 34 |
this.scope = $scope; |
| 35 |
|
| 36 |
$scope.$element = $element; |
| 37 |
$scope.$nodeScope = null; |
| 38 |
$scope.$type = 'uiTreeHandle'; |
| 39 |
|
| 40 |
} |
| 41 |
]); |
| 42 |
})(); |
| 43 |
|
| 44 |
(function () { |
| 45 |
'use strict'; |
| 46 |
|
| 47 |
angular.module('ui.tree') |
| 48 |
.controller('TreeNodeController', ['$scope', '$element', |
| 49 |
function ($scope, $element) { |
| 50 |
this.scope = $scope; |
| 51 |
|
| 52 |
$scope.$element = $element; |
| 53 |
$scope.$modelValue = null; |
| 54 |
$scope.$parentNodeScope = null; |
| 55 |
$scope.$childNodesScope = null; |
| 56 |
$scope.$parentNodesScope = null; |
| 57 |
$scope.$treeScope = null; |
| 58 |
$scope.$handleScope = null; |
| 59 |
$scope.$type = 'uiTreeNode'; |
| 60 |
$scope.$$allowNodeDrop = false; |
| 61 |
$scope.collapsed = false; |
| 62 |
$scope.expandOnHover = false; |
| 63 |
|
| 64 |
|
| 65 |
$scope.init = function (controllersArr) { |
| 66 |
var treeNodesCtrl = controllersArr[0]; |
| 67 |
$scope.$treeScope = controllersArr[1] ? controllersArr[1].scope : null; |
| 68 |
|
| 69 |
|
| 70 |
$scope.$parentNodeScope = treeNodesCtrl.scope.$nodeScope; |
| 71 |
|
| 72 |
|
| 73 |
$scope.$modelValue = treeNodesCtrl.scope.$modelValue[$scope.$index]; |
| 74 |
$scope.$parentNodesScope = treeNodesCtrl.scope; |
| 75 |
|
| 76 |
|
| 77 |
treeNodesCtrl.scope.initSubNode($scope); |
| 78 |
|
| 79 |
$element.on('$destroy', function () { |
| 80 |
|
| 81 |
|
| 82 |
treeNodesCtrl.scope.destroySubNode($scope); |
| 83 |
}); |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
$scope.index = function () { |
| 88 |
return $scope.$parentNodesScope.$modelValue.indexOf($scope.$modelValue); |
| 89 |
}; |
| 90 |
|
| 91 |
$scope.dragEnabled = function () { |
| 92 |
return !($scope.$treeScope && !$scope.$treeScope.dragEnabled); |
| 93 |
}; |
| 94 |
|
| 95 |
$scope.isSibling = function (targetNode) { |
| 96 |
return $scope.$parentNodesScope == targetNode.$parentNodesScope; |
| 97 |
}; |
| 98 |
|
| 99 |
$scope.isChild = function (targetNode) { |
| 100 |
var nodes = $scope.childNodes(); |
| 101 |
return nodes && nodes.indexOf(targetNode) > -1; |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
$scope.prev = function () { |
| 106 |
var index = $scope.index(); |
| 107 |
if (index > 0) { |
| 108 |
return $scope.siblings()[index - 1]; |
| 109 |
} |
| 110 |
return null; |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
$scope.siblings = function () { |
| 115 |
return $scope.$parentNodesScope.childNodes(); |
| 116 |
}; |
| 117 |
|
| 118 |
$scope.childNodesCount = function () { |
| 119 |
return $scope.childNodes() ? $scope.childNodes().length : 0; |
| 120 |
}; |
| 121 |
|
| 122 |
$scope.hasChild = function () { |
| 123 |
return $scope.childNodesCount() > 0; |
| 124 |
}; |
| 125 |
|
| 126 |
$scope.childNodes = function () { |
| 127 |
return $scope.$childNodesScope && $scope.$childNodesScope.$modelValue ? |
| 128 |
$scope.$childNodesScope.childNodes() : |
| 129 |
null; |
| 130 |
}; |
| 131 |
|
| 132 |
$scope.accept = function (sourceNode, destIndex) { |
| 133 |
return $scope.$childNodesScope && |
| 134 |
$scope.$childNodesScope.$modelValue && |
| 135 |
$scope.$childNodesScope.accept(sourceNode, destIndex); |
| 136 |
}; |
| 137 |
|
| 138 |
$scope.remove = function () { |
| 139 |
return $scope.$parentNodesScope.removeNode($scope); |
| 140 |
}; |
| 141 |
|
| 142 |
$scope.toggle = function () { |
| 143 |
$scope.collapsed = !$scope.collapsed; |
| 144 |
$scope.$treeScope.$callbacks.toggle($scope.collapsed, $scope); |
| 145 |
}; |
| 146 |
|
| 147 |
$scope.collapse = function () { |
| 148 |
$scope.collapsed = true; |
| 149 |
}; |
| 150 |
|
| 151 |
$scope.expand = function () { |
| 152 |
$scope.collapsed = false; |
| 153 |
}; |
| 154 |
|
| 155 |
$scope.depth = function () { |
| 156 |
var parentNode = $scope.$parentNodeScope; |
| 157 |
if (parentNode) { |
| 158 |
return parentNode.depth() + 1; |
| 159 |
} |
| 160 |
return 1; |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
function countSubTreeDepth(scope) { |
| 170 |
if (!scope) { |
| 171 |
return 0; |
| 172 |
} |
| 173 |
var thisLevelDepth = 0, |
| 174 |
childNodes = scope.childNodes(), |
| 175 |
childNode, |
| 176 |
childDepth, |
| 177 |
i; |
| 178 |
if (!childNodes || childNodes.length === 0) { |
| 179 |
return 0; |
| 180 |
} |
| 181 |
for (i = childNodes.length - 1; i >= 0 ; i--) { |
| 182 |
childNode = childNodes[i], |
| 183 |
childDepth = 1 + countSubTreeDepth(childNode); |
| 184 |
thisLevelDepth = Math.max(thisLevelDepth, childDepth); |
| 185 |
} |
| 186 |
return thisLevelDepth; |
| 187 |
} |
| 188 |
|
| 189 |
$scope.maxSubDepth = function () { |
| 190 |
return $scope.$childNodesScope ? countSubTreeDepth($scope.$childNodesScope) : 0; |
| 191 |
}; |
| 192 |
} |
| 193 |
]); |
| 194 |
})(); |
| 195 |
|
| 196 |
(function () { |
| 197 |
'use strict'; |
| 198 |
|
| 199 |
angular.module('ui.tree') |
| 200 |
|
| 201 |
.controller('TreeNodesController', ['$scope', '$element', '$timeout', |
| 202 |
function ($scope, $element, $timeout) { |
| 203 |
this.scope = $scope; |
| 204 |
|
| 205 |
$scope.$element = $element; |
| 206 |
$scope.$modelValue = null; |
| 207 |
$scope.$nodeScope = null; |
| 208 |
$scope.$treeScope = null; |
| 209 |
$scope.$type = 'uiTreeNodes'; |
| 210 |
$scope.$nodesMap = {}; |
| 211 |
|
| 212 |
$scope.nodropEnabled = false; |
| 213 |
$scope.maxDepth = 0; |
| 214 |
$scope.cloneEnabled = false; |
| 215 |
|
| 216 |
$scope.initSubNode = function (subNode) { |
| 217 |
if (!subNode.$modelValue) { |
| 218 |
return null; |
| 219 |
} |
| 220 |
$scope.$nodesMap[subNode.$modelValue.$$hashKey] = subNode; |
| 221 |
}; |
| 222 |
|
| 223 |
$scope.destroySubNode = function (subNode) { |
| 224 |
if (!subNode.$modelValue) { |
| 225 |
return null; |
| 226 |
} |
| 227 |
$scope.$nodesMap[subNode.$modelValue.$$hashKey] = null; |
| 228 |
}; |
| 229 |
|
| 230 |
$scope.accept = function (sourceNode, destIndex) { |
| 231 |
return $scope.$treeScope.$callbacks.accept(sourceNode, $scope, destIndex); |
| 232 |
}; |
| 233 |
|
| 234 |
$scope.beforeDrag = function (sourceNode) { |
| 235 |
return $scope.$treeScope.$callbacks.beforeDrag(sourceNode); |
| 236 |
}; |
| 237 |
|
| 238 |
$scope.isParent = function (node) { |
| 239 |
return node.$parentNodesScope == $scope; |
| 240 |
}; |
| 241 |
|
| 242 |
$scope.hasChild = function () { |
| 243 |
return $scope.$modelValue.length > 0; |
| 244 |
}; |
| 245 |
|
| 246 |
|
| 247 |
$scope.removeNode = function (node) { |
| 248 |
var index = $scope.$modelValue.indexOf(node.$modelValue); |
| 249 |
if (index > -1) { |
| 250 |
$timeout(function () { |
| 251 |
$scope.$modelValue.splice(index, 1)[0]; |
| 252 |
}); |
| 253 |
return $scope.$treeScope.$callbacks.removed(node); |
| 254 |
} |
| 255 |
return null; |
| 256 |
}; |
| 257 |
|
| 258 |
|
| 259 |
$scope.insertNode = function (index, nodeData) { |
| 260 |
$timeout(function () { |
| 261 |
$scope.$modelValue.splice(index, 0, nodeData); |
| 262 |
}); |
| 263 |
}; |
| 264 |
|
| 265 |
$scope.childNodes = function () { |
| 266 |
var i, nodes = []; |
| 267 |
if ($scope.$modelValue) { |
| 268 |
for (i = 0; i < $scope.$modelValue.length; i++) { |
| 269 |
nodes.push($scope.$nodesMap[$scope.$modelValue[i].$$hashKey]); |
| 270 |
} |
| 271 |
} |
| 272 |
return nodes; |
| 273 |
}; |
| 274 |
|
| 275 |
$scope.depth = function () { |
| 276 |
if ($scope.$nodeScope) { |
| 277 |
return $scope.$nodeScope.depth(); |
| 278 |
} |
| 279 |
return 0; |
| 280 |
}; |
| 281 |
|
| 282 |
|
| 283 |
$scope.outOfDepth = function (sourceNode) { |
| 284 |
var maxDepth = $scope.maxDepth || $scope.$treeScope.maxDepth; |
| 285 |
if (maxDepth > 0) { |
| 286 |
return $scope.depth() + sourceNode.maxSubDepth() + 1 > maxDepth; |
| 287 |
} |
| 288 |
return false; |
| 289 |
}; |
| 290 |
|
| 291 |
} |
| 292 |
]); |
| 293 |
})(); |
| 294 |
|
| 295 |
(function () { |
| 296 |
'use strict'; |
| 297 |
|
| 298 |
angular.module('ui.tree') |
| 299 |
|
| 300 |
.controller('TreeController', ['$scope', '$element', |
| 301 |
function ($scope, $element) { |
| 302 |
this.scope = $scope; |
| 303 |
|
| 304 |
$scope.$element = $element; |
| 305 |
$scope.$nodesScope = null; |
| 306 |
$scope.$type = 'uiTree'; |
| 307 |
$scope.$emptyElm = null; |
| 308 |
$scope.$dropzoneElm = null; |
| 309 |
$scope.$callbacks = null; |
| 310 |
|
| 311 |
$scope.dragEnabled = true; |
| 312 |
$scope.emptyPlaceholderEnabled = true; |
| 313 |
$scope.maxDepth = 0; |
| 314 |
$scope.dragDelay = 0; |
| 315 |
$scope.cloneEnabled = false; |
| 316 |
$scope.nodropEnabled = false; |
| 317 |
$scope.dropzoneEnabled = false; |
| 318 |
|
| 319 |
|
| 320 |
$scope.isEmpty = function () { |
| 321 |
return ($scope.$nodesScope && $scope.$nodesScope.$modelValue |
| 322 |
&& $scope.$nodesScope.$modelValue.length === 0); |
| 323 |
}; |
| 324 |
|
| 325 |
|
| 326 |
$scope.place = function (placeElm) { |
| 327 |
$scope.$nodesScope.$element.append(placeElm); |
| 328 |
$scope.$emptyElm.remove(); |
| 329 |
}; |
| 330 |
|
| 331 |
this.resetEmptyElement = function () { |
| 332 |
if ((!$scope.$nodesScope.$modelValue || $scope.$nodesScope.$modelValue.length === 0) && |
| 333 |
$scope.emptyPlaceholderEnabled) { |
| 334 |
$element.append($scope.$emptyElm); |
| 335 |
} else { |
| 336 |
$scope.$emptyElm.remove(); |
| 337 |
} |
| 338 |
}; |
| 339 |
|
| 340 |
this.resetDropzoneElement = function () { |
| 341 |
if ((!$scope.$nodesScope.$modelValue || $scope.$nodesScope.$modelValue.length !== 0) && |
| 342 |
$scope.dropzoneEnabled) { |
| 343 |
$element.append($scope.$dropzoneElm); |
| 344 |
} else { |
| 345 |
$scope.$dropzoneElm.remove(); |
| 346 |
} |
| 347 |
}; |
| 348 |
|
| 349 |
$scope.resetEmptyElement = this.resetEmptyElement; |
| 350 |
$scope.resetDropzoneElement = this.resetDropzoneElement; |
| 351 |
} |
| 352 |
]); |
| 353 |
})(); |
| 354 |
|
| 355 |
(function () { |
| 356 |
'use strict'; |
| 357 |
|
| 358 |
angular.module('ui.tree') |
| 359 |
.directive('uiTree', ['treeConfig', '$window', |
| 360 |
function (treeConfig, $window) { |
| 361 |
return { |
| 362 |
restrict: 'A', |
| 363 |
scope: true, |
| 364 |
controller: 'TreeController', |
| 365 |
link: function (scope, element, attrs, ctrl) { |
| 366 |
var callbacks = { |
| 367 |
accept: null, |
| 368 |
beforeDrag: null |
| 369 |
}, |
| 370 |
config = {}, |
| 371 |
tdElm, |
| 372 |
$trElm, |
| 373 |
emptyElmColspan; |
| 374 |
|
| 375 |
|
| 376 |
angular.extend(config, treeConfig); |
| 377 |
|
| 378 |
if (config.treeClass) { |
| 379 |
element.addClass(config.treeClass); |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
if (element.prop('tagName').toLowerCase() === 'table') { |
| 384 |
scope.$emptyElm = angular.element($window.document.createElement('tr')); |
| 385 |
$trElm = element.find('tr'); |
| 386 |
|
| 387 |
|
| 388 |
if ($trElm.length > 0) { |
| 389 |
emptyElmColspan = angular.element($trElm).children().length; |
| 390 |
} else { |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
emptyElmColspan = 1000000; |
| 395 |
} |
| 396 |
tdElm = angular.element($window.document.createElement('td')) |
| 397 |
.attr('colspan', emptyElmColspan); |
| 398 |
scope.$emptyElm.append(tdElm); |
| 399 |
} else { |
| 400 |
scope.$emptyElm = angular.element($window.document.createElement('div')); |
| 401 |
scope.$dropzoneElm = angular.element($window.document.createElement('div')); |
| 402 |
} |
| 403 |
|
| 404 |
if (config.emptyTreeClass) { |
| 405 |
scope.$emptyElm.addClass(config.emptyTreeClass); |
| 406 |
} |
| 407 |
if (config.dropzoneClass) { |
| 408 |
scope.$dropzoneElm.addClass(config.dropzoneClass); |
| 409 |
} |
| 410 |
|
| 411 |
scope.$watch('$nodesScope.$modelValue.length', function (val) { |
| 412 |
if (!angular.isNumber(val)) { |
| 413 |
return; |
| 414 |
} |
| 415 |
|
| 416 |
ctrl.resetEmptyElement(); |
| 417 |
ctrl.resetDropzoneElement(); |
| 418 |
}, true); |
| 419 |
|
| 420 |
scope.$watch(attrs.dragEnabled, function (val) { |
| 421 |
if ((typeof val) == 'boolean') { |
| 422 |
scope.dragEnabled = val; |
| 423 |
} |
| 424 |
}); |
| 425 |
|
| 426 |
scope.$watch(attrs.emptyPlaceholderEnabled, function (val) { |
| 427 |
if ((typeof val) == 'boolean') { |
| 428 |
scope.emptyPlaceholderEnabled = val; |
| 429 |
ctrl.resetEmptyElement(); |
| 430 |
} |
| 431 |
}); |
| 432 |
|
| 433 |
scope.$watch(attrs.nodropEnabled, function (val) { |
| 434 |
if ((typeof val) == 'boolean') { |
| 435 |
scope.nodropEnabled = val; |
| 436 |
} |
| 437 |
}); |
| 438 |
|
| 439 |
scope.$watch(attrs.dropzoneEnabled, function (val) { |
| 440 |
if ((typeof val) == 'boolean') { |
| 441 |
scope.dropzoneEnabled = val; |
| 442 |
ctrl.resetDropzoneElement(); |
| 443 |
} |
| 444 |
}); |
| 445 |
|
| 446 |
scope.$watch(attrs.cloneEnabled, function (val) { |
| 447 |
if ((typeof val) == 'boolean') { |
| 448 |
scope.cloneEnabled = val; |
| 449 |
} |
| 450 |
}); |
| 451 |
|
| 452 |
scope.$watch(attrs.maxDepth, function (val) { |
| 453 |
if ((typeof val) == 'number') { |
| 454 |
scope.maxDepth = val; |
| 455 |
} |
| 456 |
}); |
| 457 |
|
| 458 |
scope.$watch(attrs.dragDelay, function (val) { |
| 459 |
if ((typeof val) == 'number') { |
| 460 |
scope.dragDelay = val; |
| 461 |
} |
| 462 |
}); |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
callbacks.accept = function (sourceNodeScope, destNodesScope, destIndex) { |
| 477 |
return !(destNodesScope.nodropEnabled || destNodesScope.$treeScope.nodropEnabled || destNodesScope.outOfDepth(sourceNodeScope)); |
| 478 |
}; |
| 479 |
|
| 480 |
callbacks.beforeDrag = function (sourceNodeScope) { |
| 481 |
return true; |
| 482 |
}; |
| 483 |
|
| 484 |
callbacks.expandTimeoutStart = function() |
| 485 |
{ |
| 486 |
|
| 487 |
}; |
| 488 |
|
| 489 |
callbacks.expandTimeoutCancel = function() |
| 490 |
{ |
| 491 |
|
| 492 |
}; |
| 493 |
|
| 494 |
callbacks.expandTimeoutEnd = function() |
| 495 |
{ |
| 496 |
|
| 497 |
}; |
| 498 |
|
| 499 |
callbacks.removed = function (node) { |
| 500 |
|
| 501 |
}; |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
callbacks.dropped = function (event) { |
| 508 |
|
| 509 |
}; |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
callbacks.dragStart = function (event) { |
| 516 |
|
| 517 |
}; |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
callbacks.dragMove = function (event) { |
| 524 |
|
| 525 |
}; |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
callbacks.dragStop = function (event) { |
| 533 |
|
| 534 |
}; |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
callbacks.beforeDrop = function (event) { |
| 545 |
|
| 546 |
}; |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
callbacks.toggle = function (collapsed, sourceNodeScope) { |
| 554 |
|
| 555 |
}; |
| 556 |
|
| 557 |
scope.$watch(attrs.uiTree, function (newVal, oldVal) { |
| 558 |
angular.forEach(newVal, function (value, key) { |
| 559 |
if (callbacks[key]) { |
| 560 |
if (typeof value === 'function') { |
| 561 |
callbacks[key] = value; |
| 562 |
} |
| 563 |
} |
| 564 |
}); |
| 565 |
|
| 566 |
scope.$callbacks = callbacks; |
| 567 |
}, true); |
| 568 |
|
| 569 |
|
| 570 |
} |
| 571 |
}; |
| 572 |
} |
| 573 |
]); |
| 574 |
})(); |
| 575 |
|
| 576 |
(function () { |
| 577 |
'use strict'; |
| 578 |
|
| 579 |
angular.module('ui.tree') |
| 580 |
.directive('uiTreeHandle', ['treeConfig', |
| 581 |
function (treeConfig) { |
| 582 |
return { |
| 583 |
require: '^uiTreeNode', |
| 584 |
restrict: 'A', |
| 585 |
scope: true, |
| 586 |
controller: 'TreeHandleController', |
| 587 |
link: function (scope, element, attrs, treeNodeCtrl) { |
| 588 |
var config = {}; |
| 589 |
angular.extend(config, treeConfig); |
| 590 |
if (config.handleClass) { |
| 591 |
element.addClass(config.handleClass); |
| 592 |
} |
| 593 |
|
| 594 |
if (scope != treeNodeCtrl.scope) { |
| 595 |
scope.$nodeScope = treeNodeCtrl.scope; |
| 596 |
treeNodeCtrl.scope.$handleScope = scope; |
| 597 |
} |
| 598 |
} |
| 599 |
}; |
| 600 |
} |
| 601 |
]); |
| 602 |
})(); |
| 603 |
|
| 604 |
(function () { |
| 605 |
'use strict'; |
| 606 |
|
| 607 |
angular.module('ui.tree') |
| 608 |
|
| 609 |
.directive('uiTreeNode', ['treeConfig', 'UiTreeHelper', '$window', '$document', '$timeout', '$q', |
| 610 |
function (treeConfig, UiTreeHelper, $window, $document, $timeout, $q) { |
| 611 |
return { |
| 612 |
require: ['^uiTreeNodes', '^uiTree'], |
| 613 |
restrict: 'A', |
| 614 |
controller: 'TreeNodeController', |
| 615 |
link: function (scope, element, attrs, controllersArr) { |
| 616 |
var config = {}, |
| 617 |
hasTouch = 'ontouchstart' in window, |
| 618 |
firstMoving, |
| 619 |
dragInfo, |
| 620 |
pos, |
| 621 |
placeElm, |
| 622 |
hiddenPlaceElm, |
| 623 |
dragElm, |
| 624 |
scrollContainerElm, |
| 625 |
unhover, |
| 626 |
treeScope = null, |
| 627 |
elements, |
| 628 |
dragDelaying = true, |
| 629 |
dragStarted = false, |
| 630 |
dragTimer = null, |
| 631 |
body = document.body, |
| 632 |
html = document.documentElement, |
| 633 |
document_height, |
| 634 |
document_width, |
| 635 |
dragStart, |
| 636 |
tagName, |
| 637 |
dragMove, |
| 638 |
dragEnd, |
| 639 |
dragStartEvent, |
| 640 |
dragMoveEvent, |
| 641 |
dragEndEvent, |
| 642 |
dragCancelEvent, |
| 643 |
dragDelay, |
| 644 |
bindDragStartEvents, |
| 645 |
bindDragMoveEvents, |
| 646 |
unbindDragMoveEvents, |
| 647 |
keydownHandler, |
| 648 |
isHandleChild, |
| 649 |
el, |
| 650 |
isUiTreeRoot, |
| 651 |
treeOfOrigin; |
| 652 |
|
| 653 |
|
| 654 |
angular.extend(config, treeConfig); |
| 655 |
|
| 656 |
if (config.nodeClass) { |
| 657 |
element.addClass(config.nodeClass); |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
scope.init(controllersArr); |
| 662 |
|
| 663 |
scope.collapsed = !!UiTreeHelper.getNodeAttribute(scope, 'collapsed') || treeConfig.defaultCollapsed; |
| 664 |
scope.expandOnHover = !!UiTreeHelper.getNodeAttribute(scope, 'expandOnHover'); |
| 665 |
scope.scrollContainer = UiTreeHelper.getNodeAttribute(scope, 'scrollContainer') || attrs.scrollContainer || null; |
| 666 |
scope.sourceOnly = scope.nodropEnabled || scope.$treeScope.nodropEnabled; |
| 667 |
|
| 668 |
scope.$watch(attrs.collapsed, function (val) { |
| 669 |
if ((typeof val) == 'boolean') { |
| 670 |
scope.collapsed = val; |
| 671 |
} |
| 672 |
}); |
| 673 |
|
| 674 |
|
| 675 |
scope.$watch('collapsed', function (val) { |
| 676 |
UiTreeHelper.setNodeAttribute(scope, 'collapsed', val); |
| 677 |
attrs.$set('collapsed', val); |
| 678 |
}); |
| 679 |
|
| 680 |
scope.$watch(attrs.expandOnHover, function(val) { |
| 681 |
if ((typeof val) === 'boolean' || (typeof val) === 'number') { |
| 682 |
scope.expandOnHover = val; |
| 683 |
} |
| 684 |
}); |
| 685 |
|
| 686 |
scope.$watch('expandOnHover', function (val) { |
| 687 |
UiTreeHelper.setNodeAttribute(scope, 'expandOnHover', val); |
| 688 |
attrs.$set('expandOnHover', val); |
| 689 |
}); |
| 690 |
|
| 691 |
attrs.$observe('scrollContainer', function(val) { |
| 692 |
if ((typeof val) === 'string') { |
| 693 |
scope.scrollContainer = val; |
| 694 |
} |
| 695 |
}); |
| 696 |
|
| 697 |
scope.$watch('scrollContainer', function(val) { |
| 698 |
UiTreeHelper.setNodeAttribute(scope, 'scrollContainer', val); |
| 699 |
attrs.$set('scrollContainer', val); |
| 700 |
scrollContainerElm = document.querySelector(val); |
| 701 |
}); |
| 702 |
|
| 703 |
scope.$on('angular-ui-tree:collapse-all', function () { |
| 704 |
scope.collapsed = true; |
| 705 |
}); |
| 706 |
|
| 707 |
scope.$on('angular-ui-tree:expand-all', function () { |
| 708 |
scope.collapsed = false; |
| 709 |
}); |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
dragStart = function (e) { |
| 718 |
|
| 719 |
|
| 720 |
if (!hasTouch && (e.button === 2 || e.which === 3)) { |
| 721 |
return; |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
if (e.uiTreeDragging || (e.originalEvent && e.originalEvent.uiTreeDragging)) { |
| 726 |
return; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
var eventElm = angular.element(e.target), |
| 731 |
isHandleChild, |
| 732 |
cloneElm, |
| 733 |
eventElmTagName, |
| 734 |
tagName, |
| 735 |
eventObj, |
| 736 |
tdElm, |
| 737 |
hStyle, |
| 738 |
isTreeNode, |
| 739 |
isTreeNodeHandle; |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
isHandleChild = UiTreeHelper.treeNodeHandlerContainerOfElement(eventElm); |
| 744 |
if (isHandleChild) { |
| 745 |
eventElm = angular.element(isHandleChild); |
| 746 |
} |
| 747 |
|
| 748 |
cloneElm = element.clone(); |
| 749 |
isTreeNode = UiTreeHelper.elementIsTreeNode(eventElm); |
| 750 |
isTreeNodeHandle = UiTreeHelper.elementIsTreeNodeHandle(eventElm); |
| 751 |
|
| 752 |
|
| 753 |
if (!isTreeNode && !isTreeNodeHandle) { |
| 754 |
return; |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
if (isTreeNode && UiTreeHelper.elementContainsTreeNodeHandler(eventElm)) { |
| 759 |
return; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
eventElmTagName = eventElm.prop('tagName').toLowerCase(); |
| 764 |
if (eventElmTagName == 'input' || |
| 765 |
eventElmTagName == 'textarea' || |
| 766 |
eventElmTagName == 'button' || |
| 767 |
eventElmTagName == 'select') { |
| 768 |
return; |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
el = angular.element(e.target); |
| 773 |
isUiTreeRoot = el[0].attributes['ui-tree']; |
| 774 |
while (el && el[0] && el[0] !== element && !isUiTreeRoot) { |
| 775 |
|
| 776 |
|
| 777 |
if (el[0].attributes) { |
| 778 |
isUiTreeRoot = el[0].attributes['ui-tree']; |
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
if (UiTreeHelper.nodrag(el)) { |
| 783 |
return; |
| 784 |
} |
| 785 |
el = el.parent(); |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
if (!scope.beforeDrag(scope)) { |
| 790 |
return; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
e.uiTreeDragging = true; |
| 795 |
if (e.originalEvent) { |
| 796 |
e.originalEvent.uiTreeDragging = true; |
| 797 |
} |
| 798 |
e.preventDefault(); |
| 799 |
|
| 800 |
|
| 801 |
eventObj = UiTreeHelper.eventObj(e); |
| 802 |
|
| 803 |
|
| 804 |
firstMoving = true; |
| 805 |
|
| 806 |
|
| 807 |
dragInfo = UiTreeHelper.dragInfo(scope); |
| 808 |
|
| 809 |
|
| 810 |
treeOfOrigin = dragInfo.source.$treeScope.$id; |
| 811 |
|
| 812 |
|
| 813 |
tagName = element.prop('tagName'); |
| 814 |
|
| 815 |
if (tagName.toLowerCase() === 'tr') { |
| 816 |
|
| 817 |
|
| 818 |
placeElm = angular.element($window.document.createElement(tagName)); |
| 819 |
|
| 820 |
|
| 821 |
tdElm = angular.element($window.document.createElement('td')) |
| 822 |
.addClass(config.placeholderClass) |
| 823 |
.attr('colspan', element[0].children.length); |
| 824 |
placeElm.append(tdElm); |
| 825 |
} else { |
| 826 |
|
| 827 |
|
| 828 |
placeElm = angular.element($window.document.createElement(tagName)) |
| 829 |
.addClass(config.placeholderClass); |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
hiddenPlaceElm = angular.element($window.document.createElement(tagName)); |
| 834 |
if (config.hiddenClass) { |
| 835 |
hiddenPlaceElm.addClass(config.hiddenClass); |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
pos = UiTreeHelper.positionStarted(eventObj, element); |
| 840 |
placeElm.css('height', element.prop('offsetHeight') + 'px'); |
| 841 |
|
| 842 |
|
| 843 |
dragElm = angular.element($window.document.createElement(scope.$parentNodesScope.$element.prop('tagName'))) |
| 844 |
.addClass(scope.$parentNodesScope.$element.attr('class')).addClass(config.dragClass); |
| 845 |
dragElm.css('width', UiTreeHelper.width(element) + 'px'); |
| 846 |
dragElm.css('z-index', 9999); |
| 847 |
|
| 848 |
|
| 849 |
hStyle = (element[0].querySelector('.angular-ui-tree-handle') || element[0]).currentStyle; |
| 850 |
if (hStyle) { |
| 851 |
document.body.setAttribute('ui-tree-cursor', $document.find('body').css('cursor') || ''); |
| 852 |
$document.find('body').css({'cursor': hStyle.cursor + '!important'}); |
| 853 |
} |
| 854 |
|
| 855 |
|
| 856 |
if (scope.sourceOnly) { |
| 857 |
placeElm.css('display', 'none'); |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
element.after(placeElm); |
| 862 |
element.after(hiddenPlaceElm); |
| 863 |
if (dragInfo.isClone() && scope.sourceOnly) { |
| 864 |
dragElm.append(cloneElm); |
| 865 |
} else { |
| 866 |
dragElm.append(element); |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
$document.find('body').append(dragElm); |
| 871 |
|
| 872 |
|
| 873 |
dragElm.css({ |
| 874 |
'left': eventObj.pageX - pos.offsetX + 'px', |
| 875 |
'top': eventObj.pageY - pos.offsetY + 'px' |
| 876 |
}); |
| 877 |
elements = { |
| 878 |
placeholder: placeElm, |
| 879 |
dragging: dragElm |
| 880 |
}; |
| 881 |
|
| 882 |
|
| 883 |
bindDragMoveEvents(); |
| 884 |
|
| 885 |
|
| 886 |
scope.$apply(function () { |
| 887 |
scope.$treeScope.$callbacks.dragStart(dragInfo.eventArgs(elements, pos)); |
| 888 |
}); |
| 889 |
|
| 890 |
|
| 891 |
document_height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); |
| 892 |
document_width = Math.max(body.scrollWidth, body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth); |
| 893 |
}; |
| 894 |
|
| 895 |
dragMove = function (e) { |
| 896 |
var eventObj = UiTreeHelper.eventObj(e), |
| 897 |
prev, |
| 898 |
next, |
| 899 |
leftElmPos, |
| 900 |
topElmPos, |
| 901 |
top_scroll, |
| 902 |
bottom_scroll, |
| 903 |
scrollContainerElmRect, |
| 904 |
target, |
| 905 |
targetX, |
| 906 |
targetY, |
| 907 |
displayElm, |
| 908 |
targetNode, |
| 909 |
targetElm, |
| 910 |
isEmpty, |
| 911 |
scrollDownBy, |
| 912 |
scrollUpBy, |
| 913 |
targetOffset, |
| 914 |
targetBefore, |
| 915 |
moveWithinTree, |
| 916 |
targetBeforeBuffer, |
| 917 |
targetHeight, |
| 918 |
targetChildElm, |
| 919 |
targetChildHeight, |
| 920 |
isDropzone; |
| 921 |
|
| 922 |
|
| 923 |
if (dragElm) { |
| 924 |
e.preventDefault(); |
| 925 |
|
| 926 |
|
| 927 |
if ($window.getSelection) { |
| 928 |
$window.getSelection().removeAllRanges(); |
| 929 |
} else if ($window.document.selection) { |
| 930 |
$window.document.selection.empty(); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
leftElmPos = eventObj.pageX - pos.offsetX; |
| 935 |
topElmPos = eventObj.pageY - pos.offsetY; |
| 936 |
|
| 937 |
|
| 938 |
if (leftElmPos < 0) { |
| 939 |
leftElmPos = 0; |
| 940 |
} |
| 941 |
|
| 942 |
|
| 943 |
if (topElmPos < 0) { |
| 944 |
topElmPos = 0; |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
if ((topElmPos + 10) > document_height) { |
| 949 |
topElmPos = document_height - 10; |
| 950 |
} |
| 951 |
|
| 952 |
|
| 953 |
if ((leftElmPos + 10) > document_width) { |
| 954 |
leftElmPos = document_width - 10; |
| 955 |
} |
| 956 |
|
| 957 |
|
| 958 |
dragElm.css({ |
| 959 |
'left': leftElmPos + 'px', |
| 960 |
'top': topElmPos + 'px' |
| 961 |
}); |
| 962 |
|
| 963 |
if (scrollContainerElm) { |
| 964 |
|
| 965 |
scrollContainerElmRect = scrollContainerElm.getBoundingClientRect(); |
| 966 |
top_scroll = scrollContainerElm.scrollTop; |
| 967 |
bottom_scroll = top_scroll + scrollContainerElm.clientHeight; |
| 968 |
|
| 969 |
|
| 970 |
if (scrollContainerElmRect.bottom < eventObj.clientY && bottom_scroll < scrollContainerElm.scrollHeight) { |
| 971 |
scrollDownBy = Math.min(scrollContainerElm.scrollHeight - bottom_scroll, 10); |
| 972 |
scrollContainerElm.scrollTop += scrollDownBy; |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
if (scrollContainerElmRect.top > eventObj.clientY && top_scroll > 0) { |
| 977 |
scrollUpBy = Math.min(top_scroll, 10); |
| 978 |
scrollContainerElm.scrollTop -= scrollUpBy; |
| 979 |
} |
| 980 |
} else { |
| 981 |
|
| 982 |
top_scroll = window.pageYOffset || $window.document.documentElement.scrollTop; |
| 983 |
bottom_scroll = top_scroll + (window.innerHeight || $window.document.clientHeight || $window.document.clientHeight); |
| 984 |
|
| 985 |
|
| 986 |
if (bottom_scroll < eventObj.pageY && bottom_scroll < document_height) { |
| 987 |
scrollDownBy = Math.min(document_height - bottom_scroll, 10); |
| 988 |
window.scrollBy(0, scrollDownBy); |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
if (top_scroll > eventObj.pageY) { |
| 993 |
scrollUpBy = Math.min(top_scroll, 10); |
| 994 |
window.scrollBy(0, -scrollUpBy); |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
UiTreeHelper.positionMoved(e, pos, firstMoving); |
| 1000 |
if (firstMoving) { |
| 1001 |
firstMoving = false; |
| 1002 |
return; |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
targetX = eventObj.pageX - ($window.pageXOffset || |
| 1007 |
$window.document.body.scrollLeft || |
| 1008 |
$window.document.documentElement.scrollLeft) - |
| 1009 |
($window.document.documentElement.clientLeft || 0); |
| 1010 |
|
| 1011 |
targetY = eventObj.pageY - ($window.pageYOffset || |
| 1012 |
$window.document.body.scrollTop || |
| 1013 |
$window.document.documentElement.scrollTop) - |
| 1014 |
($window.document.documentElement.clientTop || 0); |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
if (angular.isFunction(dragElm.hide)) { |
| 1020 |
dragElm.hide(); |
| 1021 |
} else { |
| 1022 |
displayElm = dragElm[0].style.display; |
| 1023 |
dragElm[0].style.display = 'none'; |
| 1024 |
} |
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
$window.document.elementFromPoint(targetX, targetY); |
| 1030 |
|
| 1031 |
|
| 1032 |
targetElm = angular.element($window.document.elementFromPoint(targetX, targetY)); |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
isHandleChild = UiTreeHelper.treeNodeHandlerContainerOfElement(targetElm); |
| 1037 |
if (isHandleChild) { |
| 1038 |
targetElm = angular.element(isHandleChild); |
| 1039 |
} |
| 1040 |
|
| 1041 |
if (angular.isFunction(dragElm.show)) { |
| 1042 |
dragElm.show(); |
| 1043 |
} else { |
| 1044 |
dragElm[0].style.display = displayElm; |
| 1045 |
} |
| 1046 |
|
| 1047 |
|
| 1048 |
if (UiTreeHelper.elementIsTree(targetElm)) { |
| 1049 |
targetNode = targetElm.controller('uiTree').scope; |
| 1050 |
} else if (UiTreeHelper.elementIsTreeNodeHandle(targetElm)) { |
| 1051 |
targetNode = targetElm.controller('uiTreeHandle').scope; |
| 1052 |
} else if (UiTreeHelper.elementIsTreeNode(targetElm)) { |
| 1053 |
targetNode = targetElm.controller('uiTreeNode').scope; |
| 1054 |
} else if (UiTreeHelper.elementIsTreeNodes(targetElm)) { |
| 1055 |
targetNode = targetElm.controller('uiTreeNodes').scope; |
| 1056 |
} else if (UiTreeHelper.elementIsPlaceholder(targetElm)) { |
| 1057 |
targetNode = targetElm.controller('uiTreeNodes').scope; |
| 1058 |
} else if (UiTreeHelper.elementIsDropzone(targetElm)) { |
| 1059 |
targetNode = targetElm.controller('uiTree').scope; |
| 1060 |
isDropzone = true; |
| 1061 |
} else if (targetElm.controller('uiTreeNode')) { |
| 1062 |
|
| 1063 |
targetNode = targetElm.controller('uiTreeNode').scope; |
| 1064 |
} |
| 1065 |
|
| 1066 |
moveWithinTree = (targetNode && targetNode.$treeScope && targetNode.$treeScope.$id && targetNode.$treeScope.$id === treeOfOrigin); |
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
if (moveWithinTree && pos.dirAx) { |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
if (pos.distX > 0) { |
| 1080 |
prev = dragInfo.prev(); |
| 1081 |
if (prev && !prev.collapsed |
| 1082 |
&& prev.accept(scope, prev.childNodesCount())) { |
| 1083 |
prev.$childNodesScope.$element.append(placeElm); |
| 1084 |
dragInfo.moveTo(prev.$childNodesScope, prev.childNodes(), prev.childNodesCount()); |
| 1085 |
} |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
if (pos.distX < 0) { |
| 1091 |
|
| 1092 |
next = dragInfo.next(); |
| 1093 |
if (!next) { |
| 1094 |
target = dragInfo.parentNode(); |
| 1095 |
if (target |
| 1096 |
&& target.$parentNodesScope.accept(scope, target.index() + 1)) { |
| 1097 |
target.$element.after(placeElm); |
| 1098 |
dragInfo.moveTo(target.$parentNodesScope, target.siblings(), target.index() + 1); |
| 1099 |
} |
| 1100 |
} |
| 1101 |
} |
| 1102 |
} else { |
| 1103 |
|
| 1104 |
|
| 1105 |
isEmpty = false; |
| 1106 |
|
| 1107 |
|
| 1108 |
if (!targetNode) { |
| 1109 |
return; |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
if (targetNode.$treeScope && !targetNode.$parent.nodropEnabled && !targetNode.$treeScope.nodropEnabled) { |
| 1114 |
placeElm.css('display', ''); |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
if (targetNode.$type === 'uiTree' && targetNode.dragEnabled) { |
| 1119 |
isEmpty = targetNode.isEmpty(); |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
if (targetNode.$type === 'uiTreeHandle') { |
| 1124 |
targetNode = targetNode.$nodeScope; |
| 1125 |
} |
| 1126 |
|
| 1127 |
|
| 1128 |
if (targetNode.$type !== 'uiTreeNode' && !isEmpty && !isDropzone) { |
| 1129 |
|
| 1130 |
|
| 1131 |
if (config.appendChildOnHover) { |
| 1132 |
next = dragInfo.next(); |
| 1133 |
if (!next && unhover) { |
| 1134 |
target = dragInfo.parentNode(); |
| 1135 |
target.$element.after(placeElm); |
| 1136 |
dragInfo.moveTo(target.$parentNodesScope, target.siblings(), target.index() + 1); |
| 1137 |
unhover = false; |
| 1138 |
} |
| 1139 |
} |
| 1140 |
return; |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
if (treeScope && placeElm.parent()[0] != treeScope.$element[0]) { |
| 1145 |
treeScope.resetEmptyElement(); |
| 1146 |
treeScope.resetDropzoneElement(); |
| 1147 |
treeScope = null; |
| 1148 |
} |
| 1149 |
|
| 1150 |
|
| 1151 |
if (isEmpty) { |
| 1152 |
treeScope = targetNode; |
| 1153 |
if (targetNode.$nodesScope.accept(scope, 0)) { |
| 1154 |
dragInfo.moveTo(targetNode.$nodesScope, targetNode.$nodesScope.childNodes(), 0); |
| 1155 |
} |
| 1156 |
|
| 1157 |
} else if (isDropzone) { |
| 1158 |
treeScope = targetNode; |
| 1159 |
if (targetNode.$nodesScope.accept(scope, targetNode.$nodesScope.childNodes().length)) { |
| 1160 |
dragInfo.moveTo(targetNode.$nodesScope, targetNode.$nodesScope.childNodes(), targetNode.$nodesScope.childNodes().length); |
| 1161 |
} |
| 1162 |
|
| 1163 |
} else if (targetNode.dragEnabled()) { |
| 1164 |
|
| 1165 |
|
| 1166 |
if (angular.isDefined(scope.expandTimeoutOn) && scope.expandTimeoutOn !== targetNode.id) { |
| 1167 |
$timeout.cancel(scope.expandTimeout); |
| 1168 |
delete scope.expandTimeout; |
| 1169 |
delete scope.expandTimeoutOn; |
| 1170 |
|
| 1171 |
scope.$callbacks.expandTimeoutCancel(); |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
if (targetNode.collapsed) { |
| 1176 |
if (scope.expandOnHover === true || (angular.isNumber(scope.expandOnHover) && scope.expandOnHover === 0)) { |
| 1177 |
targetNode.collapsed = false; |
| 1178 |
targetNode.$treeScope.$callbacks.toggle(false, targetNode); |
| 1179 |
} else if (scope.expandOnHover !== false && angular.isNumber(scope.expandOnHover) && scope.expandOnHover > 0) { |
| 1180 |
|
| 1181 |
|
| 1182 |
if (angular.isUndefined(scope.expandTimeoutOn)) { |
| 1183 |
scope.expandTimeoutOn = targetNode.$id; |
| 1184 |
|
| 1185 |
scope.$callbacks.expandTimeoutStart(); |
| 1186 |
scope.expandTimeout = $timeout(function() |
| 1187 |
{ |
| 1188 |
scope.$callbacks.expandTimeoutEnd(); |
| 1189 |
targetNode.collapsed = false; |
| 1190 |
targetNode.$treeScope.$callbacks.toggle(false, targetNode); |
| 1191 |
}, scope.expandOnHover); |
| 1192 |
} |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
|
| 1197 |
targetElm = targetNode.$element; |
| 1198 |
targetOffset = UiTreeHelper.offset(targetElm); |
| 1199 |
targetHeight = UiTreeHelper.height(targetElm); |
| 1200 |
targetChildElm = targetNode.$childNodesScope ? targetNode.$childNodesScope.$element : null; |
| 1201 |
targetChildHeight = targetChildElm ? UiTreeHelper.height(targetChildElm) : 0; |
| 1202 |
targetHeight -= targetChildHeight; |
| 1203 |
targetBeforeBuffer = config.appendChildOnHover ? targetHeight * 0.25 : UiTreeHelper.height(targetElm) / 2; |
| 1204 |
targetBefore = eventObj.pageY < (targetOffset.top + targetBeforeBuffer); |
| 1205 |
|
| 1206 |
if (targetNode.$parentNodesScope.accept(scope, targetNode.index())) { |
| 1207 |
if (targetBefore) { |
| 1208 |
targetElm[0].parentNode.insertBefore(placeElm[0], targetElm[0]); |
| 1209 |
dragInfo.moveTo(targetNode.$parentNodesScope, targetNode.siblings(), targetNode.index()); |
| 1210 |
} else { |
| 1211 |
|
| 1212 |
if (config.appendChildOnHover && targetNode.accept(scope, targetNode.childNodesCount())) { |
| 1213 |
targetNode.$childNodesScope.$element.prepend(placeElm); |
| 1214 |
dragInfo.moveTo(targetNode.$childNodesScope, targetNode.childNodes(), 0); |
| 1215 |
unhover = true; |
| 1216 |
} else { |
| 1217 |
targetElm.after(placeElm); |
| 1218 |
dragInfo.moveTo(targetNode.$parentNodesScope, targetNode.siblings(), targetNode.index() + 1); |
| 1219 |
} |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
} else if (!targetBefore && targetNode.accept(scope, targetNode.childNodesCount())) { |
| 1224 |
targetNode.$childNodesScope.$element.append(placeElm); |
| 1225 |
dragInfo.moveTo(targetNode.$childNodesScope, targetNode.childNodes(), targetNode.childNodesCount()); |
| 1226 |
} |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
scope.$apply(function () { |
| 1232 |
scope.$treeScope.$callbacks.dragMove(dragInfo.eventArgs(elements, pos)); |
| 1233 |
}); |
| 1234 |
} |
| 1235 |
}; |
| 1236 |
|
| 1237 |
dragEnd = function (e) { |
| 1238 |
|
| 1239 |
var dragEventArgs = dragInfo.eventArgs(elements, pos); |
| 1240 |
|
| 1241 |
e.preventDefault(); |
| 1242 |
|
| 1243 |
|
| 1244 |
unbindDragMoveEvents(); |
| 1245 |
|
| 1246 |
|
| 1247 |
$timeout.cancel(scope.expandTimeout); |
| 1248 |
|
| 1249 |
scope.$treeScope.$apply(function () { |
| 1250 |
$q.when(scope.$treeScope.$callbacks.beforeDrop(dragEventArgs)) |
| 1251 |
|
| 1252 |
|
| 1253 |
.then(function (allowDrop) { |
| 1254 |
if (allowDrop !== false && scope.$$allowNodeDrop) { |
| 1255 |
|
| 1256 |
dragInfo.apply(); |
| 1257 |
|
| 1258 |
|
| 1259 |
scope.$treeScope.$callbacks.dropped(dragEventArgs); |
| 1260 |
} else { |
| 1261 |
|
| 1262 |
bindDragStartEvents(); |
| 1263 |
} |
| 1264 |
}) |
| 1265 |
|
| 1266 |
|
| 1267 |
.catch(function () { |
| 1268 |
bindDragStartEvents(); |
| 1269 |
}) |
| 1270 |
.finally(function () { |
| 1271 |
|
| 1272 |
|
| 1273 |
hiddenPlaceElm.replaceWith(scope.$element); |
| 1274 |
placeElm.remove(); |
| 1275 |
|
| 1276 |
|
| 1277 |
if (dragElm) { |
| 1278 |
dragElm.remove(); |
| 1279 |
dragElm = null; |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
scope.$treeScope.$callbacks.dragStop(dragEventArgs); |
| 1284 |
scope.$$allowNodeDrop = false; |
| 1285 |
dragInfo = null; |
| 1286 |
|
| 1287 |
|
| 1288 |
var oldCur = document.body.getAttribute('ui-tree-cursor'); |
| 1289 |
if (oldCur !== null) { |
| 1290 |
$document.find('body').css({'cursor': oldCur}); |
| 1291 |
document.body.removeAttribute('ui-tree-cursor'); |
| 1292 |
} |
| 1293 |
}); |
| 1294 |
}); |
| 1295 |
}; |
| 1296 |
|
| 1297 |
dragStartEvent = function (e) { |
| 1298 |
if (scope.dragEnabled()) { |
| 1299 |
dragStart(e); |
| 1300 |
} |
| 1301 |
}; |
| 1302 |
|
| 1303 |
dragMoveEvent = function (e) { |
| 1304 |
dragMove(e); |
| 1305 |
}; |
| 1306 |
|
| 1307 |
dragEndEvent = function (e) { |
| 1308 |
scope.$$allowNodeDrop = true; |
| 1309 |
dragEnd(e); |
| 1310 |
}; |
| 1311 |
|
| 1312 |
dragCancelEvent = function (e) { |
| 1313 |
dragEnd(e); |
| 1314 |
}; |
| 1315 |
|
| 1316 |
dragDelay = (function () { |
| 1317 |
var to; |
| 1318 |
|
| 1319 |
return { |
| 1320 |
exec: function (fn, ms) { |
| 1321 |
if (!ms) { |
| 1322 |
ms = 0; |
| 1323 |
} |
| 1324 |
this.cancel(); |
| 1325 |
to = $timeout(fn, ms); |
| 1326 |
}, |
| 1327 |
cancel: function () { |
| 1328 |
$timeout.cancel(to); |
| 1329 |
} |
| 1330 |
}; |
| 1331 |
})(); |
| 1332 |
|
| 1333 |
keydownHandler = function (e) { |
| 1334 |
if (e.keyCode === 27) { |
| 1335 |
dragEndEvent(e); |
| 1336 |
} |
| 1337 |
}; |
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
bindDragStartEvents = function () { |
| 1344 |
element.bind('touchstart mousedown', function (e) { |
| 1345 |
|
| 1346 |
if (scope.dragDelay > 0) { |
| 1347 |
dragDelay.exec(function () { |
| 1348 |
dragStartEvent(e); |
| 1349 |
}, scope.dragDelay); |
| 1350 |
} else { |
| 1351 |
dragStartEvent(e); |
| 1352 |
} |
| 1353 |
}); |
| 1354 |
element.bind('touchend touchcancel mouseup', function () { |
| 1355 |
if (scope.dragDelay > 0) { |
| 1356 |
dragDelay.cancel(); |
| 1357 |
} |
| 1358 |
}); |
| 1359 |
}; |
| 1360 |
bindDragStartEvents(); |
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
bindDragMoveEvents = function () { |
| 1366 |
angular.element($document).bind('touchend', dragEndEvent); |
| 1367 |
angular.element($document).bind('touchcancel', dragEndEvent); |
| 1368 |
angular.element($document).bind('touchmove', dragMoveEvent); |
| 1369 |
angular.element($document).bind('mouseup', dragEndEvent); |
| 1370 |
angular.element($document).bind('mousemove', dragMoveEvent); |
| 1371 |
angular.element($document).bind('mouseleave', dragCancelEvent); |
| 1372 |
angular.element($document).bind('keydown', keydownHandler); |
| 1373 |
}; |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
unbindDragMoveEvents = function () { |
| 1379 |
angular.element($document).unbind('touchend', dragEndEvent); |
| 1380 |
angular.element($document).unbind('touchcancel', dragEndEvent); |
| 1381 |
angular.element($document).unbind('touchmove', dragMoveEvent); |
| 1382 |
angular.element($document).unbind('mouseup', dragEndEvent); |
| 1383 |
angular.element($document).unbind('mousemove', dragMoveEvent); |
| 1384 |
angular.element($document).unbind('mouseleave', dragCancelEvent); |
| 1385 |
angular.element($document).unbind('keydown', keydownHandler); |
| 1386 |
}; |
| 1387 |
} |
| 1388 |
}; |
| 1389 |
} |
| 1390 |
]); |
| 1391 |
})(); |
| 1392 |
|
| 1393 |
(function () { |
| 1394 |
'use strict'; |
| 1395 |
|
| 1396 |
angular.module('ui.tree') |
| 1397 |
.directive('uiTreeNodes', ['treeConfig', '$window', |
| 1398 |
function (treeConfig) { |
| 1399 |
return { |
| 1400 |
require: ['ngModel', '?^uiTreeNode', '^uiTree'], |
| 1401 |
restrict: 'A', |
| 1402 |
scope: true, |
| 1403 |
controller: 'TreeNodesController', |
| 1404 |
link: function (scope, element, attrs, controllersArr) { |
| 1405 |
|
| 1406 |
var config = {}, |
| 1407 |
ngModel = controllersArr[0], |
| 1408 |
treeNodeCtrl = controllersArr[1], |
| 1409 |
treeCtrl = controllersArr[2]; |
| 1410 |
|
| 1411 |
angular.extend(config, treeConfig); |
| 1412 |
if (config.nodesClass) { |
| 1413 |
element.addClass(config.nodesClass); |
| 1414 |
} |
| 1415 |
|
| 1416 |
if (treeNodeCtrl) { |
| 1417 |
treeNodeCtrl.scope.$childNodesScope = scope; |
| 1418 |
scope.$nodeScope = treeNodeCtrl.scope; |
| 1419 |
} else { |
| 1420 |
|
| 1421 |
treeCtrl.scope.$nodesScope = scope; |
| 1422 |
} |
| 1423 |
scope.$treeScope = treeCtrl.scope; |
| 1424 |
|
| 1425 |
if (ngModel) { |
| 1426 |
ngModel.$render = function () { |
| 1427 |
scope.$modelValue = ngModel.$modelValue; |
| 1428 |
}; |
| 1429 |
} |
| 1430 |
|
| 1431 |
scope.$watch(function () { |
| 1432 |
return attrs.maxDepth; |
| 1433 |
}, function (val) { |
| 1434 |
if ((typeof val) == 'number') { |
| 1435 |
scope.maxDepth = val; |
| 1436 |
} |
| 1437 |
}); |
| 1438 |
|
| 1439 |
scope.$watch(function () { |
| 1440 |
return attrs.nodropEnabled; |
| 1441 |
}, function (newVal) { |
| 1442 |
if ((typeof newVal) != 'undefined') { |
| 1443 |
scope.nodropEnabled = true; |
| 1444 |
} |
| 1445 |
}, true); |
| 1446 |
|
| 1447 |
} |
| 1448 |
}; |
| 1449 |
} |
| 1450 |
]); |
| 1451 |
})(); |
| 1452 |
|
| 1453 |
(function () { |
| 1454 |
'use strict'; |
| 1455 |
|
| 1456 |
angular.module('ui.tree') |
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
.factory('UiTreeHelper', ['$document', '$window', 'treeConfig', |
| 1468 |
function ($document, $window, treeConfig) { |
| 1469 |
return { |
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
nodesData: {}, |
| 1476 |
|
| 1477 |
setNodeAttribute: function (scope, attrName, val) { |
| 1478 |
if (!scope.$modelValue) { |
| 1479 |
return null; |
| 1480 |
} |
| 1481 |
var data = this.nodesData[scope.$modelValue.$$hashKey]; |
| 1482 |
if (!data) { |
| 1483 |
data = {}; |
| 1484 |
this.nodesData[scope.$modelValue.$$hashKey] = data; |
| 1485 |
} |
| 1486 |
data[attrName] = val; |
| 1487 |
}, |
| 1488 |
|
| 1489 |
getNodeAttribute: function (scope, attrName) { |
| 1490 |
if (!scope.$modelValue) { |
| 1491 |
return null; |
| 1492 |
} |
| 1493 |
var data = this.nodesData[scope.$modelValue.$$hashKey]; |
| 1494 |
if (data) { |
| 1495 |
return data[attrName]; |
| 1496 |
} |
| 1497 |
return null; |
| 1498 |
}, |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
nodrag: function (targetElm) { |
| 1507 |
if (typeof targetElm.attr('data-nodrag') != 'undefined') { |
| 1508 |
return targetElm.attr('data-nodrag') !== 'false'; |
| 1509 |
} |
| 1510 |
return false; |
| 1511 |
}, |
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
eventObj: function (e) { |
| 1520 |
var obj = e; |
| 1521 |
if (e.targetTouches !== undefined) { |
| 1522 |
|
| 1523 |
obj = e.targetTouches.item(0); |
| 1524 |
|
| 1525 |
} else if (e.originalEvent !== undefined && e.originalEvent.targetTouches !== undefined) { |
| 1526 |
obj = e.originalEvent.targetTouches.item(0); |
| 1527 |
} |
| 1528 |
return obj; |
| 1529 |
}, |
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
dragInfo: function (node) { |
| 1537 |
return { |
| 1538 |
source: node, |
| 1539 |
sourceInfo: { |
| 1540 |
cloneModel: node.$treeScope.cloneEnabled === true ? angular.copy(node.$modelValue) : undefined, |
| 1541 |
nodeScope: node, |
| 1542 |
index: node.index(), |
| 1543 |
nodesScope: node.$parentNodesScope |
| 1544 |
}, |
| 1545 |
index: node.index(), |
| 1546 |
|
| 1547 |
|
| 1548 |
siblings: node.siblings().slice(0), |
| 1549 |
parent: node.$parentNodesScope, |
| 1550 |
|
| 1551 |
|
| 1552 |
resetParent: function() { |
| 1553 |
this.parent = node.$parentNodesScope; |
| 1554 |
}, |
| 1555 |
|
| 1556 |
|
| 1557 |
moveTo: function (parent, siblings, index) { |
| 1558 |
this.parent = parent; |
| 1559 |
|
| 1560 |
|
| 1561 |
this.siblings = siblings.slice(0); |
| 1562 |
|
| 1563 |
|
| 1564 |
var i = this.siblings.indexOf(this.source); |
| 1565 |
if (i > -1) { |
| 1566 |
this.siblings.splice(i, 1); |
| 1567 |
if (this.source.index() < index) { |
| 1568 |
index--; |
| 1569 |
} |
| 1570 |
} |
| 1571 |
|
| 1572 |
this.siblings.splice(index, 0, this.source); |
| 1573 |
this.index = index; |
| 1574 |
}, |
| 1575 |
|
| 1576 |
|
| 1577 |
parentNode: function () { |
| 1578 |
return this.parent.$nodeScope; |
| 1579 |
}, |
| 1580 |
|
| 1581 |
|
| 1582 |
prev: function () { |
| 1583 |
if (this.index > 0) { |
| 1584 |
return this.siblings[this.index - 1]; |
| 1585 |
} |
| 1586 |
|
| 1587 |
return null; |
| 1588 |
}, |
| 1589 |
|
| 1590 |
|
| 1591 |
next: function () { |
| 1592 |
if (this.index < this.siblings.length - 1) { |
| 1593 |
return this.siblings[this.index + 1]; |
| 1594 |
} |
| 1595 |
|
| 1596 |
return null; |
| 1597 |
}, |
| 1598 |
|
| 1599 |
|
| 1600 |
isClone: function () { |
| 1601 |
return this.source.$treeScope.cloneEnabled === true; |
| 1602 |
}, |
| 1603 |
|
| 1604 |
|
| 1605 |
clonedNode: function (node) { |
| 1606 |
return angular.copy(node); |
| 1607 |
}, |
| 1608 |
|
| 1609 |
|
| 1610 |
isDirty: function () { |
| 1611 |
return this.source.$parentNodesScope != this.parent || |
| 1612 |
this.source.index() != this.index; |
| 1613 |
}, |
| 1614 |
|
| 1615 |
|
| 1616 |
isForeign: function () { |
| 1617 |
return this.source.$treeScope !== this.parent.$treeScope; |
| 1618 |
}, |
| 1619 |
|
| 1620 |
|
| 1621 |
eventArgs: function (elements, pos) { |
| 1622 |
return { |
| 1623 |
source: this.sourceInfo, |
| 1624 |
dest: { |
| 1625 |
index: this.index, |
| 1626 |
nodesScope: this.parent |
| 1627 |
}, |
| 1628 |
elements: elements, |
| 1629 |
pos: pos |
| 1630 |
}; |
| 1631 |
}, |
| 1632 |
|
| 1633 |
|
| 1634 |
apply: function () { |
| 1635 |
|
| 1636 |
var nodeData = this.source.$modelValue; |
| 1637 |
|
| 1638 |
|
| 1639 |
if (this.parent.nodropEnabled || this.parent.$treeScope.nodropEnabled) { |
| 1640 |
return; |
| 1641 |
} |
| 1642 |
|
| 1643 |
|
| 1644 |
if (!this.isDirty()) { |
| 1645 |
return; |
| 1646 |
} |
| 1647 |
|
| 1648 |
|
| 1649 |
if (this.isClone() && this.isForeign()) { |
| 1650 |
this.parent.insertNode(this.index, this.sourceInfo.cloneModel); |
| 1651 |
|
| 1652 |
} else { |
| 1653 |
this.source.remove(); |
| 1654 |
this.parent.insertNode(this.index, nodeData); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
}; |
| 1658 |
}, |
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
height: function (element) { |
| 1672 |
return element.prop('scrollHeight'); |
| 1673 |
}, |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
width: function (element) { |
| 1687 |
return element.prop('scrollWidth'); |
| 1688 |
}, |
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
offset: function (element) { |
| 1702 |
var boundingClientRect = element[0].getBoundingClientRect(); |
| 1703 |
|
| 1704 |
return { |
| 1705 |
width: element.prop('offsetWidth'), |
| 1706 |
height: element.prop('offsetHeight'), |
| 1707 |
top: boundingClientRect.top + ($window.pageYOffset || $document[0].body.scrollTop || $document[0].documentElement.scrollTop), |
| 1708 |
left: boundingClientRect.left + ($window.pageXOffset || $document[0].body.scrollLeft || $document[0].documentElement.scrollLeft) |
| 1709 |
}; |
| 1710 |
}, |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
positionStarted: function (e, target) { |
| 1725 |
var pos = {}, |
| 1726 |
pageX = e.pageX, |
| 1727 |
pageY = e.pageY; |
| 1728 |
|
| 1729 |
|
| 1730 |
if (e.originalEvent && e.originalEvent.touches && (e.originalEvent.touches.length > 0)) { |
| 1731 |
pageX = e.originalEvent.touches[0].pageX; |
| 1732 |
pageY = e.originalEvent.touches[0].pageY; |
| 1733 |
} |
| 1734 |
pos.offsetX = pageX - this.offset(target).left; |
| 1735 |
pos.offsetY = pageY - this.offset(target).top; |
| 1736 |
pos.startX = pos.lastX = pageX; |
| 1737 |
pos.startY = pos.lastY = pageY; |
| 1738 |
pos.nowX = pos.nowY = pos.distX = pos.distY = pos.dirAx = 0; |
| 1739 |
pos.dirX = pos.dirY = pos.lastDirX = pos.lastDirY = pos.distAxX = pos.distAxY = 0; |
| 1740 |
return pos; |
| 1741 |
}, |
| 1742 |
|
| 1743 |
positionMoved: function (e, pos, firstMoving) { |
| 1744 |
|
| 1745 |
var pageX = e.pageX, |
| 1746 |
pageY = e.pageY, |
| 1747 |
newAx; |
| 1748 |
|
| 1749 |
|
| 1750 |
if (e.originalEvent && e.originalEvent.touches && (e.originalEvent.touches.length > 0)) { |
| 1751 |
pageX = e.originalEvent.touches[0].pageX; |
| 1752 |
pageY = e.originalEvent.touches[0].pageY; |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
pos.lastX = pos.nowX; |
| 1757 |
pos.lastY = pos.nowY; |
| 1758 |
|
| 1759 |
|
| 1760 |
pos.nowX = pageX; |
| 1761 |
pos.nowY = pageY; |
| 1762 |
|
| 1763 |
|
| 1764 |
pos.distX = pos.nowX - pos.lastX; |
| 1765 |
pos.distY = pos.nowY - pos.lastY; |
| 1766 |
|
| 1767 |
|
| 1768 |
pos.lastDirX = pos.dirX; |
| 1769 |
pos.lastDirY = pos.dirY; |
| 1770 |
|
| 1771 |
|
| 1772 |
pos.dirX = pos.distX === 0 ? 0 : pos.distX > 0 ? 1 : -1; |
| 1773 |
pos.dirY = pos.distY === 0 ? 0 : pos.distY > 0 ? 1 : -1; |
| 1774 |
|
| 1775 |
|
| 1776 |
newAx = Math.abs(pos.distX) > Math.abs(pos.distY) ? 1 : 0; |
| 1777 |
|
| 1778 |
|
| 1779 |
if (firstMoving) { |
| 1780 |
pos.dirAx = newAx; |
| 1781 |
pos.moving = true; |
| 1782 |
return; |
| 1783 |
} |
| 1784 |
|
| 1785 |
|
| 1786 |
if (pos.dirAx !== newAx) { |
| 1787 |
pos.distAxX = 0; |
| 1788 |
pos.distAxY = 0; |
| 1789 |
} else { |
| 1790 |
pos.distAxX += Math.abs(pos.distX); |
| 1791 |
if (pos.dirX !== 0 && pos.dirX !== pos.lastDirX) { |
| 1792 |
pos.distAxX = 0; |
| 1793 |
} |
| 1794 |
pos.distAxY += Math.abs(pos.distY); |
| 1795 |
if (pos.dirY !== 0 && pos.dirY !== pos.lastDirY) { |
| 1796 |
pos.distAxY = 0; |
| 1797 |
} |
| 1798 |
} |
| 1799 |
pos.dirAx = newAx; |
| 1800 |
}, |
| 1801 |
|
| 1802 |
elementIsTreeNode: function (element) { |
| 1803 |
return typeof element.attr('ui-tree-node') !== 'undefined'; |
| 1804 |
}, |
| 1805 |
|
| 1806 |
elementIsTreeNodeHandle: function (element) { |
| 1807 |
return typeof element.attr('ui-tree-handle') !== 'undefined'; |
| 1808 |
}, |
| 1809 |
elementIsTree: function (element) { |
| 1810 |
return typeof element.attr('ui-tree') !== 'undefined'; |
| 1811 |
}, |
| 1812 |
elementIsTreeNodes: function (element) { |
| 1813 |
return typeof element.attr('ui-tree-nodes') !== 'undefined'; |
| 1814 |
}, |
| 1815 |
elementIsPlaceholder: function (element) { |
| 1816 |
return element.hasClass(treeConfig.placeholderClass); |
| 1817 |
}, |
| 1818 |
elementIsDropzone: function (element) { |
| 1819 |
return element.hasClass(treeConfig.dropzoneClass); |
| 1820 |
}, |
| 1821 |
elementContainsTreeNodeHandler: function (element) { |
| 1822 |
return element[0].querySelectorAll('[ui-tree-handle]').length >= 1; |
| 1823 |
}, |
| 1824 |
treeNodeHandlerContainerOfElement: function (element) { |
| 1825 |
return findFirstParentElementWithAttribute('ui-tree-handle', element[0]); |
| 1826 |
} |
| 1827 |
}; |
| 1828 |
} |
| 1829 |
]); |
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
function findFirstParentElementWithAttribute(attributeName, childObj) { |
| 1835 |
|
| 1836 |
if (childObj === undefined) { |
| 1837 |
return null; |
| 1838 |
} |
| 1839 |
var testObj = childObj.parentNode, |
| 1840 |
count = 1, |
| 1841 |
|
| 1842 |
res = (typeof testObj.setAttribute === 'function' && testObj.hasAttribute(attributeName)) ? testObj : null; |
| 1843 |
while (testObj && typeof testObj.setAttribute === 'function' && !testObj.hasAttribute(attributeName)) { |
| 1844 |
testObj = testObj.parentNode; |
| 1845 |
res = testObj; |
| 1846 |
|
| 1847 |
if (testObj === document.documentElement) { |
| 1848 |
res = null; |
| 1849 |
break; |
| 1850 |
} |
| 1851 |
count++; |
| 1852 |
} |
| 1853 |
return res; |
| 1854 |
} |
| 1855 |
|
| 1856 |
})(); |