Skip to content

Commit 0fbc05e

Browse files
authored
Core: Don't reset alpha to 1 if all red, green, blue & alpha provided
Before this commit the following code: jQuery.Color( { red: 10, green: 20, blue: 30, alpha: 0.4 } ) was incorrectly creating a Color object with the alpha property set to 1. Fixes #58 Closes #121
1 parent b64cf11 commit 0fbc05e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

jquery.color.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ color.fn = jQuery.extend( color.prototype, {
297297
if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
298298

299299
// use the default of 1
300-
inst[ cache ][ 3 ] = 1;
300+
if ( inst[ cache ][ 3 ] == null ) {
301+
inst[ cache ][ 3 ] = 1;
302+
}
303+
301304
if ( space.from ) {
302305
inst._rgba = space.from( inst[ cache ] );
303306
}

test/unit/color.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ QUnit.test( "jQuery.Color( 255, 255, 255 )", function( assert ) {
3636
}, assert );
3737
} );
3838

39+
40+
QUnit.test( "jQuery.Color({ red: 10, green: 20, blue: 30, alpha: 0.4 })", function( assert ) {
41+
var blue = jQuery.Color( { red: 10, green: 20, blue: 30, alpha: 0.4 } );
42+
testParts( blue, {
43+
red: 10,
44+
green: 20,
45+
blue: 30,
46+
alpha: 0.4
47+
}, assert );
48+
assert.ok( !blue._hsla, "No HSLA cache" );
49+
} );
50+
3951
QUnit.test( "jQuery.Color( element, \"color\" )", function( assert ) {
4052
var $div = jQuery( "<div>" ).css( "color", "#fff" );
4153
assert.expect( 8 );
@@ -85,6 +97,17 @@ QUnit.test( "jQuery.Color({ alpha: 1 })", function( assert ) {
8597
assert.ok( !blue._hsla, "No HSLA cache" );
8698
} );
8799

100+
QUnit.test( "jQuery.Color({ alpha: 0.4 })", function( assert ) {
101+
var blue = jQuery.Color( { alpha: 0.4 } );
102+
testParts( blue, {
103+
red: null,
104+
green: null,
105+
blue: null,
106+
alpha: 0.4
107+
}, assert );
108+
assert.ok( !blue._hsla, "No HSLA cache" );
109+
} );
110+
88111
QUnit.test( "jQuery.Color({ alpha: 1, hue: 100 })", function( assert ) {
89112
var blue = jQuery.Color( { alpha: 1, hue: 100 } );
90113
testParts( blue, {

0 commit comments

Comments
 (0)