cyp/app/js/elements/song.js

39 lines
982 B
JavaScript
Raw Normal View History

2020-03-10 05:24:31 +08:00
import * as format from "../format.js";
import * as html from "../html.js";
2020-03-12 05:46:28 +08:00
import Item from "../item.js";
2020-03-10 05:24:31 +08:00
export default class Song extends Item {
constructor(data) {
super();
2020-03-14 06:01:16 +08:00
this._data = data;
2020-03-10 05:24:31 +08:00
}
2020-03-14 06:01:16 +08:00
get file() { return this._data["file"]; }
get songId() { return this._data["Id"]; }
2020-03-10 05:24:31 +08:00
connectedCallback() {
2020-03-14 06:01:16 +08:00
const data = this._data;
2020-03-13 17:36:13 +08:00
const block = html.node("div", {className:"multiline"}, "", this);
const title = this._buildTitle(data);
block.appendChild(title);
if (data["Track"]) {
const track = html.node("span", {className:"track"}, data["Track"].padStart(2, "0"));
title.insertBefore(html.text(" "), title.firstChild);
title.insertBefore(track, title.firstChild);
}
if (data["Title"]) {
const subtitle = format.subtitle(data);
html.node("span", {className:"subtitle"}, subtitle, block);
}
}
2020-03-11 17:55:18 +08:00
2020-03-13 17:36:13 +08:00
_buildTitle(data) {
2020-03-14 06:01:16 +08:00
return super._buildTitle(data["Title"] || format.fileName(this.file));
2020-03-10 22:25:43 +08:00
}
2020-03-10 05:24:31 +08:00
}
customElements.define("cyp-song", Song);