JavaScript API¶
Public JS surface area for zer0-mistakes. Everything below is intended for consumers; anything not listed here may change without notice.
Related docs: Theming Β· Layouts and navigation Β· Code blocks Β· Customization
Module structure¶
assets/js/
βββ modules/
β βββ navigation/
β β βββ index.js β entry point (loaded as <script type="module">)
β β βββ config.js β selectors, breakpoints, shortcuts
β β βββ navbar.js β dropdowns, mobile menu, tooltips
β β βββ scroll-spy.js β active TOC link tracking
β β βββ smooth-scroll.js β anchor scrolling with header offset
β β βββ keyboard.js β /, [, ], b, t, ? shortcuts
β β βββ gestures.js β edge-swipe sidebar toggle
β β βββ focus.js β offcanvas focus management
β β βββ sidebar-state.js β localStorage for expanded nodes
β βββ theme/
β βββ appearance.js β runtime Appearance panel (opt-in)
βββ ui-helpers.js β showToast, copyToClipboard, [data-copy]
βββ background-customizer.js β window.zer0Bg
βββ theme-customizer.js β admin theme page (skin grid, YAML export)
βββ theme-preview.js β admin preview page (live skin/mode labels)
βββ code-copy.js β line numbers, language header, copy button
βββ search-modal.js β search dialog
βββ halfmoon.js β navbar color-mode toggle
βββ navigation.js β DEPRECATED shim (logs warning)
Global namespaces¶
window.zer0Navigation β navigation orchestrator¶
Exposed by assets/js/modules/navigation/index.js. Instantiated on DOMContentLoaded.
window.zer0Navigation.getModule(name);
// 'scrollSpy' | 'smoothScroll' | 'keyboard' | 'gestures' | 'focus' | 'state' | 'navbar'
window.zer0Navigation.getConfig();
window.zer0Navigation.scrollTo('#section-id');
Events:
| Event | Detail | When |
|---|---|---|
navigation:ready |
{ modules: string[] } |
All navigation modules initialized |
Example:
document.addEventListener('navigation:ready', (e) => {
const kb = window.zer0Navigation.getModule('keyboard');
console.log('Shortcuts active:', e.detail.modules.includes('keyboard'));
});
See layouts-and-navigation.md for sidebar, TOC, and FAB behavior.
window.zer0UI β UI helpers¶
Exposed by assets/js/ui-helpers.js.
window.zer0UI.showToast('Saved', { variant: 'success', duration: 3000 });
window.zer0UI.copyToClipboard('text to copy'); // Promise
Variants: 'info' | 'success' | 'warning' | 'danger'.
Declarative copy:
Used by code blocks for non-pre copy targets.
window.zer0Bg β background customizer¶
Exposed by assets/js/background-customizer.js. See theming.md.
window.zer0Bg.setSkin('aqua');
window.zer0Bg.toggle();
window.zer0Bg.toggle(false); // force off
window.zer0Bg.setOpacity('texture', 0.1);
window.zer0Bg.currentSkin();
Events:
| Event | Detail | When |
|---|---|---|
zer0:skin-change |
{ skin: string } |
After setSkin() |
zer0:bg-toggle |
{ enabled: boolean } |
After toggle() |
Storage keys:
| Key | Value |
|---|---|
zer0-theme-skin |
Active skin name |
zer0-bg-enabled |
"true" / "false" |
Appearance panel β localStorage¶
When appearance_panel: true:
| Key | Value |
|---|---|
theme |
"light" | "dark" | "auto" |
zer0-appearance |
JSON, e.g. { "primary": "#0ea5e9" } |
Initial paint: script in _includes/core/tokens-inline.html.
Extend the panel β see extending.md Β§ Add an Appearance panel control.
Admin theme scripts¶
theme-customizer.js (page: /about/settings/theme/):
- Listens for skin card clicks β
zer0Bg.setSkin() - Rebuilds YAML export on color picker input
- Dispatches/listens to
zer0:skin-change
theme-preview.js (page: /about/settings/theme-preview/):
- Updates live labels for active skin and color mode
These are page-scoped; they do not expose a global namespace.
Navigation configuration¶
assets/js/modules/navigation/config.js:
import { config, isBelowBreakpoint, syncBreakpointsFromCss } from './config.js';
config.selectors.toc; // '#TableOfContents'
config.scrollSpy.offset; // null β derive from scroll-padding-top
config.scrollSpy.tolerance; // 4 (px slack at the reading line)
config.keyboard.keys.search; // '/'
config.breakpoints.lg; // 992
isBelowBreakpoint('lg'); // boolean
syncBreakpointsFromCss(); // read --zer0-bp-* from :root
Disable shortcuts:
Writing a navigation module¶
// assets/js/modules/navigation/my-module.js
import { config } from './config.js';
export class MyModule {
constructor() { this._handlers = []; }
init() {
const el = document.querySelector(config.selectors.mainContent);
if (!el) return;
const handler = () => { /* β¦ */ };
el.addEventListener('scroll', handler);
this._handlers.push({ target: el, type: 'scroll', handler });
}
destroy() {
this._handlers.forEach(({ target, type, handler }) =>
target.removeEventListener(type, handler));
this._handlers = [];
}
}
Register in assets/js/modules/navigation/index.js.
Head scripts (non-module)¶
Loaded with defer from _includes/core/head.html:
| Script | Purpose |
|---|---|
auto-hide-nav.js |
Hide navbar on scroll down |
back-to-top.js |
#backToTopBtn visibility |
halfmoon.js |
Color mode dropdown |
code-copy.js |
Code block enhancements |
side-bar-folders.js |
Folder disclosure in sidebar |
Migration from legacy globals¶
| Was | Now |
|---|---|
assets/js/navigation.js IIFE |
ES module orchestrator |
alert("Link copiedβ¦") |
window.zer0UI.showToast(β¦) |
Inline onclick clipboard |
data-copy attribute |
assets/js/color-modes.js |
Removed; use halfmoon.js + Appearance panel |
assets/js/navigation.js remains a no-op shim with a deprecation warning.
Backward compatibility¶
halfmoon.jsand Appearance panel sharelocalStorage["theme"].- Legacy
_data/navigation/*.ymlschema unchanged;nav_list.htmldelegates tonav-tree.html.
Further reading¶
- theming.md β skins, color modes, storage keys
- code-blocks.md β
code-copy.jsbehavior - layouts-and-navigation.md β keyboard shortcuts, FABs