Skip to content

Commit cd85aaf

Browse files
authored
Merge pull request TheThingsIndustries#350 from TheThingsIndustries/doc/anchor-js
Change anchor hashes to JS
2 parents 7c745c5 + ea2414f commit cd85aaf

6 files changed

Lines changed: 42 additions & 18 deletions

File tree

doc/assets/css/common/global.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ table.fixed td { overflow: auto; }
278278
font-size: 100%;
279279
visibility: hidden;
280280
color: silver;
281+
padding-left: 0.375rem;
281282
}
282283

283284
h2, h3, h4, h5, h6 {

doc/assets/css/header/nav.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
align-items: center;
1818
background-color: $blue;
1919
display: none; // or `flex`
20+
padding: 0 2rem 0 2rem;
2021
}
2122

2223
.navbar {

doc/assets/js/theme.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
document.addEventListener('DOMContentLoaded', function () {
16-
var migrationInfoAccepted = window.localStorage.getItem('migrationInfoAccepted')
17-
if(migrationInfoAccepted != 'true') {
18-
var migrationBar = document.getElementById('migration-info')
19-
migrationBar.style.display = 'flex';
20-
document.documentElement.classList.add("has-navbar-banner-top")
21-
var migrationButton = document.getElementById('migration-button')
22-
migrationButton.addEventListener('click', function (){
23-
window.localStorage.setItem('migrationInfoAccepted', true)
24-
migrationBar.style.display = 'none';
25-
document.documentElement.classList.remove("has-navbar-banner-top")
26-
})
27-
}
28-
15+
function addNavBarBurgers(){
2916
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0)
3017
if ($navbarBurgers.length > 0) {
3118
$navbarBurgers.forEach(function(el) {
@@ -37,7 +24,22 @@ document.addEventListener('DOMContentLoaded', function () {
3724
})
3825
})
3926
}
27+
}
28+
29+
function addAnchor(element) {
30+
element.insertAdjacentHTML('beforeend',
31+
`<a class="header-hash" href="#${element.id}" ariaLabel="Anchor">#</a>` )
32+
}
33+
34+
function addAnchors() {
35+
var headers = document.querySelectorAll(
36+
'.docs-content h2[id], .docs-content h3[id], .docs-content h4[id], .docs-content h5[id], .docs-content h6[id]')
37+
if (headers) {
38+
headers.forEach(addAnchor)
39+
}
40+
}
4041

42+
function addTabs(){
4143
const tabs = [...document.querySelectorAll('.tabs li')]
4244
const tabContent = [...document.querySelectorAll('.tab-content section')]
4345
const activeClass = 'is-active'
@@ -102,4 +104,26 @@ document.addEventListener('DOMContentLoaded', function () {
102104
}
103105

104106
init()
107+
}
108+
109+
function addMigrationBar(){
110+
var migrationInfoAccepted = window.localStorage.getItem('migrationInfoAccepted')
111+
if(migrationInfoAccepted != 'true') {
112+
var migrationBar = document.getElementById('migration-info')
113+
migrationBar.style.display = 'flex';
114+
document.documentElement.classList.add("has-navbar-banner-top")
115+
var migrationButton = document.getElementById('migration-button')
116+
migrationButton.addEventListener('click', function (){
117+
window.localStorage.setItem('migrationInfoAccepted', true)
118+
migrationBar.style.display = 'none';
119+
document.documentElement.classList.remove("has-navbar-banner-top")
120+
})
121+
}
122+
}
123+
124+
document.addEventListener('DOMContentLoaded', function () {
125+
addAnchors()
126+
addMigrationBar()
127+
addNavBarBurgers()
128+
addTabs()
105129
})

doc/layouts/_default/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1 class="title is-size-2">{{ .Title }}
1818
</h1>
1919

2020
<div class="content">
21-
{{ partial "header-hash.html" .Content }}
21+
{{ .Content }}
2222
</div>
2323
{{ if and .Pages (not (eq .Parent .FirstSection)) }}
2424
{{ partial "pages-cards.html" .Pages }}

doc/layouts/_default/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1 class="title is-size-2">{{ .Title }}
1818
</h1>
1919

2020
<div class="content">
21-
{{ partial "header-hash.html" .Content }}
21+
{{ .Content }}
2222
</div>
2323
{{ partial "prev-next-in-section" . }}
2424
{{ partial "feedback" . }}

doc/layouts/partials/header-hash.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)