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

add datalist support #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@
return unique.reverse().slice(0, opts.maxSelectionSize);
}

function readDatalistPalette() {
var listID = $(element).attr('list');
if(listID) {
option("showPalette", true);
option("palette", $("datalist#" + listID).find("option").filter(function() {
return !$(this).is(":disabled") && $.trim(this.value) !== "";
}).map(function() {
return this.value;
}).toArray());
}
}

function drawPalette() {

var currentColor = get();
Expand Down Expand Up @@ -617,6 +629,8 @@
return;
}

readDatalistPalette();

hideAll();
visible = true;

Expand Down
16 changes: 16 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ test( "Palette click events work ", function() {

});

test( "Palette defined in html datalist is read", function() {
var container = $("<input id='spec' value='red' list='testlist' /><datalist id='testlist'>" +
"<option>#00FF00</option><option>#FF00FF</option></datalist>").appendTo("body");
var el = $("#spec").spectrum({
palette: [
["red", "green", "blue"]
]
});

el.spectrum("show");
deepEqual (
el.spectrum("option", "palette"), ["#00FF00", "#FF00FF"],
"datalist should replace default palette"
);
});

test( "hideAfterPaletteSelect: Palette stays open after color select", function() {
var el = $("<input id='spec' value='red' />").spectrum({
showPalette: true,
Expand Down