Skip to content

Commit 1707f86

Browse files
committed
Add API Docs search field
1 parent 0d0f55a commit 1707f86

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

content/static/script.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,97 @@ document.addEventListener("DOMContentLoaded", function(e) {
177177

178178
window.focusSampleIframe = focusSampleIframe();
179179

180+
// API Docs search filter
181+
initApiDocsSearch();
182+
183+
function initApiDocsSearch() {
184+
var body = document.body;
185+
if (!body.classList.contains('page-api-docs-index')) return;
186+
187+
var main = document.querySelector('.page-standard .page-container .content-right main');
188+
if (!main) return;
189+
190+
var tables = main.querySelectorAll('table');
191+
if (tables.length === 0) return;
192+
193+
// Build search index from all tables, grouped by category
194+
var categories = [];
195+
for (var i = 0; i < tables.length; i++) {
196+
var table = tables[i];
197+
var rows = table.querySelectorAll('tbody tr');
198+
var categoryData = {
199+
table: table,
200+
header: null,
201+
rows: []
202+
};
203+
204+
// Find the h2 header before this table
205+
var prev = table.previousElementSibling;
206+
while (prev) {
207+
if (prev.tagName === 'H2') {
208+
categoryData.header = prev;
209+
break;
210+
}
211+
prev = prev.previousElementSibling;
212+
}
213+
214+
for (var j = 0; j < rows.length; j++) {
215+
var row = rows[j];
216+
var firstCell = row.querySelector('td:first-child');
217+
if (firstCell) {
218+
var link = firstCell.querySelector('a');
219+
var typeName = link ? link.textContent : firstCell.textContent;
220+
categoryData.rows.push({
221+
row: row,
222+
typeName: typeName.toLowerCase()
223+
});
224+
}
225+
}
226+
227+
categories.push(categoryData);
228+
}
229+
230+
// Create search input
231+
var searchContainer = document.createElement('div');
232+
searchContainer.className = 'api-search-container';
233+
searchContainer.innerHTML = '<input type="text" class="api-search-input" placeholder="Search a type..." />';
234+
235+
// Insert before first h2 (after intro)
236+
var firstH2 = main.querySelector('h2');
237+
if (firstH2) {
238+
main.insertBefore(searchContainer, firstH2);
239+
} else {
240+
main.insertBefore(searchContainer, main.firstChild);
241+
}
242+
243+
var searchInput = searchContainer.querySelector('.api-search-input');
244+
245+
// Filter function
246+
searchInput.addEventListener('input', function() {
247+
var query = this.value.toLowerCase().trim();
248+
249+
for (var i = 0; i < categories.length; i++) {
250+
var category = categories[i];
251+
var visibleCount = 0;
252+
253+
for (var j = 0; j < category.rows.length; j++) {
254+
var item = category.rows[j];
255+
if (query === '' || item.typeName.indexOf(query) !== -1) {
256+
item.row.style.display = '';
257+
visibleCount++;
258+
} else {
259+
item.row.style.display = 'none';
260+
}
261+
}
262+
263+
// Hide category header and table if no visible rows
264+
var showCategory = visibleCount > 0;
265+
category.table.style.display = showCategory ? '' : 'none';
266+
if (category.header) {
267+
category.header.style.display = showCategory ? '' : 'none';
268+
}
269+
}
270+
});
271+
}
272+
180273
});

content/static/style.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,4 +1366,32 @@ body#page-examples.page-examples-index {
13661366
#page-api-docs.page-api-docs-index .content-right main table th:last-child {
13671367
display: none;
13681368
}
1369+
}
1370+
1371+
/* API Docs Search */
1372+
.api-search-container {
1373+
margin-top: 30px;
1374+
margin-bottom: 30px;
1375+
}
1376+
1377+
.api-search-input {
1378+
width: 100%;
1379+
max-width: 400px;
1380+
padding: 10px 14px;
1381+
font-size: 15px;
1382+
background-color: #252525;
1383+
border: 1px solid #404040;
1384+
color: #ddd;
1385+
border-radius: 4px;
1386+
outline: none;
1387+
transition: border-color 0.15s;
1388+
box-sizing: border-box;
1389+
}
1390+
1391+
.api-search-input:focus {
1392+
border-color: #60AFEF;
1393+
}
1394+
1395+
.api-search-input::placeholder {
1396+
color: #666;
13691397
}

0 commit comments

Comments
 (0)