Skip to content

Commit

Permalink
Add anchors for headings in documentation (#2852)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiendang committed Jul 14, 2023
1 parent 80d5475 commit 4c77b06
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
12 changes: 12 additions & 0 deletions _sass/components/heading-anchor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// HEADING ANCHOR
//------------------------------------------------
//------------------------------------------------

.heading-anchor {
visibility: hidden;
padding-left: 0.5em;

&:hover {
text-decoration: none;
}
}
28 changes: 28 additions & 0 deletions _sass/layout/documentation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@
.tag-inline {
float: none;
}

h1,
h3,
h4,
h5,
h6 {
.heading-anchor {
color: $base-font-color;
}

&:hover {
.heading-anchor {
visibility: visible;
}
}
}

h2 {
.heading-anchor {
color: $brand-tertiary;
}

&:hover {
.heading-anchor {
visibility: visible;
}
}
}
}

a.new-version-notice {
Expand Down
1 change: 1 addition & 0 deletions resources/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
@import 'components/search';
@import 'components/dropdown';
@import 'components/wip-notice';
@import 'components/heading-anchor.scss';
12 changes: 12 additions & 0 deletions resources/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,15 @@ $(document).ready(function () {
$('#contributors').html(contributorsHtml);
});
});

$(document).ready(function() {
const icon = '<i class="fa fa-link fa-2xs" aria-hidden="true"></i>'
const anchor = '<a class="heading-anchor" aria-hidden="true"></a>'

$('.content-primary.documentation').find('h1, h2, h3, h4, h5, h6').each(function() {
const id = $(this).attr('id');
if (id) {
$(this).append($(anchor).attr('href', '#' + id).html(icon));
}
});
});

0 comments on commit 4c77b06

Please sign in to comment.