Skip to content

Commit 75bcc68

Browse files
committed
doc: hide menus in appropriate pages
1 parent 96e4e58 commit 75bcc68

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

doc/api_assets/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ li.picker-header a span {
238238
padding-left: 1rem;
239239
}
240240

241+
.picker li a.active,
242+
.picker li a.active:hover,
243+
.picker li a.active:focus {
244+
font-weight: 700;
245+
}
246+
241247
.picker li:last-child a {
242248
border-bottom-right-radius: 1px;
243249
border-bottom-left-radius: 1px;

doc/template.html

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,9 @@ <h1>Node.js __VERSION__ documentation</h1>
4040
<div id="gtoc">
4141
<ul>
4242
<li class="pinner-header">Node.js __VERSION__</li>
43-
<li class="picker-header">
44-
<a href="#">
45-
<span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
46-
Table of contents
47-
</a>
48-
49-
<div class="picker">__TOC_PICKER__</div>
50-
</li>
43+
__TOC_PICKER__
5144
__ALTDOCS__
52-
<li class="picker-header gtoc-picker-header">
53-
<a href="#">
54-
<span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
55-
Index
56-
</a>
57-
58-
<div class="picker">__GTOC__</div>
59-
</li>
45+
__GTOC_PICKER__
6046
<li>
6147
<a href="all.html">View on single page</a>
6248
</li>
@@ -114,12 +100,16 @@ <h1>Node.js __VERSION__ documentation</h1>
114100

115101
// Handle pickers with click/taps rather than hovers
116102
const pickers = document.querySelectorAll('.picker-header');
117-
for(const picker of document.querySelectorAll('.picker-header')) {
118-
picker.addEventListener('click', function() {
119-
if(picker.classList.contains('expanded')) {
103+
for(const picker of pickers) {
104+
picker.addEventListener('click', e => {
105+
if (!e.target.closest('.picker')) {
106+
e.preventDefault();
107+
}
108+
109+
if (picker.classList.contains('expanded')) {
120110
picker.classList.remove('expanded');
121111
} else {
122-
for(const other of pickers) {
112+
for (const other of pickers) {
123113
other.classList.remove('expanded');
124114
}
125115

tools/doc/html.mjs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export function toHTML({ input, content, filename, nodeVersion, versions }) {
9999
.replace('__SECTION__', content.section)
100100
.replace(/__VERSION__/g, nodeVersion)
101101
.replace(/__TOC__/g, content.toc)
102-
.replace(/__TOC_PICKER__/g, content.tocPicker)
102+
.replace(/__TOC_PICKER__/g, tocPicker(id, content))
103+
.replace(/__GTOC_PICKER__/g, gtocPicker(id))
103104
.replace(/__GTOC__/g, gtocHTML.replace(
104105
`class="nav-${id}"`, `class="nav-${id} active"`))
105106
.replace('__EDIT_ON_GITHUB__', editOnGitHub(filename))
@@ -523,3 +524,41 @@ function altDocs(filename, docCreated, versions) {
523524
function editOnGitHub(filename) {
524525
return `<li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/${filename}.md">Edit on GitHub</a></li>`;
525526
}
527+
528+
function gtocPicker(id) {
529+
if (id === 'index') {
530+
return '';
531+
}
532+
533+
const gtoc = gtocHTML.replace(
534+
`class="nav-${id}"`, `class="nav-${id} active"`
535+
);
536+
537+
return `
538+
<li class="picker-header">
539+
<a href="#">
540+
<span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
541+
Index
542+
</a>
543+
544+
<div class="picker">${gtoc}</div>
545+
</li>
546+
`;
547+
}
548+
549+
function tocPicker(id, content) {
550+
if (id === 'index') {
551+
return '';
552+
}
553+
554+
return `
555+
<li class="picker-header">
556+
<a href="#">
557+
<span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
558+
Table of contents
559+
</a>
560+
561+
<div class="picker">${content.tocPicker}</div>
562+
</li>
563+
`;
564+
}

0 commit comments

Comments
 (0)