| |
| |
| |
| import Component from '../../component.js'; |
| import * as Dom from '../../utils/dom.js'; |
| import {clamp} from '../../utils/num.js'; |
| import {bind_, throttle, UPDATE_REFRESH_INTERVAL} from '../../utils/fn.js'; |
| import {silencePromise} from '../../utils/promise'; |
| |
| import './seek-bar.js'; |
| |
| |
| |
| |
| |
| |
| |
| class ProgressControl extends Component { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| constructor(player, options) { |
| super(player, options); |
| this.handleMouseMove = throttle(bind_(this, this.handleMouseMove), UPDATE_REFRESH_INTERVAL); |
| this.throttledHandleMouseSeek = throttle(bind_(this, this.handleMouseSeek), UPDATE_REFRESH_INTERVAL); |
| this.handleMouseUpHandler_ = (e) => this.handleMouseUp(e); |
| this.handleMouseDownHandler_ = (e) => this.handleMouseDown(e); |
| |
| this.enable(); |
| } |
| |
| |
| |
| |
| |
| |
| |
| createEl() { |
| return super.createEl('div', { |
| className: 'vjs-progress-control vjs-control' |
| }); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| handleMouseMove(event) { |
| const seekBar = this.getChild('seekBar'); |
| |
| if (!seekBar) { |
| return; |
| } |
| |
| const playProgressBar = seekBar.getChild('playProgressBar'); |
| const mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay'); |
| |
| if (!playProgressBar && !mouseTimeDisplay) { |
| return; |
| } |
| |
| const seekBarEl = seekBar.el(); |
| const seekBarRect = Dom.findPosition(seekBarEl); |
| let seekBarPoint = Dom.getPointerPosition(seekBarEl, event).x; |
| |
| |
| |
| |
| seekBarPoint = clamp(seekBarPoint, 0, 1); |
| |
| if (mouseTimeDisplay) { |
| mouseTimeDisplay.update(seekBarRect, seekBarPoint); |
| } |
| |
| if (playProgressBar) { |
| playProgressBar.update(seekBarRect, seekBar.getProgress()); |
| } |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| handleMouseSeek(event) { |
| const seekBar = this.getChild('seekBar'); |
| |
| if (seekBar) { |
| seekBar.handleMouseMove(event); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| enabled() { |
| return this.enabled_; |
| } |
| |
| |
| |
| |
| disable() { |
| this.children().forEach((child) => child.disable && child.disable()); |
| |
| if (!this.enabled()) { |
| return; |
| } |
| |
| this.off(['mousedown', 'touchstart'], this.handleMouseDownHandler_); |
| this.off(this.el_, 'mousemove', this.handleMouseMove); |
| |
| this.removeListenersAddedOnMousedownAndTouchstart(); |
| |
| this.addClass('disabled'); |
| |
| this.enabled_ = false; |
| |
| |
| if (this.player_.scrubbing()) { |
| const seekBar = this.getChild('seekBar'); |
| |
| this.player_.scrubbing(false); |
| |
| if (seekBar.videoWasPlaying) { |
| silencePromise(this.player_.play()); |
| } |
| } |
| } |
| |
| |
| |
| |
| enable() { |
| this.children().forEach((child) => child.enable && child.enable()); |
| |
| if (this.enabled()) { |
| return; |
| } |
| |
| this.on(['mousedown', 'touchstart'], this.handleMouseDownHandler_); |
| this.on(this.el_, 'mousemove', this.handleMouseMove); |
| this.removeClass('disabled'); |
| |
| this.enabled_ = true; |
| } |
| |
| |
| |
| |
| removeListenersAddedOnMousedownAndTouchstart() { |
| const doc = this.el_.ownerDocument; |
| |
| this.off(doc, 'mousemove', this.throttledHandleMouseSeek); |
| this.off(doc, 'touchmove', this.throttledHandleMouseSeek); |
| this.off(doc, 'mouseup', this.handleMouseUpHandler_); |
| this.off(doc, 'touchend', this.handleMouseUpHandler_); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| handleMouseDown(event) { |
| const doc = this.el_.ownerDocument; |
| const seekBar = this.getChild('seekBar'); |
| |
| if (seekBar) { |
| seekBar.handleMouseDown(event); |
| } |
| |
| this.on(doc, 'mousemove', this.throttledHandleMouseSeek); |
| this.on(doc, 'touchmove', this.throttledHandleMouseSeek); |
| this.on(doc, 'mouseup', this.handleMouseUpHandler_); |
| this.on(doc, 'touchend', this.handleMouseUpHandler_); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| handleMouseUp(event) { |
| const seekBar = this.getChild('seekBar'); |
| |
| if (seekBar) { |
| seekBar.handleMouseUp(event); |
| } |
| |
| this.removeListenersAddedOnMousedownAndTouchstart(); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| ProgressControl.prototype.options_ = { |
| children: [ |
| 'seekBar' |
| ] |
| }; |
| |
| Component.registerComponent('ProgressControl', ProgressControl); |
| export default ProgressControl; |