Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Closed
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
22 changes: 13 additions & 9 deletions src/js/bootstrap-treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

levels: 2,

readOnly: false,

expandIcon: 'glyphicon glyphicon-plus',
collapseIcon: 'glyphicon glyphicon-minus',
emptyIcon: 'glyphicon',
Expand Down Expand Up @@ -114,7 +116,7 @@
getEnabled: $.proxy(this.getEnabled, this),

// Select methods
selectNode: $.proxy(this.selectNode, this),
selectNode: $.proxy(this.selectNode, this, options),
unselectNode: $.proxy(this.unselectNode, this),
toggleNodeSelected: $.proxy(this.toggleNodeSelected, this),

Expand Down Expand Up @@ -320,7 +322,7 @@

var target = $(event.target);
var node = this.findNode(target);
if (!node || node.state.disabled) return;
if (!node || node.state.disabled || this.options.readOnly) return;

var classList = target.attr('class') ? target.attr('class').split(' ') : [];
if ((classList.indexOf('expand-icon') !== -1)) {
Expand Down Expand Up @@ -515,6 +517,7 @@
.addClass('node-' + _this.elementId)
.addClass(node.state.checked ? 'node-checked' : '')
.addClass(node.state.disabled ? 'node-disabled': '')
.addClass(_this.options.readOnly ? 'node-readonly' : '')
.addClass(node.state.selected ? 'node-selected' : '')
.addClass(node.searchResult ? 'search-result' : '')
.attr('data-nodeid', node.nodeId)
Expand Down Expand Up @@ -549,7 +552,7 @@
// Add node icon
if (_this.options.showIcon) {

var classList = ['node-icon'];
classList = ['node-icon'];

classList.push(node.icon || _this.options.nodeIcon);
if (node.state.selected) {
Expand All @@ -567,7 +570,7 @@
// Add check / unchecked icon
if (_this.options.showCheckbox) {

var classList = ['check-icon'];
classList = ['check-icon'];
if (node.state.checked) {
classList.push(_this.options.checkedIcon);
}
Expand All @@ -582,7 +585,7 @@
}

// Add text
if (_this.options.enableLinks) {
if (_this.options.enableLinks && !_this.options.readOnly) {
// Add hyperlink
treeItem
.append($(_this.template.link)
Expand Down Expand Up @@ -695,7 +698,7 @@
badge: '<span class="badge"></span>'
};

Tree.prototype.css = '.treeview .list-group-item{cursor:pointer}.treeview span.indent{margin-left:10px;margin-right:10px}.treeview span.icon{width:12px;margin-right:5px}.treeview .node-disabled{color:silver;cursor:not-allowed}'
Tree.prototype.css = '.treeview .list-group-item{cursor:pointer}.treeview span.indent{margin-left:10px;margin-right:10px}.treeview span.icon{width:12px;margin-right:5px}.treeview .node-disabled{color:silver;cursor:not-allowed}.treeview .node-readonly{color:silver;cursor:not-allowed}';


/**
Expand Down Expand Up @@ -920,7 +923,7 @@
while (parentNode) {
this.setExpandedState(parentNode, true, options);
parentNode = this.getParent(parentNode);
};
}
}, this));

this.render();
Expand Down Expand Up @@ -1112,7 +1115,8 @@
if (pattern && pattern.length > 0) {

if (options.exactMatch) {
pattern = '^' + pattern + '$';
// need to escape special characters potentially in the node value
pattern = '^' + pattern.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + '$';
}

var modifier = 'g';
Expand All @@ -1127,7 +1131,7 @@
// and when identifying result to be cleared
$.each(results, function (index, node) {
node.searchResult = true;
})
});
}

// If revealResults, then render is triggered from revealNode
Expand Down