Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for a 0 alpha value in a swatch #261

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions jquery.minicolors.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@

// The wrapper
minicolors
.addClass('minicolors-theme-' + settings.theme)
.toggleClass('minicolors-with-opacity', settings.opacity);
.addClass('minicolors-theme-' + settings.theme)
.toggleClass('minicolors-with-opacity', settings.opacity);

// Custom positioning
if(settings.position !== undefined) {
Expand All @@ -176,13 +176,13 @@

// The input
input
.addClass('minicolors-input')
.data('minicolors-initialized', false)
.data('minicolors-settings', settings)
.prop('size', size)
.wrap(minicolors)
.after(
'<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
.addClass('minicolors-input')
.data('minicolors-initialized', false)
.data('minicolors-settings', settings)
.prop('size', size)
.wrap(minicolors)
.after(
'<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
'<div class="minicolors-slider minicolors-sprite">' +
'<div class="minicolors-picker"></div>' +
'</div>' +
Expand All @@ -194,7 +194,7 @@
'<div class="minicolors-picker"><div></div></div>' +
'</div>' +
'</div>'
);
);

// The swatch
if(!settings.inline) {
Expand All @@ -213,10 +213,10 @@
if(settings.swatches && settings.swatches.length !== 0) {
panel.addClass('minicolors-with-swatches');
swatches = $('<ul class="minicolors-swatches"></ul>')
.appendTo(panel);
.appendTo(panel);
for(i = 0; i < settings.swatches.length; ++i) {
// allow for custom objects as swatches
if($.type(settings.swatches[i]) === "object") {
if($.type(settings.swatches[i]) === 'object') {
name = settings.swatches[i].name;
swatch = settings.swatches[i].color;
} else {
Expand All @@ -225,13 +225,13 @@
}
swatch = isRgb(swatch) ? parseRgb(swatch, true) : hex2rgb(parseHex(swatch, true));
$('<li class="minicolors-swatch minicolors-sprite"><span class="minicolors-swatch-color" title="' + name + '"></span></li>')
.appendTo(swatches)
.data('swatch-color', settings.swatches[i])
.find('.minicolors-swatch-color')
.css({
backgroundColor: rgb2hex(swatch),
opacity: swatch.a
});
.appendTo(swatches)
.data('swatch-color', settings.swatches[i])
.find('.minicolors-swatch-color')
.css({
backgroundColor: rgb2hex(swatch),
opacity: swatch.a
});
settings.swatches[i] = swatch;
}
}
Expand Down Expand Up @@ -354,17 +354,17 @@
top: y + 'px'
};
if(target.is('.minicolors-grid')) {
styles.left = x + 'px'
styles.left = x + 'px';
}
if (picker.animate) {
picker
.stop(true)
.animate(styles, duration, settings.animationEasing, function() {
updateFromControl(input, target);
});
.stop(true)
.animate(styles, duration, settings.animationEasing, function() {
updateFromControl(input, target);
});
} else {
picker
.css(styles);
.css(styles);
updateFromControl(input, target);
}
}
Expand Down Expand Up @@ -831,13 +831,13 @@
rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255);
rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255);
rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255);
if(rgba[3]) {
if(rgba[3] !== undefined) {
rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1);
}

// Return RGBA object
if( obj ) {
if (rgba[3]) {
if (rgba[3] !== undefined) {
return {
r: rgba[0],
g: rgba[1],
Expand Down Expand Up @@ -1068,8 +1068,8 @@
value = settings.defaultValue;
} else if(settings.format === 'rgb') {
value = settings.opacity ?
parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
} else {
value = rgb2hex(rgba);
}
Expand All @@ -1079,9 +1079,9 @@
swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1;
if(value.toLowerCase() === 'transparent') swatchOpacity = 0;
input
.closest('.minicolors')
.find('.minicolors-input-swatch > span')
.css('opacity', swatchOpacity);
.closest('.minicolors')
.find('.minicolors-input-swatch > span')
.css('opacity', swatchOpacity);

// Set input value
input.val(value);
Expand Down
Loading