diff options
author | Sam Potts <sam@potts.es> | 2018-04-17 22:49:28 +1000 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-04-17 22:49:28 +1000 |
commit | 46fe3eecff478a80636f538a9f843bb0f21f4802 (patch) | |
tree | 65dc653a626b466e02e5f4133cf10d47c08ec34f /src/js/controls.js | |
parent | 3061a701d57ab04a3b48ebe5174e9c9bef8d6d7d (diff) | |
download | plyr-46fe3eecff478a80636f538a9f843bb0f21f4802.tar.lz plyr-46fe3eecff478a80636f538a9f843bb0f21f4802.tar.xz plyr-46fe3eecff478a80636f538a9f843bb0f21f4802.zip |
Fixed bug for captions with no srclang and labels and improved logic (fixes #875)
Diffstat (limited to 'src/js/controls.js')
-rw-r--r-- | src/js/controls.js | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/src/js/controls.js b/src/js/controls.js index 160c3665..c44cd13a 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -456,6 +456,9 @@ const controls = { const toggle = !utils.is.empty(this.options.quality) && this.options.quality.length > 1; controls.toggleTab.call(this, type, toggle); + // Check if we need to toggle the parent + controls.checkMenu.call(this); + // If we're hiding, nothing more to do if (!toggle) { return; @@ -495,13 +498,15 @@ const controls = { }; // Sort options by the config and then render options - this.options.quality.sort((a, b) => { - const sorting = this.config.quality.options; - return sorting.indexOf(a) > sorting.indexOf(b) ? 1 : -1; - }).forEach(quality => { - const label = controls.getLabel.call(this, 'quality', quality); - controls.createMenuItem.call(this, quality, list, type, label, getBadge(quality)); - }); + this.options.quality + .sort((a, b) => { + const sorting = this.config.quality.options; + return sorting.indexOf(a) > sorting.indexOf(b) ? 1 : -1; + }) + .forEach(quality => { + const label = controls.getLabel.call(this, 'quality', quality); + controls.createMenuItem.call(this, quality, list, type, label, getBadge(quality)); + }); controls.updateSetting.call(this, type, list); }, @@ -517,10 +522,11 @@ const controls = { if (utils.is.number(value)) { return `${value}p`; } + return utils.toTitleCase(value); case 'captions': - return controls.getLanguage.call(this); + return captions.getLabel.call(this); default: return null; @@ -535,7 +541,16 @@ const controls = { switch (setting) { case 'captions': - value = this.captions.active ? this.captions.language : i18n.get('disabled', this.config); + if (this.captions.active) { + if (this.options.captions.length > 2 || !this.options.captions.some(lang => lang === 'enabled')) { + value = this.captions.language; + } else { + value = 'enabled'; + } + } else { + value = ''; + } + break; default: @@ -567,16 +582,13 @@ const controls = { } // Update the label - if (!utils.is.empty(value)) { - const label = this.elements.settings.tabs[setting].querySelector(`.${this.config.classNames.menu.value}`); - label.innerHTML = controls.getLabel.call(this, setting, value); - } + const label = this.elements.settings.tabs[setting].querySelector(`.${this.config.classNames.menu.value}`); + label.innerHTML = controls.getLabel.call(this, setting, value); - // Find the radio option + // Find the radio option and check it const target = list && list.querySelector(`input[value="${value}"]`); if (utils.is.element(target)) { - // Check it target.checked = true; } }, @@ -627,21 +639,7 @@ const controls = { // Get current selected caption language // TODO: rework this to user the getter in the API? - getLanguage() { - if (!this.supported.ui) { - return null; - } - - if (support.textTracks && captions.getTracks.call(this).length && this.captions.active) { - const currentTrack = captions.getCurrentTrack.call(this); - - if (utils.is.track(currentTrack)) { - return currentTrack.label; - } - } - return i18n.get('disabled', this.config); - }, // Set a list of available captions languages setCaptionsMenu() { @@ -656,6 +654,9 @@ const controls = { // Empty the menu utils.emptyElement(list); + // Check if we need to toggle the parent + controls.checkMenu.call(this); + // If there's no captions, bail if (!toggle) { return; @@ -663,8 +664,8 @@ const controls = { // Re-map the tracks into just the data we need const tracks = captions.getTracks.call(this).map(track => ({ - language: track.language, - label: !utils.is.empty(track.label) ? track.label : track.language.toUpperCase(), + language: !utils.is.empty(track.language) ? track.language : 'enabled', + label: captions.getLabel.call(this, track), })); // Add the "Disabled" option to turn off captions @@ -680,12 +681,15 @@ const controls = { track.language, list, 'language', - track.label || track.language, - controls.createBadge.call(this, track.language.toUpperCase()), + track.label, + track.language !== 'enabled' ? controls.createBadge.call(this, track.language.toUpperCase()) : null, track.language.toLowerCase() === this.captions.language.toLowerCase(), ); }); + // Store reference + this.options.captions = tracks.map(track => track.language); + controls.updateSetting.call(this, type, list); }, @@ -1211,7 +1215,7 @@ const controls = { seektime: this.config.seekTime, speed: this.speed, quality: this.quality, - captions: controls.getLanguage.call(this), + captions: captions.getLabel.call(this), // TODO: Looping // loop: 'None', }); |