Ensure language is set in case the track is added after initialization, and trigger languagechange event when language is initially set
This commit is contained in:
@ -16,17 +16,6 @@ const captions = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default language if not set
|
|
||||||
const stored = this.storage.get('language');
|
|
||||||
|
|
||||||
if (!utils.is.empty(stored)) {
|
|
||||||
this.captions.language = stored;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (utils.is.empty(this.captions.language)) {
|
|
||||||
this.captions.language = this.config.captions.language.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only Vimeo and HTML5 video supported at this point
|
// Only Vimeo and HTML5 video supported at this point
|
||||||
if (!this.isVideo || this.isYouTube || (this.isHTML5 && !support.textTracks)) {
|
if (!this.isVideo || this.isYouTube || (this.isHTML5 && !support.textTracks)) {
|
||||||
// Clear menu and hide
|
// Clear menu and hide
|
||||||
@ -93,8 +82,14 @@ const captions = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
// Set language
|
// Update tracks
|
||||||
captions.setLanguage.call(this);
|
const tracks = captions.getTracks.call(this);
|
||||||
|
this.options.captions = tracks.map(({language}) => language);
|
||||||
|
|
||||||
|
// Set language if it hasn't been set already
|
||||||
|
if (!this.language) {
|
||||||
|
this.language = this.storage.get('language') || (this.config.captions.language || '').toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
// Toggle the class hooks
|
// Toggle the class hooks
|
||||||
utils.toggleClass(this.elements.container, this.config.classNames.captions.enabled, !utils.is.empty(captions.getTracks.call(this)));
|
utils.toggleClass(this.elements.container, this.config.classNames.captions.enabled, !utils.is.empty(captions.getTracks.call(this)));
|
||||||
|
5
src/js/controls.js
vendored
5
src/js/controls.js
vendored
@ -883,13 +883,10 @@ const controls = {
|
|||||||
'language',
|
'language',
|
||||||
track.label,
|
track.label,
|
||||||
track.language !== 'enabled' ? controls.createBadge.call(this, track.language.toUpperCase()) : null,
|
track.language !== 'enabled' ? controls.createBadge.call(this, track.language.toUpperCase()) : null,
|
||||||
track.language.toLowerCase() === this.captions.language.toLowerCase(),
|
track.language.toLowerCase() === this.language,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store reference
|
|
||||||
this.options.captions = tracks.map(track => track.language);
|
|
||||||
|
|
||||||
controls.updateSetting.call(this, type, list);
|
controls.updateSetting.call(this, type, list);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user