8000 Core: Use a space when serializing, remove the transparent case · jquery/jquery-color@aaf03cc · GitHub
[go: up one dir, main page]

Skip to content

Commit aaf03cc

Browse files
committed
Core: Use a space when serializing, remove the transparent case
When serializing a color, add a space after a comma; instead of: rgb(100,150,200) hsl(240,100%,50%) use: rgb(100, 150, 200) hsl(240, 100%, 50%) This matches the standard browser serialization algorithm for rgb(a): https://drafts.csswg.org/cssom/#serializing-css-values Another change is that transparent colors no longer return the "transparent" when cast to a string, also to match the standard. Fixes #88
1 parent 1323208 commit aaf03cc

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

jquery.color.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ color.fn = jQuery.extend( color.prototype, {
413413
prefix = "rgb(";
414414
}
415415

416-
return prefix + rgba.join() + ")";
416+
return prefix + rgba.join( ", " ) + ")";
417417
},
418418
toHslaString: function() {
419419
var prefix = "hsla(",
@@ -433,7 +433,7 @@ color.fn = jQuery.extend( color.prototype, {
433433
hsla.pop();
434434
prefix = "hsl(";
435435
}
436-
return prefix + hsla.join() + ")";
436+
return prefix + hsla.join( ", " ) + ")";
437437
},
438438
toHexString: function( includeAlpha ) {
439439
var rgba = this._rgba.slice(),
@@ -450,7 +450,7 @@ color.fn = jQuery.extend( color.prototype, {
450450
} ).join( "" );
451451
},
452452
toString: function() {
453-
return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
453+
return this.toRgbaString();
454454
}
455455
} );
456456
color.fn.parse.prototype = color.fn;

