]>
Commit | Line | Data |
---|---|---|
512decf3 | 1 | import videojs from 'video.js' |
c6352f2c C |
2 | import { ResolutionMenuItem } from './resolution-menu-item' |
3 | ||
f5fcd9f7 C |
4 | const Menu = videojs.getComponent('Menu') |
5 | const MenuButton = videojs.getComponent('MenuButton') | |
c6352f2c | 6 | class ResolutionMenuButton extends MenuButton { |
f5fcd9f7 | 7 | labelEl_: HTMLElement |
c6352f2c | 8 | |
7e37e111 | 9 | constructor (player: videojs.Player, options?: videojs.MenuButtonOptions) { |
c6352f2c | 10 | super(player, options) |
c6352f2c | 11 | |
f5fcd9f7 C |
12 | this.controlText('Quality') |
13 | ||
e367da94 | 14 | player.peertubeResolutions().on('resolutionsAdded', () => this.buildQualities()) |
2adfc7ea | 15 | |
e367da94 C |
16 | // For parent |
17 | player.peertubeResolutions().on('resolutionChanged', () => { | |
18 | setTimeout(() => this.trigger('labelUpdated')) | |
19 | }) | |
c6352f2c C |
20 | } |
21 | ||
22 | createEl () { | |
23 | const el = super.createEl() | |
24 | ||
f5fcd9f7 | 25 | this.labelEl_ = videojs.dom.createEl('div', { |
2adfc7ea | 26 | className: 'vjs-resolution-value' |
f5fcd9f7 | 27 | }) as HTMLElement |
c6352f2c C |
28 | |
29 | el.appendChild(this.labelEl_) | |
30 | ||
31 | return el | |
32 | } | |
33 | ||
34 | updateARIAAttributes () { | |
35 | this.el().setAttribute('aria-label', 'Quality') | |
36 | } | |
37 | ||
38 | createMenu () { | |
2adfc7ea C |
39 | return new Menu(this.player_) |
40 | } | |
41 | ||
42 | buildCSSClass () { | |
43 | return super.buildCSSClass() + ' vjs-resolution-button' | |
44 | } | |
3a6f351b | 45 | |
2adfc7ea C |
46 | buildWrapperCSSClass () { |
47 | return 'vjs-resolution-control ' + super.buildWrapperCSSClass() | |
48 | } | |
49 | ||
3b6f205c C |
50 | private addClickListener (component: any) { |
51 | component.on('click', () => { | |
c4710631 | 52 | const children = this.menu.children() |
3b6f205c C |
53 | |
54 | for (const child of children) { | |
55 | if (component !== child) { | |
f5fcd9f7 | 56 | (child as videojs.MenuItem).selected(false) |
3b6f205c C |
57 | } |
58 | } | |
59 | }) | |
60 | } | |
61 | ||
e367da94 C |
62 | private buildQualities () { |
63 | for (const d of this.player().peertubeResolutions().getResolutions()) { | |
8ff604c7 | 64 | const label = d.label === '0p' |
f5fcd9f7 | 65 | ? this.player().localize('Audio-only') |
3a149e9f C |
66 | : d.label |
67 | ||
2adfc7ea | 68 | this.menu.addChild(new ResolutionMenuItem( |
c6352f2c C |
69 | this.player_, |
70 | { | |
2adfc7ea | 71 | id: d.id, |
3a149e9f | 72 | label, |
e367da94 | 73 | selected: d.selected |
c6352f2c C |
74 | }) |
75 | ) | |
76 | } | |
77 | ||
3b6f205c C |
78 | for (const m of this.menu.children()) { |
79 | this.addClickListener(m) | |
80 | } | |
81 | ||
82 | this.trigger('menuChanged') | |
a8462c8e | 83 | } |
c6352f2c | 84 | } |
e945b184 | 85 | |
f5fcd9f7 | 86 | videojs.registerComponent('ResolutionMenuButton', ResolutionMenuButton) |