Skip to content

Commit

Permalink
Create rt-html-css-fallback.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ledangtrung committed Dec 5, 2024
1 parent ebed852 commit 91bce26
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions js/rt-html-css-fallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Check if theme variables are valid color codes
document.addEventListener('DOMContentLoaded', () => {
const root = document.documentElement;
const style = getComputedStyle(root);

function isValidColor(color) {
const s = new Option().style;
s.color = color;
return s.color !== '';
}

// 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');
}
});

0 comments on commit 91bce26

Please sign in to comment.