-
-
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
8 changed files
with
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<dialog id="overlay"></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,19 @@ | ||
<!-- Post secondary topbar --> | ||
|
||
<div id="post-topbar" class="d-flex flex-row 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 %} | ||
{% 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> |
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,70 @@ | ||
/* | ||
* Post topbar functions | ||
*/ | ||
|
||
const stickyTopbar = document.getElementById('post-topbar'); | ||
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 LOADED = 'd-block'; | ||
const UNLOADED = 'd-none'; | ||
|
||
function initPostTopbar() { | ||
window.addEventListener('scroll', () => { | ||
if (window.scrollY >= stickyTopbar.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.classList.add(LOADED); | ||
overlay.showModal(); | ||
} | ||
|
||
static hide() { | ||
document.body.classList.remove('noscroll'); | ||
// overlay.classList.remove(LOADED); | ||
overlay.close(); | ||
} | ||
|
||
static addTocToOverlay() { | ||
const toc = document.getElementById('toc-wrapper'); | ||
const clonedToc = toc.cloneNode(true); | ||
this.removeContent(); | ||
overlay.appendChild(clonedToc); | ||
} | ||
|
||
static removeContent() { | ||
while (overlay.firstChild) { | ||
overlay.removeChild(overlay.firstChild); | ||
} | ||
} | ||
|
||
static init() { | ||
overlay?.addEventListener('click', () => { | ||
this.removeContent(); | ||
this.hide(); | ||
}); | ||
|
||
overlayTrigger?.addEventListener('click', () => { | ||
this.addTocToOverlay(); | ||
this.show(); | ||
}); | ||
} | ||
} | ||
|
||
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
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