2020-03-10 05:24:31 +08:00
|
|
|
import Selection from "./selection.js";
|
2020-03-09 05:11:46 +08:00
|
|
|
|
2020-03-09 16:26:10 +08:00
|
|
|
|
2020-03-16 06:14:55 +08:00
|
|
|
export default class Component extends HTMLElement {
|
2020-03-10 17:42:13 +08:00
|
|
|
constructor(options = {}) {
|
2020-03-09 05:11:46 +08:00
|
|
|
super();
|
2020-03-10 17:07:30 +08:00
|
|
|
if (options.selection) { this.selection = new Selection(this, options.selection); }
|
2020-03-09 21:26:39 +08:00
|
|
|
}
|
2020-03-09 05:11:46 +08:00
|
|
|
|
2020-03-09 21:26:39 +08:00
|
|
|
connectedCallback() {
|
2020-03-17 05:57:13 +08:00
|
|
|
if (this.selection) {
|
|
|
|
const parent = this._app.querySelector("footer");
|
|
|
|
this.selection.appendTo(parent);
|
|
|
|
}
|
2020-03-09 16:26:10 +08:00
|
|
|
this._app.addEventListener("load", _ => this._onAppLoad());
|
|
|
|
this._app.addEventListener("component-change", _ => {
|
2020-03-13 23:52:24 +08:00
|
|
|
const component = this._app.component;
|
2020-03-09 16:26:10 +08:00
|
|
|
const isThis = (this.nodeName.toLowerCase() == `cyp-${component}`);
|
|
|
|
this._onComponentChange(component, isThis);
|
2020-03-09 05:11:46 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-16 06:14:55 +08:00
|
|
|
get _app() { return this.closest("cyp-app"); }
|
|
|
|
get _mpd() { return this._app.mpd; }
|
|
|
|
|
2020-03-09 16:26:10 +08:00
|
|
|
_onAppLoad() {}
|
2020-03-10 05:24:31 +08:00
|
|
|
_onComponentChange(_component, _isThis) {}
|
2020-03-09 01:06:54 +08:00
|
|
|
}
|