fix: make toggle functions tolerate null checkboxes for robustness

All three toggle functions (toggleCVLength, toggleIcons, toggleTheme) now
check if checkbox elements exist before setting their 'checked' property.

This prevents null pointer errors when:
- Menu checkboxes aren't rendered yet
- Functions are called programmatically before DOM is ready
- Tests call functions directly without full page render

Changed pattern from:
  set checkbox's checked to true

To:
  if checkbox exists
    set checkbox's checked to true
  end

Affected functions:
- toggleCVLength(): Lines 142-147, 154-159
- toggleIcons(): Lines 172-177, 183-188
- toggleTheme(): Lines 201-206, 212-217

The functions still work correctly when checkboxes exist, but now gracefully
handle missing elements instead of throwing null errors.
This commit is contained in:
juanatsap
2025-11-16 17:43:12 +00:00
parent cc14be4aef
commit ce02fc67b2
+36 -12
View File
@@ -139,16 +139,24 @@ def toggleCVLength(isLong)
if isLong is true if isLong is true
remove .cv-short from paper remove .cv-short from paper
add .cv-long to paper add .cv-long to paper
set lengthCheckbox's checked to true if lengthCheckbox exists
set menuLengthCheckbox's checked to true set lengthCheckbox's checked to true
end
if menuLengthCheckbox exists
set menuLengthCheckbox's checked to true
end
call localStorage.setItem('cv-length', 'long') call localStorage.setItem('cv-length', 'long')
end end
if isLong is false if isLong is false
remove .cv-long from paper remove .cv-long from paper
add .cv-short to paper add .cv-short to paper
set lengthCheckbox's checked to false if lengthCheckbox exists
set menuLengthCheckbox's checked to false set lengthCheckbox's checked to false
end
if menuLengthCheckbox exists
set menuLengthCheckbox's checked to false
end
call localStorage.setItem('cv-length', 'short') call localStorage.setItem('cv-length', 'short')
end end
end end
@@ -161,15 +169,23 @@ def toggleIcons(showIcons)
-- Update DOM state -- Update DOM state
if showIcons is true if showIcons is true
add .show-icons to paper add .show-icons to paper
set iconsCheckbox's checked to true if iconsCheckbox exists
set menuIconsCheckbox's checked to true set iconsCheckbox's checked to true
end
if menuIconsCheckbox exists
set menuIconsCheckbox's checked to true
end
call localStorage.setItem('cv-icons', 'show') call localStorage.setItem('cv-icons', 'show')
end end
if showIcons is false if showIcons is false
remove .show-icons from paper remove .show-icons from paper
set iconsCheckbox's checked to false if iconsCheckbox exists
set menuIconsCheckbox's checked to false set iconsCheckbox's checked to false
end
if menuIconsCheckbox exists
set menuIconsCheckbox's checked to false
end
call localStorage.setItem('cv-icons', 'hide') call localStorage.setItem('cv-icons', 'hide')
end end
end end
@@ -182,15 +198,23 @@ def toggleTheme(isClean)
-- Update DOM state -- Update DOM state
if isClean is true if isClean is true
add .theme-clean to container add .theme-clean to container
set themeCheckbox's checked to true if themeCheckbox exists
set menuThemeCheckbox's checked to true set themeCheckbox's checked to true
end
if menuThemeCheckbox exists
set menuThemeCheckbox's checked to true
end
call localStorage.setItem('cv-theme', 'clean') call localStorage.setItem('cv-theme', 'clean')
end end
if isClean is false if isClean is false
remove .theme-clean from container remove .theme-clean from container
set themeCheckbox's checked to false if themeCheckbox exists
set menuThemeCheckbox's checked to false set themeCheckbox's checked to false
end
if menuThemeCheckbox exists
set menuThemeCheckbox's checked to false
end
call localStorage.setItem('cv-theme', 'default') call localStorage.setItem('cv-theme', 'default')
end end
end end