Skip to content

Commit 2b86995

Browse files
authored
Merge pull request #261 from malissa/swatch-0-transparency
Allow for a 0 alpha value in a swatch; formatting corrections
2 parents a4ad885 + d250eb1 commit 2b86995

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

jquery.minicolors.js

+32-32
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@
157157

158158
// The wrapper
159159
minicolors
160-
.addClass('minicolors-theme-' + settings.theme)
161-
.toggleClass('minicolors-with-opacity', settings.opacity);
160+
.addClass('minicolors-theme-' + settings.theme)
161+
.toggleClass('minicolors-with-opacity', settings.opacity);
162162

163163
// Custom positioning
164164
if(settings.position !== undefined) {
@@ -176,13 +176,13 @@
176176

177177
// The input
178178
input
179-
.addClass('minicolors-input')
180-
.data('minicolors-initialized', false)
181-
.data('minicolors-settings', settings)
182-
.prop('size', size)
183-
.wrap(minicolors)
184-
.after(
185-
'<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
179+
.addClass('minicolors-input')
180+
.data('minicolors-initialized', false)
181+
.data('minicolors-settings', settings)
182+
.prop('size', size)
183+
.wrap(minicolors)
184+
.after(
185+
'<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
186186
'<div class="minicolors-slider minicolors-sprite">' +
187187
'<div class="minicolors-picker"></div>' +
188188
'</div>' +
@@ -194,7 +194,7 @@
194194
'<div class="minicolors-picker"><div></div></div>' +
195195
'</div>' +
196196
'</div>'
197-
);
197+
);
198198

199199
// The swatch
200200
if(!settings.inline) {
@@ -213,10 +213,10 @@
213213
if(settings.swatches && settings.swatches.length !== 0) {
214214
panel.addClass('minicolors-with-swatches');
215215
swatches = $('<ul class="minicolors-swatches"></ul>')
216-
.appendTo(panel);
216+
.appendTo(panel);
217217
for(i = 0; i < settings.swatches.length; ++i) {
218218
// allow for custom objects as swatches
219-
if($.type(settings.swatches[i]) === "object") {
219+
if($.type(settings.swatches[i]) === 'object') {
220220
name = settings.swatches[i].name;
221221
swatch = settings.swatches[i].color;
222222
} else {
@@ -225,13 +225,13 @@
225225
}
226226
swatch = isRgb(swatch) ? parseRgb(swatch, true) : hex2rgb(parseHex(swatch, true));
227227
$('<li class="minicolors-swatch minicolors-sprite"><span class="minicolors-swatch-color" title="' + name + '"></span></li>')
228-
.appendTo(swatches)
229-
.data('swatch-color', settings.swatches[i])
230-
.find('.minicolors-swatch-color')
231-
.css({
232-
backgroundColor: rgb2hex(swatch),
233-
opacity: swatch.a
234-
});
228+
.appendTo(swatches)
229+
.data('swatch-color', settings.swatches[i])
230+
.find('.minicolors-swatch-color')
231+
.css({
232+
backgroundColor: rgb2hex(swatch),
233+
opacity: swatch.a
234+
});
235235
settings.swatches[i] = swatch;
236236
}
237237
}
@@ -354,17 +354,17 @@
354354
top: y + 'px'
355355
};
356356
if(target.is('.minicolors-grid')) {
357-
styles.left = x + 'px'
357+
styles.left = x + 'px';
358358
}
359359
if (picker.animate) {
360360
picker
361-
.stop(true)
362-
.animate(styles, duration, settings.animationEasing, function() {
363-
updateFromControl(input, target);
364-
});
361+
.stop(true)
362+
.animate(styles, duration, settings.animationEasing, function() {
363+
updateFromControl(input, target);
364+
});
365365
} else {
366366
picker
367-
.css(styles);
367+
.css(styles);
368368
updateFromControl(input, target);
369369
}
370370
}
@@ -831,13 +831,13 @@
831831
rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255);
832832
rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255);
833833
rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255);
834-
if(rgba[3]) {
834+
if(rgba[3] !== undefined) {
835835
rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1);
836836
}
837837

838838
// Return RGBA object
839839
if( obj ) {
840-
if (rgba[3]) {
840+
if (rgba[3] !== undefined) {
841841
return {
842842
r: rgba[0],
843843
g: rgba[1],
@@ -1068,8 +1068,8 @@
10681068
value = settings.defaultValue;
10691069
} else if(settings.format === 'rgb') {
10701070
value = settings.opacity ?
1071-
parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
1072-
parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
1071+
parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
1072+
parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
10731073
} else {
10741074
value = rgb2hex(rgba);
10751075
}
@@ -1079,9 +1079,9 @@
10791079
swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1;
10801080
if(value.toLowerCase() === 'transparent') swatchOpacity = 0;
10811081
input
1082-
.closest('.minicolors')
1083-
.find('.minicolors-input-swatch > span')
1084-
.css('opacity', swatchOpacity);
1082+
.closest('.minicolors')
1083+
.find('.minicolors-input-swatch > span')
1084+
.css('opacity', swatchOpacity);
10851085

10861086
// Set input value
10871087
input.val(value);

0 commit comments

Comments
 (0)