You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
907 B
JavaScript
35 lines
907 B
JavaScript
|
3 years ago
|
export class Page extends HTMLElement {
|
||
|
3 years ago
|
constructor() {
|
||
|
3 years ago
|
super()
|
||
|
3 years ago
|
const shadow = this.attachShadow({mode: 'open'})
|
||
|
3 years ago
|
this.textArea = document.createElement('textarea')
|
||
|
|
this.header = document.createElement('h1')
|
||
|
|
this.textArea.addEventListener('input', e => {
|
||
|
|
const path = this.getAttribute('path')
|
||
|
3 years ago
|
localStorage.setItem(
|
||
|
3 years ago
|
path,
|
||
|
3 years ago
|
e.target.value
|
||
|
3 years ago
|
)
|
||
|
|
})
|
||
|
3 years ago
|
const div = document.createElement('div')
|
||
|
3 years ago
|
div.appendChild(this.header)
|
||
|
|
div.appendChild(this.textArea)
|
||
|
3 years ago
|
shadow.appendChild(div)
|
||
|
3 years ago
|
}
|
||
|
|
|
||
|
|
connectedCallback() {
|
||
|
3 years ago
|
const path = this.getAttribute('path')
|
||
|
|
this.header.innerText = path
|
||
|
|
this.textArea.value = localStorage.getItem(
|
||
|
|
path
|
||
|
|
) ?? ''
|
||
|
3 years ago
|
const style = document.createElement('style')
|
||
|
|
style.textContent = `
|
||
|
|
textarea {
|
||
|
|
width: 80%;
|
||
|
3 years ago
|
height: 45vh;
|
||
|
3 years ago
|
}
|
||
|
|
`
|
||
|
|
this.shadowRoot.append(style)
|
||
|
3 years ago
|
}
|
||
|
|
}
|