--- /dev/null
+'use strict';
+
+exports.__esModule = true;
+
+var _component = require('../../component.js');
+
+var _component2 = _interopRequireDefault(_component);
+
+var _dom = require('../../utils/dom.js');
+
+var Dom = _interopRequireWildcard(_dom);
+
+var _fn = require('../../utils/fn.js');
+
+var Fn = _interopRequireWildcard(_fn);
+
+var _formatTime = require('../../utils/format-time.js');
+
+var _formatTime2 = _interopRequireDefault(_formatTime);
+
+var _computedStyle = require('../../utils/computed-style.js');
+
+var _computedStyle2 = _interopRequireDefault(_computedStyle);
+
+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; } }
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+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; }
+
+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; } /**
+ * @file mouse-time-display.js
+ */
+
+
+/**
+ * The Mouse Time Display component shows the time you will seek to
+ * when hovering over the progress bar
+ *
+ * @extends Component
+ */
+var MouseTimeDisplay = function (_Component) {
+ _inherits(MouseTimeDisplay, _Component);
+
+ /**
+ * Creates an instance of this class.
+ *
+ * @param {Player} player
+ * The `Player` that this class should be attached to.
+ *
+ * @param {Object} [options]
+ * The key/value store of player options.
+ */
+ function MouseTimeDisplay(player, options) {
+ _classCallCheck(this, MouseTimeDisplay);
+
+ var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
+
+ if (options.playerOptions && options.playerOptions.controlBar && options.playerOptions.controlBar.progressControl && options.playerOptions.controlBar.progressControl.keepTooltipsInside) {
+ _this.keepTooltipsInside = options.playerOptions.controlBar.progressControl.keepTooltipsInside;
+ }
+
+ if (_this.keepTooltipsInside) {
+ _this.tooltip = Dom.createEl('div', { className: 'vjs-time-tooltip' });
+ _this.el().appendChild(_this.tooltip);
+ _this.addClass('vjs-keep-tooltips-inside');
+ }
+
+ _this.update(0, 0);
+
+ player.on('ready', function () {
+ _this.on(player.controlBar.progressControl.el(), 'mousemove', Fn.throttle(Fn.bind(_this, _this.handleMouseMove), 25));
+ });
+ return _this;
+ }
+
+ /**
+ * Create the `Component`'s DOM element
+ *
+ * @return {Element}
+ * The element that was created.
+ */
+
+
+ MouseTimeDisplay.prototype.createEl = function createEl() {
+ return _Component.prototype.createEl.call(this, 'div', {
+ className: 'vjs-mouse-display'
+ });
+ };
+
+ /**
+ * Handle the mouse move event on the `MouseTimeDisplay`.
+ *
+ * @param {EventTarget~Event} event
+ * The `mousemove` event that caused this to event to run.
+ *
+ * @listen mousemove
+ */
+
+
+ MouseTimeDisplay.prototype.handleMouseMove = function handleMouseMove(event) {
+ var duration = this.player_.duration();
+ var newTime = this.calculateDistance(event) * duration;
+ var position = event.pageX - Dom.findElPosition(this.el().parentNode).left;
+
+ this.update(newTime, position);
+ };
+
+ /**
+ * Update the time and posistion of the `MouseTimeDisplay`.
+ *
+ * @param {number} newTime
+ * Time to change the `MouseTimeDisplay` to.
+ *
+ * @param {nubmer} position
+ * Postion from the left of the in pixels.
+ */
+
+
+ MouseTimeDisplay.prototype.update = function update(newTime, position) {
+ var time = (0, _formatTime2['default'])(newTime, this.player_.duration());
+
+ this.el().style.left = position + 'px';
+ this.el().setAttribute('data-current-time', time);
+
+ if (this.keepTooltipsInside) {
+ var clampedPosition = this.clampPosition_(position);
+ var difference = position - clampedPosition + 1;
+ var tooltipWidth = parseFloat((0, _computedStyle2['default'])(this.tooltip, 'width'));
+ var tooltipWidthHalf = tooltipWidth / 2;
+
+ this.tooltip.innerHTML = time;
+ this.tooltip.style.right = '-' + (tooltipWidthHalf - difference) + 'px';
+ }
+ };
+
+ /**
+ * Get the mouse pointers x coordinate in pixels.
+ *
+ * @param {EventTarget~Event} [event]
+ * The `mousemove` event that was passed to this function by
+ * {@link MouseTimeDisplay#handleMouseMove}
+ *
+ * @return {number}
+ * THe x position in pixels of the mouse pointer.
+ */
+
+
+ MouseTimeDisplay.prototype.calculateDistance = function calculateDistance(event) {
+ return Dom.getPointerPosition(this.el().parentNode, event).x;
+ };
+
+ /**
+ * This takes in a horizontal position for the bar and returns a clamped position.
+ * Clamped position means that it will keep the position greater than half the width
+ * of the tooltip and smaller than the player width minus half the width o the tooltip.
+ * It will only clamp the position if `keepTooltipsInside` option is set.
+ *
+ * @param {number} position
+ * The position the bar wants to be
+ *
+ * @return {number}
+ * The (potentially) new clamped position.
+ *
+ * @private
+ */
+
+
+ MouseTimeDisplay.prototype.clampPosition_ = function clampPosition_(position) {
+ if (!this.keepTooltipsInside) {
+ return position;
+ }
+
+ var playerWidth = parseFloat((0, _computedStyle2['default'])(this.player().el(), 'width'));
+ var tooltipWidth = parseFloat((0, _computedStyle2['default'])(this.tooltip, 'width'));
+ var tooltipWidthHalf = tooltipWidth / 2;
+ var actualPosition = position;
+
+ if (position < tooltipWidthHalf) {
+ actualPosition = Math.ceil(tooltipWidthHalf);
+ } else if (position > playerWidth - tooltipWidthHalf) {
+ actualPosition = Math.floor(playerWidth - tooltipWidthHalf);
+ }
+
+ return actualPosition;
+ };
+
+ return MouseTimeDisplay;
+}(_component2['default']);
+
+_component2['default'].registerComponent('MouseTimeDisplay', MouseTimeDisplay);
+exports['default'] = MouseTimeDisplay;