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 2 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
6 changes: 5 additions & 1 deletion 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 @@ -36,7 +40,7 @@

// This increases the size of the progress holder so there is an increased
// hit area for clicks/touches.
.video-js .vjs-progress-control:hover .vjs-progress-holder {
.video-js .vjs-progress-control:hover .vjs-progress-holder.enabled {
Copy link
Member

Choose a reason for hiding this comment

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

do we need an enabled class? Can that just be the default and also have a disabled class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure we can do that

font-size: 1.666666666666666666em;
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 only want to increase the size on hover when enabled

}

Expand Down
6 changes: 6 additions & 0 deletions src/css/components/_slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
@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 {
text-shadow: 0em 0em 1em rgba($primary-foreground-color, 1);

Expand Down
53 changes: 50 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,54 @@ 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.removeClass('enabled');
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.addClass('enabled');

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
61 changes: 59 additions & 2 deletions src/js/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,74 @@ 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.addClass('enabled');
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need an enabled class, like mentioned earlier

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.removeClass('enabled');
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