Skip to content
Browse files

Fix alpha value in rgb and hsl colors; was getting set to 0, should be 1

  • Loading branch information...
1 parent 535902a commit 0b100c1da14f8d0cea57d52dd6f7ec4757f19188 Jason Johnston committed Nov 24, 2011
Showing with 26 additions and 3 deletions.
  1. +2 −2 sources/Color.js
  2. +24 −1 tests/color-names.html
View
4 sources/Color.js
@@ -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() ) ) {
View
25 tests/color-names.html
@@ -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">
@@ -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;
@@ -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>')
}

0 comments on commit 0b100c1

Please sign in to comment.
Something went wrong with that request. Please try again.