Permalink
Browse files

Use parseFloat for hsla arguments, which usually use the % character

  • Loading branch information...
1 parent c2032d0 commit e2f07dcc9d36bd0dcead41c3ed6609c00b7f88bc @arian arian committed Aug 9, 2012
Showing with 5 additions and 4 deletions.
  1. +4 −4 lib/color.js
  2. +1 −0 test/test.parsers.js
View
@@ -67,10 +67,10 @@ var HUEtoRGB = function(p, q, t){
var HSLtoRGB = function(h, s, l, a){
var r, b, g
if (a == null || a === "") a = 1
- h /= 360
- s /= 100
- l /= 100
- a /= 1
+ h = parseFloat(h) / 360
+ s = parseFloat(s) / 100
+ l = parseFloat(l) / 100
+ a = parseFloat(a) / 1
if (h > 1 || h < 0 || s > 1 || s < 0 || l > 1 || l < 0 || a > 1 || a < 0) return null
if (s === 0){
r = b = g = l
View
@@ -75,6 +75,7 @@ describe('CSS Parsers', function (){
expect(moofx.parse('color', "rgb(0,0,0)")).to.be("rgb(0,0,0)")
expect(moofx.parse('color', "#ff330099")).to.be("rgba(255,51,0,0.6)")
expect(moofx.parse('color', "#f309")).to.be("rgba(255,51,0,0.6)")
+ expect(moofx.parse('color', "hsla(0,0%,100%,0.3)")).to.be("rgba(255,255,255,0.3)")
// normalized
expect(moofx.parse('color', "", true)).to.be("rgba(0,0,0,1)")

0 comments on commit e2f07dc

Please sign in to comment.