cyp/app/js/elements/song.js

44 lines
932 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";
import { Item } from "../component.js";
export default class Song extends Item {
constructor(data) {
super();
this.data = data;
this.dataset.songId = data["Id"];
}
connectedCallback() {
2020-03-11 21:21:04 +08:00
let block = html.node("div", {className:"multiline"}, "", this);
2020-03-10 05:24:31 +08:00
let lines = formatSongInfo(this.data);
2020-03-11 21:21:04 +08:00
block.appendChild(this._buildTitle(lines.shift()));
2020-03-11 17:55:18 +08:00
2020-03-11 21:21:04 +08:00
lines.length && html.node("span", {className:"subtitle"}, lines.shift(), block);
2020-03-10 22:25:43 +08:00
}
2020-03-10 05:24:31 +08:00
}
customElements.define("cyp-song", Song);
// FIXME vyfaktorovat nekam do haje
function formatSongInfo(data) {
let lines = [];
if (data["Title"]) {
2020-03-11 17:55:18 +08:00
lines.push(data["Title"]);
2020-03-10 05:24:31 +08:00
lines.push(format.subtitle(data));
} else {
lines.push(fileName(data));
lines.push("\u00A0");
}
return lines;
}
// FIXME vyfaktorovat nekam do haje
function fileName(data) {
return data["file"].split("/").pop();
}