mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-08-09 11:20:30 +00:00
Add search bar to docs
This commit is contained in:
parent
81c594087a
commit
b83b6decd2
1 changed files with 37 additions and 0 deletions
37
third_party/chibicc/dox2.c
vendored
37
third_party/chibicc/dox2.c
vendored
|
@ -549,6 +549,7 @@ static void PrintDox(struct Dox *dox, FILE *f) {
|
||||||
width: 80ch;\n\
|
width: 80ch;\n\
|
||||||
}\n\
|
}\n\
|
||||||
.toc {\n\
|
.toc {\n\
|
||||||
|
display: block;\n\
|
||||||
overflow-x: auto;\n\
|
overflow-x: auto;\n\
|
||||||
}\n\
|
}\n\
|
||||||
.toc a {\n\
|
.toc a {\n\
|
||||||
|
@ -587,7 +588,23 @@ static void PrintDox(struct Dox *dox, FILE *f) {
|
||||||
margin-bottom: .5em;\n\
|
margin-bottom: .5em;\n\
|
||||||
margin-left: 1em;\n\
|
margin-left: 1em;\n\
|
||||||
}\n\
|
}\n\
|
||||||
|
#search {\n\
|
||||||
|
top: 1ch;\n\
|
||||||
|
right: 1ch;\n\
|
||||||
|
float: right;\n\
|
||||||
|
position: sticky;\n\
|
||||||
|
margin: 1ch;\n\
|
||||||
|
}\n\
|
||||||
|
@media (max-width: 60ch) {\n\
|
||||||
|
.toc {\n\
|
||||||
|
display: none;\n\
|
||||||
|
}\n\
|
||||||
|
}\n\
|
||||||
</style>\n\
|
</style>\n\
|
||||||
|
<noscript><style>\n\
|
||||||
|
.toc { display: block; }\n\
|
||||||
|
#search { display: none; }\n\
|
||||||
|
</style></noscript>\n\
|
||||||
\n\
|
\n\
|
||||||
<header>\n\
|
<header>\n\
|
||||||
<img width=\"196\" height=\"105\"\n\
|
<img width=\"196\" height=\"105\"\n\
|
||||||
|
@ -662,6 +679,26 @@ static void PrintDox(struct Dox *dox, FILE *f) {
|
||||||
|
|
||||||
fprintf(f, "<main>\n");
|
fprintf(f, "<main>\n");
|
||||||
|
|
||||||
|
// search bar
|
||||||
|
fprintf(f, "\
|
||||||
|
<input type=\"search\" id=\"search\" placeholder=\"Search...\" list=\"search-list\" spellcheck=\"false\" />\n\
|
||||||
|
<datalist id=\"search-list\"></datalist>\n\
|
||||||
|
<script>\n\
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {\n\
|
||||||
|
var datalist = document.getElementById('search-list')\n\
|
||||||
|
document.querySelectorAll('.api').forEach(function (el) {\n\
|
||||||
|
var option = document.createElement('option')\n\
|
||||||
|
option.setAttribute('value', el.id)\n\
|
||||||
|
datalist.appendChild(option)\n\
|
||||||
|
})\n\
|
||||||
|
document.getElementById('search').addEventListener('change', function (event) {\n\
|
||||||
|
var value = event.target.value\n\
|
||||||
|
if (document.getElementById(value)) {\n\
|
||||||
|
location.hash = value\n\
|
||||||
|
}\n\
|
||||||
|
})\n\
|
||||||
|
})\n\
|
||||||
|
</script>\n\n");
|
||||||
|
|
||||||
// righthand contents
|
// righthand contents
|
||||||
for (i = 0; i < dox->index.n; ++i) {
|
for (i = 0; i < dox->index.n; ++i) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue