Skip to content

Commit f5c5a2f

Browse files
committed
introduced js and css for mobile header
1 parent e1b1745 commit f5c5a2f

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

src/css/sections-header.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,15 @@ html.is-clipped--navbar {
438438
}
439439

440440
body:has(.sections-body) {
441-
padding-top: unset;
441+
padding-top: 0;
442442
}
443443

444444
.sections-body .sections-docu-title {
445445
display: block;
446-
margin-left: 15px;
446+
margin-left: 35px;
447447
white-space: nowrap;
448448
color: #8da5bf;
449+
margin-top: -2rem;
450+
z-index: 900;
449451
}
450452
}

src/js/05-mobile-navbar.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,74 @@
3535
// console.log('section-body not found')
3636
// }
3737
// }
38+
39+
const header = document.querySelector('header')
40+
const navbarToggle = document.querySelector('.nav-toggle')
41+
const sectionBody = document.querySelector('.sections-body')
42+
const toolbar = document.querySelector('.toolbar')
43+
44+
if (!navbarToggle) return
45+
46+
navbarToggle.addEventListener('click', toggleMobileNav)
47+
48+
function toggleMobileNav (e) {
49+
e.stopPropagation()
50+
document.documentElement.classList.toggle('is-clipped--navbar')
51+
this.classList.toggle('is-active')
52+
const menuId = this.dataset.target
53+
const menu = document.getElementById(menuId)
54+
if (menu) {
55+
menu.classList.toggle('is-active')
56+
if (menu.classList.contains('is-active')) {
57+
adjustMenuHeight(menu)
58+
} else {
59+
menu.style.maxHeight = ''
60+
}
61+
}
62+
}
63+
64+
function adjustMenuHeight (menu) {
65+
const expectedMaxHeight = window.innerHeight - menu.getBoundingClientRect().top
66+
const actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10)
67+
if (actualMaxHeight !== expectedMaxHeight) {
68+
menu.style.maxHeight = expectedMaxHeight + 'px'
69+
}
70+
}
71+
72+
if (!sectionBody) return
73+
74+
let windowWidth = window.innerWidth
75+
adjustLayoutForWindowSize(windowWidth)
76+
77+
window.addEventListener('resize', function () {
78+
const newWindowWidth = window.innerWidth
79+
if (newWindowWidth !== windowWidth) {
80+
windowWidth = newWindowWidth
81+
adjustLayoutForWindowSize(windowWidth)
82+
}
83+
})
84+
85+
function adjustLayoutForWindowSize (windowWidth) {
86+
if (windowWidth < 1024) {
87+
removeHeaderAndAdjustPadding()
88+
} else {
89+
restoreHeaderAndAdjustPadding()
90+
}
91+
}
92+
93+
function removeHeaderAndAdjustPadding () {
94+
if (header && document.body.contains(header)) {
95+
header.remove()
96+
document.body.style.paddingTop = '0'
97+
if (toolbar) toolbar.style.top = '0'
98+
}
99+
}
100+
101+
function restoreHeaderAndAdjustPadding () {
102+
if (header && !document.body.contains(header)) {
103+
document.body.insertBefore(header, document.body.firstChild)
104+
document.body.style.paddingTop = '3.5rem'
105+
if (toolbar) toolbar.style.top = '3.5rem'
106+
}
107+
}
38108
})()

src/partials/toolbar.hbs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<a href="{{{relativize this}}}" class="home-link{{#if @root.page.home}} is-current{{/if}}"></a>
55
{{/with}}
66
{{> breadcrumbs}}
7-
<span class="sections-docu-title">
8-
{{site.title}}
9-
</span>
107
{{> page-versions}}
118
{{#if (and page.fileUri (not env.CI))}}
129
<div class="edit-this-page"><a href="{{page.fileUri}}">Edit this Page</a></div>

0 commit comments

Comments
 (0)