Swatches order not respected in chrome #75

pablograna opened this Issue Feb 19, 2014 · 3 comments

2 participants


The swatches is a map of color name to color definition. Each color is pulled from the map with jquery.each. That operation does not guarantee the iteration order. IFAIK, this is today only a problem in chrome and opera (I only tested it in chrome).

I guess it would be better to implement the swatches as a list instead of an object.


Using Chrome myself, and never noticed a problem with it.
I always thought the problem was mostly theoretical; the standard doesn't guarentee an order, but all JS engines kept the same order anyway.
It shouldn't be hard (although it will be quite tedious) to convert the map to an array of maps [ {name:..., r:..., g:..., b:...}, {...}, ...], which should have guarenteed order.
Preferably a solution would handle the current format too, for backwards compatibility.

@vanderlee vanderlee closed this Feb 19, 2014
@vanderlee vanderlee reopened this Feb 19, 2014

Here is an example that is failing in chrome (Version 28.0.1500.71 Ubuntu 12.04 (28.0.1500.71-0ubuntu1.12.04.1). In my case, the black is shown at the end of the list. As a workaround, I prepended to the color name, the order starting from 1.

jQuery.colorpicker.swatches.palette = {
'000000': {r: 0, g: 0, b: 0},
'444444': {r: 0.266666666666667, g: 0.266666666666667, b:
'666666': {r: 0.4, g: 0.4, b: 0.4},
'999999': {r: 0.6, g: 0.6, b: 0.6},


I hacked something that looks like it works, but I don't know if it is ok with you. I added an operation to the plugin _eachSwatch that takes care of the difference of each element of the array/object. Then I replaced:

  • $.each(swatches, function(swatchName, current) {


  • this._eachSwatch(function(swatchName, current) {

every time the plugin iterates over the swatches. I also had to remove an optimization that assumes that the swatches is an object instead of array (in _getSwatch).

Let me know if you agree with this, or have another idea. I'll send a pull request in the next days (or maybe hours...).

@pablograna pablograna pushed a commit that referenced this issue Feb 20, 2014
Pablo Gra\~na Fix for #75: support array of swatches.
Specify swatches as an array of {name: '000000', r: 0, g: 0, b: 0}.
@vanderlee vanderlee closed this Feb 20, 2014
@vanderlee vanderlee pushed a commit that referenced this issue Feb 20, 2014
Martijn van der Lee Modified swatch lists to match @timgluz's fix for #75. a11c14b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment