From c5bf760bf4827a6217754bbf30044be89e74eeb5 Mon Sep 17 00:00:00 2001 From: Will Latourelle Date: Sun, 10 May 2020 21:35:09 -0700 Subject: [PATCH] support images --- dist/animated-background.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/dist/animated-background.js b/dist/animated-background.js index b56056d..f2dbcb7 100644 --- a/dist/animated-background.js +++ b/dist/animated-background.js @@ -427,6 +427,14 @@ function renderBackgroundHTML() { var html_to_render; if (state_url != "" && Hui) { var bg = Hui.shadowRoot.getElementById("background-iframe"); + var video_type = urlIsVideo(state_url); + var doc_body; + if(video_type){ + doc_body = `` + } + else{ + doc_body = `` + } var source_doc = ` @@ -451,12 +459,21 @@ function renderBackgroundHTML() { left: 50%; transform: translate(-50%, -50%); } + + img { + min-width: 100%; + min-height: 100%; + width: auto; + height: auto; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + } - - + + ${doc_body} `; if (!bg) { @@ -485,7 +502,6 @@ function renderBackgroundHTML() { Previous_Url = state_url; } else { - html_to_render = ``; if (current_config.entity || (Previous_Url != state_url)) { if (!current_config.entity) { STATUS_MESSAGE("Applying default background", true); @@ -499,6 +515,16 @@ function renderBackgroundHTML() { } } +function urlIsVideo(url){ + if(url.slice(url.length - 3).toLowerCase() == "mp4" || url.slice(url.length - 4).toLowerCase() == "webm"){ + return url.slice(url.length - 3).toLowerCase(); + } + if(url.slice(url.length - 4).toLowerCase() == "webm"){ + return url.slice(url.length - 4).toLowerCase(); + } + return false; +} + //removes lovelace theme background function removeDefaultBackground(node) { if (node.style.background != 'transparent' || View_Layout.style.background != 'transparent') {