Skip to content

Commit

Permalink
fix: set the 'lang' attribute on text track display elements, if the …
Browse files Browse the repository at this point in the history
…language of the track is known (#7493)

Fixes #7487

Co-authored-by: Gary Katsevman <git@gkatsev.com>
  • Loading branch information
OwenEdwards and gkatsev authored Nov 2, 2021
1 parent 6faad26 commit f326cf3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/tracks/text-track-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ class TextTrackDisplay extends Component {

Dom.addClass(cueEl, 'vjs-text-track-cue');
Dom.addClass(cueEl, 'vjs-text-track-cue-' + ((track.language) ? track.language : i));
if (track.language) {
Dom.setAttribute(cueEl, 'lang', track.language);
}
}
if (this.player_.textTrackSettings) {
this.updateDisplayState(track);
Expand Down
45 changes: 45 additions & 0 deletions test/unit/tracks/text-tracks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,51 @@ QUnit.test('should check for text track changes when emulating text tracks', fun
tech.dispose();
});

QUnit.test('no lang attribute on cue elements if one is provided', function(assert) {
const player = TestHelpers.makePlayer();
const tt = new TextTrack({
tech: player.tech_,
mode: 'showing'
});

tt.addCue({
id: '1',
startTime: 2,
endTime: 5
});
player.tech_.textTracks().addTrack(tt);

player.currentTime(2);
player.trigger('timeupdate');

assert.notOk(tt.activeCues[0].displayState.hasAttribute('lang'), 'no lang attribute should be set');

player.dispose();
});

QUnit.test('set lang attribute on cue elements if one is provided', function(assert) {
const player = TestHelpers.makePlayer();
const tt = new TextTrack({
srclang: 'en',
tech: player.tech_,
mode: 'showing'
});

tt.addCue({
id: '1',
startTime: 2,
endTime: 5
});
player.tech_.textTracks().addTrack(tt);

player.currentTime(2);
player.trigger('timeupdate');

assert.equal(tt.activeCues[0].displayState.getAttribute('lang'), 'en', 'the lang should be set to en');

player.dispose();
});

QUnit.test('removes cuechange event when text track is hidden for emulated tracks', function(assert) {
const player = TestHelpers.makePlayer();
const tt = new TextTrack({
Expand Down

0 comments on commit f326cf3

Please sign in to comment.