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

View file

@ -40,6 +40,7 @@ window.addEventListener('DOMContentLoaded', () => {
// add scroll to top button // add scroll to top button
const btn = document.getElementById('scroll-to-top') const btn = document.getElementById('scroll-to-top')
if(btn) {
window.addEventListener('scroll', function () { window.addEventListener('scroll', function () {
if (window.scrollY > 300) { if (window.scrollY > 300) {
btn.classList.add('show') btn.classList.add('show')
@ -55,4 +56,5 @@ window.addEventListener('DOMContentLoaded', () => {
behavior: 'smooth' behavior: 'smooth'
}) })
}) })
}
}) })

View file

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

View file

@ -18,4 +18,5 @@
<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> <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 }}
{{ end }}
{{ end }} {{ end }}