From 74185f0bebe64361c17fe6f5fceb841f6d4e8125 Mon Sep 17 00:00:00 2001 From: squidwardy Date: Thu, 23 Aug 2018 11:14:47 +0200 Subject: [PATCH] Add support for JS modules in custom panels. (#1588) * Added support for JS modules in custom panels. * Update load-custom-panel.js * Corrected syntax * Force push * Fixed EOL * Delete index.html * Fixed tempA href missing module_url name --- src/panels/custom/ha-panel-custom.js | 2 +- src/util/custom-panel/load-custom-panel.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/panels/custom/ha-panel-custom.js b/src/panels/custom/ha-panel-custom.js index 412f576252..a6b9faa0bf 100644 --- a/src/panels/custom/ha-panel-custom.js +++ b/src/panels/custom/ha-panel-custom.js @@ -47,7 +47,7 @@ class HaPanelCustom extends NavigateMixin(EventsMixin(PolymerElement)) { const config = panel.config._panel_custom; const tempA = document.createElement('a'); - tempA.href = config.html_url || config.js_url; + tempA.href = config.html_url || config.js_url || config.module_url; if (!config.trust_external && !['localhost', '127.0.0.1', location.hostname].includes(tempA.hostname)) { if (!confirm(`Do you trust the external panel "${config.name}" at "${tempA.href}"? diff --git a/src/util/custom-panel/load-custom-panel.js b/src/util/custom-panel/load-custom-panel.js index 64d938c4f5..8d1d8af418 100644 --- a/src/util/custom-panel/load-custom-panel.js +++ b/src/util/custom-panel/load-custom-panel.js @@ -1,4 +1,4 @@ -import { loadJS } from '../../common/dom/load_resource.js'; +import { loadJS, loadModule } from '../../common/dom/load_resource.js'; // Make sure we only import every JS-based panel once (HTML import has this built-in) const JS_CACHE = {}; @@ -20,6 +20,8 @@ export default function loadCustomPanel(panelConfig) { JS_CACHE[panelConfig.js_url] = loadJS(panelConfig.js_url); } return JS_CACHE[panelConfig.js_url]; + } else if (panelConfig.module_url) { + return loadModule(panelConfig.module_url); } return Promise.reject('No valid url found in panel config.'); }