modif of the script to use html templates and slots with shadow DOM

This commit is contained in:
asus
2023-11-03 10:29:50 +01:00
parent ebb7279644
commit 138711c082
8 changed files with 28 additions and 342 deletions

View File

@@ -9,12 +9,36 @@ customElements.define(
super();
let path = this.dataset.path;
let templateContent = document.createDocumentFragment();
let load_content = (content_to_load) => {
let template = document.createElement('template');
template.innerHTML = content_to_load;
templateContent = template.content;
let templateContent = template.content;
//this.appendChild(templateContent.cloneNode(true));
this.replaceWith(templateContent.cloneNode(true));
}
fetch(path)
.then(response => response.text())
.then(load_content)
.catch(error => console.log('Error:', error));
}
},
);
customElements.define(
"load-html-shadow",
class extends HTMLElement {
constructor() {
super();
let path = this.dataset.path;
let load_content = (content_to_load) => {
let template = document.createElement('template');
template.innerHTML = content_to_load;
let templateContent = template.content;
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(templateContent.cloneNode(true));
}