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

use allowEmpty at showPaletteOnly #545

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 14 additions & 12 deletions spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,12 @@
if(current) {
var tiny = tinycolor(current);
var c = tiny.toHsl().l < 0.5 ? "sp-thumb-el sp-thumb-dark" : "sp-thumb-el sp-thumb-light";
c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
var formattedString = tiny.toString(opts.preferredFormat || "rgb");
var swatchStyle = rgbaSupport ? ("background-color:" + tiny.toRgbString()) : "filter:" + tiny.toFilter();
html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';" /></span>');
} else {
var cls = 'sp-clear-display';
html.push($('<div />')
.append($('<span data-color="" style="background-color:transparent;" class="' + cls + '"></span>')
.attr('title', opts.noColorSelectedText)
)
.html()
);
html.push('<span class="sp-thumb-el sp-clear-display" ><span class="sp-clear-palette-only" style="background-color: transparent;" /></span>');
}
}
return "<div class='sp-cf " + className + "'>" + html.join('') + "</div>";
Expand Down Expand Up @@ -237,7 +231,7 @@
currentPreferredFormat = opts.preferredFormat,
clickoutFiresChange = !opts.showButtons || opts.clickoutFiresChange,
isEmpty = !initialColor,
allowEmpty = opts.allowEmpty && !isInputTypeColor;
allowEmpty = opts.allowEmpty;

function applyOptions() {

Expand All @@ -257,6 +251,12 @@
paletteLookup[rgb] = true;
}
}

// if showPaletteOnly and didn't set initialcolor
// set initialcolor to first palette
if (opts.showPaletteOnly && !opts.color) {
initialColor = (palette[0][0] === '') ? palette[0][0] : Object.keys(paletteLookup)[0];
}
}

container.toggleClass("sp-flat", flat);
Expand Down Expand Up @@ -445,8 +445,10 @@
currentPreferredFormat = opts.preferredFormat || tinycolor(initialColor).format;

addColorToSelectionPalette(initialColor);
}
else {
} else if (initialColor === '') {
set(initialColor);
updateUI();
} else {
updateUI();
}

Expand Down Expand Up @@ -697,7 +699,7 @@
}

var newColor, newHsv;
if (!color && allowEmpty) {
if ((!color || color === undefined) && allowEmpty) {
isEmpty = true;
} else {
isEmpty = false;
Expand Down