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

Remove the pause button from the Play widget #2703

Merged
merged 1 commit into from
Jan 9, 2020
Merged
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
37 changes: 11 additions & 26 deletions packages/controls/src/widget_int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,36 +862,29 @@ class PlayView extends DOMWidgetView {
this.el.classList.add('widget-inline-hbox');
this.el.classList.add('widget-play');

this.playButton = document.createElement('button');
this.pauseButton = document.createElement('button');
this.playPauseButton = document.createElement('button');
this.stopButton = document.createElement('button');
this.repeatButton = document.createElement('button');

this.playButton.className = 'jupyter-button';
this.pauseButton.className = 'jupyter-button';
this.playPauseButton.className = 'jupyter-button';
this.stopButton.className = 'jupyter-button';
this.repeatButton.className = 'jupyter-button';

this.el.appendChild(this.playButton); // Toggle button with playing
this.el.appendChild(this.pauseButton); // Disable if not playing
this.el.appendChild(this.playPauseButton); // Toggle button with playing
this.el.appendChild(this.stopButton); // Disable if not playing
this.el.appendChild(this.repeatButton); // Always enabled, but may be hidden

const playIcon = document.createElement('i');
playIcon.className = 'fa fa-play';
this.playButton.appendChild(playIcon);
const pauseIcon = document.createElement('i');
pauseIcon.className = 'fa fa-pause';
this.pauseButton.appendChild(pauseIcon);
this.playPauseButton.appendChild(playIcon);
const stopIcon = document.createElement('i');
stopIcon.className = 'fa fa-stop';
this.stopButton.appendChild(stopIcon);
const repeatIcon = document.createElement('i');
repeatIcon.className = 'fa fa-retweet';
this.repeatButton.appendChild(repeatIcon);

this.playButton.onclick = this.model.play.bind(this.model);
this.pauseButton.onclick = this.model.pause.bind(this.model);
this.playPauseButton.onclick = this.model.play.bind(this.model);
this.stopButton.onclick = this.model.stop.bind(this.model);
this.repeatButton.onclick = this.model.repeat.bind(this.model);

Expand All @@ -905,8 +898,7 @@ class PlayView extends DOMWidgetView {

update(): void {
const disabled = this.model.get('disabled');
this.playButton.disabled = disabled;
this.pauseButton.disabled = disabled;
this.playPauseButton.disabled = disabled;
this.stopButton.disabled = disabled;
this.repeatButton.disabled = disabled;
this.updatePlaying();
Expand All @@ -925,32 +917,25 @@ class PlayView extends DOMWidgetView {

updatePlaying(): void {
const playing = this.model.get('playing');
const disabled = this.model.get('disabled');
const icon = this.playPauseButton.getElementsByTagName('i')[0];
if (playing) {
if (!disabled) {
this.pauseButton.disabled = false;
}
this.playButton.classList.add('mod-active');
icon.className = 'fa fa-pause';
} else {
if (!disabled) {
this.pauseButton.disabled = true;
}
this.playButton.classList.remove('mod-active');
icon.className = 'fa fa-play';
}
}

updateRepeat(): void {
const repeat = this.model.get('repeat');
this.repeatButton.style.display = this.model.get('show_repeat') ? this.playButton.style.display : 'none';
this.repeatButton.style.display = this.model.get('show_repeat') ? this.playPauseButton.style.display : 'none';
if (repeat) {
this.repeatButton.classList.add('mod-active');
} else {
this.repeatButton.classList.remove('mod-active');
}
}

playButton: HTMLButtonElement;
pauseButton: HTMLButtonElement;
playPauseButton: HTMLButtonElement;
stopButton: HTMLButtonElement;
repeatButton: HTMLButtonElement;
model: PlayModel;
Expand Down