Skip to content

Commit

Permalink
Merge pull request #1 from mechie/fix-mobile-menu
Browse files Browse the repository at this point in the history
Use optional chaining to add listeners to optional UI elements.
  • Loading branch information
tchartron authored Jan 30, 2022
2 parents bfa42d2 + 4fdce5f commit 19ce007
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/js/lang.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
document.addEventListener("DOMContentLoaded", function() {
document.getElementById('switch-lang').addEventListener('click', switchLang);
document.getElementById('switch-lang')?.addEventListener('click', switchLang);
})

function switchLang(event) {
Expand Down
6 changes: 3 additions & 3 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ document.addEventListener("DOMContentLoaded", function() {
document.getElementById("syntax_highlight").href = "/syntax-light.css";
}
// Switch theme action
document.getElementById('switch-theme').addEventListener('click', switchTheme);
document.getElementById('switch-theme')?.addEventListener('click', switchTheme);

// ---------------- Toggle Sidebar -------------------------
document.getElementById('toggle-sidebar').addEventListener('click', toggleSidebar);
document.getElementById('toggle-sidebar')?.addEventListener('click', toggleSidebar);

// ---------------- Toggle Mobile menu -------------------------
document.getElementById('toggle-mobile-menu').addEventListener('click', toggleMobileMenu);
document.getElementById('toggle-mobile-menu')?.addEventListener('click', toggleMobileMenu);
});

function switchTheme() {
Expand Down
2 changes: 1 addition & 1 deletion static/js/lang.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/js/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19ce007

Please sign in to comment.