draft
This commit is contained in:
parent
0873d43d72
commit
65671ab7ba
28 changed files with 447 additions and 9 deletions
38
8-web-components/2-custom-elements/head.html
Normal file
38
8-web-components/2-custom-elements/head.html
Normal file
|
@ -0,0 +1,38 @@
|
|||
<script>
|
||||
/*
|
||||
class TimeFormatted extends HTMLElement {
|
||||
|
||||
render() {
|
||||
let date = new Date(this.getAttribute('datetime') || Date.now());
|
||||
|
||||
this.innerHTML = new Intl.DateTimeFormat("default", {
|
||||
year: this.getAttribute('year') || undefined,
|
||||
month: this.getAttribute('month') || undefined,
|
||||
day: this.getAttribute('day') || undefined,
|
||||
hour: this.getAttribute('hour') || undefined,
|
||||
minute: this.getAttribute('minute') || undefined,
|
||||
second: this.getAttribute('second') || undefined,
|
||||
timeZoneName: this.getAttribute('time-zone-name') || undefined,
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
connectedCallback() { // (2)
|
||||
if (!this.rendered) {
|
||||
this.render();
|
||||
this.rendered = true;
|
||||
}
|
||||
}
|
||||
|
||||
static get observedAttributes() { // (3)
|
||||
return ['datetime', 'year', 'month', 'day', 'hour', 'minute', 'second', 'time-zone-name'];
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldValue, newValue) { // (4)
|
||||
this.render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.customElements && customElements.define("time-formatted", TimeFormatted);
|
||||
*/
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue