Skip to content

Instantly share code, notes, and snippets.

@kkckkc
Created May 9, 2019 13:25
Show Gist options
  • Save kkckkc/3b34c0d700f3a25aee949f7768d97b46 to your computer and use it in GitHub Desktop.
Save kkckkc/3b34c0d700f3a25aee949f7768d97b46 to your computer and use it in GitHub Desktop.
Solution to scrollable popup windows in Home Assistant (lovelace)
customElements.whenDefined('card-tools').then(() => {
let cardTools = customElements.get('card-tools');
cardTools.popUp = function (title, message, large=false) {
cardTools.moreInfo(Object.keys(cardTools.hass.states)[0]);
setTimeout(() => {
const moreInfo = document.querySelector("home-assistant")._moreInfoEl;
const controls = moreInfo.shadowRoot.querySelector("more-info-controls");
moreInfo.large = large;
const stateCard = controls.shadowRoot.querySelector("state-card-content");
stateCard.style.display = 'none';
const existingScrollable = controls.shadowRoot.querySelector("paper-dialog-scrollable");
existingScrollable.style.display = 'none';
const existingTitle = controls.shadowRoot.querySelector("app-toolbar").querySelector(".main-title");
existingTitle.style.display = 'none';
var titleEl = document.createElement("div");
titleEl.className = 'main-title';
titleEl.innerText = title;
controls.shadowRoot.querySelector("app-toolbar").appendChild(titleEl);
var el = document.createElement("paper-dialog-scrollable");
el.id = 'popup-scrollable';
el.dialogElement = document.querySelector("home-assistant")._moreInfoEl;
el.style.paddingTop = "16px";
controls.shadowRoot.appendChild(el);
el.shadowRoot.querySelector("slot").appendChild(message);
moreInfo.refit();
setTimeout(() => {
let interval = setInterval(() => {
if (moreInfo.getAttribute('aria-hidden')) {
el.parentNode.removeChild(el);
titleEl.parentNode.removeChild(titleEl);
stateCard.style.display = 'block';
existingScrollable.style.display = 'block';
existingTitle.style.display = 'block';
clearInterval(interval);
}
}, 100);
}, 1000);
}, 0);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment