Files
shaka-player/ui/settings_menu.js
T
Álvaro Velad Galván 1c8539698c feat(UI): Modernization of the UI (#8409)
Changes:
- The look has been changed to make it more similar to YouTube:
  - The main background color is now black, and the font is white.
  - Presentation time has been moved to the bottom.
  - Cast and airplay buttons are now more accessible.
  - Tooltips have been enabled except on mobile platforms.
- The ad information has been moved to appear in the same position as
the presentation time when the ad is present.
- A mark indicating the current quality has been added (e.g.: HD, 2K,
4K, 8K)
- The spinner has been replaced with one that works well on Smart TVs
and is very similar to the current one. The animation is included in the
SVG element itself rather than through CSS.
- More LESS variables have been added to make customization easier in
forks.
- The maximum size of the menus is dynamically calculated so that they
never extend outside the video container.
- The size of the subtitle container when the UI appears is now
calculated dynamically.
- The Demo has been updated to show the seekbar when trickplays are
enabled.
- UI performance on Smart TVs has been improved (Tested on Tizen 5.0)
- Many offsets that were hardcoded have been removed, but not all (in
CSS).

Close https://github.com/shaka-project/shaka-player/issues/8406
2025-04-08 13:46:23 +02:00

176 lines
5.3 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shaka.ui.SettingsMenu');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Enums');
goog.require('shaka.ui.Utils');
goog.require('shaka.util.Dom');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.Iterables');
goog.requireType('shaka.ui.Controls');
/**
* @extends {shaka.ui.Element}
* @implements {shaka.extern.IUISettingsMenu}
* @export
*/
shaka.ui.SettingsMenu = class extends shaka.ui.Element {
/**
* @param {!HTMLElement} parent
* @param {!shaka.ui.Controls} controls
* @param {string} iconText
*/
constructor(parent, controls, iconText) {
super(parent, controls);
/** @private {HTMLElement } */
this.videoContainer_ = this.controls.getVideoContainer();
this.addButton_(iconText);
this.addMenu_();
this.inOverflowMenu_();
this.eventManager.listen(this.button, 'click', () => {
if (!this.controls.isOpaque()) {
return;
}
this.onButtonClick_();
});
}
/**
* @param {string} iconText
* @private
*/
addButton_(iconText) {
/** @protected {!HTMLButtonElement} */
this.button = shaka.util.Dom.createButton();
this.button.classList.add('shaka-overflow-button');
/** @protected {!HTMLElement}*/
this.icon = shaka.util.Dom.createHTMLElement('i');
this.icon.classList.add('material-icons-round');
this.icon.textContent = iconText;
this.button.appendChild(this.icon);
const label = shaka.util.Dom.createHTMLElement('label');
label.classList.add('shaka-overflow-button-label');
label.classList.add('shaka-overflow-menu-only');
label.classList.add('shaka-overflow-button-label-inline');
/** @protected {!HTMLElement}*/
this.nameSpan = shaka.util.Dom.createHTMLElement('span');
label.appendChild(this.nameSpan);
/** @protected {!HTMLElement}*/
this.currentSelection = shaka.util.Dom.createHTMLElement('span');
this.currentSelection.classList.add('shaka-current-selection-span');
label.appendChild(this.currentSelection);
this.button.appendChild(label);
this.parent.appendChild(this.button);
}
/** @private */
addMenu_() {
/** @protected {!HTMLElement}*/
this.menu = shaka.util.Dom.createHTMLElement('div');
this.menu.classList.add('shaka-no-propagation');
this.menu.classList.add('shaka-show-controls-on-mouse-over');
this.menu.classList.add('shaka-settings-menu');
this.menu.classList.add('shaka-hidden');
/** @protected {!HTMLButtonElement}*/
this.backButton = shaka.util.Dom.createButton();
this.backButton.classList.add('shaka-back-to-overflow-button');
this.menu.appendChild(this.backButton);
this.eventManager.listen(this.backButton, 'click', () => {
this.controls.hideSettingsMenus();
});
const backIcon = shaka.util.Dom.createHTMLElement('i');
backIcon.classList.add('material-icons-round');
backIcon.textContent = shaka.ui.Enums.MaterialDesignIcons.CLOSE;
this.backButton.appendChild(backIcon);
/** @protected {!HTMLElement}*/
this.backSpan = shaka.util.Dom.createHTMLElement('span');
this.backButton.appendChild(this.backSpan);
const controlsContainer = this.controls.getControlsContainer();
controlsContainer.appendChild(this.menu);
}
/** @private */
inOverflowMenu_() {
// Initially, submenus are created with a "Close" option. When present
// inside of the overflow menu, that option must be replaced with a
// "Back" arrow that returns the user to the main menu.
if (this.parent.classList.contains('shaka-overflow-menu')) {
this.backButton.firstChild.textContent =
shaka.ui.Enums.MaterialDesignIcons.BACK;
this.eventManager.listen(this.menu, 'click', () => {
shaka.ui.Utils.setDisplay(this.menu, false);
shaka.ui.Utils.setDisplay(this.parent, true);
const isDisplayed =
(element) => element.classList.contains('shaka-hidden') == false;
const Iterables = shaka.util.Iterables;
if (Iterables.some(this.parent.childNodes, isDisplayed)) {
// Focus on the first visible child of the overflow menu
const visibleElements =
Iterables.filter(this.parent.childNodes, isDisplayed);
/** @type {!HTMLElement} */ (visibleElements[0]).focus();
}
// Make sure controls are displayed
this.controls.computeOpacity();
this.computeMaxHeight_();
});
}
}
/** @private */
onButtonClick_() {
if (this.menu.classList.contains('shaka-hidden')) {
this.controls.dispatchEvent(new shaka.util.FakeEvent('submenuopen'));
shaka.ui.Utils.setDisplay(this.menu, true);
shaka.ui.Utils.focusOnTheChosenItem(this.menu);
this.computeMaxHeight_();
} else {
shaka.ui.Utils.setDisplay(this.menu, false);
}
}
/**
* @private
*/
computeMaxHeight_() {
const rectMenu = this.menu.getBoundingClientRect();
const styleMenu = window.getComputedStyle(this.menu);
const paddingTop = parseFloat(styleMenu.paddingTop);
const paddingBottom = parseFloat(styleMenu.paddingBottom);
const rectContainer = this.videoContainer_.getBoundingClientRect();
const heightIntersection =
rectMenu.bottom - rectContainer.top - paddingTop - paddingBottom;
this.menu.style.maxHeight = heightIntersection + 'px';
}
};