Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search revamp #300

Merged
merged 9 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions support/web/js/equations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("hashchange", scrollToHash);

function scrollToHash() {
if (window.location.hash != '') {
const id = window.location.hash.slice(1);
// #id doesn't work with numerical IDs
const elem = document.querySelector(`[id="${id}"]`);
if (!(elem instanceof HTMLInputElement)) return;
// If the element is in a commented-out block or a <details> tag, unhide it
// and scroll to it.
const commentedOut = elem.closest('.commented-out') as HTMLInputElement | null;
if (commentedOut)
commentedOut.style.display = 'revert';
const details = elem.closest('details') as HTMLInputElement | null;
if (details)
details.setAttribute("open", "");
if (commentedOut || details)
elem.scrollIntoView();
}
if (window.location.hash === '') return;

const id = window.location.hash.slice(1);
// #id doesn't work with numerical IDs
const elem = document.querySelector(`[id="${id}"]`);
if (!(elem instanceof HTMLInputElement)) return;
// If the element is in a commented-out block or a <details> tag, unhide it
// and scroll to it.
const commentedOut = elem.closest('.commented-out') as HTMLInputElement | null;
if (commentedOut)
commentedOut.style.display = 'revert';
const details = elem.closest('details') as HTMLInputElement | null;
if (details)
details.setAttribute("open", "");
if (commentedOut || details)
elem.scrollIntoView();
}

export { };
28 changes: 17 additions & 11 deletions support/web/js/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import { JSX, type Content } from "./lib/jsx";
import { type Theme, themeSetting, equationSetting, Setting, hiddenCodeSetting, footnoteSetting, serifFontSetting } from "./lib/settings";

// This is pretty evil, but a loose <script> tag assigns these to the
// window object in the HTML template.
const links: { baseURL: string, source: string } = window as any;

function Button(props: { label: Content, icon?: string, click: ((ev: MouseEvent) => void) | string, ['class']?: string }): HTMLButtonElement {
const style = `background-image: url('${links.baseURL}/static/icons/${props.icon}.svg');`;

const ic: HTMLElement = typeof props.click === 'string' ?
<a class="icon" style={style} href={props.click} /> :
<span class="icon" style={style} />;

const el: HTMLElement =
<button class={`labelled-button ${props['class']}`}>
<span class="icon" style={`background-image: url('/static/icons/${props.icon}.svg');`}></span>
<button class={`labelled-button ${props['class'] ?? ''}`}>
{ic}
<span class="hover-label">{props.label}</span>
</button>;

el.addEventListener("click", (ev) => {
if (typeof props.click === 'string') {
window.location.href = props.click;
return;
}
props.click(ev)
});
if (typeof props.click !== 'string') {
el.addEventListener("click", (ev) => {
(props.click as any)(ev)
});
};

return el as HTMLButtonElement;
}
Expand Down Expand Up @@ -55,8 +63,6 @@ function Toggle(props: { label: string, sync: Setting<boolean> }): HTMLElement {
);
}

const links: { baseURL: string, source: string } = window as any;

document.addEventListener("DOMContentLoaded", () => {
const main = document.querySelector("div#post-toc-container");
if (!main) return;
Expand Down