Skip to content

Commit

Permalink
refactor: player.hasStarted() (#4680)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocoten1992 authored and gkatsev committed Oct 31, 2017
1 parent 5e9655f commit cde8335
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class Player extends Component {
// Turn off API access because we're loading a new tech that might load asynchronously
this.isReady_ = false;

// Init state hasStarted_
this.hasStarted_ = false;

// if the global option object was accidentally blown away by
// someone, bail early with an informative error
if (!this.options_ ||
Expand Down Expand Up @@ -1124,29 +1127,31 @@ class Player extends Component {
*
* @fires Player#firstplay
*
* @param {boolean} hasStarted
* @param {boolean} request
* - true: adds the class
* - false: remove the class
*
* @return {boolean}
* the boolean value of hasStarted
*/
hasStarted(hasStarted) {
if (hasStarted !== undefined) {
// only update if this is a new value
if (this.hasStarted_ !== hasStarted) {
this.hasStarted_ = hasStarted;
if (hasStarted) {
this.addClass('vjs-has-started');
// trigger the firstplay event if this newly has played
this.trigger('firstplay');
} else {
this.removeClass('vjs-has-started');
}
}
* the boolean value of hasStarted_
*/
hasStarted(request) {
if (request === undefined) {
// act as getter, if we have no request to change
return this.hasStarted_;
}

if (request === this.hasStarted_) {
return;
}
return !!this.hasStarted_;

this.hasStarted_ = request;

if (this.hasStarted_) {
this.addClass('vjs-has-started');
this.trigger('firstplay');
} else {
this.removeClass('vjs-has-started');
}
}

/**
Expand Down

0 comments on commit cde8335

Please sign in to comment.