Jump to content

FieldtypeColor


kixe
 Share

Recommended Posts

@adrian Thanks for pointing on this. I added a fallback to the standard dechex() function for 64-bit systems.

In the rare case that neither the BCMath extension is installed nor the system can handle 64-bit integers, the module is not installable.

  • Like 1
Link to comment
Share on other sites

Thanks @kixe

One more request for you please.

I am using this setup:

image.png.a4fa403e7f33b8fa2e5543a4fd1d6ab3.png

$('#{id}').on('keyup', function() {
       $(this).css({'background-color' : $(this).val()});
       $(this).css({'color' : ($(this).val().replace('#','0x')) > (0xffffff/2) ? '#333' : '#fff'});
});

so that the input background changed dynamically as the hex code changes,

ESRXOQoY8z.gif.23b0188b6054738aad30649379515c58.gif

but I also want the background to be colored onload so I changed case 4 to this:

            case 4:
                $this->attr('style', "color: $textColor; background: $bgColor;");
                if ($this->alpha) $this->attr('value', $color32);
                else $this->attr('value', $color24);
                break;

I guess I could probably modify the JS code to do the onload as well, but I was wondering if you thought such a setup would be a worthwhile core option?

  • Thanks 1
Link to comment
Share on other sites

Another nice option might be to extend spectrum to do this. I just did this via browser dev tools, but I expect it could be done with JS quite easily if we has the option to inject JS when using the Inputfield with Spectrum Color Picker (JavaScript) option.

I really like being able to see the hex code without having to open the picker.

What do you think?

image.png.a529d237c984b5954c378bc30c398876.png

image.png.fe1a1b9dc83c09207725a5ec0d78c1bb.png

Link to comment
Share on other sites

2 hours ago, adrian said:

What do you think?

As you know I tested the module with several different javascript based color pickers via the included custom script option. I will leave this as is. Use and modify the picker you like.

Another thing is the dynamically change of the input and background color in the Textfield. This is pretty good and if I find time I will implement this.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...
  • 9 months later...
On 1/12/2019 at 5:42 PM, slave said:

I have a new problem Mr.
rgba(0, 56, 119, 1.)
but I need it so
rgba(0, 56, 119, 1) or rgba(0, 56, 119, 1.0)

Everything fixed. Current module version 1.1.3

Link to comment
Share on other sites

  • 2 months later...

I ran into a specific multilanguage problem.
When setting the default language C parameter of LanguageSupport to nl_NL.UTF-8 (or nl_BE.UTF-8),
then the Color module hsl return value has a comma as decimal separator, which is not a valid CSS value (or a valid hsl value for that matter).

Example with dutch locale: hsl(195, 96,2%, 59%);
Should always be: hsl(195, 96.2%, 59%); no matter the chosen locale.

(note: the comma is the expected/normal decimal separator in dutch, so it's not a LanguageSupport mistake)

  • Like 1
Link to comment
Share on other sites

  • 2 months later...
On 1/11/2020 at 3:00 PM, JFn said:

Example with dutch locale: hsl(195, 96,2%, 59%);
Should always be: hsl(195, 96.2%, 59%); no matter the chosen locale.

This bug is fixed now. Current module version 1.1.4

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I'm running into an error using the 1.1.4. version.

In field input settings:
Inputfield type = "text" and value type = 8 digits.

In actual page where I'm using this:
If I try to use #ff000000 I get HTML 5 field error stating "Please match the format requested" and saving the page fails.
If I try to use #000000 I get "InputfieldColor: Does not match required pattern: /#?[a-fA-F\d]{8}/"

So something is stopping me from using it with alphavalues. If I go back to using 6 digit hex value it works fine.

EDIT: It would be awesome if I could use RGBA(0,0,0,0) as input value as well. Using the hex value I'll have to google the value each time instead of just typing it out. Another great thing would be, if I could choose "empty" as default value. The forced #000000 may not print anything, but looks very confusing because it looks like someone has typed a value in the field.

Link to comment
Share on other sites

  • 2 weeks later...

@Hurme

On 5/4/2020 at 1:10 PM, Hurme said:

If I try to use #ff000000 I get HTML 5 field error stating "Please match the format requested" and saving the page fails.
If I try to use #000000 I get "InputfieldColor: Does not match required pattern: /#?[a-fA-F\d]{8}/"

This looks like you have choosen the wrong input type:

217156930_Bildschirmfoto2020-05-15um14_14_58.png.08825458e74dd386e1570a08ab5c6174.png

On 5/4/2020 at 1:10 PM, Hurme said:

EDIT: It would be awesome if I could use RGBA(0,0,0,0) as input value as well.

For your needs please use SpectrumColorPicker as Input and add the following code

showAlpha: true, showInput: true 

in the color picker options field. This setup will provide something like:

1579478737_Bildschirmfoto2020-05-15um13_07_40.png.2cce0d91017e7462df0a598a77be9b06.png

 

Link to comment
Share on other sites

  • 1 year later...

Added some useful functions to FieldtypeColor class:
 

/**
 * Find the "naive" difference between two colors.
 * @param int[] $color_a Three-element array with R,G,B color values 0-255.
 * @param int[] $color_b Three-element array with R,G,B color values 0-255.
 * @return int
 */
public function getColorDistance(array $color_a, array $color_b)

/**
 * Find the difference between two colors' luminance values.
 * @param int[] $color_a Three-element array with R,G,B color values 0-255.
 * @param int[] $color_b Three-element array with R,G,B color values 0-255.
 * @return int
 */
public function getLuminanceDistance(array $color_a, array $color_b)

/**
 * Find the closest named color
 * @param hexcolor 6 or 8 digits, with or without leading '#'
 * @return string
 */
public function getClosestColorName(string $color)

Usage example:

$fc = $modules->get('FieldtypeColor');
$colorname = $fc->getClosestColorName('#01fb99');
var_dump($colorname); // string(17) "MediumSpringGreen" 

 

I needed this for the COLOR property in .ics file type. According to the specifications, the value must be a valid CSS3 color name.
https://icalendar.org/New-Properties-for-iCalendar-RFC-7986/5-9-color-property.html

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...