Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/ColorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function hexIsBlack(string $color)

public static function isValidHex($color)
{
return preg_match('/^#[0-9a-f]{3}(?:[0-9a-f]{3})?$/i', $color) ? true : false;
return preg_match('/^#?[0-9a-f]{3}(?:[0-9a-f]{3})?$/i', $color) ? true : false;
}

public static function hexToRgba($color, $opacity = false, $asArray = false)
Expand Down
14 changes: 12 additions & 2 deletions src/templates/_fields/colorit/input.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
handle == paletteColor.handle ? 'colorit--palette-colorIsSelected' : null,
]|filter|join(' ') %}

{% set processedColor = field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(paletteColor.color, opacity) : paletteColor.color %}
{% set color = paletteColor.color %}
{% if not (color starts with '#' or color starts with 'rgb') %}
{% set color = '#' ~ color %}
{% endif %}

{% set processedColor = field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(paletteColor.color, opacity) : color %}

<li class="{{ class }}" title="{{ paletteColor.label }}" data-handle="{{ paletteColor.handle }}" data-color="{{ paletteColor.color }}" style="background:{{ processedColor }};" data-colorit-palette-color>
</li>
Expand All @@ -42,7 +47,12 @@

{% if field.allowCustomColor %}

{% set processedColor = custom and field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(custom, opacity) : custom %}
{% set color = custom %}
{% if not (color starts with '#' or color starts with 'rgb') %}
{% set color = '#' ~ color %}
{% endif %}

{% set processedColor = custom and field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(custom, opacity) : color %}

<div class="colorit--palette-customColor{{ processedColor ? ' colorit--palette-colorIsSelected' }}" data-colorit-palette-custom>
{{ forms.text({
Expand Down
14 changes: 12 additions & 2 deletions src/templates/_fields/colorit/preview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
craft.colorit.colors.hexIsTransparent(paletteColor.color) ? 'colorit--palette-colorIsTransparent' : null,
]|filter|join(' ') %}

{% set processedColor = field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(paletteColor.color, opacity) : paletteColor.color %}
{% set color = paletteColor.color %}
{% if not (color starts with '#' or color starts with 'rgb') %}
{% set color = '#' ~ color %}
{% endif %}

{% set processedColor = field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(paletteColor.color, opacity) : color %}

<li class="{{ class }}" title="{{ paletteColor.label }}" style="background:{{ processedColor }};"></li>

Expand All @@ -34,7 +39,12 @@

{% if field.allowCustomColor %}

{% set processedColor = custom and field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(custom, opacity) : custom %}
{% set color = custom %}
{% if not (color starts with '#' or color starts with 'rgb') %}
{% set color = '#' ~ color %}
{% endif %}

{% set processedColor = custom and field.allowOpacity and opacity < 100 ? craft.colorit.colors.hexToRgba(custom, opacity) : color %}

<div class="colorit--palette-customColor{{ processedColor ? ' colorit--palette-colorIsSelected' }}">
<input class="text" type="text" value="{{ custom }}" placeholder="#D65B4B" novalidate disabled/>
Expand Down