Skip to content

Commit

Permalink
feat: toggle playback with space when focused on seekbar (#4005)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Feb 3, 2017
1 parent 4f79e1e commit 516c9f9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/js/control-bar/progress-control/seek-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,44 @@ class SeekBar extends Slider {
stepBack() {
this.player_.currentTime(this.player_.currentTime() - STEP_SECONDS);
}

/**
* Toggles the playback state of the player
* This gets called when enter or space is used on the seekbar
*
* @param {EventTarget~Event} event
* The `keydown` event that caused this function to be called
*
*/
handleAction(event) {
if (this.player_.paused()) {
this.player_.play();
} else {
this.player_.pause();
}
}

/**
* Called when this SeekBar has focus and a key gets pressed down. By
* default it will call `this.handleAction` when the key is space or enter.
*
* @param {EventTarget~Event} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
*/
handleKeyPress(event) {

// Support Space (32) or Enter (13) key operation to fire a click event
if (event.which === 32 || event.which === 13) {
event.preventDefault();
this.handleAction(event);
} else if (super.handleKeyPress) {

// Pass keypress handling up for unsupported keys
super.handleKeyPress(event);
}
}
}

/**
Expand Down

0 comments on commit 516c9f9

Please sign in to comment.