Merge pull request #1038 from friday/captions-input-lowercase

Small captions fixes
This commit is contained in:
Sam Potts 2018-06-17 00:40:56 +10:00 committed by GitHub
commit 828ce66942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,7 +71,7 @@ const captions = {
const languages = dedupe(Array.from(navigator.languages || navigator.userLanguage) const languages = dedupe(Array.from(navigator.languages || navigator.userLanguage)
.map(language => language.split('-')[0])); .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' // Use first browser language when language is 'auto'
if (language === 'auto') { if (language === 'auto') {
@ -156,6 +156,12 @@ const captions = {
// Update state and trigger event // Update state and trigger event
if (active !== toggled) { 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 // Force language if the call isn't passive and there is no matching language to toggle to
if (!this.language && active && !passive) { if (!this.language && active && !passive) {
const tracks = captions.getTracks.call(this); const tracks = captions.getTracks.call(this);
@ -183,12 +189,6 @@ const captions = {
// Update settings menu // Update settings menu
controls.updateSetting.call(this, 'captions'); 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) // Trigger event (not used internally)
triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled'); triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled');
} }
@ -241,24 +241,25 @@ const captions = {
triggerEvent.call(this, this.media, 'languagechange'); triggerEvent.call(this, this.media, 'languagechange');
} }
// Show captions
captions.toggle.call(this, true, passive);
if (this.isHTML5 && this.isVideo) { if (this.isHTML5 && this.isVideo) {
// If we change the active track while a cue is already displayed we need to update it // If we change the active track while a cue is already displayed we need to update it
captions.updateCues.call(this); captions.updateCues.call(this);
} }
// Show captions
captions.toggle.call(this, true, passive);
}, },
// Set captions by language // Set captions by language
// Used internally for the language setter with the passive option forced to false // Used internally for the language setter with the passive option forced to false
setLanguage(language, passive = true) { setLanguage(input, passive = true) {
if (!is.string(language)) { if (!is.string(input)) {
this.debug.warn('Invalid language argument', language); this.debug.warn('Invalid language argument', input);
return; return;
} }
// Normalize // Normalize
this.captions.language = language.toLowerCase(); const language = input.toLowerCase();
this.captions.language = language;
// Set currentTrack // Set currentTrack
const tracks = captions.getTracks.call(this); const tracks = captions.getTracks.call(this);