Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit 5c29a5a

Browse files
ahmadtawakolmaykar
andauthored
Added option to hide the sidebar menu icon. (#70)
* Added option to hide the sidebar menu icon. * Update README.md Co-authored-by: Ryan Meek <[email protected]>
1 parent 9bb52f6 commit 5c29a5a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ resources:
6565
|:---------------|:---------------|:---------------|:----------|
6666
|`kiosk:`| Boolean | false | Hides both the header and sidebar.
6767
|`hide_header:` | Boolean | false | Hides only the header.
68-
|`hide_sidebar:` | Boolean | false | Hides only the sidebar.
68+
|`hide_sidebar:` | Boolean | false | Hides only the sidebar. Disables swipe to open.
69+
|`hide_menubutton:` | Boolean | false | Hides only the sidebar menu icon. Does not disable swipe to open.
6970
|`hide_overflow:` | Boolean | false | Hides the top right menu.
7071
|`ignore_entity_settings:` | Boolean | false | Useful for [conditional configs](#conditional-lovelace-config) and will cause `entity_settings` to be ignored.
7172
|`ignore_mobile_settings:` | Boolean | false | Useful for [conditional configs](#conditional-lovelace-config) and will cause `mobile_settings` to be ignored.
@@ -183,6 +184,7 @@ The query string options are:
183184
* `?hide_header` to hide only the header
184185
* `?hide_sidebar` to hide only the sidebar
185186
* `?hide_overflow` to hide the top right menu
187+
* `?hide_menubutton` to hide sidebar menu button
186188
187189
## Query String Caching
188190

Diff for: kiosk-mode.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class KioskMode {
22
constructor() {
33
window.kioskModeEntities = {};
4-
if (this.queryString("clear_km_cache")) this.setCache(["kmHeader", "kmSidebar", "kmOverflow"], "false");
4+
if (this.queryString("clear_km_cache")) this.setCache(["kmHeader", "kmSidebar", "kmOverflow", "kmMenuButton"], "false");
55
this.ha = document.querySelector("home-assistant");
66
this.main = this.ha.shadowRoot.querySelector("home-assistant-main").shadowRoot;
77
this.user = this.ha.hass.user;
@@ -42,17 +42,19 @@ class KioskMode {
4242

4343
// Retrieve localStorage values & query string options.
4444
const queryStringsSet =
45-
this.cached(["kmHeader", "kmSidebar", "kmOverflow"]) || this.queryString(["kiosk", "hide_sidebar", "hide_header", "hide_overflow"]);
45+
this.cached(["kmHeader", "kmSidebar", "kmOverflow", "kmMenuButton"]) || this.queryString(["kiosk", "hide_sidebar", "hide_header", "hide_overflow", "hide_menubutton"]);
4646
if (queryStringsSet) {
4747
this.hideHeader = this.cached("kmHeader") || this.queryString(["kiosk", "hide_header"]);
4848
this.hideSidebar = this.cached("kmSidebar") || this.queryString(["kiosk", "hide_sidebar"]);
49-
this.hideOverflow = this.cached("kmOverflow") || this.queryString(["kiosk", "hide_overflow"])
49+
this.hideOverflow = this.cached("kmOverflow") || this.queryString(["kiosk", "hide_overflow"]);
50+
this.hideMenuButton = this.cached("kmMenuButton") || this.queryString(["kiosk", "hide_menubutton"]);
5051
}
5152

5253
// Use config values only if config strings and cache aren't used.
5354
this.hideHeader = queryStringsSet ? this.hideHeader : config.kiosk || config.hide_header;
5455
this.hideSidebar = queryStringsSet ? this.hideSidebar : config.kiosk || config.hide_sidebar;
5556
this.hideOverflow = queryStringsSet ? this.hideOverflow : config.kiosk || config.hide_overflow;
57+
this.hideMenuButton = queryStringsSet ? this.hideMenuButton : config.kiosk || config.hide_menubutton;
5658

5759
const adminConfig = this.user.is_admin ? config.admin_settings : config.non_admin_settings;
5860
if (adminConfig) this.setOptions(adminConfig);
@@ -78,6 +80,7 @@ class KioskMode {
7880
if ("hide_header" in conf) this.hideHeader = conf.hide_header;
7981
if ("hide_sidebar" in conf) this.hideSidebar = conf.hide_sidebar;
8082
if ("hide_overflow" in conf) this.hideOverflow = conf.hide_overflow;
83+
if ("hide_menubutton" in conf) this.hideMenuButton = conf.hide_menubutton;
8184
if ("kiosk" in conf) this.hideHeader = this.hideSidebar = conf.kiosk;
8285
}
8386
}
@@ -111,6 +114,13 @@ class KioskMode {
111114
this.removeStyle([appToolbar, drawerLayout]);
112115
}
113116

117+
if (this.hideMenuButton) {
118+
this.addStyle("ha-menu-button{display:none !important;}", appToolbar);
119+
if (this.queryString("cache")) this.setCache("kmMenuButton", "true");
120+
} else {
121+
this.removeStyle(appToolbar);
122+
}
123+
114124
// Resize window to "refresh" view.
115125
window.dispatchEvent(new Event("resize"));
116126

@@ -147,7 +157,8 @@ class KioskMode {
147157
setOptions(config) {
148158
this.hideHeader = config.kiosk || config.hide_header;
149159
this.hideSidebar = config.kiosk || config.hide_sidebar;
150-
this.hideOverflow = config.kiosk || config.hide_overflow
160+
this.hideOverflow = config.kiosk || config.hide_overflow;
161+
this.hideMenuButton = config.kiosk || config.hide_menubutton;
151162
this.ignoreEntity = config.ignore_entity_settings;
152163
this.ignoreMobile = config.ignore_mobile_settings;
153164
}

0 commit comments

Comments
 (0)