Implement mastodon comments
This commit is contained in:
40
public/js/webComponents/profilePic.js
Normal file
40
public/js/webComponents/profilePic.js
Normal file
@ -0,0 +1,40 @@
|
||||
const template = document.createElement('template');
|
||||
|
||||
template.innerHTML = `
|
||||
<style>
|
||||
#profilePic {
|
||||
border-radius: var(--wc-profile-pic-border-radius);
|
||||
width: var(--wc-profile-pic-size);
|
||||
height: var(--wc-profile-pic-size);
|
||||
}
|
||||
</style>
|
||||
|
||||
<img src="" id="profilePic"/>
|
||||
`
|
||||
|
||||
class profilePic extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._shadowRoot = this.attachShadow({ 'mode': 'open' });
|
||||
this._shadowRoot.appendChild(template.content.cloneNode(true));
|
||||
this.$profilePic = this._shadowRoot.querySelector('#profilePic');
|
||||
}
|
||||
|
||||
static get observedAttributes() {
|
||||
return ['url'];
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
if (oldVal != newVal) {
|
||||
this[name] = newVal;
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
this.url ? this.$profilePic.src = this.url : null;
|
||||
}
|
||||
}
|
||||
|
||||
window.customElements.define('wc-profile-pic', profilePic);
|
Reference in New Issue
Block a user