-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8b0018
commit f854b79
Showing
1 changed file
with
14 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
// Check if theme variables are valid color codes | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const root = document.documentElement; | ||
const style = getComputedStyle(root); | ||
|
||
// Default theme colors | ||
const defaultColors = { | ||
primary: '#2c3e50', | ||
secondary: '#3498db', | ||
background: '#f8f9fa', | ||
accent: '#f5f5f5' | ||
}; | ||
|
||
function isValidColor(color) { | ||
if (!color) return false; | ||
const s = new Option().style; | ||
s.color = color; | ||
return s.color !== ''; | ||
} | ||
|
||
function setFallbackColors(prefix) { | ||
const colorTypes = ['primary', 'secondary', 'background', 'accent']; | ||
|
||
colorTypes.forEach(type => { | ||
const varName = `--${prefix}${type}`; | ||
const currentColor = style.getPropertyValue(varName).trim(); | ||
|
||
if (!isValidColor(currentColor)) { | ||
root.style.setProperty(varName, defaultColors[type]); | ||
} | ||
}); | ||
// Check and set fallback colors if needed | ||
if (!isValidColor(style.getPropertyValue('--primary-color').trim())) { | ||
root.style.setProperty('--primary-color', '#2c3e50'); | ||
root.style.setProperty('--secondary-color', '#3498db'); | ||
root.style.setProperty('--background-color', '#f8f9fa'); | ||
root.style.setProperty('--accent-color', '#f5f5f5'); | ||
} | ||
|
||
// Check both naming conventions | ||
setFallbackColors(''); | ||
setFallbackColors('color_theme_'); | ||
// Check and set fallback colors if needed | ||
if (!isValidColor(style.getPropertyValue('--color_theme_primary').trim())) { | ||
root.style.setProperty('--color_theme_primary', '#2c3e50'); | ||
root.style.setProperty('--color_theme_secondary', '#3498db'); | ||
root.style.setProperty('--color_theme_background', '#f8f9fa'); | ||
root.style.setProperty('--color_theme_accent', '#f5f5f5'); | ||
} | ||
}); |