Skip to content

Commit d2f0a8a

Browse files
Will LatourelleWill Latourelle
authored andcommitted
icon now settable anywhere
1 parent f81188c commit d2f0a8a

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ order:
101101
| bottom | boolean | **Optional** | Setting this option to `true` will group the item with the bottom items (Configuration, Developer Tools, etc) instead of at the top.
102102
| hide | boolean | **Optional** | Hide item in sidebar.
103103
| href | string | **Optional** | Define the href for the sidebar link.
104+
| icon | string | **Optional** | Set the icon of the sidebar item.
104105
| new_item | boolean | **Optional** | Set to true to create a new link in the sidebar. Using this option now makes `item`, `href`, and `icon` required.
105-
| icon | string | **Optional** | Only used with `new_item`.
106106

107107
## Exceptions
108108
Exceptions can be used if you would like to define an order for a specific user/device.

dist/custom-sidebar.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function rearrange(order){
6565
}
6666
}
6767
for (var i = order.length - 1; i >= 0; i--) {
68-
moveItem(Root, order[i].item.toLowerCase(), order[i].bottom, order[i].hide, order[i].href);
68+
moveItem(Root, order[i].item.toLowerCase(), order[i].bottom, order[i].hide, order[i].href, order[i]);
6969
}
7070
}
7171

@@ -83,7 +83,7 @@ function run() {
8383
req.onerror = function () {
8484
clearInterval(Hacky_Hackerson);
8585
}
86-
req.open('GET', "/local/sidebar-order.yaml?rnd=" + rando());
86+
req.open("GET", "/local/sidebar-order.yaml?rnd=" + rando());
8787
req.send();
8888
}
8989
}
@@ -114,7 +114,7 @@ function createItem(elements, item) {
114114
function getConfigurationElement(elements){
115115
for (var i = 0; i < elements.children.length; i++) {
116116
if (elements.children[i].tagName == "A") {
117-
var current = elements.children[i].children[0].getElementsByTagName('span')[0].innerHTML;
117+
var current = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML;
118118
if (current == "<!---->Configuration<!---->") {
119119
console.log(elements.children[i]);
120120
return elements.children[i];
@@ -123,14 +123,33 @@ function getConfigurationElement(elements){
123123
}
124124
}
125125

126-
function moveItem(elements, name, after_space, hide, href) {
126+
function moveItem(elements, name, after_space, hide, href, config_entry) {
127127
for (var i = 0; i < elements.children.length; i++) {
128128
if (elements.children[i].tagName == "A") {
129-
var current = elements.children[i].children[0].getElementsByTagName('span')[0].innerHTML;
129+
var current = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML;
130130
if (current.toLowerCase().includes(name)) {
131131
if(href){
132132
elements.children[i].href = href;
133133
}
134+
if(config_entry.icon){
135+
console.log(elements.children[i]);
136+
var icon_holder = elements.children[i].querySelector("ha-icon");
137+
if(icon_holder){
138+
icon_holder.setAttribute("icon", config_entry.icon);
139+
}
140+
else{
141+
var old_icon = elements.children[i].querySelector("ha-svg-icon");
142+
if(old_icon){
143+
var icon_item = elements.children[i].querySelector("paper-icon-item");
144+
icon_item.removeChild(old_icon);
145+
icon_holder = document.createElement("ha-icon");
146+
icon_holder.setAttribute("slot", "item-icon");
147+
icon_holder.setAttribute("icon", config_entry.icon);
148+
icon_item.prepend(icon_holder);
149+
}
150+
}
151+
console.log("test");
152+
}
134153
if (hide == true) {
135154
elements.children[i].style.display = "none";
136155
}

0 commit comments

Comments
 (0)