1
Fork 0
mirror of https://github.com/glassflame/glassflame.github.io.git synced 2024-11-21 23:54:26 +00:00

Garasauto

This commit is contained in:
Steffo 2023-10-19 16:00:32 +02:00
parent 2793449bb6
commit 6bb92bc00d
4 changed files with 17 additions and 9 deletions

View file

@ -1,5 +1,4 @@
import {nameFromFileURL, getVaultFile} from "./fetch.mjs"; import {nameFromFileURL, getVaultFile} from "./fetch.mjs";
import {parsePageContents} from "./page.mjs";
export class CardElement extends HTMLElement { export class CardElement extends HTMLElement {
@ -13,6 +12,11 @@ export class CardElement extends HTMLElement {
*/ */
contentsElement contentsElement
/**
* The element consisting of a button which requests the load of the card.
*/
loadElement
/** /**
* Get the {@link URL} this card is available at via the `href` attribute. * Get the {@link URL} this card is available at via the `href` attribute.
* *
@ -43,13 +47,16 @@ export class CardElement extends HTMLElement {
this.contentsElement = document.createElement("div") this.contentsElement = document.createElement("div")
this.contentsElement.setAttribute("slot", "card-contents") this.contentsElement.setAttribute("slot", "card-contents")
this.loadElement = document.createElement("button")
this.loadElement.innerText = "Load"
this.loadElement.addEventListener("click", () => this.loadContents())
this.contentsElement.appendChild(this.loadElement)
this.appendChild(this.nameElement) this.appendChild(this.nameElement)
this.appendChild(this.contentsElement) this.appendChild(this.contentsElement)
const shadow = this.attachShadow({ mode: "open" }) const shadow = this.attachShadow({ mode: "open" })
shadow.appendChild(instanceElement) shadow.appendChild(instanceElement)
this.loadContents()
} }
/** /**
@ -71,11 +78,9 @@ export class CardElement extends HTMLElement {
const file = await this.getCardVaultFile() const file = await this.getCardVaultFile()
switch(file.kind) { switch(file.kind) {
case "page": case "page":
const parsed = parsePageContents(file.contents) return `<x-page markdown="${file.contents}"></x-page>`
return parsed
case "canvas": case "canvas":
// TODO return `<x-canvas json="${file.contents}"></x-canvas>"`
return "TODO"
default: default:
return "" return ""
} }
@ -87,7 +92,10 @@ export class CardElement extends HTMLElement {
* @returns {Promise<void>} Nothing. * @returns {Promise<void>} Nothing.
*/ */
async loadContents() { async loadContents() {
this.loadElement.disable()
const contents = await this.getCardContents() const contents = await this.getCardContents()
this.loadElement.removeEventListener("click")
this.contentsElement.innerHTML = contents this.contentsElement.innerHTML = contents
} }
} }

View file

@ -1,6 +1,6 @@
import {CardElement} from "./card.mjs" import {CardElement} from "./card.mjs"
import {WikilinkElement} from "./wikilink.mjs"; import {WikilinkElement} from "./elements/wikilink.mjs";
import {HashtagElement} from "./hashtag.mjs"; import {HashtagElement} from "./elements/hashtag.mjs";
customElements.define("x-card", CardElement) customElements.define("x-card", CardElement)
customElements.define("x-wikilink", WikilinkElement) customElements.define("x-wikilink", WikilinkElement)