From 8fea2d99b6dacd01c3a3a56a643ca24da044ca9c Mon Sep 17 00:00:00 2001 From: sculpt0r Date: Wed, 9 Dec 2020 07:29:32 +0100 Subject: [PATCH] Fix alpha range in rgb from hex --- core/tools/color.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/tools/color.js b/core/tools/color.js index e49cbd975c6..f574f4ae1b7 100644 --- a/core/tools/color.js +++ b/core/tools/color.js @@ -246,11 +246,20 @@ if ( colorCode.match( CKEDITOR.tools.color.hex6CharsRegExp ) || colorCode.match( CKEDITOR.tools.color.hex8CharsRegExp ) ) { var parts = colorCode.split( '' ); + var alpha = 1; + + if ( parts[ 7 ] && parts[ 8 ] ) { + alpha = hexToValue( parts[ 7 ] + parts[ 8 ] ); + + alpha = ( alpha / CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ); + alpha = alpha < 1 && alpha > 0 ? alpha.toFixed( 1 ) : alpha; + } + return [ hexToValue( parts[ 1 ] + parts[ 2 ] ), hexToValue( parts[ 3 ] + parts[ 4 ] ), hexToValue( parts[ 5 ] + parts [ 6 ] ), - parts[ 7 ] && parts[ 8 ] ? hexToValue( parts[ 7 ] + parts[ 8 ] ) : 1 + alpha ]; }