This commit is contained in:
Ondrej Zara 2019-04-01 15:16:39 +02:00
parent 2a11e6f886
commit e0bbd1107b
5 changed files with 34 additions and 8 deletions

View file

@ -42,7 +42,7 @@ button {
flex-shrink: 0; flex-shrink: 0;
} }
button .icon { button .icon {
vertical-align: top; vertical-align: middle;
} }
.long-line { .long-line {
white-space: nowrap; white-space: nowrap;

View file

@ -40,7 +40,7 @@ button {
cursor: pointer; cursor: pointer;
flex-shrink: 0; flex-shrink: 0;
.icon { vertical-align: top; } .icon { vertical-align: middle; }
} }
.long-line { .long-line {

View file

@ -22,6 +22,7 @@ function buildHeader(path) {
button.addEventListener("click", e => list(path)); button.addEventListener("click", e => list(path));
}); });
search.reset();
header.appendChild(search.getNode()); header.appendChild(search.getNode());
} }
@ -30,11 +31,15 @@ function buildDirectory(data, parent) {
let name = path.split("/").pop(); let name = path.split("/").pop();
let node = ui.group(ui.CTX_FS, name, path, parent); let node = ui.group(ui.CTX_FS, name, path, parent);
node.addEventListener("click", e => list(path)); node.addEventListener("click", e => list(path));
node.dataset.name = name;
return node; return node;
} }
function buildFile(data, parent) { function buildFile(data, parent) {
return ui.song(ui.CTX_FS, data, parent); let node = ui.song(ui.CTX_FS, data, parent);
let name = data["file"].split("/").pop();
node.dataset.name = name;
return node;
} }
function buildResults(results) { function buildResults(results) {
@ -52,7 +57,10 @@ async function list(path) {
} }
function onSearch(e) { function onSearch(e) {
Array.from(node.querySelectorAll("[data-name]")).forEach(node => {
let name = node.dataset.name;
node.style.display = (search.match(name) ? "" : "none");
});
} }
export async function activate() { export async function activate() {

View file

@ -18,16 +18,25 @@ export default class Search extends EventTarget {
this._node.addEventListener("click", e => { this._node.addEventListener("click", e => {
if (e.target == this._input) { return; } if (e.target == this._input) { return; }
if (this._node.classList.contains(OPEN)) { if (this._node.classList.contains(OPEN)) {
this.reset() this.reset();
this.dispatchEvent(new Event("input"));
} else { } else {
this._node.classList.add(OPEN); this._node.classList.add(OPEN);
} }
}); });
this._input.addEventListener("input", e => {
this.dispatchEvent(new Event("input"));
});
} }
getNode() { return this._node; } getNode() { return this._node; }
getValue() { return this._input.value; } match(str) {
let q = normalize(this._input.value.trim());
if (!q) { return true; }
return normalize(str).split(" ").some(str => str.indexOf(q) == 0);
}
reset() { reset() {
this._input.value = ""; this._input.value = "";

View file

@ -30,6 +30,7 @@ function buildHeader(filter) {
} }
} }
search.reset();
header.appendChild(search.getNode()); header.appendChild(search.getNode());
} }
@ -37,6 +38,7 @@ function buildAlbum(album, filter, parent) {
let childFilter = Object.assign({}, filter, {"Album": album}); let childFilter = Object.assign({}, filter, {"Album": album});
let node = ui.group(ui.CTX_LIBRARY, album, childFilter, parent); let node = ui.group(ui.CTX_LIBRARY, album, childFilter, parent);
node.addEventListener("click", e => listSongs(childFilter)); node.addEventListener("click", e => listSongs(childFilter));
node.dataset.name = album;
return node; return node;
} }
@ -44,6 +46,7 @@ function buildArtist(artist, filter, parent) {
let childFilter = Object.assign({}, filter, {"Artist": artist}); let childFilter = Object.assign({}, filter, {"Artist": artist});
let node = ui.group(ui.CTX_LIBRARY, artist, childFilter, parent); let node = ui.group(ui.CTX_LIBRARY, artist, childFilter, parent);
node.addEventListener("click", e => listAlbums(childFilter)); node.addEventListener("click", e => listAlbums(childFilter));
node.dataset.name = artist;
return node; return node;
} }
@ -51,7 +54,10 @@ function buildSongs(songs, filter) {
let ul = node.querySelector("ul"); let ul = node.querySelector("ul");
html.clear(ul); html.clear(ul);
songs.map(song => ui.song(ui.CTX_LIBRARY, song, ul)); songs.map(song => {
let node = ui.song(ui.CTX_LIBRARY, song, ul);
node.dataset.name = song["Title"];
});
} }
function buildAlbums(albums, filter) { function buildAlbums(albums, filter) {
@ -87,7 +93,10 @@ async function listArtists(filter) {
} }
function onSearch(e) { function onSearch(e) {
Array.from(node.querySelectorAll("[data-name]")).forEach(node => {
let name = node.dataset.name;
node.style.display = (search.match(name) ? "" : "none");
});
} }
export async function activate() { export async function activate() {