project-ufa / jpicker

jPicker is a fast, lightweight color picker jQuery plugin.
0 stars 0 forks source link

jPicker.Color.val() method not working when the first parameter is null #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Attach a jPicker to some block element.
2. Create javascript code to manually set the active color of the picker, 
setting the first parameter to null and the second to an anonymous object with 
the desired color (e.g. "$.jPicker.List[0].color.active.val(null, {r: 56, g: 
112, b: 213 })").

What is the expected output? What do you see instead?
The color should change to the one specified by the anonymous object's 
properties, but nothing happens (see "additional information" section).

What version of the product are you using? On what operating system?
Using version 1.1.6 on Windows XP.

Please provide any additional information below.
This issue happens due to how the .val() method's code checks which properties 
were specified on the anonymous object. 

More specifically -- on jpicker-1.1.6.js, line 684:

    if (value.r !== undefined && !name.indexOf('r') == -1) name += 'r';

"!name.indexOf('r') == -1" will always return false, since "name" is an empty 
string, and the ! operator takes precedence over the == operator, which causes 
"!name.indexOf('r')" to be evaluated before being compared to "-1". Since the 
indexOf anything on an empty string is always -1, and "!-1" is false, "name += 
'r'" never gets executed (and the same is valid for the other properties, up to 
line 690), which leaves "name" empty.

With "name" being empty, the code that follows doesn't execute, and no colors 
are set.

Original issue reported on code.google.com by cobrabr on 26 Apr 2012 at 11:02

GoogleCodeExporter commented 9 years ago
To fix this issue, I simply removed the ! operator from before the 
"name.indexOf" call on my local copy of the .js file.

Original comment by cobrabr on 26 Apr 2012 at 11:07

GoogleCodeExporter commented 9 years ago
The picker is not not designed to accept NULL as a color type to set. Since the 
picker has to make decisions on what values to set based on the data you send 
it, e.g. setting both RGB and HSV would conflict with each other, this 
assignment of yours would require a setting type of "rgb" to properly assign 
those values.

I had originally considered accepting NULL, and merely use the JSON data 
supplied in the second parameter, but that conflict of RGB and HSV made me 
decide that I would require specificity in the assignment.

Original comment by christop...@gmail.com on 5 Nov 2012 at 5:35