current conditions in HTML
This commit is contained in:
parent
6504edc253
commit
ff98d970ef
11 changed files with 499 additions and 660 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue