Skip to content

Commit

Permalink
Fix alpha range in rgb from hex
Browse files Browse the repository at this point in the history
  • Loading branch information
sculpt0r committed Dec 11, 2020
1 parent d581dd2 commit 8fea2d9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/tools/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}

Expand Down

0 comments on commit 8fea2d9

Please sign in to comment.