mirror of
https://codeberg.org/vegvisir/website.git
synced 2025-09-14 08:53:42 +02:00
Brand new design for the website following the new design language I used for [version 2.0 of my personal website](https://codeberg.org/vlw/vlw.se/releases/tag/2.0.0). Reviewed-on: https://codeberg.org/vegvisir/website/pulls/2 Co-authored-by: vlw <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
45 lines
No EOL
996 B
JavaScript
45 lines
No EOL
996 B
JavaScript
const PUBLIC_ELEMENT_STYLESHEET_DIR = "/assets/css/snippets/";
|
|
|
|
export class CustomElement extends HTMLElement {
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* Return a pathname to a custom element CSS stylesheet
|
|
* @param {String} stylesheet
|
|
* @returns {String}
|
|
*/
|
|
static #getElementStylesheetHref(stylesheet) {
|
|
return `${PUBLIC_ELEMENT_STYLESHEET_DIR}${stylesheet}.css`;
|
|
}
|
|
|
|
/**
|
|
* Include a stylesheet for a custom element
|
|
* @param {String} stylesheet
|
|
*/
|
|
importElementStylesheet(stylesheet) {
|
|
if (document.head.querySelector(`link[href="${CustomElement.#getElementStylesheetHref(stylesheet)}"]`)) {
|
|
return;
|
|
}
|
|
|
|
const element = document.createElement("link");
|
|
element.href = CustomElement.#getElementStylesheetHref(stylesheet);
|
|
element.rel = "stylesheet";
|
|
|
|
document.head.appendChild(element);
|
|
}
|
|
|
|
connectedCallback() {
|
|
if ("connected" in this) {
|
|
this.connected();
|
|
}
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
if ("disconnected" in this) {
|
|
this.disconnected();
|
|
}
|
|
}
|
|
|
|
} |