Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #91 from alice/master
Browse files Browse the repository at this point in the history
Correctly parse alpha in rgba colors
  • Loading branch information
Alice committed May 28, 2014
2 parents af27e95 + c1ee15e commit 272d5a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/js/AccessibilityUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,13 @@ axs.utils.parseColor = function(colorString) {
return new axs.utils.Color(r, g, b, a);
}

var rgbaRegex = /^rgba\((\d+), (\d+), (\d+), (\d+(\.\d+)?)\)/;
var rgbaRegex = /^rgba\((\d+), (\d+), (\d+), (\d*(\.\d+)?)\)/;
match = colorString.match(rgbaRegex);
if (match) {
var a = parseInt(match[4], 10);
var r = parseInt(match[1], 10);
var g = parseInt(match[2], 10);
var b = parseInt(match[3] ,10);
var a = parseFloat(match[4]);
return new axs.utils.Color(r, g, b, a);
}

Expand Down
10 changes: 10 additions & 0 deletions test/js/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,13 @@ test("nth-of-type does not refer to a selector but a tagName", function() {
equal(lastLi, document.querySelector(selector),
'selector "' + selector + '" does not match element');
});

module("parseColor");
test("parses alpha values correctly", function() {
var colorString = 'rgba(255, 255, 255, .47)';
var color = axs.utils.parseColor(colorString);
equal(color.red, 255);
equal(color.blue, 255);
equal(color.green, 255);
equal(color.alpha, .47);
});

0 comments on commit 272d5a7

Please sign in to comment.