Initial commit
This commit is contained in:
35
views/static/feed-item.js
Normal file
35
views/static/feed-item.js
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
class FeedItem extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.attachShadow({mode: 'open'});
|
||||
}
|
||||
|
||||
load() {
|
||||
const template = document.createElement('template');
|
||||
template.innerHTML = `
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
* {
|
||||
max-width: 100%;
|
||||
}
|
||||
img {
|
||||
margin: auto auto;
|
||||
}
|
||||
</style>
|
||||
`;
|
||||
|
||||
if (!this.loaded) {
|
||||
return fetch(`/api/item/${this.getAttribute('item-id')}`)
|
||||
.then(res => res.json())
|
||||
.then(item => {
|
||||
template.innerHTML += item.Content || item.Description;
|
||||
this.shadowRoot.appendChild(template.content.cloneNode(true));
|
||||
})
|
||||
.then(() => this.loaded = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
customElements.define('feed-item', FeedItem);
|
Reference in New Issue
Block a user