mirror of
https://github.com/videojs/video.js.git
synced 2025-02-04 11:43:27 +02:00
refactor: player.hasStarted() (#4680)
This commit is contained in:
parent
5e9655f4a0
commit
cde83351fb
@ -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
|
||||
* 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');
|
||||
}
|
||||
}
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user