Skip to content

Commit 9ba7189

Browse files
committed
[css-color-4][meta] Per Lea's suggestion, use CSS.supports() rather than WPT-ish hacks.
1 parent acd5bca commit 9ba7189

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

css-color-4/Overview.bs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,13 @@ table.deltaE td.dE5 { background: rgb(243, 103, 68); color: white}
7676

7777
<script>
7878
document.addEventListener("DOMContentLoaded", ()=>{
79-
const testEl = document.createElement("div");
80-
document.body.appendChild(testEl);
8179
[...document.querySelectorAll(".swatch")].forEach(e=>{
82-
/* test that the swatch color is recognized */
83-
const testColor = getComputedStyle(e).getPropertyValue("--color");
84-
testEl.style.color = "#010203";
85-
const controlColor = getComputedStyle(testEl).color;
86-
testEl.style.color = testColor;
87-
const resultColor = getComputedStyle(testEl).color;
88-
if(resultColor != controlColor) {
89-
/* success! */
90-
return
80+
const swatchColor = getComputedStyle(e).getPropertyValue("--color");
81+
if(!CSS.supports('color', swatchColor)) {
82+
e.style.background = "repeating-linear-gradient(135deg, red 0, red 4px, white 4px, white 8px)";
83+
e.setAttribute("title", "Your browser does not recognize this color value, so we can't preview it.");
9184
}
92-
/* otherwise, indicate it's a failure */
93-
e.style.background = "repeating-linear-gradient(135deg, red 0, red 4px, white 4px, white 8px)";
94-
e.setAttribute("title", "Your browser does not recognize this color value, so we can't preview it.");
9585
});
96-
document.body.removeChild(testEl);
9786
});
9887
</script>
9988

0 commit comments

Comments
 (0)