diff options
author | Sam Potts <sam@potts.es> | 2018-06-17 00:40:56 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-17 00:40:56 +1000 |
commit | 828ce6694232f60d2fb463505757ccc767ae6c3b (patch) | |
tree | e4440ab6863653d0a1c731d4161edd16a0fcfe9b /src | |
parent | ccc2608cf62f1406c3d626ed8dbd31f1acd714ce (diff) | |
parent | 8f359adf9c510a2c4c5a9fc4ecea542c2b782083 (diff) | |
download | plyr-828ce6694232f60d2fb463505757ccc767ae6c3b.tar.lz plyr-828ce6694232f60d2fb463505757ccc767ae6c3b.tar.xz plyr-828ce6694232f60d2fb463505757ccc767ae6c3b.zip |
Merge pull request #1038 from friday/captions-input-lowercase
Small captions fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/js/captions.js | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/js/captions.js b/src/js/captions.js index fd2692f7..94500290 100644 --- a/src/js/captions.js +++ b/src/js/captions.js @@ -71,7 +71,7 @@ const captions = { const languages = dedupe(Array.from(navigator.languages || navigator.userLanguage) .map(language => language.split('-')[0])); - let language = this.storage.get('language') || this.config.captions.language; + let language = (this.storage.get('language') || this.config.captions.language || 'auto').toLowerCase(); // Use first browser language when language is 'auto' if (language === 'auto') { @@ -156,6 +156,12 @@ const captions = { // Update state and trigger event if (active !== toggled) { + // When passive, don't override user preferences + if (!passive) { + this.captions.active = active; + this.storage.set({ captions: active }); + } + // Force language if the call isn't passive and there is no matching language to toggle to if (!this.language && active && !passive) { const tracks = captions.getTracks.call(this); @@ -183,12 +189,6 @@ const captions = { // Update settings menu controls.updateSetting.call(this, 'captions'); - // When passive, don't override user preferences - if (!passive) { - this.captions.active = active; - this.storage.set({ captions: active }); - } - // Trigger event (not used internally) triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled'); } @@ -241,24 +241,25 @@ const captions = { triggerEvent.call(this, this.media, 'languagechange'); } + // Show captions + captions.toggle.call(this, true, passive); + if (this.isHTML5 && this.isVideo) { // If we change the active track while a cue is already displayed we need to update it captions.updateCues.call(this); } - - // Show captions - captions.toggle.call(this, true, passive); }, // Set captions by language // Used internally for the language setter with the passive option forced to false - setLanguage(language, passive = true) { - if (!is.string(language)) { - this.debug.warn('Invalid language argument', language); + setLanguage(input, passive = true) { + if (!is.string(input)) { + this.debug.warn('Invalid language argument', input); return; } // Normalize - this.captions.language = language.toLowerCase(); + const language = input.toLowerCase(); + this.captions.language = language; // Set currentTrack const tracks = captions.getTracks.call(this); |