Commit 7e33c7ba authored by olau@iola.dk's avatar olau@iola.dk

Fix color helpers plugin to return black rather than dieing when

somebody tries to parse "" or another unknown color


git-svn-id: https://flot.googlecode.com/svn/trunk@321 1e0a6537-2640-0410-bfb7-f154510ff394
parent a095971b
/* Plugin for jQuery for working with colors.
*
* Version 1.0.
* Version 1.1.
*
* Inspiration from jQuery color animation plugin by John Resig.
*
......@@ -13,8 +13,11 @@
* console.log(c.r, c.g, c.b, c.a);
* $.color.make(100, 50, 25, 0.4).toString() // returns "rgba(100,50,25,0.4)"
*
* Note that .scale() and .add() work in-place instead of returning
* new objects.
* Note that .scale() and .add() return the same modified object
* instead of making a new one.
*
* V. 1.1: Fix error handling so e.g. parsing an empty string does
* produce a color rather than just crashing.
*/
(function($) {
......@@ -88,7 +91,8 @@
}
// parse CSS color string (like "rgb(10, 32, 43)" or "#fff"),
// returns color object
// returns color object, if parsing failed, you get black (0, 0,
// 0) out
$.color.parse = function (str) {
var res, m = $.color.make;
......@@ -121,7 +125,8 @@
if (name == "transparent")
return m(255, 255, 255, 0);
else {
res = lookupColors[name];
// default to black
res = lookupColors[name] || [0, 0, 0];
return m(res[0], res[1], res[2]);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment