File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Block/Adminhtml/System/Config/Form/Field Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,35 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
12
12
$(document).ready(function () {
13
13
var $el = $("# ' . $ element ->getHtmlId () . '");
14
14
$el.css("backgroundColor", " ' . $ value .'");
15
+ $el.css("color", getContrastColor(" ' . $ value .'"));
15
16
16
17
// Attach the color picker
17
18
$el.ColorPicker({
18
19
color: " ' . $ value .'",
19
20
onChange: function (hsb, hex, rgb) {
20
21
$el.css("backgroundColor", "#" + hex).val("#" + hex);
22
+ $el.css("color", getContrastColor(hex));
21
23
}
22
24
});
25
+
26
+ function getContrastColor(hexcolor) {
27
+ var rgb = hexToRgb(hexcolor);
28
+ if (rgb) {
29
+ var o = Math.round(((parseInt(rgb.r) * 299) + (parseInt(rgb.g) * 587) + (parseInt(rgb.b) * 114)) / 1000);
30
+ return (o >= 125) ? "black" : "white";
31
+ } else {
32
+ return "black";
33
+ }
34
+ }
35
+
36
+ function hexToRgb(hex) {
37
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
38
+ return result ? {
39
+ r: parseInt(result[1], 16),
40
+ g: parseInt(result[2], 16),
41
+ b: parseInt(result[3], 16)
42
+ } : null;
43
+ }
23
44
});
24
45
});
25
46
</script> ' ;
You can’t perform that action at this time.
0 commit comments