kixe Posted September 8, 2018 Author Share Posted September 8, 2018 @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. 1 Link to comment Share on other sites More sharing options...
adrian Posted September 8, 2018 Share Posted September 8, 2018 Thanks @kixe One more request for you please. I am using this setup: $('#{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, 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? 1 Link to comment Share on other sites More sharing options...
adrian Posted September 8, 2018 Share Posted September 8, 2018 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? Link to comment Share on other sites More sharing options...
kixe Posted September 8, 2018 Author Share Posted September 8, 2018 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. 1 Link to comment Share on other sites More sharing options...
tpr Posted September 8, 2018 Share Posted September 8, 2018 Offtopic: if I will have some time I will add a similar feature to aos. The reason I haven't done this already is that never had the need for a color picker in the admin. This is the js I plan to use: https://github.com/narsenico/a-color-picker 3 Link to comment Share on other sites More sharing options...
slave Posted October 29, 2018 Share Posted October 29, 2018 I use these settings 'rgba(68, 100, 221, 0.98)' But the issue looks like this (render)rgba(234, 25, 25, 0,93)but I need it so rgba(234, 25, 25, 0.93) what am I doing wrong 1 Link to comment Share on other sites More sharing options...
kixe Posted January 12, 2019 Author Share Posted January 12, 2019 On 10/29/2018 at 4:28 PM, slave said: what am I doing wrong Nothing ? I fixed this. Update to 1.0.9 2 Link to comment Share on other sites More sharing options...
slave Posted January 12, 2019 Share Posted January 12, 2019 15 hours ago, kixe said: Nothing ? I fixed this. Update to 1.0.9 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) Blease update Link to comment Share on other sites More sharing options...
kixe Posted October 17, 2019 Author Share Posted October 17, 2019 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 More sharing options...
JFn Posted January 11, 2020 Share Posted January 11, 2020 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) 1 Link to comment Share on other sites More sharing options...
kixe Posted March 21, 2020 Author Share Posted March 21, 2020 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 1 Link to comment Share on other sites More sharing options...
Hurme Posted May 4, 2020 Share Posted May 4, 2020 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 More sharing options...
kixe Posted May 15, 2020 Author Share Posted May 15, 2020 @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: 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: Link to comment Share on other sites More sharing options...
kixe Posted May 15, 2020 Author Share Posted May 15, 2020 I have added Fieldtype Select Color Options to the package. Read more here: Link to comment Share on other sites More sharing options...
kixe Posted October 10, 2021 Author Share Posted October 10, 2021 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 4 Link to comment Share on other sites More sharing options...
gornycreative Posted May 5 Share Posted May 5 (edited) Hi, I'm using this in a module config and want to call the value up and pass it through to LESS within the module, but the default format doesn't comply with LESS formatting so - since I don't need alpha for my application is the best method to do as suggested above: $color_out = '#' . ltrim( $color_in, '#ff' ); Or is there a more elegant way to handle this? EDIT Okay obviously not that exactly but pulling the rightmost 6 chars and prefixing a #. Edited May 5 by gornycreative Duh Link to comment Share on other sites More sharing options...
kixe Posted May 6 Author Share Posted May 6 @gornycreative Go to Field settings > 'Details' tab and choose your preferred output formatting. Link to comment Share on other sites More sharing options...
gornycreative Posted May 7 Share Posted May 7 On 5/6/2023 at 3:42 AM, kixe said: @gornycreative Go to Field settings > 'Details' tab and choose your preferred output formatting. I'm using this as a module configuration inputfield in this case, not as a site facing Fieldtype. An admin theming module. So the LESS is being applied on the admin side. Link to comment Share on other sites More sharing options...
kixe Posted May 8 Author Share Posted May 8 $f = wire('modules')->get('InputfieldColor'); $f->inputType = 1; Simplest solution: Choose inputType 0 or 1. If you want to use the Spectrum color picker (inputType = 3). I added an option to explicitly disable the alpha channel. Please update to version 1.1.6 and disable the alpha channel: $f = wire('modules')->get('InputfieldColor'); $f->inputType = 3; // spectrum $f->alpha = false; If you want to use a custom JS input type (inputType = 4), the alpha channel is disabled by default. The following additional properties are provided to make it work with your custom color picker: initJS (initial JS) fileJS (custom JS file) fileCSS (custom CSS file) $f = wire('modules')->get('InputfieldColor'); $f->inputType = 4; // custom js and css $f->initJS = '$("{id}").initCustomJS({ color: "{value}" });'; // placeholders for value and id of HTML input element $f->fileJS = "/path/to/file.js"; $f->fileCSS = "/path/to/file.css"; 1 Link to comment Share on other sites More sharing options...
kixe Posted May 9 Author Share Posted May 9 On 5/5/2023 at 9:38 PM, gornycreative said: $color_out = '#' . ltrim( $color_in, '#ff' ); Or is there a more elegant way to handle this? BTW. Your solution will not work ... $color_in = "#ffff0000"; // red with alpha channel $color_out = '#' . ltrim( $color_in, '#ff'); var_dump($color_out); // "#0000" invalid color hex code $color_out = '#' . substr($color_in, 3); var_dump($color_out); // "#ff0000" your expected result Link to comment Share on other sites More sharing options...
gornycreative Posted May 11 Share Posted May 11 On 5/9/2023 at 2:30 AM, kixe said: BTW. Your solution will not work ... Yes I copied from elsewhere in this thread but realized after I posted that it wasn't an actual solution. On 5/5/2023 at 2:38 PM, gornycreative said: EDIT Okay obviously not that exactly but pulling the rightmost 6 chars and prefixing a #. I was under the impression the field always stored values in the db as a 32-bit hex regardless of the output method? Link to comment Share on other sites More sharing options...
kixe Posted May 11 Author Share Posted May 11 52 minutes ago, gornycreative said: I was under the impression the field always stored values in the db as a 32-bit hex regardless of the output method? FieldtypeColor always stores the value as 32-bit (int) in the database (page field). If we are talking about InputfieldColor, the transmitted value is either a 24- or 32-bit colour hexcode, which depends on the selected inputType as described above. I assume you want to use the input field as a configuration field for your module. In this case, the transmitted value of the input field is relevant. Module configuration data is always stored as a json encoded string in the database. 1 Link to comment Share on other sites More sharing options...
gornycreative Posted May 11 Share Posted May 11 2 hours ago, kixe said: FieldtypeColor always stores the value as 32-bit (int) in the database (page field). If we are talking about InputfieldColor, the transmitted value is either a 24- or 32-bit colour hexcode, which depends on the selected inputType as described above. I assume you want to use the input field as a configuration field for your module. In this case, the transmitted value of the input field is relevant. Module configuration data is always stored as a json encoded string in the database. Yes, the input value with or without alpha is important in different contexts, but when I am trying to read the value from the fieldtype I can't directly pass the value to the wikimedia LESS parser as it isn't caught up to the JS version and so if I send a raw 32bit integer to get included in the admin.less process it throws and error as an unacceptable format. The strPos( $color, 3) solution works fine - I add a # and the LESS parser is happy. I didn't know if any of the output formatting methods from the fieldtype were exposed on the admin side. Not a big deal either way. For my purposes I've got it working. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now