allow embed customization

This commit is contained in:
yequari 2026-01-03 16:06:26 -07:00
parent cddf2563ce
commit 27b9f2299e

View File

@ -1,3 +1,4 @@
class GuestbookForm extends HTMLElement { class GuestbookForm extends HTMLElement {
static get observedAttributes() { static get observedAttributes() {
return ['guestbook']; return ['guestbook'];
@ -6,6 +7,8 @@ class GuestbookForm extends HTMLElement {
constructor() { constructor() {
super(); super();
this.attachShadow({ mode: 'open' }); this.attachShadow({ mode: 'open' });
let template = document.getElementById("custom-guestbook-form");
this.templateContent = template.content;
this._guestbook = this.getAttribute('guestbook') || ''; this._guestbook = this.getAttribute('guestbook') || '';
this._postUrl = `${this._guestbook}/comments/create/remote` this._postUrl = `${this._guestbook}/comments/create/remote`
this.render(); this.render();
@ -63,6 +66,7 @@ class GuestbookForm extends HTMLElement {
</div> </div>
</form> </form>
`; `;
this.shadowRoot.appendChild(document.importNode(this.templateContent, true))
} }
} }
@ -74,9 +78,12 @@ class CommentList extends HTMLElement {
constructor() { constructor() {
super(); super();
this.attachShadow({ mode: 'open' }); this.attachShadow({ mode: 'open' });
let template = document.getElementById("custom-guestbook-comments");
this.templateContent = template.content;
this.comments = []; this.comments = [];
this.loading = false; this.loading = false;
this.error = null; this.error = null;
} }
connectedCallback() { connectedCallback() {
@ -169,9 +176,11 @@ class CommentList extends HTMLElement {
} }
</div> </div>
`; `;
this.shadowRoot.appendChild(document.importNode(this.templateContent, true))
} }
} }
customElements.define('guestbook-form', GuestbookForm); customElements.define('guestbook-form', GuestbookForm);
customElements.define('guestbook-comments', CommentList); customElements.define('guestbook-comments', CommentList);