Skip to content

Commit 0e5442f

Browse files
gstrat88gkatsev
authored andcommitted
feat(player): add playerreset event (#5335)
1 parent 7d127c8 commit 0e5442f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/js/mixins/evented.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ const isEvented = (object) =>
2323
!!object.eventBusEl_ &&
2424
['on', 'one', 'off', 'trigger'].every(k => typeof object[k] === 'function');
2525

26+
/**
27+
* Adds a callback to run after the evented mixin applied.
28+
*
29+
* @param {Object} object
30+
* An object to Add
31+
* @param {Function} callback
32+
* The callback to run.
33+
*/
34+
const addEventedCallback = (target, callback) => {
35+
if (isEvented(target)) {
36+
callback();
37+
} else {
38+
if (!target.eventedCallbacks) {
39+
target.eventedCallbacks = [];
40+
}
41+
target.eventedCallbacks.push(callback);
42+
}
43+
};
44+
2645
/**
2746
* Whether a value is a valid event type - non-empty string or array.
2847
*
@@ -366,6 +385,12 @@ function evented(target, options = {}) {
366385

367386
Obj.assign(target, EventedMixin);
368387

388+
if (target.eventedCallbacks) {
389+
target.eventedCallbacks.forEach((callback) => {
390+
callback();
391+
});
392+
}
393+
369394
// When any evented object is disposed, it removes all its listeners.
370395
target.on('dispose', () => {
371396
target.off();
@@ -379,3 +404,4 @@ function evented(target, options = {}) {
379404

380405
export default evented;
381406
export {isEvented};
407+
export {addEventedCallback};

src/js/player.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import document from 'global/document';
99
import window from 'global/window';
1010
import tsml from 'tsml';
1111
import evented from './mixins/evented';
12+
import {isEvented, addEventedCallback} from './mixins/evented';
1213
import * as Events from './utils/events.js';
1314
import * as Dom from './utils/dom.js';
1415
import * as Fn from './utils/fn.js';
@@ -442,6 +443,9 @@ class Player extends Component {
442443
// Make this an evented object and use `el_` as its event bus.
443444
evented(this, {eventBusKey: 'el_'});
444445

446+
if (this.fluid_) {
447+
this.on('playerreset', this.updateStyleEl_);
448+
}
445449
// We also want to pass the original player options to each component and plugin
446450
// as well so they don't need to reach back into the player for options later.
447451
// We also need to do another copy of this.options_ so we don't end up with
@@ -825,9 +829,15 @@ class Player extends Component {
825829

826830
this.fluid_ = !!bool;
827831

832+
if (isEvented(this)) {
833+
this.off('playerreset', this.updateStyleEl_);
834+
}
828835
if (bool) {
829836
this.addClass('vjs-fluid');
830837
this.fill(false);
838+
addEventedCallback(function() {
839+
this.on('playerreset', this.updateStyleEl_);
840+
});
831841
} else {
832842
this.removeClass('vjs-fluid');
833843
}
@@ -2910,6 +2920,9 @@ class Player extends Component {
29102920
}
29112921
this.loadTech_(this.options_.techOrder[0], null);
29122922
this.techCall_('reset');
2923+
if (isEvented(this)) {
2924+
this.trigger('playerreset');
2925+
}
29132926
}
29142927

29152928
/**

0 commit comments

Comments
 (0)