1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-09-10 09:49:54 +00:00

json & web search

This commit is contained in:
Laura
2025-08-11 00:15:58 +02:00
parent 5ae60e0f94
commit a8cbef7c7b
19 changed files with 374 additions and 59 deletions

View File

@@ -5,13 +5,15 @@
#_selected;
#_search;
#maxTags = false;
#search = false;
#selected = false;
#options = [];
constructor(el) {
constructor(el, maxTags = false) {
this.#_select = el;
this.#maxTags = maxTags;
this.#search = "searchable" in el.dataset;
this.#_select.querySelectorAll("option").forEach((option) => {
@@ -101,15 +103,23 @@
_opt.appendChild(_label);
// option tags (optional)
if (option.tags?.length) {
const tags = option.tags;
if (option.tags.length) {
const _tags = make("div", "tags");
for (const tag of option.tags) {
const _tag = make("div", "tag", tag);
_tags.title = `${this.#maxTags ? `${tags.length}/${this.#maxTags}: ` : ""}${tags.join(", ")}`;
_tag.title = tag;
if (this.#maxTags && tags.length >= this.#maxTags) {
const _all = make("div", "tag", "all");
_tags.appendChild(_tag);
_tags.appendChild(_all);
} else {
for (const tag of tags) {
const _tag = make("div", "tag", tag);
_tags.appendChild(_tag);
}
}
_opt.appendChild(_tags);
@@ -220,5 +230,5 @@
});
});
window.dropdown = (el) => new Dropdown(el);
window.dropdown = (el, maxTags = false) => new Dropdown(el, maxTags);
})();