Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new option to allow links to open in new browser window #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ order:
| hide | boolean | **Optional** | Hide item in sidebar.
| exact | boolean | **Optional** | Specify whether the item string match will be exact match instead of substring.
| href | string | **Optional** | Define the href for the sidebar link.
| open_new | boolean | **Optional** | Specify whether the link should open in a new browser window.
| icon | string | **Optional** | Set the icon of the sidebar item.
| 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.

Expand Down Expand Up @@ -142,6 +143,7 @@ order:
- new_item: true
item: Server Controls
href: /config/server_control
open_new: true
icon: "mdi:server"
bottom: true
exceptions:
Expand Down
7 changes: 7 additions & 0 deletions dist/custom-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ function createItem(elements, item) {
cln.querySelector("paper-icon-item").querySelector("ha-icon").setAttribute("icon", item.icon);
cln.querySelector("paper-icon-item").querySelector("span").innerHTML = item.item;
cln.href = item.href;
if (item.open_new == true) {
cln.setAttribute("target", "_blank");
}
cln.setAttribute("data-panel", item.item);
elements.insertBefore(cln, elements.children[0]);
}
Expand Down Expand Up @@ -193,6 +196,10 @@ function moveItem(elements, config_entry) {
if (config_entry.href) {
elements.children[i].href = config_entry.href;
}

if (config_entry.open_new) {
elements.children[i].setAttribute("target", "_blank");
}

if (config_entry.name) {
elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML = elements.children[i].children[0].getElementsByTagName("span")[0].innerHTML.replace(current, config_entry.name);
Expand Down