mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Refactor blog bootstrap loader
This commit is contained in:
1 parent
455da6b3ea
commit
e8e4a1e168
2 files changed
+17
-17
No files matched your search
@@ -42,7 +42,18 @@
|
||||
<link rel="stylesheet" href="./css/tailwind.generated.css" />
|
||||
<script src="./js/tracking.js" defer></script>
|
||||
<script type="module" crossorigin>
|
||||
import "./js/blog/index.js";
|
||||
import { bootstrapBlog } from "./js/blog/index.js";
|
||||
import { initZapthreadsEmbed } from "./js/blog/zapthreadsEmbed.js";
|
||||
|
||||
const startBlog = () => {
|
||||
bootstrapBlog({ initZapthreadsEmbed });
|
||||
};
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", startBlog, { once: true });
|
||||
} else {
|
||||
startBlog();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body class="blog-body">
|
||||
|
||||
+5
-16
@@ -1,4 +1,3 @@
|
||||
import { initZapthreadsEmbed } from './zapthreadsEmbed.js';
|
||||
import { createCarousel, advanceSlide, destroyCarousel } from './carousel.js';
|
||||
import { mountProgressBar } from './progressBar.js';
|
||||
import { applyDynamicStyles } from '../ui/styleSystem.js';
|
||||
@@ -460,7 +459,7 @@ function extractZapthreadsOptions(element) {
|
||||
return options;
|
||||
}
|
||||
|
||||
function initializeZapthreads({ registerCleanup, isDestroyed }) {
|
||||
function initializeZapthreads({ registerCleanup, isDestroyed, initZapthreadsEmbed }) {
|
||||
if (typeof initZapthreadsEmbed !== 'function') {
|
||||
return;
|
||||
}
|
||||
@@ -528,7 +527,7 @@ function initializeZapthreads({ registerCleanup, isDestroyed }) {
|
||||
});
|
||||
}
|
||||
|
||||
function mountBlogApp() {
|
||||
function mountBlogApp({ initZapthreadsEmbed } = {}) {
|
||||
const runtime = {
|
||||
destroyed: false,
|
||||
cleanupCallbacks: new Set(),
|
||||
@@ -720,6 +719,7 @@ function mountBlogApp() {
|
||||
initializeZapthreads({
|
||||
registerCleanup,
|
||||
isDestroyed: () => runtime.destroyed,
|
||||
initZapthreadsEmbed,
|
||||
});
|
||||
|
||||
return destroy;
|
||||
@@ -727,11 +727,11 @@ function mountBlogApp() {
|
||||
|
||||
let activeTeardown = null;
|
||||
|
||||
export function bootstrapBlog() {
|
||||
export function bootstrapBlog(options = {}) {
|
||||
if (typeof activeTeardown === 'function') {
|
||||
activeTeardown();
|
||||
}
|
||||
const destroy = mountBlogApp();
|
||||
const destroy = mountBlogApp(options);
|
||||
activeTeardown = () => {
|
||||
destroy();
|
||||
activeTeardown = null;
|
||||
@@ -745,14 +745,3 @@ export function teardownBlog() {
|
||||
}
|
||||
}
|
||||
|
||||
function runBlogBootstrap() {
|
||||
bootstrapBlog();
|
||||
}
|
||||
|
||||
if (typeof document !== 'undefined') {
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', runBlogBootstrap, { once: true });
|
||||
} else {
|
||||
runBlogBootstrap();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user