diff options
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r-- | src/js/plyr.js | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index 04913046..d90110f2 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -12,12 +12,12 @@ import utils from './utils'; import Console from './console'; import Fullscreen from './fullscreen'; +import Listeners from './listeners'; import Storage from './storage'; import Ads from './plugins/ads'; import captions from './captions'; import controls from './controls'; -import listeners from './listeners'; import media from './media'; import source from './source'; import ui from './ui'; @@ -235,6 +235,9 @@ class Plyr { return; } + // Create listeners + this.listeners = new Listeners(this); + // Setup local storage for user settings this.storage = new Storage(this); @@ -250,9 +253,6 @@ class Plyr { // Allow focus to be captured this.elements.container.setAttribute('tabindex', 0); - // Global listeners - listeners.global.call(this); - // Add style hook ui.addStyleHook.call(this); @@ -272,6 +272,12 @@ class Plyr { ui.build.call(this); } + // Container listeners + this.listeners.container(); + + // Global listeners + this.listeners.global(true); + // Setup fullscreen this.fullscreen = new Fullscreen(this); @@ -309,15 +315,12 @@ class Plyr { * Play the media, or play the advertisement (if they are not blocked) */ play() { - // Return the promise (for HTML5) + // If ads are enabled, wait for them first if (this.ads.enabled && !this.ads.initialized) { - return this.ads.managerPromise.then(() => { - this.ads.play(); - }).catch(() => { - this.media.play(); - }); + return this.ads.managerPromise.then(() => this.ads.play()).catch(() => this.media.play()); } + // Return the promise (for HTML5) return this.media.play(); } @@ -1057,6 +1060,9 @@ class Plyr { // Replace the container with the original element provided utils.replaceElement(this.elements.original, this.elements.container); + // Unbind global listeners + this.listeners.global(false); + // Event utils.dispatchEvent.call(this, this.elements.original, 'destroyed', true); |