-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Add table of contents to articles (#5)
- Loading branch information
1 parent
44da6b4
commit c0d6f5e
Showing
6 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const TOC_ID = 'obsah'; | ||
|
||
const generateToc = () => { | ||
tocbot.init({ | ||
activeLinkClass: 'is-active', | ||
collapsibleClass: 'is-collapsible', | ||
contentSelector: '.js-table-of-contents-source', | ||
headingSelector: 'h1, h2, h3', | ||
isCollapsedClass: 'is-collapsed', | ||
linkClass: 'table-of-contents__link', | ||
listClass: 'table-of-contents__list', | ||
listItemClass: 'table-of-contents__list__item', | ||
scrollSmooth: false, | ||
tocSelector: `#${TOC_ID}`, | ||
}); | ||
|
||
document.getElementById(TOC_ID).classList.add('table-of-contents--active'); | ||
}; | ||
|
||
const destroyToc = () => { | ||
document.getElementById(TOC_ID).classList.remove('table-of-contents--active'); | ||
tocbot.destroy(); | ||
}; | ||
|
||
const updateToc = () => { | ||
const tocEl = document.getElementById(TOC_ID); | ||
|
||
if (window.getComputedStyle(tocEl).display !== 'none') { | ||
if (!tocEl.innerHTML) { | ||
generateToc(); | ||
} | ||
} else if (tocEl.innerHTML) { | ||
destroyToc(); | ||
} | ||
}; | ||
|
||
window.addEventListener('load', () => updateToc()); | ||
window.addEventListener('resize', () => updateToc()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@use '../../settings/container'; | ||
@use '../../tools/breakpoint'; | ||
@use '../../tools/spacing'; | ||
@use '../../tools/transition'; | ||
@use '../../tools/typography'; | ||
|
||
$_breakpoint: xl; | ||
|
||
.table-of-contents { | ||
@include breakpoint.up($_breakpoint) { | ||
@include transition.add('visibility, opacity'); | ||
|
||
position: sticky; | ||
top: 0; | ||
right: 0; | ||
display: block; | ||
//visibility: hidden; | ||
//opacity: 0; | ||
width: calc((100vw - #{container.$article-width}) / 2); | ||
height: 0; | ||
padding: spacing.of(2) container.$padding-sm; | ||
line-height: typography.line-height(dense); | ||
will-change: visibility, opacity; | ||
} | ||
} | ||
|
||
.table-of-contents__list { | ||
//@include breakpoint.up($_breakpoint) { | ||
@include typography.style(small); | ||
//} | ||
} | ||
|
||
.table-of-contents__list .table-of-contents__list { | ||
font-size: inherit; | ||
} | ||
|
||
.table-of-contents--active { | ||
//@include breakpoint.up($_breakpoint) { | ||
// visibility: visible; | ||
// opacity: 1; | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.12.0/tocbot.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters