Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit 9b76a69

Browse files
committed
feat: appearance changed on colors JS related file added
1 parent df2183e commit 9b76a69

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Drupal.behaviors.displayColorDefinitions = {
2+
attach() {
3+
/**
4+
*
5+
* @param x
6+
*/
7+
function hex(x) {
8+
return `0${parseInt(x, 10).toString(16)}`.slice(-2);
9+
}
10+
11+
/**
12+
*
13+
* @param color
14+
*/
15+
function rgb2hex(color) {
16+
const rgb = color.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
17+
return `#${hex(rgb[1])}${hex(rgb[2])}${hex(rgb[3])}`;
18+
}
19+
20+
const swatches = document.querySelectorAll('.cl-colors__item');
21+
if (swatches) {
22+
swatches.forEach((swatch) => {
23+
const color = window
24+
.getComputedStyle(swatch.querySelector('.cl-colors__swatch'), null)
25+
.getPropertyValue('background-color');
26+
27+
const definition = swatch.querySelector('.cl-colors__definition');
28+
console.log(swatch);
29+
definition.textContent = rgb2hex(color);
30+
});
31+
}
32+
},
33+
};

0 commit comments

Comments
 (0)