current conditions in HTML

This commit is contained in:
Matt Walsh
2022-08-02 21:39:27 -05:00
parent 6504edc253
commit ff98d970ef
11 changed files with 499 additions and 660 deletions

View File

@@ -463,4 +463,30 @@ class WeatherDisplay {
});
}
}
fillTemplate(name, fillValues) {
// get the template
const templateNode = this.templates[name];
if (!templateNode) return false;
// clone it
const template = templateNode.cloneNode(true);
Object.entries(fillValues).forEach(([key, value]) => {
// get the specified element
const elem = template.querySelector(`.${key}`);
if (!elem) return;
// fill based on type provided
if (typeof value === 'string' || typeof value === 'number') {
// string and number fill the first found selector
elem.innerHTML = value;
} else if (value?.type === 'img') {
// fill the image source
elem.querySelector('img').src = value.src;
}
});
return template;
}
}