Files
ArtPlayer/packages/artplayer/src/notice.js
T
2019-04-30 15:10:30 +08:00

28 lines
784 B
JavaScript

export default class Notice {
constructor(art) {
this.art = art;
this.timer = null;
}
show(msg, autoHide = true, time = 1000) {
const { $player, $noticeInner } = this.art.template;
this.state = true;
$player.classList.add('artplayer-notice-show');
$noticeInner.innerHTML = msg instanceof Error ? msg.message.trim() : msg;
clearTimeout(this.timer);
if (autoHide) {
this.timer = setTimeout(() => {
this.hide();
}, time);
}
this.art.emit('notice:show');
}
hide() {
const { $player } = this.art.template;
this.state = false;
$player.classList.remove('artplayer-notice-show');
this.art.emit('notice:hide');
}
}