Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
Use parseFloat for hsla arguments, which usually use the % character
Browse files Browse the repository at this point in the history
  • Loading branch information
arian committed Aug 9, 2012
1 parent c2032d0 commit e2f07dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/color.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ var HUEtoRGB = function(p, q, t){
var HSLtoRGB = function(h, s, l, a){ var HSLtoRGB = function(h, s, l, a){
var r, b, g var r, b, g
if (a == null || a === "") a = 1 if (a == null || a === "") a = 1
h /= 360 h = parseFloat(h) / 360
s /= 100 s = parseFloat(s) / 100
l /= 100 l = parseFloat(l) / 100
a /= 1 a = parseFloat(a) / 1
if (h > 1 || h < 0 || s > 1 || s < 0 || l > 1 || l < 0 || a > 1 || a < 0) return null if (h > 1 || h < 0 || s > 1 || s < 0 || l > 1 || l < 0 || a > 1 || a < 0) return null
if (s === 0){ if (s === 0){
r = b = g = l r = b = g = l
Expand Down
1 change: 1 addition & 0 deletions test/test.parsers.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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', "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', "#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', "#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 // normalized
expect(moofx.parse('color', "", true)).to.be("rgba(0,0,0,1)") expect(moofx.parse('color', "", true)).to.be("rgba(0,0,0,1)")
Expand Down

0 comments on commit e2f07dc

Please sign in to comment.