mirror of
https://github.com/wassname/template.git
synced 2026-07-24 13:20:06 +08:00
Fix bug discovered by Fred where katex in dev mode would interfere with svelte figures updating
This commit is contained in:
+39
-33
@@ -45,38 +45,41 @@ import { DistillHeader } from './distill-components/distill-header';
|
||||
import { DistillAppendix } from './distill-components/distill-appendix';
|
||||
import { DistillFooter } from './distill-components/distill-footer';
|
||||
|
||||
const distillMain = function() {
|
||||
|
||||
if (window.distillRunlevel < 1) {
|
||||
throw new Error('Insufficient Runlevel for Distill Template!');
|
||||
let templateIsLoading = false;
|
||||
let runlevel = 0;
|
||||
const initialize = function() {
|
||||
if (window.distill.runlevel < 1) {
|
||||
throw new Error("Insufficient Runlevel for Distill Template!");
|
||||
}
|
||||
|
||||
/* 1. Flag that we're being loaded */
|
||||
if ('distillTemplateIsLoading' in window && window.distillTemplateIsLoading) {
|
||||
throw new Error('Runlevel 1: Distill Template is getting loaded more than once, aborting!');
|
||||
if ("distill" in window && window.distill.templateIsLoading) {
|
||||
throw new Error(
|
||||
"Runlevel 1: Distill Template is getting loaded more than once, aborting!"
|
||||
);
|
||||
} else {
|
||||
window.distillTemplateIsLoading = true;
|
||||
console.debug('Runlevel 1: Distill Template has started loading.');
|
||||
window.distill.templateIsLoading = true;
|
||||
console.debug("Runlevel 1: Distill Template has started loading.");
|
||||
}
|
||||
|
||||
/* 2. Add styles if they weren't added during prerendering */
|
||||
makeStyleTag(document);
|
||||
console.debug('Runlevel 1: Static Distill styles have been added.');
|
||||
console.debug('Runlevel 1->2.');
|
||||
window.distillRunlevel += 1;
|
||||
console.debug("Runlevel 1: Static Distill styles have been added.");
|
||||
console.debug("Runlevel 1->2.");
|
||||
window.distill.runlevel += 1;
|
||||
|
||||
/* 3. Register Controller listener functions */
|
||||
/* Needs to happen before components to their connected callbacks have a controller to talk to. */
|
||||
for (const [functionName, callback] of Object.entries(Controller.listeners)) {
|
||||
if (typeof callback === 'function') {
|
||||
if (typeof callback === "function") {
|
||||
document.addEventListener(functionName, callback);
|
||||
} else {
|
||||
console.error('Runlevel 2: Controller listeners need to be functions!');
|
||||
console.error("Runlevel 2: Controller listeners need to be functions!");
|
||||
}
|
||||
}
|
||||
console.debug('Runlevel 2: We can now listen to controller events.');
|
||||
console.debug('Runlevel 2->3.');
|
||||
window.distillRunlevel += 1;
|
||||
console.debug("Runlevel 2: We can now listen to controller events.");
|
||||
console.debug("Runlevel 2->3.");
|
||||
window.distill.runlevel += 1;
|
||||
|
||||
/* 4. Register components */
|
||||
const components = [
|
||||
@@ -85,22 +88,22 @@ const distillMain = function() {
|
||||
Slider, Interstitial
|
||||
];
|
||||
|
||||
const distillComponents = [
|
||||
DistillHeader, DistillAppendix, DistillFooter,
|
||||
];
|
||||
const distillComponents = [DistillHeader, DistillAppendix, DistillFooter];
|
||||
|
||||
if (window.distillRunlevel < 2) {
|
||||
throw new Error('Insufficient Runlevel for adding custom elements!');
|
||||
if (window.distill.runlevel < 2) {
|
||||
throw new Error("Insufficient Runlevel for adding custom elements!");
|
||||
}
|
||||
const allComponents = components.concat(distillComponents);
|
||||
for (const component of allComponents) {
|
||||
console.debug('Runlevel 2: Registering custom element: ' + component.is);
|
||||
console.debug("Runlevel 2: Registering custom element: " + component.is);
|
||||
customElements.define(component.is, component);
|
||||
}
|
||||
|
||||
console.debug('Runlevel 3: Distill Template finished registering custom elements.');
|
||||
console.debug('Runlevel 3->4.');
|
||||
window.distillRunlevel += 1;
|
||||
console.debug(
|
||||
"Runlevel 3: Distill Template finished registering custom elements."
|
||||
);
|
||||
console.debug("Runlevel 3->4.");
|
||||
window.distill.runlevel += 1;
|
||||
|
||||
// If template was added after DOMContentLoaded we may have missed that event.
|
||||
// Controller will check for that case, so trigger the event explicitly:
|
||||
@@ -108,17 +111,20 @@ const distillMain = function() {
|
||||
Controller.listeners.DOMContentLoaded();
|
||||
}
|
||||
|
||||
console.debug('Runlevel 4: Distill Template initialisation complete.');
|
||||
console.debug("Runlevel 4: Distill Template initialisation complete.");
|
||||
window.distill.templateIsLoading = false;
|
||||
window.distill.templateHasLoaded = true;
|
||||
};
|
||||
|
||||
window.distillRunlevel = 0;
|
||||
window.distill = { runlevel, initialize, templateIsLoading };
|
||||
|
||||
/* 0. Check browser feature support; synchronously polyfill if needed */
|
||||
if (Polyfills.browserSupportsAllFeatures()) {
|
||||
console.debug('Runlevel 0: No need for polyfills.');
|
||||
console.debug('Runlevel 0->1.');
|
||||
window.distillRunlevel += 1;
|
||||
distillMain();
|
||||
console.debug("Runlevel 0: No need for polyfills.");
|
||||
console.debug("Runlevel 0->1.");
|
||||
window.distill.runlevel += 1;
|
||||
window.distill.initialize();
|
||||
} else {
|
||||
console.debug('Runlevel 0: Distill Template is loading polyfills.');
|
||||
Polyfills.load(distillMain);
|
||||
console.debug("Runlevel 0: Distill Template is loading polyfills.");
|
||||
Polyfills.load(window.distill.initialize);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user