Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit b0daa42

Browse files
authored
Merge pull request #83 from skateman/icon-background
Add support for the iconBackground property
2 parents ffee788 + 3f24486 commit b0daa42

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ If you want to do more, here's the full node specification
130130
color: "#000000",
131131
backColor: "#FFFFFF",
132132
iconColor: "#FFFFFF",
133+
iconBackground: "#000000",
133134
selectable: true,
134135
checkable: true,
135136
state: {
@@ -203,6 +204,11 @@ The background color used on a given node, overrides global color option.
203204

204205
The color used on a given node's icon.
205206

207+
#### iconBackground
208+
`String` `Optional`
209+
210+
The color used under a given node's background icon.
211+
206212
#### lazyLoad
207213
`Boolean` `Default: false`
208214

src/css/bootstrap-treeview.css

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@
2626
margin-right: 10px;
2727
}
2828

29+
2930
.treeview span.icon {
30-
width: 12px;
31-
margin-right: 5px;
31+
width: 12px;
32+
margin-right: 5px;
3233
}
3334

3435
.treeview .node-disabled {
35-
color: silver;
36-
cursor: not-allowed;
36+
color: silver;
37+
cursor: not-allowed;
3738
}
3839

3940
.treeview .node-hidden {
40-
display: none;
41+
display: none;
4142
}
4243

4344
.treeview span.image {
@@ -50,3 +51,8 @@
5051
margin-right: 5px;
5152
line-height: 1em;
5253
}
54+
55+
.treeview span.icon.node-icon-background {
56+
padding: 2px 2px 2px 2px;
57+
width: calc(1em + 4px);
58+
}

src/js/bootstrap-treeview.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,12 @@
10181018
// Add node icon
10191019
Tree.prototype._addIcon = function (node) {
10201020
if (this._options.showIcon && !(this._options.showImage && node.image)) {
1021-
node.$el
1022-
.append(this._template.icon.node.clone()
1023-
.addClass(node.icon || this._options.nodeIcon)
1024-
);
1021+
var icon = this._template.icon.node.clone().addClass(node.icon || this._options.nodeIcon);
1022+
if (node.iconBackground) {
1023+
icon.addClass('node-icon-background');
1024+
}
1025+
1026+
node.$el.append(icon);
10251027
}
10261028
}
10271029

@@ -1162,6 +1164,11 @@
11621164
var innerStyle = 'color:' + node.iconColor + ';';
11631165
style += '.node-' + this._elementId + '[data-nodeId="' + node.nodeId + '"] .node-icon{' + innerStyle + '}';
11641166
}
1167+
1168+
if (node.iconBackground) {
1169+
var innerStyle = 'background:' + node.iconBackground + ';';
1170+
style += '.node-' + this._elementId + '[data-nodeId="' + node.nodeId + '"] .node-icon{' + innerStyle + '}';
1171+
}
11651172
}, this));
11661173

11671174
return this._css + style;

0 commit comments

Comments
 (0)