Fix tabs for jsonp

This commit is contained in:
Cadence Ember
2025-11-08 13:43:12 +13:00
parent 1dd90f5a7d
commit 5c3ff9b37c
7 changed files with 62 additions and 24 deletions

View File

@@ -2,7 +2,7 @@
// sample: bandori/wiki/BanG_Dream!_Wikia
// sample: ensemble-stars/wiki/The_English_Ensemble_Stars_Wiki
import {h, htm, render, signal, computed, effect} from "./preact.js"
import {h, htm, render, signal, computed, effect} from "preact"
const html = htm.bind(h)
const now = signal(Date.now())

View File

@@ -1,6 +1,11 @@
import {h, htm, render, signal, computed, effect} from "./preact.js"
import {h, htm, render, signal, computed, effect} from "preact"
const html = htm.bind(h)
// *** Status
const loaded = signal(false)
export {loaded}
// *** Loading indicator
render(html`Loading, please wait...`, document.getElementById("loading"))
@@ -69,6 +74,7 @@ async function cont() {
if (redirectTo) {
redirectTo.click()
}
loaded.value = true
})
xhr.open("POST", "/api/render/wiki")

View File

@@ -1,4 +1,4 @@
import {h, htm, render, signal, computed, effect} from "./preact.js"
import {h, htm, render, signal, computed, effect} from "preact"
const html = htm.bind(h)
const classNames = classArr => classArr.filter(el => el).join(" ")

View File

@@ -1,19 +1,22 @@
"use strict";
import {effect} from "preact"
import {loaded} from "jsonp"
const tabFromHash = location.hash.length > 1 ? location.hash.substring(1) : null
for (const tabber of document.body.querySelectorAll(".wds-tabber")) {
for (const [tab, content] of getTabberTabs(tabber)) {
// set up click listener on every tab
tab.addEventListener("click", e => {
setCurrentTab(tabber, tab, content)
e.preventDefault()
})
function setUpAllTabs() {
for (const tabber of document.body.querySelectorAll(".wds-tabber")) {
for (const [tab, content] of getTabberTabs(tabber)) {
// set up click listener on every tab
tab.addEventListener("click", e => {
setCurrentTab(tabber, tab, content)
e.preventDefault()
})
// re-open a specific tab on page load based on the URL hash
if (tab.dataset.hash === tabFromHash) {
setCurrentTab(tabber, tab, content)
tab.scrollIntoView()
// re-open a specific tab on page load based on the URL hash
if (tab.dataset.hash === tabFromHash) {
setCurrentTab(tabber, tab, content)
tab.scrollIntoView()
}
}
}
}
@@ -37,4 +40,16 @@ function setCurrentTab(tabber, tab, content) {
}
}
if (!BWData.jsonp) {
setUpAllTabs()
} else if (loaded.value) {
setUpAllTabs()
} else {
effect(() => {
if (loaded.value) {
setUpAllTabs()
}
})
}
document.body.classList.remove("bw-tabs-nojs")