3 exports.__esModule = true;
5 var _component = require('../../component.js');
7 var _component2 = _interopRequireDefault(_component);
9 var _dom = require('../../utils/dom.js');
11 var Dom = _interopRequireWildcard(_dom);
13 var _fn = require('../../utils/fn.js');
15 var Fn = _interopRequireWildcard(_fn);
17 var _formatTime = require('../../utils/format-time.js');
19 var _formatTime2 = _interopRequireDefault(_formatTime);
21 var _computedStyle = require('../../utils/computed-style.js');
23 var _computedStyle2 = _interopRequireDefault(_computedStyle);
25 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; } }
27 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
29 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31 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; }
33 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; } /**
34 * @file mouse-time-display.js
39 * The Mouse Time Display component shows the time you will seek to
40 * when hovering over the progress bar
44 var MouseTimeDisplay = function (_Component) {
45 _inherits(MouseTimeDisplay, _Component);
48 * Creates an instance of this class.
50 * @param {Player} player
51 * The `Player` that this class should be attached to.
53 * @param {Object} [options]
54 * The key/value store of player options.
56 function MouseTimeDisplay(player, options) {
57 _classCallCheck(this, MouseTimeDisplay);
59 var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
61 if (options.playerOptions && options.playerOptions.controlBar && options.playerOptions.controlBar.progressControl && options.playerOptions.controlBar.progressControl.keepTooltipsInside) {
62 _this.keepTooltipsInside = options.playerOptions.controlBar.progressControl.keepTooltipsInside;
65 if (_this.keepTooltipsInside) {
66 _this.tooltip = Dom.createEl('div', { className: 'vjs-time-tooltip' });
67 _this.el().appendChild(_this.tooltip);
68 _this.addClass('vjs-keep-tooltips-inside');
73 player.on('ready', function () {
74 _this.on(player.controlBar.progressControl.el(), 'mousemove', Fn.throttle(Fn.bind(_this, _this.handleMouseMove), 25));
80 * Create the `Component`'s DOM element
83 * The element that was created.
87 MouseTimeDisplay.prototype.createEl = function createEl() {
88 return _Component.prototype.createEl.call(this, 'div', {
89 className: 'vjs-mouse-display'
94 * Handle the mouse move event on the `MouseTimeDisplay`.
96 * @param {EventTarget~Event} event
97 * The `mousemove` event that caused this to event to run.
103 MouseTimeDisplay.prototype.handleMouseMove = function handleMouseMove(event) {
104 var duration = this.player_.duration();
105 var newTime = this.calculateDistance(event) * duration;
106 var position = event.pageX - Dom.findElPosition(this.el().parentNode).left;
108 this.update(newTime, position);
112 * Update the time and posistion of the `MouseTimeDisplay`.
114 * @param {number} newTime
115 * Time to change the `MouseTimeDisplay` to.
117 * @param {nubmer} position
118 * Postion from the left of the in pixels.
122 MouseTimeDisplay.prototype.update = function update(newTime, position) {
123 var time = (0, _formatTime2['default'])(newTime, this.player_.duration());
125 this.el().style.left = position + 'px';
126 this.el().setAttribute('data-current-time', time);
128 if (this.keepTooltipsInside) {
129 var clampedPosition = this.clampPosition_(position);
130 var difference = position - clampedPosition + 1;
131 var tooltipWidth = parseFloat((0, _computedStyle2['default'])(this.tooltip, 'width'));
132 var tooltipWidthHalf = tooltipWidth / 2;
134 this.tooltip.innerHTML = time;
135 this.tooltip.style.right = '-' + (tooltipWidthHalf - difference) + 'px';
140 * Get the mouse pointers x coordinate in pixels.
142 * @param {EventTarget~Event} [event]
143 * The `mousemove` event that was passed to this function by
144 * {@link MouseTimeDisplay#handleMouseMove}
147 * THe x position in pixels of the mouse pointer.
151 MouseTimeDisplay.prototype.calculateDistance = function calculateDistance(event) {
152 return Dom.getPointerPosition(this.el().parentNode, event).x;
156 * This takes in a horizontal position for the bar and returns a clamped position.
157 * Clamped position means that it will keep the position greater than half the width
158 * of the tooltip and smaller than the player width minus half the width o the tooltip.
159 * It will only clamp the position if `keepTooltipsInside` option is set.
161 * @param {number} position
162 * The position the bar wants to be
165 * The (potentially) new clamped position.
171 MouseTimeDisplay.prototype.clampPosition_ = function clampPosition_(position) {
172 if (!this.keepTooltipsInside) {
176 var playerWidth = parseFloat((0, _computedStyle2['default'])(this.player().el(), 'width'));
177 var tooltipWidth = parseFloat((0, _computedStyle2['default'])(this.tooltip, 'width'));
178 var tooltipWidthHalf = tooltipWidth / 2;
179 var actualPosition = position;
181 if (position < tooltipWidthHalf) {
182 actualPosition = Math.ceil(tooltipWidthHalf);
183 } else if (position > playerWidth - tooltipWidthHalf) {
184 actualPosition = Math.floor(playerWidth - tooltipWidthHalf);
187 return actualPosition;
190 return MouseTimeDisplay;
191 }(_component2['default']);
193 _component2['default'].registerComponent('MouseTimeDisplay', MouseTimeDisplay);
194 exports['default'] = MouseTimeDisplay;