From 717c913db7608adb850d43c1d383aff905727b6e Mon Sep 17 00:00:00 2001 From: hualuomoli Date: Mon, 25 Jul 2016 15:16:01 +0800 Subject: [PATCH 1/3] add checked --- src/abn_tree_directive.coffee | 155 ++++++++++++++++++++++++++++++++-- src/abn_tree_template.jade | 4 + test/test_page.coffee | 26 +++++- test/test_page.jade | 12 +-- 4 files changed, 185 insertions(+), 12 deletions(-) diff --git a/src/abn_tree_directive.coffee b/src/abn_tree_directive.coffee index ae4f83b..b82a373 100644 --- a/src/abn_tree_directive.coffee +++ b/src/abn_tree_directive.coffee @@ -10,7 +10,9 @@ module.directive 'abnTree',['$timeout',($timeout)-> scope: treeData:'=' onSelect:'&' + onCheck:'&' initialSelection:'@' + initialChecked:'=' treeControl:'=' link:(scope,element,attrs)-> @@ -27,6 +29,10 @@ module.directive 'abnTree',['$timeout',($timeout)-> attrs.iconCollapse ?= 'icon-minus glyphicon glyphicon-minus fa fa-minus' attrs.iconLeaf ?= 'icon-file glyphicon glyphicon-file fa fa-file' + attrs.iconChecked ?= 'icon-check glyphicon glyphicon-check fa fa-check-square' + attrs.iconUnchecked ?= 'icon-check-empty glyphicon glyphicon-unchecked fa fa-square' + attrs.iconSomeChecked ?= 'icon-sign-blank glyphicon glyphicon-stop fa fa-square-o' + attrs.expandLevel ?= '3' expand_level = parseInt attrs.expandLevel,10 @@ -44,6 +50,37 @@ module.directive 'abnTree',['$timeout',($timeout)-> return + # + # + # + do_for_each_branch = (branch, fn)-> + do_f = (branch)-> + if !!branch.children && branch.children.length > 0 + for child in branch.children + fn(branch, child) + do_f(child) + else + fn(branch, null) + return + + do_f(branch) + + # + # + # + do_for_each_ancestors = (branch, fn)-> + do_f = (branch)-> + p = get_parent(branch) + if !!p + fn(branch, p) + do_f(p) + else + fn(branch, null) + return + + do_f(branch) + + # # internal utilities... # @@ -105,6 +142,78 @@ module.directive 'abnTree',['$timeout',($timeout)-> if branch isnt selected_branch select_branch(branch) + # + # checked + # + _v_checked = 2 + _v_check_some = 1 + _v_unchecked = 0 + # checked_branch = [] + + get_checked = ()-> + checked_branch = [] + do_f = (branch)-> + if branch.checked == _v_checked + checked_branch.push(branch) + else if branch.checked == _v_check_some + for child in branch.children + do_f(child) + + for root_branch in scope.treeData + do_f(root_branch) + + return checked_branch + + check_branch = (branch)-> + + if !branch.checked + branch.checked = _v_checked + else if branch.checked == _v_checked + branch.checked = _v_unchecked + else if branch.checked == _v_check_some + branch.checked = _v_checked + else if branch.checked == _v_unchecked + branch.checked = _v_checked + + # child + do_for_each_branch branch, (branch, child)-> + return if !child + child.checked = branch.checked + + # parent + do_for_each_ancestors branch, (branch, parent)-> + if !!parent + children = parent.children + total = children.length + checked = 0 + unchecked = 0 + for child in children + checked += 1 if child.checked == _v_checked + unchecked += 1 if child.checked == _v_unchecked + + if total == checked + parent.checked = _v_checked + else if total == unchecked + parent.checked == _v_unchecked + else + parent.checked = _v_check_some + + # + # check: + # 1) branch.onCheck + # 2) tree.onCheck + # + if branch.onCheck? + $timeout -> + branch.onCheck(branch) + else + if scope.onCheck? + $timeout -> + scope.onCheck({checkedes:get_checked()}) + + + scope.user_check_branch = (branch)-> + check_branch branch get_parent = (child)-> parent = undefined @@ -190,9 +299,24 @@ module.directive 'abnTree',['$timeout',($timeout)-> if not branch.expanded? branch.expanded = false + if !branch.checked + branch.checked = _v_unchecked + if not branch.classes? branch.classes = [] + # + # icons can be Bootstrap or Font-Awesome icons: + # they will be rendered like: + # + # + if branch.checked == _v_checked + tree_check_icon = attrs.iconChecked + else if branch.checked == _v_check_some + tree_check_icon = attrs.iconSomeChecked + else + tree_check_icon = attrs.iconUnchecked + # # icons can be Bootstrap or Font-Awesome icons: # they will be rendered like: @@ -212,12 +336,13 @@ module.directive 'abnTree',['$timeout',($timeout)-> # append to the list of "Tree Row" objects: # scope.tree_rows.push - level : level - branch : branch - label : branch.label - classes : branch.classes - tree_icon : tree_icon - visible : visible + level : level + branch : branch + label : branch.label + classes : branch.classes + tree_icon : tree_icon + tree_check_icon : tree_check_icon + visible : visible # # recursively add all children of this branch...( at Level+1 ) @@ -257,6 +382,21 @@ module.directive 'abnTree',['$timeout',($timeout)-> $timeout -> select_branch b + # + # initial-checked="[]" + # if specified, find and check the branch: + # + if scope.initialChecked? && scope.initialChecked.length > 0 + console.log scope.initialChecked + for_each_branch (b)-> + for checked in scope.initialChecked + if b.uid == checked + $timeout -> + check_branch b + + + + # # expand to the proper level # @@ -299,6 +439,9 @@ module.directive 'abnTree',['$timeout',($timeout)-> tree.get_selected_branch = -> selected_branch + tree.get_checked = -> + get_checked + tree.get_parent_branch = (b)-> get_parent(b) diff --git a/src/abn_tree_template.jade b/src/abn_tree_template.jade index bec2c02..1e4bc3b 100644 --- a/src/abn_tree_template.jade +++ b/src/abn_tree_template.jade @@ -9,6 +9,10 @@ ul.nav.nav-list.nav-pills.nav-stacked.abn-tree a(ng-click="user_clicks_branch(row.branch)") + i.indented.tree-icon( + ng-class="row.tree_check_icon" + ng-click="user_check_branch(row.branch)" + ) i.indented.tree-icon( ng-class="row.tree_icon" ng-click="row.branch.expanded = !row.branch.expanded" diff --git a/test/test_page.coffee b/test/test_page.coffee index c857473..997ae2b 100644 --- a/test/test_page.coffee +++ b/test/test_page.coffee @@ -21,6 +21,22 @@ app.controller 'AbnTestController',($scope,$timeout)-> # ...but your handler could do anything here... # + # + # a default "on-check" handler can be specified + # for the tree ( as attribute "on-check" ) + # + $scope.my_tree_check = (checkedes)-> + $scope.output = "You checked: " + if !!checkedes && checkedes.length > 0 + for branch in checkedes + $scope.output += branch.label + if branch.data?.description + $scope.output += '('+branch.data.description+')' + # + # This example handler just sets "output", + # ...but your handler could do anything here... + # + # # Each branch can define an "on-select" handler, @@ -61,10 +77,12 @@ app.controller 'AbnTestController',($scope,$timeout)-> description:"man's best friend" , label:'Cat' + uid:'02' data: description:"Felis catus" , label:'Hippopotamus' + uid:'03' data: description:"hungry, hungry" , @@ -74,6 +92,7 @@ app.controller 'AbnTestController',($scope,$timeout)-> , label:'Vegetable' + uid:"2" data: definition:"A plant or part of a plant used as food, typically as accompaniment to meat or fish, such as a cabbage, potato, carrot, or bean." data_can_contain_anything:true @@ -81,6 +100,12 @@ app.controller 'AbnTestController',($scope,$timeout)-> onSelect:(branch)-> # special "on-select" function for this branch $scope.output = "Vegetable: "+branch.data.definition + onCheck:(branch)-> + # special "on-check" function for this branch + if branch.checked == 2 + $scope.output = "Check Vegetable: "+branch.data.definition + else + $scope.output = "UnCheck Vegetable: "+branch.data.definition children:[ @@ -147,7 +172,6 @@ app.controller 'AbnTestController',($scope,$timeout)-> ] ] - $scope.my_data = treedata_avm $scope.try_changing_the_tree_data = ()-> # diff --git a/test/test_page.jade b/test/test_page.jade index cb93404..cff73a6 100644 --- a/test/test_page.jade +++ b/test/test_page.jade @@ -7,19 +7,19 @@ html(ng-app='AbnTest') // Bootstrap 2 or Bootstrap 3 ? // if bs == "2" - link(rel="stylesheet",href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css") + link(rel="stylesheet",href="http://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap-combined.min.css") if bs == "3" - link(rel="stylesheet",href="//netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css") + link(rel="stylesheet",href="http://cdn.bootcss.com/bootstrap/3.0.1/css/bootstrap.min.css") // // Angular 1.1.5 or 1.2.12 ? // if ng == "1.1.5" - script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js") + script(src="http://cdn.bootcss.com/angular.js/angularjs/1.1.5/angular.js") if ng == "1.2.12" - script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js") - script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular-animate.js") + script(src="http://cdn.bootcss.com/angular.js/1.2.12/angular.js") + script(src="http://cdn.bootcss.com/angular.js/1.2.12/angular-animate.js") // Font Awesome (optional) @@ -162,8 +162,10 @@ html(ng-app='AbnTest') tree-data = "my_data" tree-control = "my_tree" on-select = "my_tree_handler(branch)" + on-check = "my_tree_check(checkedes)" expand-level = "2" initial-selection = "Granny Smith" + initial-checked = "['02','03','2']" ) td(style="padding:20px;vertical-align:top;") From e30b8a546e1fb8b346cc131bcb1e8371a6cfbe7c Mon Sep 17 00:00:00 2001 From: hualuomoli Date: Mon, 25 Jul 2016 15:16:50 +0800 Subject: [PATCH 2/3] created by grunt --- dist/abn_tree_directive.js | 204 ++++++++++++++++++++++++++++++---- temp/_directive.coffee | 203 ++++++++++++++++++++++++++++----- temp/_template.html | 7 +- test/bs2_ng115_test_page.html | 46 +++----- test/bs2_ng120_test_page.html | 48 +++----- test/bs3_ng115_test_page.html | 46 +++----- test/bs3_ng120_test_page.html | 48 +++----- test/test_page.js | 27 +++++ test/tests_page.html | 11 +- 9 files changed, 446 insertions(+), 194 deletions(-) diff --git a/dist/abn_tree_directive.js b/dist/abn_tree_directive.js index f309995..089591c 100644 --- a/dist/abn_tree_directive.js +++ b/dist/abn_tree_directive.js @@ -8,16 +8,18 @@ '$timeout', function($timeout) { return { restrict: 'E', - template: "", + template: "", replace: true, scope: { treeData: '=', onSelect: '&', + onCheck: '&', initialSelection: '@', + initialChecked: '=', treeControl: '=' }, link: function(scope, element, attrs) { - var error, expand_all_parents, expand_level, for_all_ancestors, for_each_branch, get_parent, n, on_treeData_change, select_branch, selected_branch, tree; + var check_branch, do_for_each_ancestors, do_for_each_branch, error, expand_all_parents, expand_level, for_all_ancestors, for_each_branch, get_checked, get_parent, n, on_treeData_change, select_branch, selected_branch, tree, _v_check_some, _v_checked, _v_unchecked; error = function(s) { console.log('ERROR:' + s); debugger; @@ -32,6 +34,15 @@ if (attrs.iconLeaf == null) { attrs.iconLeaf = 'icon-file glyphicon glyphicon-file fa fa-file'; } + if (attrs.iconChecked == null) { + attrs.iconChecked = 'icon-check glyphicon glyphicon-check fa fa-check-square'; + } + if (attrs.iconUnchecked == null) { + attrs.iconUnchecked = 'icon-check-empty glyphicon glyphicon-unchecked fa fa-square'; + } + if (attrs.iconSomeChecked == null) { + attrs.iconSomeChecked = 'icon-sign-blank glyphicon glyphicon-stop fa fa-square-o'; + } if (attrs.expandLevel == null) { attrs.expandLevel = '3'; } @@ -48,6 +59,37 @@ return; } } + do_for_each_branch = function(branch, fn) { + var do_f; + do_f = function(branch) { + var child, _i, _len, _ref; + if (!!branch.children && branch.children.length > 0) { + _ref = branch.children; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + child = _ref[_i]; + fn(branch, child); + do_f(child); + } + } else { + fn(branch, null); + } + }; + return do_f(branch); + }; + do_for_each_ancestors = function(branch, fn) { + var do_f; + do_f = function(branch) { + var p; + p = get_parent(branch); + if (!!p) { + fn(branch, p); + do_f(p); + } else { + fn(branch, null); + } + }; + return do_f(branch); + }; for_each_branch = function(f) { var do_f, root_branch, _i, _len, _ref, _results; do_f = function(branch, level) { @@ -107,6 +149,91 @@ return select_branch(branch); } }; + _v_checked = 2; + _v_check_some = 1; + _v_unchecked = 0; + get_checked = function() { + var checked_branch, do_f, root_branch, _i, _len, _ref; + checked_branch = []; + do_f = function(branch) { + var child, _i, _len, _ref, _results; + if (branch.checked === _v_checked) { + return checked_branch.push(branch); + } else if (branch.checked === _v_check_some) { + _ref = branch.children; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + child = _ref[_i]; + _results.push(do_f(child)); + } + return _results; + } + }; + _ref = scope.treeData; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + root_branch = _ref[_i]; + do_f(root_branch); + } + return checked_branch; + }; + check_branch = function(branch) { + if (!branch.checked) { + branch.checked = _v_checked; + } else if (branch.checked === _v_checked) { + branch.checked = _v_unchecked; + } else if (branch.checked === _v_check_some) { + branch.checked = _v_checked; + } else if (branch.checked === _v_unchecked) { + branch.checked = _v_checked; + } + do_for_each_branch(branch, function(branch, child) { + if (!child) { + return; + } + return child.checked = branch.checked; + }); + do_for_each_ancestors(branch, function(branch, parent) { + var checked, child, children, total, unchecked, _i, _len; + if (!!parent) { + children = parent.children; + total = children.length; + checked = 0; + unchecked = 0; + for (_i = 0, _len = children.length; _i < _len; _i++) { + child = children[_i]; + if (child.checked === _v_checked) { + checked += 1; + } + if (child.checked === _v_unchecked) { + unchecked += 1; + } + } + if (total === checked) { + return parent.checked = _v_checked; + } else if (total === unchecked) { + return parent.checked === _v_unchecked; + } else { + return parent.checked = _v_check_some; + } + } + }); + if (branch.onCheck != null) { + return $timeout(function() { + return branch.onCheck(branch); + }); + } else { + if (scope.onCheck != null) { + return $timeout(function() { + return scope.onCheck({ + checkedes: get_checked() + }); + }); + } + } + }; + scope.user_check_branch = function(branch) { + return check_branch(branch); + }; get_parent = function(child) { var parent; parent = void 0; @@ -135,25 +262,6 @@ scope.tree_rows = []; on_treeData_change = function() { var add_branch_to_list, root_branch, _i, _len, _ref, _results; - for_each_branch(function(b, level) { - if (!b.uid) { - return b.uid = "" + Math.random(); - } - }); - console.log('UIDs are set.'); - for_each_branch(function(b) { - var child, _i, _len, _ref, _results; - if (angular.isArray(b.children)) { - _ref = b.children; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - child = _ref[_i]; - _results.push(child.parent_uid = b.uid); - } - return _results; - } - }); - scope.tree_rows = []; for_each_branch(function(branch) { var child, f; if (branch.children) { @@ -183,14 +291,43 @@ return branch.children = []; } }); + for_each_branch(function(b, level) { + if (!b.uid) { + return b.uid = "" + Math.random(); + } + }); + console.log('UIDs are set.'); + for_each_branch(function(b) { + var child, _i, _len, _ref, _results; + if (angular.isArray(b.children)) { + _ref = b.children; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + child = _ref[_i]; + _results.push(child.parent_uid = b.uid); + } + return _results; + } + }); + scope.tree_rows = []; add_branch_to_list = function(level, branch, visible) { - var child, child_visible, tree_icon, _i, _len, _ref, _results; + var child, child_visible, tree_check_icon, tree_icon, _i, _len, _ref, _results; if (branch.expanded == null) { branch.expanded = false; } + if (!branch.checked) { + branch.checked = _v_unchecked; + } if (branch.classes == null) { branch.classes = []; } + if (branch.checked === _v_checked) { + tree_check_icon = attrs.iconChecked; + } else if (branch.checked === _v_check_some) { + tree_check_icon = attrs.iconSomeChecked; + } else { + tree_check_icon = attrs.iconUnchecked; + } if (!branch.noLeaf && (!branch.children || branch.children.length === 0)) { tree_icon = attrs.iconLeaf; if (__indexOf.call(branch.classes, "leaf") < 0) { @@ -209,6 +346,7 @@ label: branch.label, classes: branch.classes, tree_icon: tree_icon, + tree_check_icon: tree_check_icon, visible: visible }); if (branch.children != null) { @@ -240,6 +378,25 @@ } }); } + if ((scope.initialChecked != null) && scope.initialChecked.length > 0) { + console.log(scope.initialChecked); + for_each_branch(function(b) { + var checked, _i, _len, _ref, _results; + _ref = scope.initialChecked; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + checked = _ref[_i]; + if (b.uid === checked) { + _results.push($timeout(function() { + return check_branch(b); + })); + } else { + _results.push(void 0); + } + } + return _results; + }); + } n = scope.treeData.length; console.log('num root branches = ' + n); for_each_branch(function(b, level) { @@ -273,6 +430,9 @@ tree.get_selected_branch = function() { return selected_branch; }; + tree.get_checked = function() { + return get_checked; + }; tree.get_parent_branch = function(b) { return get_parent(b); }; diff --git a/temp/_directive.coffee b/temp/_directive.coffee index 157f442..c6c4bf5 100644 --- a/temp/_directive.coffee +++ b/temp/_directive.coffee @@ -1,4 +1,3 @@ - module = angular.module 'angularBootstrapNavTree',[] module.directive 'abnTree',['$timeout',($timeout)-> @@ -8,18 +7,15 @@ module.directive 'abnTree',['$timeout',($timeout)-> template: """ """ # will be replaced by Grunt, during build, with the actual Template HTML replace:true scope: treeData:'=' onSelect:'&' + onCheck:'&' initialSelection:'@' + initialChecked:'=' treeControl:'=' link:(scope,element,attrs)-> @@ -36,6 +32,10 @@ module.directive 'abnTree',['$timeout',($timeout)-> attrs.iconCollapse ?= 'icon-minus glyphicon glyphicon-minus fa fa-minus' attrs.iconLeaf ?= 'icon-file glyphicon glyphicon-file fa fa-file' + attrs.iconChecked ?= 'icon-check glyphicon glyphicon-check fa fa-check-square' + attrs.iconUnchecked ?= 'icon-check-empty glyphicon glyphicon-unchecked fa fa-square' + attrs.iconSomeChecked ?= 'icon-sign-blank glyphicon glyphicon-stop fa fa-square-o' + attrs.expandLevel ?= '3' expand_level = parseInt attrs.expandLevel,10 @@ -53,6 +53,37 @@ module.directive 'abnTree',['$timeout',($timeout)-> return + # + # + # + do_for_each_branch = (branch, fn)-> + do_f = (branch)-> + if !!branch.children && branch.children.length > 0 + for child in branch.children + fn(branch, child) + do_f(child) + else + fn(branch, null) + return + + do_f(branch) + + # + # + # + do_for_each_ancestors = (branch, fn)-> + do_f = (branch)-> + p = get_parent(branch) + if !!p + fn(branch, p) + do_f(p) + else + fn(branch, null) + return + + do_f(branch) + + # # internal utilities... # @@ -114,6 +145,78 @@ module.directive 'abnTree',['$timeout',($timeout)-> if branch isnt selected_branch select_branch(branch) + # + # checked + # + _v_checked = 2 + _v_check_some = 1 + _v_unchecked = 0 + # checked_branch = [] + + get_checked = ()-> + checked_branch = [] + do_f = (branch)-> + if branch.checked == _v_checked + checked_branch.push(branch) + else if branch.checked == _v_check_some + for child in branch.children + do_f(child) + + for root_branch in scope.treeData + do_f(root_branch) + + return checked_branch + + check_branch = (branch)-> + + if !branch.checked + branch.checked = _v_checked + else if branch.checked == _v_checked + branch.checked = _v_unchecked + else if branch.checked == _v_check_some + branch.checked = _v_checked + else if branch.checked == _v_unchecked + branch.checked = _v_checked + + # child + do_for_each_branch branch, (branch, child)-> + return if !child + child.checked = branch.checked + + # parent + do_for_each_ancestors branch, (branch, parent)-> + if !!parent + children = parent.children + total = children.length + checked = 0 + unchecked = 0 + for child in children + checked += 1 if child.checked == _v_checked + unchecked += 1 if child.checked == _v_unchecked + + if total == checked + parent.checked = _v_checked + else if total == unchecked + parent.checked == _v_unchecked + else + parent.checked = _v_check_some + + # + # check: + # 1) branch.onCheck + # 2) tree.onCheck + # + if branch.onCheck? + $timeout -> + branch.onCheck(branch) + else + if scope.onCheck? + $timeout -> + scope.onCheck({checkedes:get_checked()}) + + + scope.user_check_branch = (branch)-> + check_branch branch get_parent = (child)-> parent = undefined @@ -152,23 +255,7 @@ module.directive 'abnTree',['$timeout',($timeout)-> on_treeData_change = -> #console.log 'tree-data-change!' - - # give each Branch a UID ( to keep AngularJS happy ) - for_each_branch (b,level)-> - if not b.uid - b.uid = ""+Math.random() - console.log 'UIDs are set.' - - - # set all parents: - for_each_branch (b)-> - if angular.isArray b.children - for child in b.children - child.parent_uid = b.uid - - - scope.tree_rows = [] - + # # if "children" is just a list of strings... # ...change them into objects: @@ -188,6 +275,23 @@ module.directive 'abnTree',['$timeout',($timeout)-> else branch.children = [] + + # give each Branch a UID ( to keep AngularJS happy ) + for_each_branch (b,level)-> + if not b.uid + b.uid = ""+Math.random() + console.log 'UIDs are set.' + + + # set all parents: + for_each_branch (b)-> + if angular.isArray b.children + for child in b.children + child.parent_uid = b.uid + + + scope.tree_rows = [] + # # add_branch_to_list: recursively add one branch @@ -198,13 +302,32 @@ module.directive 'abnTree',['$timeout',($timeout)-> if not branch.expanded? branch.expanded = false + if !branch.checked + branch.checked = _v_unchecked + + if not branch.classes? + branch.classes = [] + + # + # icons can be Bootstrap or Font-Awesome icons: + # they will be rendered like: + # + # + if branch.checked == _v_checked + tree_check_icon = attrs.iconChecked + else if branch.checked == _v_check_some + tree_check_icon = attrs.iconSomeChecked + else + tree_check_icon = attrs.iconUnchecked + # # icons can be Bootstrap or Font-Awesome icons: # they will be rendered like: # # - if not branch.children or branch.children.length == 0 + if not branch.noLeaf and (not branch.children or branch.children.length == 0) tree_icon = attrs.iconLeaf + branch.classes.push "leaf" if "leaf" not in branch.classes else if branch.expanded tree_icon = attrs.iconCollapse @@ -216,11 +339,13 @@ module.directive 'abnTree',['$timeout',($timeout)-> # append to the list of "Tree Row" objects: # scope.tree_rows.push - level : level - branch : branch - label : branch.label - tree_icon : tree_icon - visible : visible + level : level + branch : branch + label : branch.label + classes : branch.classes + tree_icon : tree_icon + tree_check_icon : tree_check_icon + visible : visible # # recursively add all children of this branch...( at Level+1 ) @@ -260,6 +385,21 @@ module.directive 'abnTree',['$timeout',($timeout)-> $timeout -> select_branch b + # + # initial-checked="[]" + # if specified, find and check the branch: + # + if scope.initialChecked? && scope.initialChecked.length > 0 + console.log scope.initialChecked + for_each_branch (b)-> + for checked in scope.initialChecked + if b.uid == checked + $timeout -> + check_branch b + + + + # # expand to the proper level # @@ -302,6 +442,9 @@ module.directive 'abnTree',['$timeout',($timeout)-> tree.get_selected_branch = -> selected_branch + tree.get_checked = -> + get_checked + tree.get_parent_branch = (b)-> get_parent(b) diff --git a/temp/_template.html b/temp/_template.html index 67f33e9..ae5f2fb 100644 --- a/temp/_template.html +++ b/temp/_template.html @@ -1,9 +1,4 @@ \ No newline at end of file diff --git a/test/bs2_ng115_test_page.html b/test/bs2_ng115_test_page.html index f1bebda..f739be8 100644 --- a/test/bs2_ng115_test_page.html +++ b/test/bs2_ng115_test_page.html @@ -4,11 +4,11 @@ - + - + @@ -24,24 +24,15 @@

angular-bootstrap-nav-tree

-
by Nick Perkins
- The code is on Github +
by Nick Perkins
The code is on Github
@@ -51,22 +42,16 @@

Angular 1.1.5


-
-
- -
+

+

-
Test the Tree Control API:
-
- -
+
Test the Tree Control API:

+
- -
+
- -
+

@@ -77,9 +62,8 @@
Test the Tree Control API:
-
- ...loading... - +
...loading... +
diff --git a/test/bs2_ng120_test_page.html b/test/bs2_ng120_test_page.html index 37ae711..e3bf2e4 100644 --- a/test/bs2_ng120_test_page.html +++ b/test/bs2_ng120_test_page.html @@ -4,12 +4,12 @@ - + - - + + @@ -25,24 +25,15 @@

angular-bootstrap-nav-tree

-
by Nick Perkins
- The code is on Github +
by Nick Perkins
The code is on Github
@@ -52,22 +43,16 @@

Angular 1.2.12


-
-
- -
+

+

-
Test the Tree Control API:
-
- -
+
Test the Tree Control API:

+
- -
+
- -
+

@@ -78,9 +63,8 @@
Test the Tree Control API:
-
- ...loading... - +
...loading... +
diff --git a/test/bs3_ng115_test_page.html b/test/bs3_ng115_test_page.html index 6cea588..3a25482 100644 --- a/test/bs3_ng115_test_page.html +++ b/test/bs3_ng115_test_page.html @@ -4,11 +4,11 @@ - + - + @@ -24,24 +24,15 @@

angular-bootstrap-nav-tree

-
by Nick Perkins
- The code is on Github +
by Nick Perkins
The code is on Github
@@ -51,22 +42,16 @@

Angular 1.1.5


-
-
- -
+

+

-
Test the Tree Control API:
-
- -
+
Test the Tree Control API:

+
- -
+
- -
+

@@ -77,9 +62,8 @@
Test the Tree Control API:
-
- ...loading... - +
...loading... +
diff --git a/test/bs3_ng120_test_page.html b/test/bs3_ng120_test_page.html index 919ee8e..bdb7472 100644 --- a/test/bs3_ng120_test_page.html +++ b/test/bs3_ng120_test_page.html @@ -4,12 +4,12 @@ - + - - + + @@ -25,24 +25,15 @@

angular-bootstrap-nav-tree

-
by Nick Perkins
- The code is on Github +
by Nick Perkins
The code is on Github
@@ -52,22 +43,16 @@

Angular 1.2.12


-
-
- -
+

+

-
Test the Tree Control API:
-
- -
+
Test the Tree Control API:

+
- -
+
- -
+

@@ -78,9 +63,8 @@
Test the Tree Control API:
-
- ...loading... - +
...loading... +
diff --git a/test/test_page.js b/test/test_page.js index 17a4519..4fbb8ff 100644 --- a/test/test_page.js +++ b/test/test_page.js @@ -18,6 +18,23 @@ return $scope.output += '(' + branch.data.description + ')'; } }; + $scope.my_tree_check = function(checkedes) { + var branch, _i, _len, _ref, _results; + $scope.output = "You checked: "; + if (!!checkedes && checkedes.length > 0) { + _results = []; + for (_i = 0, _len = checkedes.length; _i < _len; _i++) { + branch = checkedes[_i]; + $scope.output += branch.label; + if ((_ref = branch.data) != null ? _ref.description : void 0) { + _results.push($scope.output += '(' + branch.data.description + ')'); + } else { + _results.push(void 0); + } + } + return _results; + } + }; apple_selected = function(branch) { return $scope.output = "APPLE! : " + branch.label; }; @@ -32,11 +49,13 @@ } }, { label: 'Cat', + uid: '02', data: { description: "Felis catus" } }, { label: 'Hippopotamus', + uid: '03', data: { description: "hungry, hungry" } @@ -47,6 +66,7 @@ ] }, { label: 'Vegetable', + uid: "2", data: { definition: "A plant or part of a plant used as food, typically as accompaniment to meat or fish, such as a cabbage, potato, carrot, or bean.", data_can_contain_anything: true @@ -54,6 +74,13 @@ onSelect: function(branch) { return $scope.output = "Vegetable: " + branch.data.definition; }, + onCheck: function(branch) { + if (branch.checked === 2) { + return $scope.output = "Check Vegetable: " + branch.data.definition; + } else { + return $scope.output = "UnCheck Vegetable: " + branch.data.definition; + } + }, children: [ { label: 'Oranges' diff --git a/test/tests_page.html b/test/tests_page.html index e2e4283..e9d5ee3 100644 --- a/test/tests_page.html +++ b/test/tests_page.html @@ -5,15 +5,6 @@

angular-bootstrap-nav-tree

-

test pages:

-
-
- Bootstrap 2 / Angular 1.1.5 -
- Bootstrap 3 / Angular 1.1.5 -
- Bootstrap 2 / Angular 1.2.0 -
- Bootstrap 3 / Angular 1.2.0 +

test pages:



Bootstrap 2 / Angular 1.1.5
Bootstrap 3 / Angular 1.1.5
Bootstrap 2 / Angular 1.2.0
Bootstrap 3 / Angular 1.2.0 \ No newline at end of file From 0f3ccdbfb89be9d3dbb7f339ae2a159f8e3a65c7 Mon Sep 17 00:00:00 2001 From: hualuomoli Date: Mon, 25 Jul 2016 15:32:44 +0800 Subject: [PATCH 3/3] update cdn --- test/bs2_ng115_test_page.html | 4 ++-- test/bs2_ng120_test_page.html | 6 +++--- test/bs3_ng115_test_page.html | 4 ++-- test/bs3_ng120_test_page.html | 6 +++--- test/test_page.jade | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/bs2_ng115_test_page.html b/test/bs2_ng115_test_page.html index f739be8..f7cb3bb 100644 --- a/test/bs2_ng115_test_page.html +++ b/test/bs2_ng115_test_page.html @@ -4,11 +4,11 @@ - + - + diff --git a/test/bs2_ng120_test_page.html b/test/bs2_ng120_test_page.html index e3bf2e4..80668b7 100644 --- a/test/bs2_ng120_test_page.html +++ b/test/bs2_ng120_test_page.html @@ -4,12 +4,12 @@ - + - - + + diff --git a/test/bs3_ng115_test_page.html b/test/bs3_ng115_test_page.html index 3a25482..8206d59 100644 --- a/test/bs3_ng115_test_page.html +++ b/test/bs3_ng115_test_page.html @@ -4,11 +4,11 @@ - + - + diff --git a/test/bs3_ng120_test_page.html b/test/bs3_ng120_test_page.html index bdb7472..68ece5f 100644 --- a/test/bs3_ng120_test_page.html +++ b/test/bs3_ng120_test_page.html @@ -4,12 +4,12 @@ - + - - + + diff --git a/test/test_page.jade b/test/test_page.jade index cff73a6..e578bcc 100644 --- a/test/test_page.jade +++ b/test/test_page.jade @@ -7,19 +7,19 @@ html(ng-app='AbnTest') // Bootstrap 2 or Bootstrap 3 ? // if bs == "2" - link(rel="stylesheet",href="http://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap-combined.min.css") + link(rel="stylesheet",href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css") if bs == "3" - link(rel="stylesheet",href="http://cdn.bootcss.com/bootstrap/3.0.1/css/bootstrap.min.css") + link(rel="stylesheet",href="//netdna.bootstrapcdn.com/bootstrap/3.0.1/css/bootstrap.min.css") // // Angular 1.1.5 or 1.2.12 ? // if ng == "1.1.5" - script(src="http://cdn.bootcss.com/angular.js/angularjs/1.1.5/angular.js") + script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js") if ng == "1.2.12" - script(src="http://cdn.bootcss.com/angular.js/1.2.12/angular.js") - script(src="http://cdn.bootcss.com/angular.js/1.2.12/angular-animate.js") + script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js") + script(src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular-animate.js") // Font Awesome (optional)