Skip to content

Commit c14beaa

Browse files
dygnarf
authored andcommitted
Add support for '.25' instead of '0.25' for alpha string parsing - Closes jquery#46
1 parent df0abd6 commit c14beaa

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

jquery.color.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
1717
// a set of RE's that can match strings and generate color tuples.
1818
stringParsers = [{
19-
re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
19+
re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(0?(?:\.\d+)?)\s*)?\)/,
2020
parse: function( execResult ) {
2121
return [
2222
execResult[ 1 ],
@@ -26,7 +26,7 @@
2626
];
2727
}
2828
}, {
29-
re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
29+
re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(0?(?:\.\d+)?)\s*)?\)/,
3030
parse: function( execResult ) {
3131
return [
3232
execResult[ 1 ] * 2.55,
@@ -56,7 +56,7 @@
5656
];
5757
}
5858
}, {
59-
re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
59+
re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(0?(?:\.\d+)?)\s*)?\)/,
6060
space: "hsla",
6161
parse: function( execResult ) {
6262
return [

test/test.html

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title></title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<script type="text/javascript" src="jquery-1.5.1.js"></script>
7+
<script type="text/javascript" src="../jquery.color.js"></script>
8+
</head>
9+
<body>
10+
<div id="test" style="background-color: #00ffff">Test string</div>
11+
12+
<script type="text/javascript">
13+
//<![CDATA[
14+
15+
var $div = $("#test");
16+
$div./*animate({"background-color": "#ffff00"}, 300).*/
17+
animate({"background-color": 'transparent'}, 400);
18+
19+
// var savedColor = $div.css("backgroundColor");
20+
// alert(savedColor);
21+
// $div.animate({"background-color": "#ffff00"}, 300).
22+
// animate({"background-color": savedColor}, 400);
23+
24+
//]]>
25+
</script>
26+
27+
</body>
28+
</html>

test/unit/color.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ parseTest( "rgb(127,127,127)", fiftypercent );
168168
parseTest( "rgb(50%,50%,50%)", fiftypercent );
169169
parseTest( "rgba(127,127,127,0.5)", fiftypercentalpha );
170170
parseTest( "rgba(50%,50%,50%,0.5)", fiftypercentalpha );
171+
parseTest( "rgba(127, 127, 127, .5)", fiftypercentalpha );
172+
parseTest( "rgba(50%, 50%, 50%, .5)", fiftypercentalpha );
171173
parseTest( "rgba(0, 0, 0, 0)", {
172174
expect: 4,
173175
red: null,
@@ -407,6 +409,17 @@ parseTest("hsla(180,50%,50%,0.5)", {
407409
alpha: 0.5
408410
});
409411

412+
parseTest("hsla( 180, 50%, 50%, .5 )", {
413+
expect: 7,
414+
hue: 180,
415+
saturation: 0.5,
416+
lightness: 0.5,
417+
red: 64,
418+
green: 191,
419+
blue: 191,
420+
alpha: 0.5
421+
});
422+
410423
parseTest("hsl(72, 77%, 59%)", {
411424
expect: 7,
412425
hue: 72,
@@ -605,4 +618,4 @@ test( "jQuery.Color.hook() - Create new hooks for color properties", 2, function
605618
ok( jQuery.fx.step.testy, "fx.step testy hook created" );
606619
delete jQuery.cssHooks.testy;
607620
delete jQuery.fx.step.testy;
608-
});
621+
});

0 commit comments

Comments
 (0)