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

fix: Make sure time displays use correctly-formatted time. #4643

Merged
merged 1 commit into from
Oct 3, 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
15 changes: 15 additions & 0 deletions src/js/control-bar/time-controls/remaining-time-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ class RemainingTimeDisplay extends TimeDisplay {
return 'vjs-remaining-time';
}

/**
* The remaining time display prefixes numbers with a "minus" character.
*
* @param {number} time
* A numeric time, in seconds.
*
* @return {string}
* A formatted time
*
* @private
*/
formatTime_(time) {
return '-' + super.formatTime_(time);
}

/**
* Update remaining time display.
*
Expand Down
19 changes: 17 additions & 2 deletions src/js/control-bar/time-controls/time-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,25 @@ class TimeDisplay extends Component {
if (this.textNode_) {
this.contentEl_.removeChild(this.textNode_);
}
this.textNode_ = document.createTextNode(` -${this.formattedTime_ || '0:00'}`);
this.textNode_ = document.createTextNode(this.formattedTime_ || '0:00');
Copy link
Member Author

Choose a reason for hiding this comment

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

This was the relevant mistake. Not all sub-classes wanted to display negative formatted times.

this.contentEl_.appendChild(this.textNode_);
}

/**
* Generates a formatted time for this component to use in display.
*
* @param {number} time
* A numeric time, in seconds.
*
* @return {string}
* A formatted time
*
* @private
*/
formatTime_(time) {
return formatTime(time);
}

/**
* Updates the time display text node if it has what was passed in changed
* the formatted time.
Expand All @@ -80,7 +95,7 @@ class TimeDisplay extends Component {
* @private
*/
updateFormattedTime_(time) {
const formattedTime = formatTime(time);
const formattedTime = this.formatTime_(time);

if (formattedTime === this.formattedTime_) {
return;
Expand Down