Skip to content

Commit

Permalink
Fix color helpers plugin to return black rather than dieing when
Browse files Browse the repository at this point in the history
somebody tries to parse "" or another unknown color


git-svn-id: https://flot.googlecode.com/svn/trunk@321 1e0a6537-2640-0410-bfb7-f154510ff394
  • Loading branch information
[email protected] committed Mar 17, 2011
1 parent a095971 commit 7e33c7b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions jquery.colorhelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Plugin for jQuery for working with colors.
*
* Version 1.0.
* Version 1.1.
*
* Inspiration from jQuery color animation plugin by John Resig.
*
Expand All @@ -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($) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
}
}
Expand Down

0 comments on commit 7e33c7b

Please sign in to comment.