Skip to content

Commit 9f7235d

Browse files
committed
Merge pull request hojberg#33 from yannickcr/master
Fix a graphical bug in Firefox - Should fix hojberg#24
2 parents 529f103 + 142f7a1 commit 9f7235d

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

public/js/lib/models/arrow.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ if (!('CSSArrowPlease' in window)) window.CSSArrowPlease = {};
3636
else if ( pos === 'right' ) return 'left';
3737
},
3838

39+
/**
40+
@method hexToRGB
41+
@description
42+
returns an rgb color from an hex color
43+
@returns {Array}
44+
**/
45+
hexToRGB: function (h) {
46+
if ( typeof h !== 'string' || !h.match(/^#([0-9A-F]{3}$)|([0-9A-F]{6}$)/i) ) return [0, 0, 0];
47+
else if ( h.match(/^(#[0-9a-f]{3})$/i) ) h = '#' + h[1] + h[1] + h[2] + h[2] + h[3] + h[3];
48+
var rgb = [],
49+
i = 1;
50+
51+
for(; i < 6; i+=2) {
52+
rgb.push(parseInt(h.substring(i, i + 2), 16));
53+
}
54+
return rgb;
55+
},
56+
3957
/**
4058
@method _baseCSS
4159
@description generates the base css
@@ -87,12 +105,14 @@ if (!('CSSArrowPlease' in window)) window.CSSArrowPlease = {};
87105
_arrowCSS: function (color, size, layer) {
88106
var pos = this.get('position'),
89107
iPos = this.invertedPosition(),
108+
rgbColor = this.hexToRGB(color),
90109
css = ".arrow_box:";
91110

92111
layer = layer || 'after';
93112

94113
css += layer + ' {\n';
95114

115+
css += '\tborder-color: rgba(' + rgbColor.join(', ') + ', 0);\n';
96116
css += '\tborder-' + iPos + '-color: ' + color + ';\n';
97117
css += '\tborder-width: ' + size + 'px;\n';
98118

public/js/spec/models/arrow_spec.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ describe("CSSArrowPlease.Arrow", function () {
9696

9797
});
9898

99+
describe('convert hex color to rgb color', function () {
100+
101+
it('converts "#888"', function () {
102+
expect( arrow.hexToRGB('#888') ).toEqual([136 , 136 , 136]);
103+
});
104+
105+
it('converts "#88B7D5"', function () {
106+
expect( arrow.hexToRGB('#88B7D5') ).toEqual([136, 183, 213]);
107+
});
108+
109+
it('converts "#C2E1F5"', function () {
110+
expect( arrow.hexToRGB('#C2E1F5') ).toEqual([194, 225, 245]);
111+
});
112+
113+
it('returns [0, 0, 0] if there is no input color', function () {
114+
expect( arrow.hexToRGB() ).toEqual([0, 0, 0]);
115+
});
116+
117+
it('returns [0, 0, 0] if the input color is invalid', function () {
118+
expect( arrow.hexToRGB('invalid') ).toEqual([0, 0, 0]);
119+
});
120+
121+
});
122+
99123
describe('toCSS', function () {
100124

101125
describe('baseCSS', function () {
@@ -177,8 +201,9 @@ describe("CSSArrowPlease.Arrow", function () {
177201
});
178202

179203
it('it has the correct color', function () {
180-
var expected = 'border-bottom-color: #888';
181-
expect( arrow._arrowCSS('#888', 20) ).toMatch( expected );
204+
var css = arrow._arrowCSS('#888', 20);
205+
expect( css ).toMatch( 'border-bottom-color: #888' );
206+
expect( css ).toMatch( 'border-color: rgba\\(136, 136, 136, 0\\)' );
182207
});
183208

184209
describe('position top', function () {

0 commit comments

Comments
 (0)