2019-03-31 06:15:32 +08:00
|
|
|
import * as html from "./html.js";
|
|
|
|
|
2019-04-01 04:02:26 +08:00
|
|
|
const OPEN = "open";
|
|
|
|
|
2019-03-31 06:15:32 +08:00
|
|
|
export function normalize(str) {
|
|
|
|
// FIXME diac/translit
|
|
|
|
return str.toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Search extends EventTarget {
|
|
|
|
constructor(parent) {
|
|
|
|
super();
|
2019-04-01 04:02:26 +08:00
|
|
|
this._node = html.node("label", {className:"search"});
|
|
|
|
|
|
|
|
this._input = html.node("input", {type:"text"}, "", this._node);
|
|
|
|
html.icon("magnify", this._node);
|
|
|
|
|
|
|
|
this._node.addEventListener("click", e => {
|
|
|
|
if (e.target == this._input) { return; }
|
|
|
|
if (this._node.classList.contains(OPEN)) {
|
|
|
|
this.reset()
|
|
|
|
} else {
|
|
|
|
this._node.classList.add(OPEN);
|
|
|
|
}
|
|
|
|
});
|
2019-03-31 06:15:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
getNode() { return this._node; }
|
|
|
|
|
|
|
|
getValue() { return this._input.value; }
|
|
|
|
|
2019-04-01 04:02:26 +08:00
|
|
|
reset() {
|
|
|
|
this._input.value = "";
|
|
|
|
this._node.classList.remove(OPEN);
|
|
|
|
}
|
2019-03-31 06:15:32 +08:00
|
|
|
}
|