Event listener fixes, loadScript promise, ads tweaks

This commit is contained in:
Sam Potts
2018-03-11 02:03:35 +11:00
parent c734bc4957
commit e206edc1f6
25 changed files with 3559 additions and 3386 deletions

View File

@@ -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);