From 6e582419495356771d499ca0139764072592cac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 21 Apr 2019 22:04:45 +0200 Subject: [PATCH] Fix in preparation for thomasloven/lovelace-card-modder#32 and other... stuff... --- layout-card.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/layout-card.js b/layout-card.js index 8562e20..dbfe21c 100644 --- a/layout-card.js +++ b/layout-card.js @@ -13,10 +13,15 @@ class LayoutCard extends cardTools.LitElement { this.rtl = config.rtl || false; this.cardSize = 1; + this.make_cards(); + window.addEventListener('resize', () => this.build()); window.addEventListener('hass-open-menu', () => setTimeout(() => this.build(), 100)); window.addEventListener('hass-close-menu', () => setTimeout(() => this.build(), 100)); - window.addEventListener('location-changed', () => setTimeout(() => this.build(), 100)); + window.addEventListener('location-changed', () => { + if(location.hash === "") setTimeout(() => + this.build(), 100) + }); if(config.rebuild) window.setTimeout(() => this.build(), config.rebuild); } @@ -72,7 +77,7 @@ class LayoutCard extends cardTools.LitElement { } make_cards() { - this.cards = this.config.cards.map((c) => { + this._cards = this.config.cards.map((c) => { if (typeof c === 'string') return c; const card = cardTools.createCard(c); if(this._hass) card.hass = this._hass; @@ -97,7 +102,7 @@ class LayoutCard extends cardTools.LitElement { this.update_columns(); - if(!this.cards) this.make_cards(); + if(!this._cards) this.make_cards(); let cols = []; let colSize = []; @@ -118,7 +123,7 @@ class LayoutCard extends cardTools.LitElement { } let i = 0; - this.cards.forEach((c) => { + this._cards.forEach((c) => { const isBreak = (typeof(c) === 'string'); const sz = c.getCardSize ? c.getCardSize() : 1; @@ -167,8 +172,8 @@ class LayoutCard extends cardTools.LitElement { set hass(hass) { this._hass = hass; - if(this.cards) - this.cards + if(this._cards) + this._cards .filter((c) => typeof(c) !== 'string') .forEach((c) => c.hass = hass); }