import { append, setStyle } from './utils'; export default class Info { constructor(art) { this.art = art; this.init(); } init() { const { template: { $infoClose }, events: { proxy }, } = this.art; proxy($infoClose, 'click', () => { this.hide(); }); } show() { const { $info, $infoPanel } = this.art.template; setStyle($info, 'display', 'block'); if (!$infoPanel.innerHTML) { append($infoPanel, this.creatInfo()); } clearTimeout(this.timer); this.loop(); this.art.emit('info:show', $info); } creatInfo() { const infoHtml = []; infoHtml.push(`
Player version:
__VERSION__
`); infoHtml.push(`
Video url:
${this.art.option.url}
`); infoHtml.push(`
Video volume:
`); infoHtml.push(`
Video time:
`); infoHtml.push(`
Video duration:
`); infoHtml.push(`
Video resolution:
x
`); return infoHtml.join(''); } readInfo() { const { $infoPanel, $video } = this.art.template; const types = Array.from($infoPanel.querySelectorAll('[data-video]')); types.forEach(item => { const value = $video[item.dataset.video]; item.innerHTML = value !== undefined ? value : 'unknown'; }); } loop() { this.readInfo(); this.timer = setTimeout(() => { this.readInfo(); this.loop(); }, 1000); } hide() { const { $info } = this.art.template; setStyle($info, 'display', 'none'); clearTimeout(this.timer); this.art.emit('info:hide', $info); } }