gopherss/views/static/feed-item.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-10-17 13:30:30 +00:00
class FeedItem extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
}
load() {
const template = document.createElement('template');
template.innerHTML = `
<style>
2020-10-17 18:50:13 +00:00
:host {
width: 100% !important;
overflow: scroll !important;
overflow-x: auto !important;
2020-10-17 13:30:30 +00:00
}
* {
2020-10-17 18:50:13 +00:00
max-width: 100% !important;
height: auto !important;
2020-10-17 18:02:52 +00:00
}
table {
2020-10-17 18:50:13 +00:00
width: 100% !important;
2020-10-17 13:30:30 +00:00
}
img {
2020-10-17 18:50:13 +00:00
margin: auto auto !important;
2020-10-17 13:30:30 +00:00
}
2020-10-17 18:50:13 +00:00
p {
font-family: 'Roboto', sans-serif;
font-size: 14px;
line-height: 20px;
letter-spacing: 0em;
font-weight: 500;
}
a {
color: #333;
font-weight: bold;
}
:host(.dark) a {
color: #ccc;
}
2020-10-17 13:30:30 +00:00
</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);