Permalink
Browse files

handle transparent as a name, rather than an rgb

  • Loading branch information...
1 parent 270b537 commit 5574bbe3e5b8021508fea427a427125b7a818f1b @bgrins committed Apr 5, 2013
Showing with 10 additions and 1 deletion.
  1. +5 −0 test/test.js
  2. +5 −1 tinycolor.js
View
@@ -319,6 +319,11 @@ test("Invalid alpha should normalize to 1", function() {
equal(tinycolor("rgba 255 0 0 100").toRgbString(), "rgb(255, 0, 0)", "Greater than 1 in string parsing");
});
+test("Alpha = 0 should act differently on toName()", function() {
+ equal(tinycolor({r:255,g:20,b:10,a: 0}).toName(), "transparent", "0");
+ equal(tinycolor("transparent").toString(), "transparent", "toString when passed");
+ equal(tinycolor("transparent").toHex(), "000000", "toHex");
+});
module("Initialization from tinycolor output");
test("HSL Object", function() {
View
@@ -89,6 +89,10 @@ function tinycolor (color, opts) {
"rgba(" + mathRound(bound01(r, 255) * 100) + "%, " + mathRound(bound01(g, 255) * 100) + "%, " + mathRound(bound01(b, 255) * 100) + "%, " + roundA + ")";
},
toName: function() {
+ if (a === 0) {
+ return "transparent";
+ }
+
return hexNames[rgbToHex(r, g, b, true)] || false;
},
toFilter: function(secondColor) {
@@ -834,7 +838,7 @@ function stringInputToObject(color) {
named = true;
}
else if (color == 'transparent') {
- return { r: 0, g: 0, b: 0, a: 0 };
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
}
// Try to match string input using regular expressions.

0 comments on commit 5574bbe

Please sign in to comment.