Skip to content

Commit 0a27080

Browse files
committed
[css-color-4] Add a script that verifies swatches can actually render.
1 parent 9603095 commit 0a27080

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

css-color-4/Overview.bs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ table.deltaE td.dE4 { background: rgb(243, 202, 68)}
7474
table.deltaE td.dE5 { background: rgb(243, 103, 68); color: white}
7575
</style>
7676

77+
<script>
78+
document.addEventListener("DOMContentLoaded", ()=>{
79+
const testEl = document.createElement("div");
80+
document.body.appendChild(testEl);
81+
[...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
91+
}
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.");
95+
});
96+
document.body.removeChild(testEl);
97+
});
98+
</script>
99+
77100
<h2 id="introduction">
78101
Introduction</h2>
79102

0 commit comments

Comments
 (0)