Reference
API Reference
Complete documentation for all JavaScript APIs, configuration options, and REST endpoints.
ThemeManager API
The ThemeManager module handles color scheme switching and persistence.
| Method / Property | Type | Description |
|---|---|---|
| ThemeManager.init() | Function | Initialize theme from localStorage or system preference. Call on DOMContentLoaded. |
| ThemeManager.toggle() | Function | Switch between light and dark mode. Saves preference. |
| ThemeManager.apply(theme) | Function | Apply a specific theme: "light" or "dark". |
| ThemeManager.STORAGE_KEY | string | localStorage key used for persistence. Default: "webdocs-theme". |
javascript
// Apply dark mode programmatically
ThemeManager.apply('dark');
// Toggle on button click
document.getElementById('my-toggle').addEventListener('click', () => {
ThemeManager.toggle();
});
Sidebar API
| Method | Description |
|---|---|
| Sidebar.init() | Bind events, highlight active page link. Called automatically. |
| Sidebar.open() | Open sidebar on mobile. Adds overlay, locks body scroll. |
| Sidebar.close() | Close sidebar. Restores scroll. Also triggered on ESC. |
| Sidebar.toggle() | Toggle sidebar open/closed state. |
Search API
Customize the search by replacing or extending the Search.data array:
javascript
// Option 1: Add entries to the default data
Search.data.push({
title: 'My New Page',
desc: 'Description of the page',
href: 'my-page.html'
});
// Option 2: Fetch from a JSON index (for large sites)
fetch('/search-index.json')
.then(r => r.json())
.then(data => { Search.data = data; });
| Field | Type | Required | Description |
|---|---|---|---|
| title | string | Yes | Page title displayed in results |
| desc | string | Yes | Short description shown under title |
| href | string | Yes | Relative URL of the page |
REST API Endpoints
WebDocs can be extended with a backend. Here are the recommended endpoint patterns if you add one:
GET
/api/search?q={query}
Public
json
// Response:
{
"results": [
{
"title": "Getting Started",
"desc": "Install and configure your project",
"href": "getting-started.html",
"score": 0.95
}
],
"total": 1,
"query": "start"
}
POST/api/feedbackAuth required
PUT/api/pages/{id}Admin only
DELETE/api/pages/{id}Admin only
Standard Response Format
json
{
"success": true,
"data": { /* response payload */ },
"error": null,
"meta": {
"version": "2.0.0",
"timestamp": "2026-06-25T00:00:00Z"
}
}