add null handling and fix merge conflicts

This commit is contained in:
Aaron Qian 2023-01-04 19:20:11 -08:00
parent 8580a1f463
commit 6e0a4b058d
No known key found for this signature in database
GPG key ID: BF1A987C395B5B0E
4 changed files with 37 additions and 34 deletions

View file

@ -31,7 +31,7 @@ window.addEventListener('DOMContentLoaded', () => {
} else {
const node = document.createElement('p')
node.textContent = 'Please enter a word or phrase above'
window.getElementById('search-results').append(node)
document.getElementById('search-results')?.append(node)
}
function executeSearch (searchQuery) {
@ -48,7 +48,7 @@ window.addEventListener('DOMContentLoaded', () => {
} else {
const node = document.createElement('p')
node.textContent = 'No matches found'
window.getElementById('search-results').append(node)
document.getElementById('search-results')?.append(node)
}
})
}

View file

@ -40,19 +40,21 @@ window.addEventListener('DOMContentLoaded', () => {
// add scroll to top button
const btn = document.getElementById('scroll-to-top')
window.addEventListener('scroll', function () {
if (window.scrollY > 300) {
btn.classList.add('show')
} else {
btn.classList.remove('show')
}
})
btn.addEventListener('click', function (e) {
e.preventDefault()
window.scrollTo({
top: 0,
behavior: 'smooth'
if(btn) {
window.addEventListener('scroll', function () {
if (window.scrollY > 300) {
btn.classList.add('show')
} else {
btn.classList.remove('show')
}
})
})
btn.addEventListener('click', function (e) {
e.preventDefault()
window.scrollTo({
top: 0,
behavior: 'smooth'
})
})
}
})

View file

@ -4,36 +4,36 @@ const updateNavBar = () => {
const themeIcon = document.getElementById('navbar-theme-icon-svg')
if (window.scrollY > 40) {
topNavbar.classList.remove('initial-navbar')
topNavbar.classList.add('final-navbar', 'shadow')
topNavbar?.classList.remove('initial-navbar')
topNavbar?.classList.add('final-navbar', 'shadow')
navbarToggler.classList.remove('navbar-dark')
navbarToggler.classList.add('navbar-light')
navbarToggler?.classList.remove('navbar-dark')
navbarToggler?.classList.add('navbar-light')
// color theme selector a.k.a. dark mode
themeIcon.classList.remove('navbar-icon-svg-dark')
themeIcon?.classList.remove('navbar-icon-svg-dark')
// get the main logo from hidden img tag
const mainLogo = document.getElementById('main-logo')
if (mainLogo !== null) {
if (mainLogo) {
const logoURL = mainLogo.getAttribute('src')
document.getElementById('logo').setAttribute('src', logoURL)
document.getElementById('logo')?.setAttribute('src', logoURL)
}
} else {
topNavbar.classList.remove('final-navbar', 'shadow')
topNavbar.classList.add('initial-navbar')
topNavbar?.classList.remove('final-navbar', 'shadow')
topNavbar?.classList.add('initial-navbar')
navbarToggler.classList.remove('navbar-light')
navbarToggler.classList.add('navbar-dark')
navbarToggler?.classList.remove('navbar-light')
navbarToggler?.classList.add('navbar-dark')
// color theme selector a.k.a. dark mode
themeIcon.classList.add('navbar-icon-svg-dark')
themeIcon?.classList.add('navbar-icon-svg-dark')
// get the inverted logo from hidden img tag
const invertedLogo = document.getElementById('inverted-logo')
if (invertedLogo !== null) {
if (invertedLogo) {
const logoURL = invertedLogo.getAttribute('src')
document.getElementById('logo').setAttribute('src', logoURL)
document.getElementById('logo')?.setAttribute('src', logoURL)
}
}
}
@ -47,14 +47,14 @@ document.addEventListener('DOMContentLoaded', function () {
// Creates a click handler to collapse the navigation when
// anchors in the mobile nav pop up are clicked
const navMain = document.getElementsByClassName('navbar-collapse')
for (const el of navMain) {
const navMain =document.getElementsByClassName('navbar-collapse')
Array.from(navMain).forEach(function(el) {
el.addEventListener('click', function (e) {
if (e.target.tagName === 'A') {
navMain.collapse('hide')
el.classList.add('collapse')
}
})
}
})
updateNavBar()
})

View file

@ -17,5 +17,6 @@
{{ with .buymeacoffee }}
<script data-name="BMC-Widget" data-cfasync="false" src="https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js" data-id="{{ .user }}" data-description="{{ .text }}" data-message="{{ .info }}" data-color="{{ .color }}" data-position="Right" data-x_margin="10" data-y_margin="18"></script>
{{ end }}
{{ end }}
{{ end }}
{{ end }}