Skip to content

Commit

Permalink
Merge pull request #2 from gkatsev/is-evented
Browse files Browse the repository at this point in the history
is evented and docs updates
  • Loading branch information
marcodeltorob committed Nov 9, 2020
2 parents a1258eb + 7f88641 commit b639954
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/js/player.js
Expand Up @@ -399,7 +399,7 @@ class Player extends Component {
this.tagAttributes = tag && Dom.getAttributes(tag);

// Update current language
this.language(this.options_.language, true);
this.language(this.options_.language);

// Update Supported Languages
if (options.languages) {
Expand Down Expand Up @@ -4280,30 +4280,36 @@ class Player extends Component {
}

/**
* The player's language code
* NOTE: The language should be set in the player options if you want the
* the controls to be built with a specific language. Changing the language
* later will not update controls text.
* The player's language code.
*
* Changing the langauge will trigger
* [languagechange]{@link Player#event:languagechange}
* which Components can use to update control text.
* ClickableComponent will update its control text by default on
* [languagechange]{@link Player#event:languagechange}.
*
* @fires Player#languagechange
*
* @param {string} [code]
* the language code to set the player to
*
* @return {string}
* The current language code when getting
*/
language(code, skipListeners) {
language(code) {
if (code === undefined) {
return this.language_;
}

if (this.language_ !== String(code).toLowerCase()) {
this.language_ = String(code).toLowerCase();
// skipListeners helps to avoid trigger on initialization when component is not evented
if (!skipListeners) {

// during first init, it's possible some things won't be evented
if (isEvented(this)) {
/**
* fires when the player language change
*
* @fires Player#languagechange
* @event Player#languagechange
* @type {EventTarget~Event}
*/
this.trigger('languagechange');
Expand Down

0 comments on commit b639954

Please sign in to comment.