// ========================================================================== // Plyr // plyr.js v3.0.0-beta.14 // https://github.com/sampotts/plyr // License: The MIT License (MIT) // ========================================================================== import { providers, types } from './types'; import defaults from './defaults'; import support from './support'; import utils from './utils'; import Console from './console'; import Fullscreen from './fullscreen'; 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'; // Private properties // TODO: Use a WeakMap for private globals // const globals = new WeakMap(); // Plyr instance class Plyr { constructor(target, options) { this.timers = {}; // State this.ready = false; this.loading = false; this.failed = false; // Set the media element this.media = target; // String selector passed if (utils.is.string(this.media)) { this.media = document.querySelectorAll(this.media); } // jQuery, NodeList or Array passed, use first element if ((window.jQuery && this.media instanceof jQuery) || utils.is.nodeList(this.media) || utils.is.array(this.media)) { // eslint-disable-next-line this.media = this.media[0]; } // Set config this.config = utils.extend( {}, defaults, options, (() => { try { return JSON.parse(this.media.getAttribute('data-plyr-config')); } catch (e) { return {}; } })(), ); // Elements cache this.elements = { container: null, buttons: {}, display: {}, progress: {}, inputs: {}, settings: { menu: null, panes: {}, tabs: {}, }, captions: null, }; // Captions this.captions = { active: null, currentTrack: null, }; // Fullscreen this.fullscreen = { active: false, }; // Options this.options = { speed: [], quality: [], }; // Debugging // TODO: move to globals this.debug = new Console(this.config.debug); // Log config options and support this.debug.log('Config', this.config); this.debug.log('Support', support); // We need an element to setup if (utils.is.nullOrUndefined(this.media) || !utils.is.element(this.media)) { this.debug.error('Setup failed: no suitable element passed'); return; } // Bail if the element is initialized if (this.media.plyr) { this.debug.warn('Target already setup'); return; } // Bail if not enabled if (!this.config.enabled) { this.debug.error('Setup failed: disabled by config'); return; } // Bail if disabled or no basic support // You may want to disable certain UAs etc if (!support.check().api) { this.debug.error('Setup failed: no support'); return; } // Cache original element state for .destroy() this.elements.original = this.media.cloneNode(true); // Set media type based on tag or data attribute // Supported: video, audio, vimeo, youtube const type = this.media.tagName.toLowerCase(); // Embed properties let iframe = null; let url = null; let params = null; // Different setup based on type switch (type) { case 'div': // Find the frame iframe = this.media.querySelector('iframe'); //