@@ -2,7 +2,9 @@ import { hideMenuItems } from './overflow-menu';
2
2
import { redirects } from './redirects' ;
3
3
import { getLovelace } from 'custom-card-helpers' ;
4
4
import { CustomHeaderConfig } from './config' ;
5
+ import { ha_elements } from './ha-elements' ;
5
6
import { CustomHeader } from './build-header' ;
7
+ import { styleHeader } from './style-header' ;
6
8
7
9
export const selectTab = ( config , ch ) => {
8
10
const headerType = config . compact_mode || config . button_scroll ? ch . header : ch . footer ;
@@ -20,6 +22,15 @@ export const selectTab = (config, ch) => {
20
22
}
21
23
} ;
22
24
25
+ const rebuild = config => {
26
+ const haElem = ha_elements ( ) ;
27
+ window . last_template_result = { } ;
28
+ const ch = new CustomHeader ( haElem ) ;
29
+ CustomHeaderConfig . buildConfig ( ch ) ;
30
+ if ( ! window . location . href . includes ( 'disable_ch' ) && haElem ) haElem . appHeader . style . display = 'none' ;
31
+ styleHeader ( config , ch , haElem ) ;
32
+ } ;
33
+
23
34
export const observers = ( config , ch , haElem ) => {
24
35
const callback = mutations => {
25
36
const headerType = config . split_mode ? ch . footer : ch . header ;
@@ -38,15 +49,7 @@ export const observers = (config, ch, haElem) => {
38
49
}
39
50
} else if ( addedNodes . length && target . nodeName == 'PARTIAL-PANEL-RESOLVER' ) {
40
51
// When returning to lovelace/overview from elsewhere in HA.
41
- if ( addedNodes [ 0 ] . nodeName == 'HA-PANEL-LOVELACE' ) {
42
- if ( window . customHeaderObservers ) {
43
- for ( const observer of window . customHeaderObservers ) {
44
- observer . disconnect ( ) ;
45
- }
46
- window . customHeaderObservers = [ ] ;
47
- }
48
- CustomHeaderConfig . buildConfig ( ch , addedNodes [ 0 ] . lovelace ) ;
49
- }
52
+ if ( addedNodes [ 0 ] . nodeName == 'HA-PANEL-LOVELACE' ) rebuild ( config ) ;
50
53
if ( haElem . main . querySelector ( 'ha-panel-lovelace' ) ) {
51
54
if ( config . compact_mode && ! config . footer_mode ) {
52
55
haElem . sidebar . main . querySelector ( '.menu' ) . style = 'height:49px;' ;
@@ -83,9 +86,7 @@ export const observers = (config, ch, haElem) => {
83
86
if ( haElem . root . querySelector ( '#ch_animated' ) ) haElem . root . querySelector ( '#ch_animated' ) . remove ( ) ;
84
87
} else if ( target . nodeName === 'APP-HEADER' && addedNodes . length ) {
85
88
// Exited edit mode.
86
- if ( ! window . customHeaderDisabled ) haElem . appHeader . style . display = 'none' ;
87
- window . last_template_result = { } ;
88
- CustomHeaderConfig . buildConfig ( new CustomHeader ( haElem ) ) ;
89
+ rebuild ( config ) ;
89
90
}
90
91
} ) ;
91
92
} ;
0 commit comments