Permalink
Browse files

refactor: player.hasStarted() (#4680)

  • Loading branch information...
kocoten1992 authored and gkatsev committed Oct 31, 2017
1 parent 5e9655f commit cde83351fb1f91f6bc50477abfcae5f8977a7f22
Showing with 22 additions and 17 deletions.
  1. +22 −17 src/js/player.js
View
@@ -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_ ||
@@ -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');
}
}
/**

0 comments on commit cde8335

Please sign in to comment.