Skip to content

Commit 4c77b06

Browse files
authored
Add anchors for headings in documentation (#2852)
1 parent 80d5475 commit 4c77b06

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

_sass/components/heading-anchor.scss

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// HEADING ANCHOR
2+
//------------------------------------------------
3+
//------------------------------------------------
4+
5+
.heading-anchor {
6+
visibility: hidden;
7+
padding-left: 0.5em;
8+
9+
&:hover {
10+
text-decoration: none;
11+
}
12+
}

_sass/layout/documentation.scss

+28
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@
6666
.tag-inline {
6767
float: none;
6868
}
69+
70+
h1,
71+
h3,
72+
h4,
73+
h5,
74+
h6 {
75+
.heading-anchor {
76+
color: $base-font-color;
77+
}
78+
79+
&:hover {
80+
.heading-anchor {
81+
visibility: visible;
82+
}
83+
}
84+
}
85+
86+
h2 {
87+
.heading-anchor {
88+
color: $brand-tertiary;
89+
}
90+
91+
&:hover {
92+
.heading-anchor {
93+
visibility: visible;
94+
}
95+
}
96+
}
6997
}
7098

7199
a.new-version-notice {

resources/css/style.scss

+1
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@
7474
@import 'components/search';
7575
@import 'components/dropdown';
7676
@import 'components/wip-notice';
77+
@import 'components/heading-anchor.scss';

resources/js/functions.js

+12
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,15 @@ $(document).ready(function () {
662662
$('#contributors').html(contributorsHtml);
663663
});
664664
});
665+
666+
$(document).ready(function() {
667+
const icon = '<i class="fa fa-link fa-2xs" aria-hidden="true"></i>'
668+
const anchor = '<a class="heading-anchor" aria-hidden="true"></a>'
669+
670+
$('.content-primary.documentation').find('h1, h2, h3, h4, h5, h6').each(function() {
671+
const id = $(this).attr('id');
672+
if (id) {
673+
$(this).append($(anchor).attr('href', '#' + id).html(icon));
674+
}
675+
});
676+
});

0 commit comments

Comments
 (0)