Skip to content

Commit b27f713

Browse files
misteroneillgkatsev
authored andcommitted
fix: TextTrackMenuItem components should not disable text tracks of different kind(s). (videojs#5741)
1 parent 175f773 commit b27f713

File tree

2 files changed

+84
-7
lines changed

2 files changed

+84
-7
lines changed

src/js/control-bar/text-track-controls/text-track-menu-item.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,37 @@ class TextTrackMenuItem extends MenuItem {
9393
* @listens click
9494
*/
9595
handleClick(event) {
96-
const kind = this.track.kind;
97-
let kinds = this.track.kinds;
96+
const referenceTrack = this.track;
9897
const tracks = this.player_.textTracks();
9998

100-
if (!kinds) {
101-
kinds = [kind];
102-
}
103-
10499
super.handleClick(event);
105100

106101
if (!tracks) {
107102
return;
108103
}
109104

105+
// Determine the relevant kind(s) of tracks for this component and filter
106+
// out empty kinds.
107+
const kinds = (referenceTrack.kinds || [referenceTrack.kind]).filter(Boolean);
108+
110109
for (let i = 0; i < tracks.length; i++) {
111110
const track = tracks[i];
112111

113-
if (track === this.track && (kinds.indexOf(track.kind) > -1)) {
112+
// If the track from the text tracks list is not of the right kind,
113+
// skip it. We do not want to affect tracks of incompatible kind(s).
114+
if (kinds.indexOf(track.kind) === -1) {
115+
continue;
116+
}
117+
118+
// If this text track is the component's track and it is not showing,
119+
// set it to showing.
120+
if (track === referenceTrack) {
114121
if (track.mode !== 'showing') {
115122
track.mode = 'showing';
116123
}
124+
125+
// If this text track is not the component's track and it is not
126+
// disabled, set it to disabled.
117127
} else if (track.mode !== 'disabled') {
118128
track.mode = 'disabled';
119129
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* eslint-env qunit */
2+
import TextTrackMenuItem from '../../../../src/js/control-bar/text-track-controls/text-track-menu-item.js';
3+
import TestHelpers from '../../test-helpers.js';
4+
5+
QUnit.module('TextTrackMenuItem', {
6+
beforeEach(assert) {
7+
this.player = TestHelpers.makePlayer();
8+
},
9+
afterEach(assert) {
10+
this.player.dispose();
11+
}
12+
});
13+
14+
QUnit.test('clicking should enable the selected track', function(assert) {
15+
assert.expect(2);
16+
17+
const foo = this.player.addTextTrack('captions', 'foo', 'en');
18+
19+
const fooItem = new TextTrackMenuItem(this.player, {
20+
track: foo
21+
});
22+
23+
assert.strictEqual(foo.mode, 'disabled', 'track "foo" begins "disabled"');
24+
25+
fooItem.trigger('click');
26+
27+
assert.strictEqual(foo.mode, 'showing', 'clicking set track "foo" to "showing"');
28+
29+
fooItem.dispose();
30+
});
31+
32+
QUnit.test('clicking should disable non-selected tracks of the same kind', function(assert) {
33+
assert.expect(9);
34+
35+
const foo = this.player.addTextTrack('captions', 'foo', 'en');
36+
const bar = this.player.addTextTrack('captions', 'bar', 'es');
37+
const bop = this.player.addTextTrack('metadata', 'bop');
38+
39+
bop.mode = 'hidden';
40+
41+
const fooItem = new TextTrackMenuItem(this.player, {
42+
track: foo
43+
});
44+
45+
const barItem = new TextTrackMenuItem(this.player, {
46+
track: bar
47+
});
48+
49+
assert.strictEqual(foo.mode, 'disabled', 'captions track "foo" begins "disabled"');
50+
assert.strictEqual(bar.mode, 'disabled', 'captions track "bar" begins "disabled"');
51+
assert.strictEqual(bop.mode, 'hidden', 'metadata track "bop" is "hidden"');
52+
53+
barItem.trigger('click');
54+
55+
assert.strictEqual(foo.mode, 'disabled', 'captions track "foo" is still "disabled"');
56+
assert.strictEqual(bar.mode, 'showing', 'captions track "bar" is now "showing"');
57+
assert.strictEqual(bop.mode, 'hidden', 'metadata track "bop" is still "hidden"');
58+
59+
fooItem.trigger('click');
60+
61+
assert.strictEqual(foo.mode, 'showing', 'captions track "foo" is now "showing"');
62+
assert.strictEqual(bar.mode, 'disabled', 'captions track "bar" is now "disabled"');
63+
assert.strictEqual(bop.mode, 'hidden', 'metadata track "bop" is still "hidden"');
64+
65+
fooItem.dispose();
66+
barItem.dispose();
67+
});

0 commit comments

Comments
 (0)