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
remove .cv-short from paper
add .cv-long to paper
set lengthCheckbox's checked to true
set menuLengthCheckbox's checked to true
if lengthCheckbox exists
set lengthCheckbox's checked to true
end
if menuLengthCheckbox exists
set menuLengthCheckbox's checked to true
end
call localStorage.setItem('cv-length', 'long')
end
if isLong is false
remove .cv-long from paper
add .cv-short to paper
set lengthCheckbox's checked to false
set menuLengthCheckbox's checked to false
if lengthCheckbox exists
set lengthCheckbox's checked to false
end
if menuLengthCheckbox exists
set menuLengthCheckbox's checked to false
end
call localStorage.setItem('cv-length', 'short')
end
end
@@ -161,15 +169,23 @@ def toggleIcons(showIcons)
-- Update DOM state
if showIcons is true
add .show-icons to paper
set iconsCheckbox's checked to true
set menuIconsCheckbox's checked to true
if iconsCheckbox exists
set iconsCheckbox's checked to true
end
if menuIconsCheckbox exists
set menuIconsCheckbox's checked to true
end
call localStorage.setItem('cv-icons', 'show')
end
if showIcons is false
remove .show-icons from paper
set iconsCheckbox's checked to false
set menuIconsCheckbox's checked to false
if iconsCheckbox exists
set iconsCheckbox's checked to false
end
if menuIconsCheckbox exists
set menuIconsCheckbox's checked to false
end
call localStorage.setItem('cv-icons', 'hide')
end
end
@@ -182,15 +198,23 @@ def toggleTheme(isClean)
-- Update DOM state
if isClean is true
add .theme-clean to container
set themeCheckbox's checked to true
set menuThemeCheckbox's checked to true
if themeCheckbox exists
set themeCheckbox's checked to true
end
if menuThemeCheckbox exists
set menuThemeCheckbox's checked to true
end
call localStorage.setItem('cv-theme', 'clean')
end
if isClean is false
remove .theme-clean from container
set themeCheckbox's checked to false
set menuThemeCheckbox's checked to false
if themeCheckbox exists
set themeCheckbox's checked to false
end
if menuThemeCheckbox exists
set menuThemeCheckbox's checked to false
end
call localStorage.setItem('cv-theme', 'default')
end
end