2021-02-18 03:53:25 +01:00
|
|
|
import videojs from 'video.js';
|
2022-04-19 18:55:32 +02:00
|
|
|
import { toCapitalCase } from 'util/string';
|
2021-02-18 03:53:25 +01:00
|
|
|
|
|
|
|
const VideoJsButtonClass = videojs.getComponent('MenuButton');
|
|
|
|
const VideoJsMenuClass = videojs.getComponent('Menu');
|
|
|
|
const VideoJsComponent = videojs.getComponent('Component');
|
|
|
|
const Dom = videojs.dom;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend vjs button class for quality button.
|
|
|
|
*/
|
|
|
|
export default class ConcreteButton extends VideoJsButtonClass {
|
|
|
|
/**
|
|
|
|
* Button constructor.
|
|
|
|
*
|
|
|
|
* @param {Player} player - videojs player instance
|
|
|
|
*/
|
|
|
|
constructor(player) {
|
|
|
|
super(player, {
|
|
|
|
title: player.localize('Quality'),
|
2021-02-18 19:45:39 +01:00
|
|
|
name: 'QualityButton',
|
2021-02-18 03:53:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates button items.
|
|
|
|
*
|
|
|
|
* @return {Array} - Button items
|
|
|
|
*/
|
|
|
|
createItems() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the menu and add all items to it.
|
|
|
|
*
|
|
|
|
* @return {Menu}
|
|
|
|
* The constructed menu
|
|
|
|
*/
|
|
|
|
createMenu() {
|
2021-02-18 19:45:39 +01:00
|
|
|
const menu = new VideoJsMenuClass(this.player_, { menuButton: this });
|
2021-02-18 03:53:25 +01:00
|
|
|
|
|
|
|
this.hideThreshold_ = 0;
|
|
|
|
|
|
|
|
// Add a title list item to the top
|
|
|
|
if (this.options_.title) {
|
|
|
|
const titleEl = Dom.createEl('li', {
|
|
|
|
className: 'vjs-menu-title',
|
2022-04-19 18:55:32 +02:00
|
|
|
innerHTML: toCapitalCase(this.options_.title),
|
2021-02-18 19:45:39 +01:00
|
|
|
tabIndex: -1,
|
2021-02-18 03:53:25 +01:00
|
|
|
});
|
2021-02-18 19:45:39 +01:00
|
|
|
const titleComponent = new VideoJsComponent(this.player_, { el: titleEl });
|
2021-02-18 03:53:25 +01:00
|
|
|
|
|
|
|
this.hideThreshold_ += 1;
|
|
|
|
|
|
|
|
menu.addItem(titleComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items = this.createItems();
|
|
|
|
|
|
|
|
if (this.items) {
|
|
|
|
// Add menu items to the menu
|
|
|
|
for (let i = 0; i < this.items.length; i++) {
|
|
|
|
menu.addItem(this.items[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
}
|