|
358 | 358 | 'use strict';
|
359 | 359 |
|
360 | 360 | angular.module('ui.tree')
|
361 |
| - .directive('uiTree', [ 'treeConfig', '$window', |
362 |
| - function(treeConfig, $window) { |
363 |
| - return { |
364 |
| - restrict: 'A', |
365 |
| - scope: true, |
366 |
| - controller: 'TreeController', |
367 |
| - link: function(scope, element, attrs) { |
368 |
| - var callbacks = { |
369 |
| - accept: null, |
370 |
| - beforeDrag: null |
371 |
| - }; |
| 361 | + .directive('uiTree', [ 'treeConfig', '$window', |
| 362 | + function(treeConfig, $window) { |
| 363 | + return { |
| 364 | + restrict: 'A', |
| 365 | + scope: true, |
| 366 | + controller: 'TreeController', |
| 367 | + link: function(scope, element, attrs) { |
| 368 | + var callbacks = { |
| 369 | + accept: null, |
| 370 | + beforeDrag: null |
| 371 | + }; |
| 372 | + |
| 373 | + var config = {}; |
| 374 | + angular.extend(config, treeConfig); |
| 375 | + if (config.treeClass) { |
| 376 | + element.addClass(config.treeClass); |
| 377 | + } |
372 | 378 |
|
373 |
| - var config = {}; |
374 |
| - angular.extend(config, treeConfig); |
375 |
| - if (config.treeClass) { |
376 |
| - element.addClass(config.treeClass); |
377 |
| - } |
| 379 | + scope.$emptyElm = angular.element($window.document.createElement('div')); |
| 380 | + if (config.emptyTreeClass) { |
| 381 | + scope.$emptyElm.addClass(config.emptyTreeClass); |
| 382 | + } |
378 | 383 |
|
379 |
| - scope.$emptyElm = angular.element($window.document.createElement('div')); |
380 |
| - if (config.emptyTreeClass) { |
381 |
| - scope.$emptyElm.addClass(config.emptyTreeClass); |
| 384 | + scope.$watch('$nodesScope.$modelValue.length', function() { |
| 385 | + if (scope.$nodesScope.$modelValue) { |
| 386 | + scope.resetEmptyElement(); |
382 | 387 | }
|
| 388 | + }, true); |
383 | 389 |
|
384 |
| - scope.$watch('$nodesScope.$modelValue.length', function() { |
385 |
| - if (scope.$nodesScope.$modelValue) { |
386 |
| - scope.resetEmptyElement(); |
387 |
| - } |
388 |
| - }, true); |
389 |
| - |
390 |
| - scope.$watch(attrs.dragEnabled, function(val) { |
391 |
| - if((typeof val) == "boolean") { |
392 |
| - scope.dragEnabled = val; |
393 |
| - } |
394 |
| - }); |
395 |
| - |
396 |
| - scope.$watch(attrs.emptyPlaceHolderEnabled, function(val) { |
397 |
| - if((typeof val) == "boolean") { |
398 |
| - scope.emptyPlaceHolderEnabled = val; |
399 |
| - } |
400 |
| - }); |
| 390 | + scope.$watch(attrs.dragEnabled, function(val) { |
| 391 | + if((typeof val) == "boolean") { |
| 392 | + scope.dragEnabled = val; |
| 393 | + } |
| 394 | + }); |
401 | 395 |
|
402 |
| - scope.$watch(attrs.nodropEnabled, function(val) { |
403 |
| - if((typeof val) == "boolean") { |
404 |
| - scope.nodropEnabled = val; |
405 |
| - } |
406 |
| - }); |
| 396 | + scope.$watch(attrs.emptyPlaceHolderEnabled, function(val) { |
| 397 | + if((typeof val) == "boolean") { |
| 398 | + scope.emptyPlaceHolderEnabled = val; |
| 399 | + } |
| 400 | + }); |
407 | 401 |
|
408 |
| - scope.$watch(attrs.cloneEnabled, function(val) { |
409 |
| - if((typeof val) == "boolean") { |
410 |
| - scope.cloneEnabled = val; |
411 |
| - } |
412 |
| - }); |
| 402 | + scope.$watch(attrs.nodropEnabled, function(val) { |
| 403 | + if((typeof val) == "boolean") { |
| 404 | + scope.nodropEnabled = val; |
| 405 | + } |
| 406 | + }); |
413 | 407 |
|
414 |
| - scope.$watch(attrs.maxDepth, function(val) { |
415 |
| - if((typeof val) == "number") { |
416 |
| - scope.maxDepth = val; |
417 |
| - } |
418 |
| - }); |
| 408 | + scope.$watch(attrs.cloneEnabled, function(val) { |
| 409 | + if((typeof val) == "boolean") { |
| 410 | + scope.cloneEnabled = val; |
| 411 | + } |
| 412 | + }); |
419 | 413 |
|
420 |
| - scope.$watch(attrs.dragDelay, function(val) { |
421 |
| - if((typeof val) == "number") { |
422 |
| - scope.dragDelay = val; |
423 |
| - } |
424 |
| - }); |
| 414 | + scope.$watch(attrs.maxDepth, function(val) { |
| 415 | + if((typeof val) == "number") { |
| 416 | + scope.maxDepth = val; |
| 417 | + } |
| 418 | + }); |
425 | 419 |
|
426 |
| - // check if the dest node can accept the dragging node |
427 |
| - // by default, we check the 'data-nodrop-enabled' attribute in `ui-tree-nodes` |
428 |
| - // and the 'max-depth' attribute in `ui-tree` or `ui-tree-nodes`. |
429 |
| - // the method can be overrided |
430 |
| - callbacks.accept = function(sourceNodeScope, destNodesScope, destIndex) { |
431 |
| - if (destNodesScope.nodropEnabled || destNodesScope.outOfDepth(sourceNodeScope)) { |
432 |
| - return false; |
433 |
| - } |
434 |
| - return true; |
435 |
| - }; |
| 420 | + scope.$watch(attrs.dragDelay, function(val) { |
| 421 | + if((typeof val) == "number") { |
| 422 | + scope.dragDelay = val; |
| 423 | + } |
| 424 | + }); |
436 | 425 |
|
437 |
| - callbacks.beforeDrag = function(sourceNodeScope) { |
438 |
| - return true; |
439 |
| - }; |
| 426 | + // check if the dest node can accept the dragging node |
| 427 | + // by default, we check the 'data-nodrop-enabled' attribute in `ui-tree-nodes` |
| 428 | + // and the 'max-depth' attribute in `ui-tree` or `ui-tree-nodes`. |
| 429 | + // the method can be overrided |
| 430 | + callbacks.accept = function(sourceNodeScope, destNodesScope, destIndex) { |
| 431 | + if (destNodesScope.nodropEnabled || destNodesScope.outOfDepth(sourceNodeScope)) { |
| 432 | + return false; |
| 433 | + } |
| 434 | + return true; |
| 435 | + }; |
440 | 436 |
|
441 |
| - callbacks.removed = function(node){ |
| 437 | + callbacks.beforeDrag = function(sourceNodeScope) { |
| 438 | + return true; |
| 439 | + }; |
442 | 440 |
|
443 |
| - }; |
| 441 | + callbacks.removed = function(node){ |
| 442 | + |
| 443 | + }; |
444 | 444 |
|
445 |
| - callbacks.dropped = function(event) { |
| 445 | + callbacks.dropped = function(event) { |
446 | 446 |
|
447 |
| - }; |
| 447 | + }; |
448 | 448 |
|
449 |
| - // |
450 |
| - callbacks.dragStart = function(event) { |
| 449 | + // |
| 450 | + callbacks.dragStart = function(event) { |
451 | 451 |
|
452 |
| - }; |
| 452 | + }; |
453 | 453 |
|
454 |
| - callbacks.dragMove = function(event) { |
| 454 | + callbacks.dragMove = function(event) { |
455 | 455 |
|
456 |
| - }; |
| 456 | + }; |
457 | 457 |
|
458 |
| - callbacks.dragStop = function(event) { |
| 458 | + callbacks.dragStop = function(event) { |
459 | 459 |
|
460 |
| - }; |
| 460 | + }; |
461 | 461 |
|
462 |
| - callbacks.beforeDrop = function(event) { |
| 462 | + callbacks.beforeDrop = function(event) { |
463 | 463 |
|
464 |
| - }; |
| 464 | + }; |
465 | 465 |
|
466 |
| - scope.$watch(attrs.uiTree, function(newVal, oldVal){ |
467 |
| - angular.forEach(newVal, function(value, key){ |
468 |
| - if (callbacks[key]) { |
469 |
| - if (typeof value === "function") { |
470 |
| - callbacks[key] = value; |
471 |
| - } |
| 466 | + scope.$watch(attrs.uiTree, function(newVal, oldVal){ |
| 467 | + angular.forEach(newVal, function(value, key){ |
| 468 | + if (callbacks[key]) { |
| 469 | + if (typeof value === "function") { |
| 470 | + callbacks[key] = value; |
472 | 471 | }
|
473 |
| - }); |
| 472 | + } |
| 473 | + }); |
474 | 474 |
|
475 |
| - scope.$callbacks = callbacks; |
476 |
| - }, true); |
| 475 | + scope.$callbacks = callbacks; |
| 476 | + }, true); |
477 | 477 |
|
478 | 478 |
|
479 |
| - } |
480 |
| - }; |
481 |
| - } |
482 |
| - ]); |
| 479 | + } |
| 480 | + }; |
| 481 | + } |
| 482 | + ]); |
483 | 483 | })();
|
484 | 484 |
|
485 | 485 | (function () {
|
|
941 | 941 | 'use strict';
|
942 | 942 |
|
943 | 943 | angular.module('ui.tree')
|
944 |
| - .directive('uiTreeNodes', [ 'treeConfig', '$window', |
945 |
| - function(treeConfig) { |
946 |
| - return { |
947 |
| - require: ['ngModel', '?^uiTreeNode', '^uiTree'], |
948 |
| - restrict: 'A', |
949 |
| - scope: true, |
950 |
| - controller: 'TreeNodesController', |
951 |
| - link: function(scope, element, attrs, controllersArr) { |
| 944 | + .directive('uiTreeNodes', [ 'treeConfig', '$window', |
| 945 | + function(treeConfig) { |
| 946 | + return { |
| 947 | + require: ['ngModel', '?^uiTreeNode', '^uiTree'], |
| 948 | + restrict: 'A', |
| 949 | + scope: true, |
| 950 | + controller: 'TreeNodesController', |
| 951 | + link: function(scope, element, attrs, controllersArr) { |
| 952 | + |
| 953 | + var config = {}; |
| 954 | + angular.extend(config, treeConfig); |
| 955 | + if (config.nodesClass) { |
| 956 | + element.addClass(config.nodesClass); |
| 957 | + } |
952 | 958 |
|
953 |
| - var config = {}; |
954 |
| - angular.extend(config, treeConfig); |
955 |
| - if (config.nodesClass) { |
956 |
| - element.addClass(config.nodesClass); |
957 |
| - } |
| 959 | + var ngModel = controllersArr[0]; |
| 960 | + var treeNodeCtrl = controllersArr[1]; |
| 961 | + var treeCtrl = controllersArr[2]; |
| 962 | + if (treeNodeCtrl) { |
| 963 | + treeNodeCtrl.scope.$childNodesScope = scope; |
| 964 | + scope.$nodeScope = treeNodeCtrl.scope; |
| 965 | + } |
| 966 | + else { // find the root nodes if there is no parent node and have a parent ui-tree |
| 967 | + treeCtrl.scope.$nodesScope = scope; |
| 968 | + } |
| 969 | + scope.$treeScope = treeCtrl.scope; |
958 | 970 |
|
959 |
| - var ngModel = controllersArr[0]; |
960 |
| - var treeNodeCtrl = controllersArr[1]; |
961 |
| - var treeCtrl = controllersArr[2]; |
962 |
| - if (treeNodeCtrl) { |
963 |
| - treeNodeCtrl.scope.$childNodesScope = scope; |
964 |
| - scope.$nodeScope = treeNodeCtrl.scope; |
965 |
| - } |
966 |
| - else { // find the root nodes if there is no parent node and have a parent ui-tree |
967 |
| - treeCtrl.scope.$nodesScope = scope; |
968 |
| - } |
969 |
| - scope.$treeScope = treeCtrl.scope; |
| 971 | + if (ngModel) { |
| 972 | + ngModel.$render = function() { |
| 973 | + if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) { |
| 974 | + scope.$modelValue = []; |
| 975 | + } |
| 976 | + scope.$modelValue = ngModel.$modelValue; |
| 977 | + }; |
| 978 | + } |
970 | 979 |
|
971 |
| - if (ngModel) { |
972 |
| - ngModel.$render = function() { |
973 |
| - if (!ngModel.$modelValue || !angular.isArray(ngModel.$modelValue)) { |
974 |
| - scope.$modelValue = []; |
975 |
| - } |
976 |
| - scope.$modelValue = ngModel.$modelValue; |
977 |
| - }; |
| 980 | + scope.$watch(attrs.maxDepth, function(val) { |
| 981 | + if((typeof val) == "number") { |
| 982 | + scope.maxDepth = val; |
978 | 983 | }
|
| 984 | + }); |
979 | 985 |
|
980 |
| - scope.$watch(attrs.maxDepth, function(val) { |
981 |
| - if((typeof val) == "number") { |
982 |
| - scope.maxDepth = val; |
983 |
| - } |
984 |
| - }); |
985 |
| - |
986 |
| - scope.$watch(function () { |
987 |
| - return attrs.nodropEnabled; |
988 |
| - }, function (newVal) { |
989 |
| - if((typeof newVal) != "undefined") { |
990 |
| - scope.nodropEnabled = true; |
991 |
| - } |
992 |
| - }, true); |
| 986 | + scope.$watch(function () { |
| 987 | + return attrs.nodropEnabled; |
| 988 | + }, function (newVal) { |
| 989 | + if((typeof newVal) != "undefined") { |
| 990 | + scope.nodropEnabled = true; |
| 991 | + } |
| 992 | + }, true); |
993 | 993 |
|
994 |
| - attrs.$observe('horizontal', function(val) { |
995 |
| - scope.horizontal = ((typeof val) != "undefined"); |
996 |
| - }); |
| 994 | + attrs.$observe('horizontal', function(val) { |
| 995 | + scope.horizontal = ((typeof val) != "undefined"); |
| 996 | + }); |
997 | 997 |
|
998 |
| - } |
999 |
| - }; |
1000 |
| - } |
1001 |
| - ]); |
| 998 | + } |
| 999 | + }; |
| 1000 | + } |
| 1001 | + ]); |
1002 | 1002 | })();
|
1003 | 1003 |
|
1004 | 1004 | (function () {
|
|
0 commit comments