Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions jquery.color.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

// a set of RE's that can match strings and generate color tuples.
stringParsers = [ {
re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
re: /^\s*rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
parse: function( execResult ) {
return [
execResult[ 1 ],
Expand All @@ -45,7 +45,7 @@
];
}
}, {
re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
re: /^\s*rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
parse: function( execResult ) {
return [
execResult[ 1 ] * 2.55,
Expand All @@ -57,7 +57,7 @@
}, {

// this regex ignores A-F because it's compared against an already lowercased string
re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?/,
re: /^\s*#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?/,
parse: function( execResult ) {
return [
parseInt( execResult[ 1 ], 16 ),
Expand All @@ -71,7 +71,7 @@
}, {

// this regex ignores A-F because it's compared against an already lowercased string
re: /#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])?/,
re: /^\s*#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])?/,
parse: function( execResult ) {
return [
parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
Expand All @@ -84,7 +84,7 @@
];
}
}, {
re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
re: /^\s*hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
space: "hsla",
parse: function( execResult ) {
return [
Expand Down
22 changes: 22 additions & 0 deletions test/unit/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ var sevens = {
};
parseTest( "#777", sevens );
parseTest( "#777777", sevens );

// Tolerate whitespace. https://github.com/jquery/jquery-ui/issues/2411
parseTest( " #777 ", sevens );
parseTest( " #777777 ", sevens );
parseTest( "#77777726", {
expect: 4,
red: 119,
Expand Down Expand Up @@ -237,6 +241,9 @@ parseTest( "rgba(127, 127, 127, 0.5)", fiftypercentalpha );
parseTest( "rgba(50%, 50%, 50%, 0.5)", fiftypercentalpha );
parseTest( "rgba(127, 127, 127, .5)", fiftypercentalpha );
parseTest( "rgba(50%, 50%, 50%, .5)", fiftypercentalpha );

// Tolerate whitespace. https://github.com/jquery/jquery-ui/issues/2411
parseTest( " rgba( 50%, 50%, 50%, .5 ) ", fiftypercentalpha );
parseTest( "rgba(0, 0, 0, 0)", {
expect: 4,
red: null,
Expand Down Expand Up @@ -675,6 +682,21 @@ QUnit.test( "Setting CSS to transparent", function( assert ) {
assert.equal( jQuery.Color( el[ 0 ].style.backgroundColor ).alpha(), 0, "CSS was set to transparent" );
} );

QUnit.test.each( "Setting CSS to a variable", {
"without fallback": [ "var(--meh)", "var(--meh)" ],
"without fallback and whitespace": [ " var( --meh ) ", "var( --meh )" ],
"with fallback": [ "var(--meh,#ff0077)", "var(--meh,#ff0077)" ],
"with fallback and whitespace": [ " var( --meh, #ff0077 ) ", "var( --meh, #ff0077 )" ]
}, function( assert, data ) {
var el = jQuery( "<div></div>" ).css( { color: data[ 0 ] } );
assert.expect( 1 );

// Support: Safari 26
// WebKit fails to trim trailing whitespace. https://bugs.webkit.org/show_bug.cgi?id=320186
var actual = el[ 0 ].style.color.replace( / +$/, "" );
assert.equal( actual, data[ 1 ], "Declared value" );
} );

QUnit.test( "jQuery.Color.hook() - Create new hooks for color properties", function( assert ) {
assert.expect( 2 );

Expand Down
Loading