Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Apr 7, 2016
2 parents 14c1195 + 052e7a2 commit 6dce197
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 29 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ var tree = new InfiniteTree({
data: data,
droppable: false, // Defaults to false
el: document.querySelector('#tree'),
selectable: true // Defaults to true
selectable: true, // Defaults to true
shouldSelectNode: function(node) { // Defaults to null
if (!node || (node === tree.getSelectedNode())) {
return false; // Prevent from deselecting the current node
}
return true;
}
});

//
Expand Down
19 changes: 12 additions & 7 deletions dist/infinite-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! infinite-tree v0.6.2 | (c) 2016 Cheton Wu <[email protected]> | MIT | https://github.com/cheton/infinite-tree */
/*! infinite-tree v0.6.3 | (c) 2016 Cheton Wu <[email protected]> | MIT | https://github.com/cheton/infinite-tree */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
Expand Down Expand Up @@ -150,7 +150,8 @@ return /******/ (function(modules) { // webpackBootstrap
droppable: false,
el: null,
rowRenderer: _renderer.defaultRowRenderer,
selectable: true
selectable: true,
shouldSelectNode: null
};
_this.state = {
openNodes: [],
Expand Down Expand Up @@ -202,10 +203,7 @@ return /******/ (function(modules) { // webpackBootstrap
return;
}

if (_this.options.selectable) {
_this.selectNode(node);
return;
}
_this.selectNode(node);
},
// https://developer.mozilla.org/en-US/docs/Web/Events/dragenter
// The dragenter event is fired when a dragged element or text selection enters a valid drop target.
Expand Down Expand Up @@ -941,8 +939,15 @@ return /******/ (function(modules) { // webpackBootstrap

InfiniteTree.prototype.selectNode = function selectNode() {
var node = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
var _options = this.options;
var selectable = _options.selectable;
var shouldSelectNode = _options.shouldSelectNode;


if (!this.options.selectable) {
if (!selectable) {
return false;
}
if (typeof shouldSelectNode === 'function' && !shouldSelectNode(node)) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions dist/infinite-tree.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/bundle.js.map

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ for (let i = 0; i < 1000; ++i) {
data.push(JSON.parse(source.replace(/"(id|label)":"([^"]*)"/g, '"$1": "$2.' + i + '"')));
}

const tree = new InfiniteTree({
autoOpen: true, // Defaults to false
droppable: true, // Defaults to false
el: document.querySelector('#tree'),
rowRenderer: rowRenderer,
selectable: true // Defaults to true
});

const updatePreview = (node) => {
const el = document.querySelector('#preview');
if (node) {
Expand All @@ -33,6 +25,20 @@ const updatePreview = (node) => {
}
};

const tree = new InfiniteTree({
autoOpen: true, // Defaults to false
droppable: true, // Defaults to false
el: document.querySelector('#tree'),
rowRenderer: rowRenderer,
selectable: true, // Defaults to true
shouldSelectNode: (node) => { // Defaults to null
if (!node || (node === tree.getSelectedNode())) {
return false; // Prevent from deselecting the current node
}
return true;
}
});

tree.on('scrollProgress', (progress) => {
document.querySelector('#scrolling-progress').style.width = progress + '%';
});
Expand All @@ -57,6 +63,9 @@ tree.on('selectNode', (node) => {

tree.loadData(data);

// Select the first node
tree.selectNode(tree.getChildNodes()[0]);

// Draggable Element
const draggableElement = document.querySelector('#draggable-element');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "infinite-tree",
"version": "0.6.2",
"version": "0.6.3",
"description": "A browser-ready tree library that can efficiently display a large tree with smooth scrolling.",
"homepage": "https://github.com/cheton/infinite-tree",
"main": "lib/index.js",
Expand Down
15 changes: 9 additions & 6 deletions src/infinite-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class InfiniteTree extends events.EventEmitter {
droppable: false,
el: null,
rowRenderer: defaultRowRenderer,
selectable: true
selectable: true,
shouldSelectNode: null
};
state = {
openNodes: [],
Expand Down Expand Up @@ -97,10 +98,7 @@ class InfiniteTree extends events.EventEmitter {
return;
}

if (this.options.selectable) {
this.selectNode(node);
return;
}
this.selectNode(node);
},
// https://developer.mozilla.org/en-US/docs/Web/Events/dragenter
// The dragenter event is fired when a dragged element or text selection enters a valid drop target.
Expand Down Expand Up @@ -771,7 +769,12 @@ class InfiniteTree extends events.EventEmitter {
// @param {Node} node The Node object. If null or undefined, deselects the current node.
// @return {boolean} Returns true on success, false otherwise.
selectNode(node = null) {
if (!this.options.selectable) {
const { selectable, shouldSelectNode } = this.options;

if (!selectable) {
return false;
}
if ((typeof shouldSelectNode === 'function') && !shouldSelectNode(node)) {
return false;
}

Expand Down

0 comments on commit 6dce197

Please sign in to comment.