Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit 61bf615

Browse files
authored
make section headings in api docs linkable
1 parent 27db87b commit 61bf615

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

website/api/index.html

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
color: grey;
194194
}
195195

196-
.reference .symbol-name {
196+
.reference .symbol .symbol-name {
197197
text-decoration: none;
198198
color: #0277BD;
199199
margin-right: 0.33em;
@@ -317,6 +317,16 @@
317317

318318
<script>
319319
document.addEventListener('DOMContentLoaded', function(e) {
320+
var isInViewport = function(elem) {
321+
var bounding = elem.getBoundingClientRect();
322+
return (
323+
bounding.top >= 0 &&
324+
bounding.left >= 0 &&
325+
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
326+
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
327+
);
328+
};
329+
320330
// Find the symbol closest to the top of the page in the reference
321331
// section and highlight it in the TOC section.
322332

@@ -342,13 +352,18 @@
342352
}
343353

344354
if (found) {
345-
tocFound = tocArea.querySelector(`[href="#${found.getAttribute('name')}"]`)
355+
tocFound = tocArea.querySelectorAll(`[href="#${found.getAttribute('name')}"]`)
356+
357+
// The first subheading in a section shares an href with its parent.
358+
tocFound = tocFound.length > 1 ? tocFound[1] : tocFound[0];
346359

347360
if (lastHighlightedTocElement) {
348361
lastHighlightedTocElement.classList.remove('highlighted');
349362
}
350363
tocFound.classList.add('highlighted');
351-
// tocFound.scrollIntoView(false);
364+
if(!isInViewport(tocFound)) {
365+
tocFound.scrollIntoView(false);
366+
}
352367
lastHighlightedTocElement = tocFound;
353368
}
354369
}
@@ -401,10 +416,14 @@
401416
</div>
402417
{{#headings}}
403418
<div class="section">
404-
<div class="section-title mdl-typography--title">{{name}}</div>
419+
<div class="section-title mdl-typography--title">
420+
<a href="#{{name}}-{{subheadings.0.name}}">{{name}}</a>
421+
</div>
405422
{{#subheadings}}
406423
<div class="subsection">
407-
<div class="sub-section-title mdl-typography--subhead">{{name}}</div>
424+
<div class="sub-section-title mdl-typography--subhead">
425+
<a href="#{{../name}}-{{name}}">{{name}}</a>
426+
</div>
408427
{{#symbols}}
409428
<div class="symbol">
410429
<a href="#{{urlHash}}">{{displayName}}</a>
@@ -421,7 +440,7 @@
421440
<div class="section">
422441
{{#subheadings}}
423442
<div class="subsection">
424-
<div class="subsection-title mdl-typography--display-3">{{../name}} &nbsp;/&nbsp; {{name}}</div>
443+
<div id="{{../name}}-{{name}}" name="{{../name}}-{{name}}" class="symbol-name subsection-title mdl-typography--display-3">{{../name}} &nbsp;/&nbsp; {{name}}</div>
425444
<div class="subsection-description mdl-typography--headline">{{{description}}}</div>
426445
{{#symbols}}
427446
<div class="symbol">

0 commit comments

Comments
 (0)