diff --git a/components/project.js b/components/project.js index 75a21e2..ced777e 100644 --- a/components/project.js +++ b/components/project.js @@ -1,27 +1,28 @@ export class Project extends HTMLElement { constructor() { super() - const path = this.getAttribute('path') const shadow = this.attachShadow({mode: 'open'}) - const textArea = document.createElement('textarea') - const header = document.createElement('h1') - header.innerText = path - textArea.value = localStorage.getItem( - path - ) ?? '' - textArea.addEventListener('input', e => { + this.textArea = document.createElement('textarea') + this.header = document.createElement('h1') + this.textArea.addEventListener('input', e => { + const path = this.getAttribute('path') localStorage.setItem( path, e.target.value ) }) const div = document.createElement('div') - div.appendChild(header) - div.appendChild(textArea) + div.appendChild(this.header) + div.appendChild(this.textArea) shadow.appendChild(div) } connectedCallback() { + const path = this.getAttribute('path') + this.header.innerText = path + this.textArea.value = localStorage.getItem( + path + ) ?? '' const style = document.createElement('style') style.textContent = ` textarea {