diff --git a/public/assets/boot/ctrl_boot_frontoffice.js b/public/assets/boot/ctrl_boot_frontoffice.js index e73c7a74..e067ce63 100644 --- a/public/assets/boot/ctrl_boot_frontoffice.js +++ b/public/assets/boot/ctrl_boot_frontoffice.js @@ -15,6 +15,7 @@ export default async function main() { // setup_sw(), // TODO setup_blue_death_screen(), setup_history(), + setup_polyfill(), ]); await Promise.all([ // procedure with dependency on config @@ -117,3 +118,9 @@ async function setup_history() { async function setup_title() { document.title = window.CONFIG.name || "Filestash"; } + +async function setup_polyfill() { + if (!("replaceChildren" in document.body)) { + await loadJS(import.meta.url, "../lib/polyfill.js"); + } +} diff --git a/public/assets/components/dropdown.js b/public/assets/components/dropdown.js index 83d3bed2..0f9b96b4 100644 --- a/public/assets/components/dropdown.js +++ b/public/assets/components/dropdown.js @@ -3,14 +3,16 @@ import { animate, slideYIn } from "../lib/animate.js"; import assert from "../lib/assert.js"; import { loadCSS } from "../helpers/loader.js"; -await loadCSS(import.meta.url, "./dropdown.css"); - export default class ComponentDropdown extends HTMLDivElement { constructor() { super(); this.render(); } + async connectedCallback() { + await loadCSS(import.meta.url, "./dropdown.css"); + } + static get observedAttributes() { return ["options"]; } diff --git a/public/assets/lib/polyfill.js b/public/assets/lib/polyfill.js index e69de29b..89b4b433 100644 --- a/public/assets/lib/polyfill.js +++ b/public/assets/lib/polyfill.js @@ -0,0 +1,11 @@ +Document.prototype.replaceChildren ||= replaceChildren; +DocumentFragment.prototype.replaceChildren ||= replaceChildren; +Element.prototype.replaceChildren ||= replaceChildren; + +function replaceChildren(...new_children) { + const { childNodes } = this; + while (childNodes.length) { + childNodes[0].remove(); + } + this.append(...new_children); +}