Skip to content

Commit

Permalink
feat: allow seeking in full height of progress control (#4004)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Feb 2, 2017
1 parent a8f2e43 commit 29c6141
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/css/components/_progress.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// This is the container for all progress bar-related components/elements.
.video-js .vjs-progress-control {
cursor: pointer;
@include flex(auto);
@include display-flex(center);
min-width: 4em;
Expand Down
66 changes: 66 additions & 0 deletions src/js/control-bar/progress-control/progress-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Component from '../../component.js';
import * as Fn from '../../utils/fn.js';
import * as Dom from '../../utils/dom.js';
import { throttle, bind } from '../../utils/fn.js';

import './seek-bar.js';

Expand All @@ -28,6 +29,9 @@ class ProgressControl extends Component {
super(player, options);
this.handleMouseMove = Fn.throttle(Fn.bind(this, this.handleMouseMove), 25);
this.on(this.el_, 'mousemove', this.handleMouseMove);

this.throttledHandleMouseSeek = throttle(bind(this, this.handleMouseSeek), 25);
this.on(['mousedown', 'touchstart'], this.handleMouseDown);
}

/**
Expand Down Expand Up @@ -68,6 +72,68 @@ class ProgressControl extends Component {

seekBar.getChild('mouseTimeDisplay').update(seekBarRect, seekBarPoint);
}

/**
* A throttled version of the {@link ProgressControl#handleMouseSeek} listener.
*
* @method ProgressControl#throttledHandleMouseSeek
* @param {EventTarget~Event} event
* The `mousemove` event that caused this function to run.
*
* @listen mousemove
* @listen touchmove
*/

/**
* Handle `mousemove` or `touchmove` events on the `ProgressControl`.
*
* @param {EventTarget~Event} event
* `mousedown` or `touchstart` event that triggered this function
*
* @listens mousemove
* @listens touchmove
*/
handleMouseSeek(event) {
const seekBar = this.getChild('seekBar');

seekBar.handleMouseMove(event);
}

/**
* Handle `mousedown` or `touchstart` events on the `ProgressControl`.
*
* @param {EventTarget~Event} event
* `mousedown` or `touchstart` event that triggered this function
*
* @listens mousedown
* @listens touchstart
*/
handleMouseDown(event) {
const doc = this.el_.ownerDocument;

this.on(doc, 'mousemove', this.throttledHandleMouseSeek);
this.on(doc, 'touchmove', this.throttledHandleMouseSeek);
this.on(doc, 'mouseup', this.handleMouseUp);
this.on(doc, 'touchend', this.handleMouseUp);
}

/**
* Handle `mouseup` or `touchend` events on the `ProgressControl`.
*
* @param {EventTarget~Event} event
* `mouseup` or `touchend` event that triggered this function.
*
* @listens touchend
* @listens mouseup
*/
handleMouseUp(event) {
const doc = this.el_.ownerDocument;

this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
this.off(doc, 'mouseup', this.handleMouseUp);
this.off(doc, 'touchend', this.handleMouseUp);
}
}

/**
Expand Down

0 comments on commit 29c6141

Please sign in to comment.