test/unit/color.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ var fiftypercent = {
227227
blue: 127,
228228
alpha: 0.5
229229
};
230-
parseTest( "rgb(127,127,127)", fiftypercent );
231-
parseTest( "rgb(50%,50%,50%)", fiftypercent );
232-
parseTest( "rgba(127,127,127,1)", fiftypercent );
233-
parseTest( "rgba(50%,50%,50%,1)", fiftypercent );
234-
parseTest( "rgba(127,127,127,0.5)", fiftypercentalpha );
235-
parseTest( "rgba(50%,50%,50%,0.5)", fiftypercentalpha );
230+
parseTest( "rgb(127, 127, 127)", fiftypercent );
231+
parseTest( "rgb(50%, 50%, 50%)", fiftypercent );
232+
parseTest( "rgba(127, 127, 127, 1)", fiftypercent );
233+
parseTest( "rgba(50%, 50%, 50%, 1)", fiftypercent );
234+
parseTest( "rgba(127, 127, 127, 0.5)", fiftypercentalpha );
235+
parseTest( "rgba(50%, 50%, 50%, 0.5)", fiftypercentalpha );
236236
parseTest( "rgba(127, 127, 127, .5)", fiftypercentalpha );
237237
parseTest( "rgba(50%, 50%, 50%, .5)", fiftypercentalpha );
238238
parseTest( "rgba(0, 0, 0, 0)", {
@@ -416,7 +416,7 @@ QUnit.test( ".is()", function( assert ) {
416416
assert.ok( red.is( red ), "Red is itself" );
417417
assert.ok( red.is( { red: 255 } ), "Red is equal to { red: 255 }" );
418418
assert.ok( red.is( { saturation: 1 } ), "Red is equal to { saturation: 1 }" );
419-
assert.ok( red.is( [ 255, 0, 0 ] ), "Red is equal to [255,0,0]" );
419+
assert.ok( red.is( [ 255, 0, 0 ] ), "Red is equal to [255, 0, 0]" );
420420
assert.ok( red.is( "red" ), "Red is equal to \"red\"" );
421421
assert.ok( !red.is( "blue" ), "Red is not blue" );
422422
assert.ok( !red.is( { alpha: 0 } ), "Red is not { alpha: 0 }" );
@@ -427,8 +427,8 @@ QUnit.test( ".toRgbaString()", function( assert ) {
427427
trans = black.alpha( 0.5 );
428428

429429
assert.expect( 2 );
430-
assert.equal( black.toRgbaString(), "rgb(0,0,0)" );
431-
assert.equal( trans.toRgbaString(), "rgba(0,0,0,0.5)" );
430+
assert.equal( black.toRgbaString(), "rgb(0, 0, 0)" );
431+
assert.equal( trans.toRgbaString(), "rgba(0, 0, 0, 0.5)" );
432432
} );
433433

434434
QUnit.test( ".toHexString()", function( assert ) {
@@ -458,7 +458,7 @@ QUnit.test( "toString() methods keep alpha intact", function( assert ) {
458458

459459
QUnit.module( "hsla" );
460460

461-
parseTest( "hsla(180,50%,50%,0.5)", {
461+
parseTest( "hsla(180, 50%, 50%, 0.5)", {
462462
expect: 7,
463463
hue: 180,
464464
saturation: 0.5,
@@ -538,17 +538,17 @@ parseTest( jQuery.Color( { saturation: 0, alpha: 0 } ), {
538538

539539
QUnit.test( "HSLA Conversions", function( assert ) {
540540
assert.expect( 11 );
541-
assert.equal( jQuery.Color( "#000" ).toHslaString(), "hsl(0,0%,0%)", "HSLA value from #000" );
542-
assert.equal( jQuery.Color( "#fff" ).toHslaString(), "hsl(0,0%,100%)", "HSLA value from #fff" );
543-
assert.equal( jQuery.Color( "#f00" ).toHslaString(), "hsl(0,100%,50%)", "HSLA value from #f00" );
544-
assert.equal( jQuery.Color( "#ff0" ).toHslaString(), "hsl(60,100%,50%)", "HSLA value from #ff0" );
545-
assert.equal( jQuery.Color( "#0f0" ).toHslaString(), "hsl(120,100%,50%)", "HSLA value from #0f0" );
546-
assert.equal( jQuery.Color( "#0ff" ).toHslaString(), "hsl(180,100%,50%)", "HSLA value from #0ff" );
547-
assert.equal( jQuery.Color( "#00f" ).toHslaString(), "hsl(240,100%,50%)", "HSLA value from #00f" );
548-
assert.equal( jQuery.Color( "#f0f" ).toHslaString(), "hsl(300,100%,50%)", "HSLA value from #f0f" );
549-
assert.equal( jQuery.Color( "#7f007f" ).toHslaString(), "hsl(300,100%,25%)", "HSLA value from #7f007f" );
550-
assert.equal( jQuery.Color( "#ff7fff" ).toHslaString(), "hsl(300,100%,75%)", "HSLA value from #ff7fff" );
551-
assert.equal( jQuery.Color( "rgba(127,127,127,0.1)" ).toHslaString(), "hsla(0,0%,50%,0.1)", "HSLA value from rgba(127,127,127,0.1)" );
541+
assert.equal( jQuery.Color( "#000" ).toHslaString(), "hsl(0, 0%, 0%)", "HSLA value from #000" );
542+
assert.equal( jQuery.Color( "#fff" ).toHslaString(), "hsl(0, 0%, 100%)", "HSLA value from #fff" );
543+
assert.equal( jQuery.Color( "#f00" ).toHslaString(), "hsl(0, 100%, 50%)", "HSLA value from #f00" );
544+
assert.equal( jQuery.Color( "#ff0" ).toHslaString(), "hsl(60, 100%, 50%)", "HSLA value from #ff0" );
545+
assert.equal( jQuery.Color( "#0f0" ).toHslaString(), "hsl(120, 100%, 50%)", "HSLA value from #0f0" );
546+
assert.equal( jQuery.Color( "#0ff" ).toHslaString(), "hsl(180, 100%, 50%)", "HSLA value from #0ff" );
547+
assert.equal( jQuery.Color( "#00f" ).toHslaString(), "hsl(240, 100%, 50%)", "HSLA value from #00f" );
548+
assert.equal( jQuery.Color( "#f0f" ).toHslaString(), "hsl(300, 100%, 50%)", "HSLA value from #f0f" );
549+
assert.equal( jQuery.Color( "#7f007f" ).toHslaString(), "hsl(300, 100%, 25%)", "HSLA value from #7f007f" );
550+
assert.equal( jQuery.Color( "#ff7fff" ).toHslaString(), "hsl(300, 100%, 75%)", "HSLA value from #ff7fff" );
551+
assert.equal( jQuery.Color( "rgba(127, 127, 127, 0.1)" ).toHslaString(), "hsla(0, 0%, 50%, 0.1)", "HSLA value from rgba(127, 127, 127, 0.1)" );
552552
} );
553553

554554
QUnit.test( "HSLA Transitions", function( assert ) {

0 commit comments

Comments
 (0)
0