From c1159a54487b1995cb14a0ab135b38b87d7ce97d Mon Sep 17 00:00:00 2001 From: yuusora Date: Thu, 13 Jan 2022 09:24:28 +0800 Subject: [PATCH] feat(sub): init old subtitle btn only url string --- src/js/controller.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index cec22f0..bb108c7 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -28,7 +28,12 @@ class Controller { this.initFullButton(); this.initQualityButton(); this.initScreenshotButton(); - this.initSubtitleButton(); + // if subtitle url not array, not init old single subtitle button + if (this.player.options.subtitle) { + if (typeof this.player.options.subtitle.url === 'string') { + this.initSubtitleButton(); + } + } this.initHighlights(); this.initAirplayButton(); if (!utils.isMobile) { @@ -280,22 +285,20 @@ class Controller { } initSubtitleButton() { - if (this.player.options.subtitle) { - this.player.events.on('subtitle_show', () => { - this.player.template.subtitleButton.dataset.balloon = this.player.tran('Hide subtitle'); - this.player.template.subtitleButtonInner.style.opacity = ''; - this.player.user.set('subtitle', 1); - }); - this.player.events.on('subtitle_hide', () => { - this.player.template.subtitleButton.dataset.balloon = this.player.tran('Show subtitle'); - this.player.template.subtitleButtonInner.style.opacity = '0.4'; - this.player.user.set('subtitle', 0); - }); + this.player.events.on('subtitle_show', () => { + this.player.template.subtitleButton.dataset.balloon = this.player.tran('Hide subtitle'); + this.player.template.subtitleButtonInner.style.opacity = ''; + this.player.user.set('subtitle', 1); + }); + this.player.events.on('subtitle_hide', () => { + this.player.template.subtitleButton.dataset.balloon = this.player.tran('Show subtitle'); + this.player.template.subtitleButtonInner.style.opacity = '0.4'; + this.player.user.set('subtitle', 0); + }); - this.player.template.subtitleButton.addEventListener('click', () => { - this.player.subtitle.toggle(); - }); - } + this.player.template.subtitleButton.addEventListener('click', () => { + this.player.subtitle.toggle(); + }); } setAutoHide() {