-
-
Notifications
You must be signed in to change notification settings - Fork 38
Events
Cheton Wu edited this page May 17, 2017
·
22 revisions
- click
- closeNode
- clusterDidChange
- clusterWillChange
- contentDidUpdate
- contentWillUpdate
- doubleClick
- keyDown
- keyUp
- openNode
- selectNode
- willCloseNode
- willOpenNode
- willSelectNode
The click event is fired on mouse click.
1.2.0
tree.on('click', function(event) {
var target = event.target || event.srcElement; // IE8
var nodeTarget = target;
while (nodeTarget && nodeTarget.parentElement !== tree.contentElement) {
nodeTarget = nodeTarget.parentElement;
}
// Call event.stopPropagation() if you want to prevent the execution of
// default tree operations like selectNode, openNode, and closeNode.
event.stopPropagation();
// Matches the specified group of selectors.
var selectors = '.dropdown .btn';
if (nodeTarget.querySelector(selectors) !== target) {
return;
}
// do stuff with the target element.
console.log(target);
});
Event delegation with jQuery:
var el = document.querySelector('#tree');
var tree = new InfiniteTree(el, { /* options */ });
$(tree.contentElement).on('click', '.dropdown .btn', function(event) {
// Call event.stopPropagation() if you want to prevent the execution of
// default tree operations like selectNode, openNode, and closeNode.
event.stopPropagation();
// do stuff with the target element.
console.log(event.target);
});
Fired when a node is closed.
0.2.0
tree.on('closeNode', function(node) {
console.log(node);
// → Node {}
});
Triggered when the clusters were changed.
1.3.0
tree.on('clusterDidChange', function() {
});
Triggered before updating clusters.
1.3.0
tree.on('clusterWillChange', function() {
});
Triggered when the tree is updated.
0.9.0
tree.on('contentDidUpdate', function() {
});
Triggered before updating the tree.
0.9.0
tree.on('contentWillUpdate', function() {
});
Triggered when the mouse dblclick
event is fired.
1.7.0
tree.on('doubleClick', function(event) {
});
Triggered when the keydown
event is fired.
1.8.0
tree.on('keyDown', function(event) {
// Prevent the default scroll
event.preventDefault();
const node = tree.getSelectedNode();
const nodeIndex = tree.getSelectedIndex();
if (event.keyCode === 37) { // Left
tree.closeNode(node);
} else if (event.keyCode === 38) { // Up
const prevNode = tree.nodes[nodeIndex - 1] || node;
tree.selectNode(prevNode);
} else if (event.keyCode === 39) { // Right
tree.openNode(node);
} else if (event.keyCode === 40) { // Down
const nextNode = tree.nodes[nodeIndex + 1] || node;
tree.selectNode(nextNode);
}
});
Triggered when the keyup
event is fired.
1.8.0
tree.on('keyUp', function(event) {
});
Fired when a node is opened.
0.2.0
tree.on('openNode', function(node) {
console.log(node);
// → Node {}
});
Fired when a node is selected or deselected.
0.2.0
tree.on('selectNode', function(node) {
console.log(node);
// → Node {} (The selected node)
// → null (No nodes selected)
});
Fired before closing a node.
1.11.0
tree.on('willCloseNode', function(node) {
console.log(node);
// → Node {}
});
Fired before opening a node.
1.11.0
tree.on('willOpenNode', function(node) {
console.log(node);
// → Node {}
});
Fired before selecting or deselecting a node.
1.11.0
tree.on('willSelectNode', function(node) {
console.log(node);
// → Node {}
// → null (No nodes selected)
});