[dev] Fix: Colorpicker javascript error
Cariad Ilmàra
cariad at adnx.net
Thu Aug 14 02:11:44 PDT 2003
Hello,
> not having an IE to check where it was failing, do you mind talking me
> through the couple of changes?
Sure. I don't use IE myself; but some people I provide Horde setup for have
reported me this problem (and javascript errors really stand out)...
The problem occurs with the bottom and right edge of the colorpicker. getColor()
might send negative or >255 values of r, g or b to makeColor(). Gecko (Mozilla,
Netscape, Firebird, ...) silently discard this error (No update is made on
demoColor()), but IE moans about anything and everything (I don't know what the
best current pratice is for Javascript interpreter...)
My patch (I'm afraid it's more a hack than a mathematically correct fix) makes
sure no off-limit values are reached by getColor()
> > - bmax = 255 - (y / 32.0) * 255;
> > + bmax = 255 - (y / 32.0) * 160;
To avoid negative values (bottom edge only)
> > - var r = Math.floor(rmax + (x / 50.0) * (255 - rmax));
> > - var g = Math.floor(gmax + (x / 50.0) * (255 - gmax));
> > - var b = Math.floor(bmax + (x / 50.0) * (255 - bmax));
> > + var r = Math.floor(rmax + (x / 50.0) * (250 - rmax));
> > + var g = Math.floor(gmax + (x / 50.0) * (250 - gmax));
> > + var b = Math.floor(bmax + (x / 50.0) * (250 - bmax));
With 255, when pointing to the right edge, you get >255 values for r, g or b
(determined by the value of y). 250 ensure no value exceed 255. After some more
tests; it seems the values I changed aren't right (you might still have r, g or
b >255 at the very very right end of the picture). I've changed the patch (see
below)
This might also be a problem with other browsers; because the value stored might
be wrong. Try to pick a color at the bottom and right edge of the colorpicker,
and check the value in the parent form. Here's what I get
Bottom edge : #FF14-3-7
Right edge : #16E1162FF
Here's the update patch :
=======================
--- colorpicker.php 2003-08-11 23:09:23.000000000 +0200
+++ colorpicker.php 2003-08-11 23:09:14.000000000 +0200
@@ -87,20 +87,19 @@
y = y - 160;
rmax = 255;
gmax = 0;
- bmax = 255 - (y / 32.0) * 255;
+ bmax = 255 - (y / 32.0) * 160;
}
if (x <= 50) {
var r = Math.floor(rmax * x / 50.0);
var g = Math.floor(gmax * x / 50.0);
var b = Math.floor(bmax * x / 50.0);
-
return makeColor(r,g,b);
} else {
x = x - 50;
- var r = Math.floor(rmax + (x / 50.0) * (255 - rmax));
- var g = Math.floor(gmax + (x / 50.0) * (255 - gmax));
- var b = Math.floor(bmax + (x / 50.0) * (255 - bmax));
+ var r = Math.floor(rmax + (x / 50.0) * (241 - rmax));
+ var g = Math.floor(gmax + (x / 50.0) * (241 - gmax));
+ var b = Math.floor(bmax + (x / 50.0) * (241 - bmax));
return makeColor(r,g,b);
}
}
--
Cariad Ilmàra
http://cariad.adnx.net/
More information about the dev
mailing list