Skip to content

Commit 1da301c

Browse files
authored
Add defensive check for missing mode and modeText elements (#5263)
1 parent 65cecba commit 1da301c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

script.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @function
44
* @global
55
*/
6-
$(document).ready(function() {
6+
$(document).ready(function () {
77
/**
88
* The user's selected mode, stored in local storage.
99
* @type {string}
@@ -29,6 +29,11 @@ $(document).ready(function() {
2929
*/
3030
var modeText = document.getElementById("modeText");
3131

32+
// Defensive: avoid crashing if expected DOM nodes are missing.
33+
if (!modeIcon || !modeText) {
34+
return;
35+
}
36+
3237
// Set the mode icon and tooltip based on the user's selected mode.
3338
if (mode === null || mode === "true") {
3439
modeIcon.innerHTML = "star_border";
@@ -45,6 +50,6 @@ $(document).ready(function() {
4550
$(".materialize-iso, .dropdown-trigger").dropdown({
4651
constrainWidth: false,
4752
hover: false, // Activate on click
48-
belowOrigin: true, // Displays dropdown below the button
53+
belowOrigin: true // Displays dropdown below the button
4954
});
5055
});

0 commit comments

Comments
 (0)