Skip to content

Commit

Permalink
Enable tag bage classing by making tags a list of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
gandie committed Jan 2, 2020
1 parent 542f57e commit 1d52c9d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ If you want to do more, here's the full node specification
expanded: true,
selected: true
},
tags: ['available'],
tags: [{text: 'available', class: 'badge-primary'}],
nodes: [
{},
...
Expand Down Expand Up @@ -212,9 +212,18 @@ Whether or not a node is expanded i.e. open. Takes precedence over global optio
Whether or not a node is selected.

#### tags
`Array of Strings` `Optional`
`Array of Objects` `Optional`

Used in conjunction with global showTags option to add additional information to the right of each node; using [Bootstrap Badges](http://getbootstrap.com/components/#badges)
Used in conjunction with global showTags option to add additional information to the right of each node; using [Bootstrap Badges](https://getbootstrap.com/docs/4.4/components/badge/)

The object must contain a `text` field and a `class` field naming the badge class, e.g. :

```javascript
{
text: 'available',
class: 'badge-primary'
}
```

### Extendible

Expand Down
24 changes: 12 additions & 12 deletions src/js/bootstrap-treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,20 @@
var target = $(event.target);
var node = this.findNode(target);
if (!node || node.state.disabled) return;

var classList = target.attr('class') ? target.attr('class').split(' ') : [];
if ((classList.indexOf('expand-icon') !== -1)) {

this.toggleExpandedState(node, _default.options);
this.render();
}
else if ((classList.indexOf('check-icon') !== -1)) {

this.toggleCheckedState(node, _default.options);
this.render();
}
else {

if (node.selectable) {
this.toggleSelectedState(node, _default.options);
} else {
Expand Down Expand Up @@ -516,7 +516,7 @@
.addClass(node.state.checked ? 'node-checked' : '')
.addClass(node.state.disabled ? 'node-disabled': '')
.addClass(node.state.selected ? 'node-selected' : '')
.addClass(node.searchResult ? 'search-result' : '')
.addClass(node.searchResult ? 'search-result' : '')
.attr('data-nodeid', node.nodeId)
.attr('style', _this.buildStyleOverride(node));

Expand Down Expand Up @@ -548,13 +548,13 @@

// Add node icon
if (_this.options.showIcon) {

var classList = ['node-icon'];

classList.push(node.icon || _this.options.nodeIcon);
if (node.state.selected) {
classList.pop();
classList.push(node.selectedIcon || _this.options.selectedIcon ||
classList.push(node.selectedIcon || _this.options.selectedIcon ||
node.icon || _this.options.nodeIcon);
}

Expand All @@ -569,7 +569,7 @@

var classList = ['check-icon'];
if (node.state.checked) {
classList.push(_this.options.checkedIcon);
classList.push(_this.options.checkedIcon);
}
else {
classList.push(_this.options.uncheckedIcon);
Expand Down Expand Up @@ -601,7 +601,7 @@
$.each(node.tags, function addTag(id, tag) {
treeItem
.append($(_this.template.badge)
.append(tag)
.append(tag.text).addClass(tag.class)
);
});
}
Expand Down Expand Up @@ -935,7 +935,7 @@
this.forEachIdentifier(identifiers, options, $.proxy(function (node, options) {
this.toggleExpandedState(node, options);
}, this));

this.render();
};

Expand Down Expand Up @@ -1085,7 +1085,7 @@

$.each(identifiers, $.proxy(function (index, identifier) {
callback(this.identifyNode(identifier), options);
}, this));
}, this));
};

/*
Expand Down Expand Up @@ -1156,9 +1156,9 @@
});

if (options.render) {
this.render();
this.render();
}

this.$element.trigger('searchCleared', $.extend(true, {}, results));
};

Expand Down

0 comments on commit 1d52c9d

Please sign in to comment.