+! New sidebar button for mobile
This commit is contained in:
parent
f97b8c0a17
commit
2a45dc6ae4
@ -2,8 +2,8 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
{{- partial "head.html" . -}}
|
{{- partial "head.html" . -}}
|
||||||
<body>
|
<body>
|
||||||
{{- partial "header.html" . -}}
|
|
||||||
<div id="layout">
|
<div id="layout">
|
||||||
|
{{- partial "header.html" . -}}
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1>Welcome to my not-a-blog</h1>
|
<h1>Welcome to my not-a-blog</h1>
|
||||||
@ -19,5 +19,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{- partial "footer.html" . -}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
<script src="/js/sidemenu.js" defer></script>
|
||||||
|
|
@ -1,3 +1,8 @@
|
|||||||
|
<!-- Menu toggler thingy -->
|
||||||
|
<a href="#menu" id="menuLink" class="menu-link">
|
||||||
|
<!-- Hamburger icon -->
|
||||||
|
<span></span>
|
||||||
|
</a>
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<a class="pure-menu-heading" href="/">Home</a>
|
<a class="pure-menu-heading" href="/">Home</a>
|
||||||
<div class="pure-menu">
|
<div class="pure-menu">
|
||||||
|
55
themes/shockrah.xyz/static/js/sidemenu.js
Normal file
55
themes/shockrah.xyz/static/js/sidemenu.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
(function (window, document) {
|
||||||
|
|
||||||
|
// we fetch the elements each time because docusaurus removes the previous
|
||||||
|
// element references on page navigation
|
||||||
|
function getElements() {
|
||||||
|
return {
|
||||||
|
layout: document.getElementById('layout'),
|
||||||
|
menu: document.getElementById('menu'),
|
||||||
|
menuLink: document.getElementById('menuLink')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleClass(element, className) {
|
||||||
|
var classes = element.className.split(/\s+/);
|
||||||
|
var length = classes.length;
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
for (; i < length; i++) {
|
||||||
|
if (classes[i] === className) {
|
||||||
|
classes.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The className is not found
|
||||||
|
if (length === classes.length) {
|
||||||
|
classes.push(className);
|
||||||
|
}
|
||||||
|
|
||||||
|
element.className = classes.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleAll() {
|
||||||
|
var active = 'active';
|
||||||
|
var elements = getElements();
|
||||||
|
|
||||||
|
toggleClass(elements.layout, active);
|
||||||
|
toggleClass(elements.menu, active);
|
||||||
|
toggleClass(elements.menuLink, active);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEvent(e) {
|
||||||
|
var elements = getElements();
|
||||||
|
|
||||||
|
if (e.target.id === elements.menuLink.id) {
|
||||||
|
toggleAll();
|
||||||
|
e.preventDefault();
|
||||||
|
} else if (elements.menu.className.indexOf('active') !== -1) {
|
||||||
|
toggleAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('click', handleEvent);
|
||||||
|
|
||||||
|
}(this, this.document));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user