Skip to content

Commit

Permalink
Allow customization of 'No Color Selected' text
Browse files Browse the repository at this point in the history
...so that it can be localized
  • Loading branch information
mlocati committed May 30, 2014
1 parent 45934a3 commit 6daf9b0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
cancelText: "cancel",
chooseText: "choose",
clearText: "Clear Color Selection",
noColorSelectedText: "No Color Selected",
preferredFormat: false,
className: "", // Deprecated - use containerClassName and replacerClassName instead.
containerClassName: "",
Expand Down Expand Up @@ -113,20 +114,25 @@
].join("");
})();

function paletteTemplate (p, color, className, tooltipFormat) {
function paletteTemplate (p, color, className, opts) {
var html = [];
for (var i = 0; i < p.length; i++) {
var current = p[i];
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" : "";
var formattedString = tiny.toString(tooltipFormat || "rgb");
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('<span title="No Color Selected" data-color="" style="background-color:transparent;" class="' + cls + '"></span>');
html.push($('<div />')
.append($('<span data-color="" style="background-color:transparent;" class="' + cls + '"></span>')
.attr('title', opts.noColorSelectedText)
)
.html()
);
}
}
return "<div class='sp-cf " + className + "'>" + html.join('') + "</div>";
Expand Down Expand Up @@ -486,13 +492,13 @@
var currentColor = get();

var html = $.map(paletteArray, function (palette, i) {
return paletteTemplate(palette, currentColor, "sp-palette-row sp-palette-row-" + i, opts.preferredFormat);
return paletteTemplate(palette, currentColor, "sp-palette-row sp-palette-row-" + i, opts);
});

updateSelectionPaletteFromStorage();

if (selectionPalette) {
html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, "sp-palette-row sp-palette-row-selection", opts.preferredFormat));
html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, "sp-palette-row sp-palette-row-selection", opts));
}

paletteContainer.html(html.join(""));
Expand All @@ -502,7 +508,7 @@
if (opts.showInitial) {
var initial = colorOnShow;
var current = get();
initialColorContainer.html(paletteTemplate([initial, current], current, "sp-palette-row-initial", opts.preferredFormat));
initialColorContainer.html(paletteTemplate([initial, current], current, "sp-palette-row-initial", opts));
}
}

Expand Down

0 comments on commit 6daf9b0

Please sign in to comment.