Skip to content

Commit 59cfd97

Browse files
committed
Add Color.TRANSPARENT
`fromCssColorString` did not support `transparent`, which is a valid CSS color. Adding `Color.TRANSPARENT` addresses this. Also added some extra defensive code around InfoBox's usage of `fromCssColorString` to make sure it doesn't crash on invalid strings.
1 parent 1c37e03 commit 59cfd97

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Source/Core/Color.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,5 +2024,14 @@ define([
20242024
*/
20252025
Color.YELLOWGREEN = freezeObject(Color.fromCssColorString('#9ACD32'));
20262026

2027+
/**
2028+
* An immutable Color instance initialized to CSS transparent.
2029+
* <span class="colorSwath" style="background: transparent;"></span>
2030+
*
2031+
* @constant
2032+
* @type {Color}
2033+
*/
2034+
Color.TRANSPARENT = freezeObject(new Color(0, 0, 0, 0));
2035+
20272036
return Color;
20282037
});

Source/Widgets/InfoBox/InfoBox.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ click: function () { closeClicked.raiseEvent(this); }');
123123
if (firstElementChild !== null && frameContent.childNodes.length === 1) {
124124
var style = window.getComputedStyle(firstElementChild);
125125
if (style !== null) {
126-
var color = Color.fromCssColorString(style['background-color']);
127-
if (color.alpha !== 0) {
126+
var backgroundColor = style['background-color'];
127+
var color = Color.fromCssColorString(backgroundColor);
128+
if (defined(color) && color.alpha !== 0) {
128129
background = style['background-color'];
129130
}
130131
}

Specs/Core/ColorSpec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ defineSuite([
161161
expect(new Color(0.1, 0.2, 0.3, 0.4).toCssColorString()).toEqual('rgba(25,51,76,0.4)');
162162
});
163163

164+
it('fromCssColorString supports transparent', function() {
165+
expect(Color.fromCssColorString('transparent')).toEqual(new Color(0.0, 0.0, 0.0, 0.0));
166+
});
167+
164168
it('fromCssColorString supports the #rgb format', function() {
165169
expect(Color.fromCssColorString('#369')).toEqual(new Color(0.2, 0.4, 0.6, 1.0));
166170
});

0 commit comments

Comments
 (0)