current-time-display.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _component = require('../../component.js');
  4. var _component2 = _interopRequireDefault(_component);
  5. var _dom = require('../../utils/dom.js');
  6. var Dom = _interopRequireWildcard(_dom);
  7. var _formatTime = require('../../utils/format-time.js');
  8. var _formatTime2 = _interopRequireDefault(_formatTime);
  9. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  11. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  13. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
  14. * @file current-time-display.js
  15. */
  16. /**
  17. * Displays the current time
  18. *
  19. * @extends Component
  20. */
  21. var CurrentTimeDisplay = function (_Component) {
  22. _inherits(CurrentTimeDisplay, _Component);
  23. /**
  24. * Creates an instance of this class.
  25. *
  26. * @param {Player} player
  27. * The `Player` that this class should be attached to.
  28. *
  29. * @param {Object} [options]
  30. * The key/value store of player options.
  31. */
  32. function CurrentTimeDisplay(player, options) {
  33. _classCallCheck(this, CurrentTimeDisplay);
  34. var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
  35. _this.on(player, 'timeupdate', _this.updateContent);
  36. return _this;
  37. }
  38. /**
  39. * Create the `Component`'s DOM element
  40. *
  41. * @return {Element}
  42. * The element that was created.
  43. */
  44. CurrentTimeDisplay.prototype.createEl = function createEl() {
  45. var el = _Component.prototype.createEl.call(this, 'div', {
  46. className: 'vjs-current-time vjs-time-control vjs-control'
  47. });
  48. this.contentEl_ = Dom.createEl('div', {
  49. className: 'vjs-current-time-display',
  50. // label the current time for screen reader users
  51. innerHTML: '<span class="vjs-control-text">Current Time </span>' + '0:00'
  52. }, {
  53. // tell screen readers not to automatically read the time as it changes
  54. 'aria-live': 'off'
  55. });
  56. el.appendChild(this.contentEl_);
  57. return el;
  58. };
  59. /**
  60. * Update current time display
  61. *
  62. * @param {EventTarget~Event} [event]
  63. * The `timeupdate` event that caused this function to run.
  64. *
  65. * @listens Player#timeupdate
  66. */
  67. CurrentTimeDisplay.prototype.updateContent = function updateContent(event) {
  68. // Allows for smooth scrubbing, when player can't keep up.
  69. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  70. var localizedText = this.localize('Current Time');
  71. var formattedTime = (0, _formatTime2['default'])(time, this.player_.duration());
  72. if (formattedTime !== this.formattedTime_) {
  73. this.formattedTime_ = formattedTime;
  74. this.contentEl_.innerHTML = '<span class="vjs-control-text">' + localizedText + '</span> ' + formattedTime;
  75. }
  76. };
  77. return CurrentTimeDisplay;
  78. }(_component2['default']);
  79. _component2['default'].registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  80. exports['default'] = CurrentTimeDisplay;