cyp/app/js/item.js

27 lines
585 B
JavaScript
Raw Permalink Normal View History

2020-03-12 05:46:28 +08:00
import * as html from "./html.js";
2020-03-16 06:14:55 +08:00
export default class Item extends HTMLElement {
2020-03-12 05:46:28 +08:00
constructor() {
super();
this.addEventListener("click", _ => this.onClick());
}
2020-03-13 06:03:26 +08:00
addButton(icon, cb) {
html.button({icon}, "", this).addEventListener("click", e => {
e.stopPropagation(); // do not select
cb();
});
}
2020-03-12 05:46:28 +08:00
onClick() { this.parentNode.selection.toggle(this); }
_buildTitle(title) {
return html.node("span", {className:"title"}, title, this);
}
2020-06-24 20:22:29 +08:00
matchPrefix(prefix) {
return this.textContent.match(/\w+/g).some(word => word.toLowerCase().startsWith(prefix));
}
2020-03-12 05:46:28 +08:00
}