Skip to content

Commit bf9cf4b

Browse files
committed
new option forceAlpha
1 parent bd230e4 commit bf9cf4b

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ $('.color').colorPicker({
5555
scrollResize: true // toggle for reposition colorPicker on window.resize/scroll
5656
gap: 4 // gap to right and bottom edge of view port if repositioned to fit
5757
preventFocus: false // prevents default on focus of input fields (e.g. no keyboard on mobile)
58-
body: document.body // the element where the events are attached to (touchstart, mousedown, pointerdown, focus, click, change)
58+
body: document.body // the element where the events are attached to (touchstart, mousedown, pointerdown, focus, click, change),
59+
forceAlpha: force printing alpha channel (undefined = auto; false = never print alpha)
5960
});
6061
```
6162
####Some tips

colors.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
};
8888

8989
Colors.prototype.toString = function(colorMode, forceAlpha) {
90-
return ColorConverter.color2text(colorMode || 'rgba', this.colors, forceAlpha);
90+
return ColorConverter.color2text(colorMode.toLowerCase() || 'rgb', this.colors, forceAlpha);
9191
};
9292

9393
// ------------------------------------------------------ //
@@ -259,17 +259,15 @@
259259
forceAlpha !== false && (forceAlpha || alpha !== 1),
260260
RGB = colors.RND.rgb,
261261
HSL = colors.RND.hsl,
262-
mode = colorMode.toLowerCase().substr(0, 3),
263-
shouldBeHex = mode === 'hex' && hasAlpha,
264-
isHex = mode === 'hex' && !shouldBeHex,
265-
isRgb = mode === 'rgb' || shouldBeHex,
262+
shouldBeHex = colorMode === 'hex' && hasAlpha,
263+
isHex = colorMode === 'hex' && !shouldBeHex,
264+
isRgb = colorMode === 'rgb' || shouldBeHex,
266265
innerText = isRgb ? RGB.r + ', ' + RGB.g + ', ' + RGB.b :
267-
HSL.h + ', ' + HSL.s + '%, ' + HSL.l + '%',
268-
text = isHex ? '#' + colors.HEX : (shouldBeHex ? 'rgb' : mode) +
269-
(hasAlpha ? 'a' : '') + '(' + innerText +
270-
(hasAlpha ? ', ' + alpha : '') + ')';
266+
!isHex ? HSL.h + ', ' + HSL.s + '%, ' + HSL.l + '%' :
267+
'#' + colors.HEX;
271268

272-
return text;
269+
return isHex ? innerText : (shouldBeHex ? 'rgb' : colorMode) +
270+
(hasAlpha ? 'a' : '') + '(' + innerText + (hasAlpha ? ', ' + alpha : '') + ')';
273271
},
274272

275273
RGB2HEX: function(RGB) {

jqColorPicker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
HSL = colors.RND.hsl,
201201
dark = '#222',
202202
light = '#ddd',
203-
colorText = _color.toString(_$trigger._colorMode),
203+
colorText = _color.toString(_$trigger._colorMode, _options.forceAlpha),
204204
HUEContrast = colors.HUELuminance > 0.22 ? dark : light,
205205
alphaContrast = colors.rgbaMixBlack.luminance > 0.22 ? dark : light,
206206
h = (1 - colors.hsv.h) * _$xy_slider._height,
@@ -277,7 +277,8 @@
277277
buildCallback: noop,
278278
body: document.body,
279279
scrollResize: true,
280-
gap: 4
280+
gap: 4,
281+
// forceAlpha: undefined,
281282
// css: '',
282283
// cssAddon: '',
283284
// margin: '',

0 commit comments

Comments
 (0)