Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow progress controls to be disabled #4649

Merged
merged 6 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/css/components/_progress.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
min-width: 4em;
}

.video-js .vjs-progress-control.disabled {
cursor: default;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really want a pointer when its disabled

}

.vjs-live .vjs-progress-control {
display: none;
}
Expand Down Expand Up @@ -40,6 +44,10 @@
font-size: 1.666666666666666666em;
}

.video-js .vjs-progress-control:hover .vjs-progress-holder.disabled {
Copy link
Member

@gkatsev gkatsev Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this block is necessary and it causes the time display not to look right
screen shot 2017-10-26 at 11 25 00
screen shot 2017-10-26 at 11 31 45
First is the "broken" one, second is the "correct" one.

Though, now that I think about it, this is probably on purpose so that the progress holder/seek handle isn't as large?

font-size: 1em;
}

// .vjs-play-progress / PlayProgressBar and .vjs-load-progress / LoadProgressBar
//
// These are bars that appear within the progress control to communicate the
Expand Down Expand Up @@ -133,6 +141,10 @@
visibility: visible;
}

.video-js .vjs-progress-control.disabled:hover .vjs-time-tooltip {
font-size: 1em;
}

// .vjs-mouse-display / MouseTimeDisplay
//
// This element tracks the mouse position along the progress control and
Expand Down
4 changes: 4 additions & 0 deletions src/css/components/_slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
@include user-select(none);

@include background-color-with-alpha($secondary-background-color, $secondary-background-transparency);
}

.video-js .vjs-slider.disabled {
cursor: default;
}

.video-js .vjs-slider:focus {
Expand Down
51 changes: 48 additions & 3 deletions src/js/control-bar/progress-control/progress-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ class ProgressControl extends Component {
constructor(player, options) {
super(player, options);
this.handleMouseMove = throttle(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);

this.enable();
}

/**
Expand Down Expand Up @@ -101,6 +100,52 @@ class ProgressControl extends Component {
seekBar.handleMouseMove(event);
}

/**
* Are controls are currently enabled for this progress control.
*
* @return {boolean}
* true if controls are enabled, false otherwise
*/
enabled() {
return this.enabled_;
}

/**
* Disable all controls on the progress control and its children
*/
disable() {
this.children().forEach((child) => child.disable && child.disable());

if (!this.enabled()) {
return;
}

this.off(['mousedown', 'touchstart'], this.handleMouseDown);
this.off(this.el_, 'mousemove', this.handleMouseMove);
this.handleMouseUp();

this.addClass('disabled');

this.enabled_ = false;
}

/**
* Enable all controls on the progress control and its children
*/
enable() {
this.children().forEach((child) => child.enable && child.enable());

if (this.enabled()) {
return;
}

this.on(['mousedown', 'touchstart'], this.handleMouseDown);
this.on(this.el_, 'mousemove', this.handleMouseMove);
this.removeClass('disabled');

this.enabled_ = true;
}

/**
* Handle `mousedown` or `touchstart` events on the `ProgressControl`.
*
Expand Down
22 changes: 22 additions & 0 deletions src/js/control-bar/progress-control/seek-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ class SeekBar extends Slider {
this.player_.currentTime(newTime);
}

enable() {
super.enable();
const mouseTimeDisplay = this.getChild('mouseTimeDisplay');

if (!mouseTimeDisplay) {
return;
}

mouseTimeDisplay.show();
}

disable() {
super.disable();
const mouseTimeDisplay = this.getChild('mouseTimeDisplay');

if (!mouseTimeDisplay) {
return;
}

mouseTimeDisplay.hide();
}

/**
* Handle mouse up on seek bar
*
Expand Down
59 changes: 57 additions & 2 deletions src/js/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,72 @@ class Slider extends Component {
// Set a horizontal or vertical class on the slider depending on the slider type
this.vertical(!!this.options_.vertical);

this.enable();
}

/**
* Are controls are currently enabled for this slider or not.
*
* @return {boolean}
* true if controls are enabled, false otherwise
*/
enabled() {
return this.enabled_;
}

/**
* Enable controls for this slider if they are disabled
*/
enable() {
if (this.enabled()) {
return;
}

this.on('mousedown', this.handleMouseDown);
this.on('touchstart', this.handleMouseDown);
this.on('focus', this.handleFocus);
this.on('blur', this.handleBlur);
this.on('click', this.handleClick);

this.on(player, 'controlsvisible', this.update);
this.on(this.player_, 'controlsvisible', this.update);

if (this.playerEvent) {
this.on(this.player_, this.playerEvent, this.update);
}

this.removeClass('disabled');
this.setAttribute('tabindex', 0);

this.enabled_ = true;
}

/**
* Disable controls for this slider if they are enabled
*/
disable() {
if (!this.enabled()) {
return;
}
const doc = this.bar.el_.ownerDocument;

this.off('mousedown', this.handleMouseDown);
this.off('touchstart', this.handleMouseDown);
this.off('focus', this.handleFocus);
this.off('blur', this.handleBlur);
this.off('click', this.handleClick);
this.off(this.player_, 'controlsvisible', this.update);
this.off(doc, 'mousemove', this.handleMouseMove);
this.off(doc, 'mouseup', this.handleMouseUp);
this.off(doc, 'touchmove', this.handleMouseMove);
this.off(doc, 'touchend', this.handleMouseUp);
this.removeAttribute('tabindex');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't allow tabbing to the slider when it is disabled

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.


this.addClass('disabled');

if (this.playerEvent) {
this.on(player, this.playerEvent, this.update);
this.off(this.player_, this.playerEvent, this.update);
}
this.enabled_ = false;
}

/**
Expand Down