Pending

User tests: Successful: Unsuccessful:

avatar ghost
ghost
15 Mar 2013

Tracker item: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=30297

Changed MooTools based color picker (MooRainbow) to a jQuery/Bootstrap based colorpicker (MiniColors).
You can see an example on http://labs.abeautifulsite.net/jquery-miniColors

Advantages

There are some big advantages to this MiniColors script over the MooRainbow script:

  • It is jQuery/Bootstrap based, instead of MooTools based. (And we need to get rid of the MooTools based stuff like this in Joomla 3 core.)
  • It doesn't look crappy! The MooRainbow color picker has serious styling issues in Joomla 3.
  • It allows for empty values. The current color picker doesn't allow an empty default value and reverts to #000000 if you try. MiniColors does allow empty values and does a good job of styling when the value is empty.

Control types

MiniColors comes with 4 types of controls: hue (default), saturation, brightness or wheel.
You can select these via the control attribute in the xml tag, like control="wheel".

Test instructions:

Add these fields to the settings part of an xml file of some extension, like a module. Then go to that extensions settings in the admin and test the different color fields.

<field name="color1" type="color" default="#049cdb" label="Default color field" />
<field name="color2" type="color" default="" label="Empty color field" />
<field name="color3" type="color" default="#46a546" disabled="true" label="Disabled color field" />
<field name="color4" type="color" default="#ffc40d" control="hue" label="Control: Hue (default)" />
<field name="color5" type="color" default="#9d261d" control="saturation" label="Control: Saturation" />
<field name="color6" type="color" default="#f89406" control="brightness" label="Control: Brightness" />
<field name="color7" type="color" default="#7a43b6" control="wheel" label="Control: Wheel" />

Backwards compatibility

All fields that use the color type should work fine with this new script.

The MooRainbow js and css files have been removed from the /media/system folder. So if any 3rd party extensions include these these directly into their code (which they shouldn't anyway), then they would need to change their code.

Custom Changes

I implemented the script to use the 'bootstrap' theme that comes with MiniColors.

But I changed a bit of css to make it fit in more with the Joomla 3 Bootstrap styling (prostar). I removed some redundant Bootstrap css, as the admin template already styles the input fields itself. And changed the font of the input field to mono-spaced (looks better for the type of value it contains).

So the css file is not a carbon copy of the stylesheet that comes with MiniColors. This may be important when updating the script/css at a later date.

Copyright / License

jQuery MiniColors: A tiny color picker built on jQuery
 Copyright Cory LaViska for A Beautiful Site, LLC. (http://www.abeautifulsite.net/)
 Dual-licensed under the MIT and GPL Version 2 licenses

Screenshot:

minicolors

Simple Color Picker

There is a 5th control type you can choose: simple
This will trigger a different script and a different type of color select field and picker.
simplecolors-1

This color picker type can be used for fields where you want to limit the color choices.

You can overrule the standard available colors by adding the colors attribute to the xml field tag, with a comma separated list of rgb colors. The empty color value can be called on by the value 'none'

Simple Color Picker: Test instructions

Add these fields to the settings part of an xml file of some extension, like a module. Then go to that extensions settings in the admin and test the different color fields.

<field name="color8" type="color" default="#049cdb" control="simple" label="Control: Simple" />
<field name="color9" type="color" default="none" control="simple" label="Simple: Empty" />
<field name="color10" type="color" default="none" control="simple" label="Simple: Custom Color List"
    colors="none,#FFFFFF,#000000,#FF0000,#00FF00,#0000FF,#00FFFF,#FF00FF,#FFFF00" />

Simple Color Picker: Copyright / License

I have based the script for the simple control type on: https://github.com/tkrotoff/jquery-simplecolorpicker

Very simple jQuery Color Picker
Copyright (C) 2012 Tanguy Krotoff
Licensed under the MIT license

However, I changed a lot of stuff in the functionality and styling. Not sure if I have changed enough to call it a fully custom script...

avatar nonumber nonumber - open - 15 Mar 2013
avatar claviska
claviska - comment - 16 Mar 2013

This looks great. I'm attaching myself to this to follow the thread. I'd love to see it make it's way into Joomla's core. Please let me know if you find any issues with the plugin so we can get them resolved quickly.

avatar nonumber
nonumber - comment - 16 Mar 2013

Thanks! We'll let you know if we run into things. Your script - if it gets into Joomla 3 - will get hundred thousands (or even millions) of users. ;)

For others: claviska is the author of the jQuery MiniColors script.

avatar nicksavov
nicksavov - comment - 16 Mar 2013
avatar Gerlof
Gerlof - comment - 16 Mar 2013

@Peter Already seen this comment on joomlacode.org?

Ingezonden door: Ben Tasker
Toevoegen datum: 2013-03-16 06:07:15
Unable to apply patch because diff lacks full index line for
jquery.minicolors.png, probably needs generating with --full-index

avatar nonumber
nonumber - comment - 16 Mar 2013

I added a 5th control type: simple
Which used a different script. See the last section in the markup.

avatar nonumber
nonumber - comment - 22 Mar 2013

Or would it be better to have the color picker panels show on the right/center, instead of below the field...?

colorpicker-right

avatar nonumber
nonumber - comment - 22 Mar 2013

Ok, changed position of the color picker panels to the right :)

avatar piotr-cz
piotr-cz - comment - 26 Mar 2013

@nonumber: what if you'd add option position to JFormFieldColor that would change plugins setting position and/or swatchPosition.

We would not have to worry about altering the code when updating plugin in future

avatar nonumber
nonumber - comment - 26 Mar 2013

Added ability to define color picker panel position by using position="" in xml (right/left/top/bottom).
In html a data-position="..." is added to the form element.

You can test with:

<field name="color11" type="color" default="" position="right" label="Right" />
<field name="color12" type="color" default="" position="left" label="Left" />
<field name="color13" type="color" default="" position="top" label="Top" />
<field name="color14" type="color" default="" position="bottom" label="Bottom" />

<field name="color21" type="color" default="" control="simple" position="right" label="Simple: Right" />
<field name="color22" type="color" default="" control="simple" position="left" label="Simple: Left" />
<field name="color23" type="color" default="" control="simple" position="top" label="Simple: Top" />
<field name="color24" type="color" default="" control="simple" position="bottom" label="Simple: Bottom" />

Add a Comment

Login with GitHub to post a comment