-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
190 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<dialog id="overlay"> | ||
<div class="d-flex flex-column"> | ||
<div class="d-flex flex-row align-items-center justify-content-between"> | ||
<h2>{{- site.data.locales[include.lang].panel.toc -}}</h2> | ||
<button id="overlay-close" type="button" class="btn btn-link"> | ||
<i class="fas fa-close fa-fw"></i> | ||
</button> | ||
</div> | ||
<div id="overlay-content"></div> | ||
</div> | ||
</dialog> |
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,30 @@ | ||
<!-- Post secondary topbar --> | ||
|
||
{% assign enable_toc = false %} | ||
{% if site.toc and page.toc %} | ||
{% if page.content contains '<h2' or page.content contains '<h3' %} | ||
{% assign enable_toc = true %} | ||
{% endif %} | ||
{% endif %} | ||
|
||
{% if enable_toc %} | ||
<div id="post-topbar" class="d-flex flex-row align-items-baseline justify-content-between"> | ||
<!-- category --> | ||
<span id="post-topbar-category"> | ||
{% if page.categories.size > 0 %} | ||
{{ page.categories | first }} | ||
{% if page.categories.size > 1 %} | ||
{{ '/' | append: ' ' | append: page.categories[1] }} | ||
{% endif %} | ||
{% else %} | ||
{{- site.data.locales[include.lang].panel.toc -}} | ||
{% endif %} | ||
</span> | ||
<!-- title --> | ||
<span id="post-topbar-title" class="d-none">{{ page.title }}</span> | ||
<!-- toc trigger --> | ||
<button id="overlay-trigger" type="button" class="btn btn-link"> | ||
<i class="fas fa-list fa-fw"></i> | ||
</button> | ||
</div> | ||
{% endif %} |
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,74 @@ | ||
/* | ||
* Post topbar functions | ||
*/ | ||
|
||
const postTitle = document.querySelector('article header'); | ||
const topbarCategory = document.getElementById('post-topbar-category'); | ||
const topbarTitle = document.getElementById('post-topbar-title'); | ||
|
||
const overlay = document.getElementById('overlay'); | ||
const overlayTrigger = document.getElementById('overlay-trigger'); | ||
const overlayContent = document.getElementById('overlay-content'); | ||
const overlayClose = document.getElementById('overlay-close'); | ||
|
||
const UNLOADED = 'd-none'; | ||
|
||
function initPostTopbar() { | ||
window.addEventListener('scroll', () => { | ||
if (window.scrollY >= postTitle?.offsetTop) { | ||
topbarCategory.classList.add(UNLOADED); | ||
topbarTitle.classList.remove(UNLOADED); | ||
} else { | ||
topbarCategory.classList.remove(UNLOADED); | ||
topbarTitle.classList.add(UNLOADED); | ||
} | ||
}); | ||
} | ||
|
||
class Overlay { | ||
static show() { | ||
document.body.classList.add('noscroll'); | ||
overlay.showModal(); | ||
} | ||
|
||
static hide() { | ||
document.body.classList.remove('noscroll'); | ||
overlay.close(); | ||
} | ||
|
||
static addTocToOverlay() { | ||
const toc = document.getElementById('toc-wrapper'); | ||
const clonedToc = toc.cloneNode(true); | ||
this.removeContent(); | ||
overlayContent.appendChild(clonedToc); | ||
} | ||
|
||
static removeContent() { | ||
while (overlayContent.firstChild) { | ||
overlayContent.removeChild(overlayContent.firstChild); | ||
} | ||
} | ||
|
||
static init() { | ||
overlay?.addEventListener('click', () => { | ||
this.hide(); | ||
this.removeContent(); | ||
}); | ||
|
||
overlayTrigger?.addEventListener('click', () => { | ||
this.addTocToOverlay(); | ||
this.show(); | ||
}); | ||
|
||
overlayClose?.addEventListener('click', () => { | ||
this.hide(); | ||
this.removeContent(); | ||
}); | ||
} | ||
} | ||
|
||
export { initPostTopbar }; | ||
|
||
export function initOverlay() { | ||
Overlay.init(); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { basic } from './layouts/basic'; | ||
export { initSidebar } from './layouts/sidebar'; | ||
export { initTopbar } from './layouts/topbar'; | ||
export { initPostTopbar, initOverlay } from './components/post-topbar'; |
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
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