Skip to content

Commit

Permalink
Fix alpha value in rgb and hsl colors; was getting set to 0, should be 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Johnston committed Nov 25, 2011
1 parent 535902a commit 0b100c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sources/Color.js
Expand Up @@ -119,13 +119,13 @@ PIE.Color = (function() {
// RGB or RGBA colors
if( m = color.match( Color.rgbOrRgbaRE ) ) {
color = me.rgbToHex( +m[1], +m[2], +m[3] );
alpha = ( 5 in m ) ? +m[5] : 1;
alpha = m[5] ? +m[5] : 1;
}
// HSL or HSLA colors
else if( m = color.match( Color.hslOrHslaRE ) ) {
rgb = hsl2rgb( m[1], m[2], m[3] );
color = me.rgbToHex( rgb.r, rgb.g, rgb.b );
alpha = ( 5 in m ) ? +m[5] : 1;
alpha = m[5] ? +m[5] : 1;
}
else {
if( Color.names.hasOwnProperty( vLower = color.toLowerCase() ) ) {
Expand Down
25 changes: 24 additions & 1 deletion tests/color-names.html
Expand Up @@ -4,7 +4,8 @@
<head>
<title>Tests for background gradients</title>

<script type="text/javascript" src="../build/PIE_uncompressed.js"></script>
<!--[if IE 9]><script src="../build/PIE_IE9_uncompressed.js"></script><![endif]-->
<!--[if lt IE 9]><script src="../build/PIE_IE678_uncompressed.js"></script><![endif]-->

<style type="text/css">

Expand Down Expand Up @@ -56,6 +57,21 @@
'currentColor': '#FF0000',
'transparent': '#000000'
},
alphaTests = {
'aqua': 1,
'beige': 1,
'#123456': 1,
'#123': 1,
'rgb(0, 0, 255)': 1,
'rgba(0, 0, 255, 0.5)': 0.5,
'rgba(0, 0, 255, .5)': 0.5,
'hsl(0, 100%, 50%)': 1,
'hsla(0, 100%, 50%, 0.5)': 0.5,
'hsla(0, 100%, 50%, .5)': 0.5,
'currentColor': 1,
'transparent': 0
},

currentColorTester = document.getElementById('currentColorTester'),
failed = false,
c, val;
Expand All @@ -73,6 +89,13 @@
failed = true;
}
}
for (c in alphaTests) {
val = PIE.getColor( c ).alpha();
if ( val !== alphaTests[ c ] ) {
document.write('<p style="color:red">PIE.Color#alpha() failed for "' + c + '": got "' + val + '", expected "' + alphaTests[c] + '"</p>')
failed = true;
}
}
if (!failed) {
document.write('<p style="color:#090">Color parsing tests all passed</p>')
}
Expand Down

0 comments on commit 0b100c1

Please sign in to comment.