Skip to content

Commit

Permalink
make section headings in api docs linkable
Browse files Browse the repository at this point in the history
  • Loading branch information
tafsiri authored Feb 15, 2018
1 parent 27db87b commit 61bf615
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions website/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
color: grey;
}

.reference .symbol-name {
.reference .symbol .symbol-name {
text-decoration: none;
color: #0277BD;
margin-right: 0.33em;
Expand Down Expand Up @@ -317,6 +317,16 @@

<script>
document.addEventListener('DOMContentLoaded', function(e) {
var isInViewport = function(elem) {
var bounding = elem.getBoundingClientRect();
return (
bounding.top >= 0 &&
bounding.left >= 0 &&
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};

// Find the symbol closest to the top of the page in the reference
// section and highlight it in the TOC section.

Expand All @@ -342,13 +352,18 @@
}

if (found) {
tocFound = tocArea.querySelector(`[href="#${found.getAttribute('name')}"]`)
tocFound = tocArea.querySelectorAll(`[href="#${found.getAttribute('name')}"]`)

// The first subheading in a section shares an href with its parent.
tocFound = tocFound.length > 1 ? tocFound[1] : tocFound[0];

if (lastHighlightedTocElement) {
lastHighlightedTocElement.classList.remove('highlighted');
}
tocFound.classList.add('highlighted');
// tocFound.scrollIntoView(false);
if(!isInViewport(tocFound)) {
tocFound.scrollIntoView(false);
}
lastHighlightedTocElement = tocFound;
}
}
Expand Down Expand Up @@ -401,10 +416,14 @@
</div>
{{#headings}}
<div class="section">
<div class="section-title mdl-typography--title">{{name}}</div>
<div class="section-title mdl-typography--title">
<a href="#{{name}}-{{subheadings.0.name}}">{{name}}</a>
</div>
{{#subheadings}}
<div class="subsection">
<div class="sub-section-title mdl-typography--subhead">{{name}}</div>
<div class="sub-section-title mdl-typography--subhead">
<a href="#{{../name}}-{{name}}">{{name}}</a>
</div>
{{#symbols}}
<div class="symbol">
<a href="#{{urlHash}}">{{displayName}}</a>
Expand All @@ -421,7 +440,7 @@
<div class="section">
{{#subheadings}}
<div class="subsection">
<div class="subsection-title mdl-typography--display-3">{{../name}} &nbsp;/&nbsp; {{name}}</div>
<div id="{{../name}}-{{name}}" name="{{../name}}-{{name}}" class="symbol-name subsection-title mdl-typography--display-3">{{../name}} &nbsp;/&nbsp; {{name}}</div>
<div class="subsection-description mdl-typography--headline">{{{description}}}</div>
{{#symbols}}
<div class="symbol">
Expand Down

0 comments on commit 61bf615

Please sign in to comment.