Source: ui/small_play_button.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.ui.SmallPlayButton');
  7. goog.require('shaka.ui.Controls');
  8. goog.require('shaka.ui.Enums');
  9. goog.require('shaka.ui.Locales');
  10. goog.require('shaka.ui.PlayButton');
  11. /**
  12. * @extends {shaka.ui.PlayButton}
  13. * @final
  14. * @export
  15. */
  16. shaka.ui.SmallPlayButton = class extends shaka.ui.PlayButton {
  17. /**
  18. * @param {!HTMLElement} parent
  19. * @param {!shaka.ui.Controls} controls
  20. */
  21. constructor(parent, controls) {
  22. super(parent, controls);
  23. this.button.classList.add('shaka-small-play-button');
  24. this.button.classList.add('material-icons-round');
  25. this.button.classList.add('shaka-tooltip');
  26. this.updateIcon();
  27. this.updateAriaLabel();
  28. }
  29. /** @override */
  30. updateIcon() {
  31. const Icons = shaka.ui.Enums.MaterialDesignIcons;
  32. if (this.isEnded()) {
  33. this.button.textContent = Icons.REPLAY;
  34. } else {
  35. this.button.textContent = this.isPaused() ? Icons.PLAY : Icons.PAUSE;
  36. }
  37. }
  38. /** @override */
  39. updateAriaLabel() {
  40. const LocIds = shaka.ui.Locales.Ids;
  41. if (this.isEnded()) {
  42. this.button.ariaLabel = this.localization.resolve(LocIds.REPLAY);
  43. } else {
  44. const label = this.isPaused() ? LocIds.PLAY : LocIds.PAUSE;
  45. this.button.ariaLabel = this.localization.resolve(label);
  46. }
  47. }
  48. };
  49. /**
  50. * @implements {shaka.extern.IUIElement.Factory}
  51. * @final
  52. */
  53. shaka.ui.SmallPlayButton.Factory = class {
  54. /** @override */
  55. create(rootElement, controls) {
  56. return new shaka.ui.SmallPlayButton(rootElement, controls);
  57. }
  58. };
  59. shaka.ui.Controls.registerElement(
  60. 'play_pause', new shaka.ui.SmallPlayButton.Factory());