Skip to content

Click $event is now available on node expansion and node selection for user functions #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ Attributes of angular treecontrol
- `selected-node` : [Node], used when `multiSelection=false`. Binding for the selected node in the tree. Updating this value updates the selection displayed in the tree. Selecting a node in the tree will update this value.
- `selected-nodes` : [Array[Node]], used when `multiSelection=true`. Binding for the selected nodes in the tree. Updating this value updates the selection displayed in the tree. Selecting a node in the tree will update this value.
- `expanded-nodes` : [Array[Node]] binding for the expanded nodes in the tree. Updating this value updates the nodes that are expanded in the tree.
- `on-selection` : `(node, selected)` callback called whenever selecting a node in the tree. The callback expression can use the selected node (`node`) and a boolean which indicates if the node was selected or deselected (`selected`).
- `on-node-toggle` : `(node, expanded)` callback called whenever a node expands or collapses in the tree. The callback expression can use the toggled node (`node`) and a boolean which indicates expansion or collapse (`expanded`).
- `on-selection` : `(node, selected,$event)` callback called whenever selecting a node in the tree. The callback expression can use the selected node (`node`), a boolean which indicates if the node was selected or deselected (`selected`) and the mouse event generated from the selection (`$event`).
- `on-node-toggle` : `(node, expanded, $event)` callback called whenever a node expands or collapses in the tree. The callback expression can use the toggled node (`node`), a boolean which indicates expansion or collapse (`expanded`) and the mouse event generated from the click (`$event`).
- `options` : different options to customize the tree control.
- `multiSelection` : [Boolean] enable multiple nodes selection in the tree.
- `nodeChildren` : the name of the property of each node that holds the node children. Defaults to 'children'.
Expand Down
14 changes: 7 additions & 7 deletions angular-tree-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
return !!$scope.expandedNodesMap[this.$id];
};

$scope.selectNodeHead = function() {
$scope.selectNodeHead = function(node,$event) {
var transcludedScope = this;
var expanding = $scope.expandedNodesMap[transcludedScope.$id] === undefined;
$scope.expandedNodesMap[transcludedScope.$id] = (expanding ? transcludedScope.node : undefined);
Expand All @@ -192,18 +192,18 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
if ($scope.onNodeToggle) {
var parentNode = (transcludedScope.$parent.node === transcludedScope.synteticRoot)?null:transcludedScope.$parent.node;
var path = createPath(transcludedScope);
$scope.onNodeToggle({node: transcludedScope.node, $parentNode: parentNode, $path: path,
$scope.onNodeToggle({node: transcludedScope.node, $event: $event, $parentNode: parentNode, $path: path,
$index: transcludedScope.$index, $first: transcludedScope.$first, $middle: transcludedScope.$middle,
$last: transcludedScope.$last, $odd: transcludedScope.$odd, $even: transcludedScope.$even, expanded: expanding});

}
};

$scope.selectNodeLabel = function( selectedNode){
$scope.selectNodeLabel = function( selectedNode, $event){
var transcludedScope = this;
if(!$scope.options.isLeaf(selectedNode, $scope) && (!$scope.options.dirSelectable || !$scope.options.isSelectable(selectedNode))) {
// Branch node is not selectable, expand
this.selectNodeHead();
this.selectNodeHead(selectedNode,$event);
}
else if($scope.options.isLeaf(selectedNode, $scope) && (!$scope.options.isSelectable(selectedNode))) {
// Leaf node is not selectable
Expand Down Expand Up @@ -242,7 +242,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
if ($scope.onSelection) {
var parentNode = (transcludedScope.$parent.node === transcludedScope.synteticRoot)?null:transcludedScope.$parent.node;
var path = createPath(transcludedScope)
$scope.onSelection({node: selectedNode, selected: selected, $parentNode: parentNode, $path: path,
$scope.onSelection({node: selectedNode, $event: $event, selected: selected, $parentNode: parentNode, $path: path,
$index: transcludedScope.$index, $first: transcludedScope.$first, $middle: transcludedScope.$middle,
$last: transcludedScope.$last, $odd: transcludedScope.$odd, $even: transcludedScope.$even});
}
Expand Down Expand Up @@ -296,9 +296,9 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
'<ul {{options.ulClass}} >' +
'<li ng-repeat="node in node.{{options.nodeChildren}} | filter:filterExpression:filterComparator {{options.orderBy}}" ng-class="headClass(node)" {{options.liClass}}' +
'set-node-to-data>' +
'<i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node)"></i>' +
'<i class="tree-branch-head" ng-class="iBranchClass()" ng-click="selectNodeHead(node,$event)"></i>' +
'<i class="tree-leaf-head {{options.iLeafClass}}"></i>' +
'<div class="tree-label {{options.labelClass}}" ng-class="[selectedClass(), unselectableClass()]" ng-click="selectNodeLabel(node)" tree-transclude></div>' +
'<div class="tree-label {{options.labelClass}}" ng-class="[selectedClass(), unselectableClass()]" ng-click="selectNodeLabel(node,$event)" tree-transclude></div>' +
'<treeitem ng-if="nodeExpanded()"></treeitem>' +
'</li>' +
'</ul>';
Expand Down
11 changes: 6 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.2.28",
"author": "Yoav Abrahami",
"contributors": [
"Benjamin Orozco <[email protected]>"
"Benjamin Orozco <[email protected]>",
"José M. Fernández <[email protected]>"
],
"main": [
"./angular-tree-control.js",
Expand All @@ -16,13 +17,13 @@
"karma.conf.js"
],
"dependencies": {
"angular": "~1.4.4"
"angular": "~1.4.4 || ~1.5.4"
},
"devDependencies": {
"angular-mocks": "~1.4.4",
"angular-mocks": "~1.4.4 || ~1.5.4",
"jquery": "~2.2.2",
"bootstrap": "~3.1.1",
"angular-bootstrap": "~0.11.0",
"bootstrap": "~3.3.6",
"angular-bootstrap": "~1.2.5",
"google-code-prettify": "1.0.1"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"author": "Yoav Abrahami",
"contributors": [
"Benjamin Orozco <[email protected]>"
"Benjamin Orozco <[email protected]>",
"José M. Fernández <[email protected]>"
],
"license": "MIT",
"bugs": {
Expand Down