From 502d5977d79148957828cbf313b7ef4c9f31973f Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 11 Apr 2020 16:23:14 +1000 Subject: Converted to 2 space indentation --- src/js/plyr.js | 2116 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 1058 insertions(+), 1058 deletions(-) (limited to 'src/js/plyr.js') diff --git a/src/js/plyr.js b/src/js/plyr.js index 00b95a5f..c755e2be 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -37,748 +37,748 @@ import { parseUrl } from './utils/urls'; // Plyr instance class Plyr { - constructor(target, options) { - this.timers = {}; - - // State - this.ready = false; - this.loading = false; - this.failed = false; - - // Touch device - this.touch = support.touch; - - // Set the media element - this.media = target; - - // String selector passed - if (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) || is.nodeList(this.media) || is.array(this.media)) { - // eslint-disable-next-line - this.media = this.media[0]; - } - - // Set config - this.config = extend( - {}, - defaults, - Plyr.defaults, - options || {}, - (() => { - try { - return JSON.parse(this.media.getAttribute('data-plyr-config')); - } catch (e) { - return {}; - } - })(), - ); - - // Elements cache - this.elements = { - container: null, - captions: null, - buttons: {}, - display: {}, - progress: {}, - inputs: {}, - settings: { - popup: null, - menu: null, - panels: {}, - buttons: {}, - }, - }; - - // Captions - this.captions = { - active: null, - currentTrack: -1, - meta: new WeakMap(), - }; - - // 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 (is.nullOrUndefined(this.media) || !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; + constructor(target, options) { + this.timers = {}; + + // State + this.ready = false; + this.loading = false; + this.failed = false; + + // Touch device + this.touch = support.touch; + + // Set the media element + this.media = target; + + // String selector passed + if (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) || is.nodeList(this.media) || is.array(this.media)) { + // eslint-disable-next-line + this.media = this.media[0]; + } + + // Set config + this.config = extend( + {}, + defaults, + Plyr.defaults, + options || {}, + (() => { + try { + return JSON.parse(this.media.getAttribute('data-plyr-config')); + } catch (e) { + return {}; } + })(), + ); + + // Elements cache + this.elements = { + container: null, + captions: null, + buttons: {}, + display: {}, + progress: {}, + inputs: {}, + settings: { + popup: null, + menu: null, + panels: {}, + buttons: {}, + }, + }; + + // Captions + this.captions = { + active: null, + currentTrack: -1, + meta: new WeakMap(), + }; + + // 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 (is.nullOrUndefined(this.media) || !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() + const clone = this.media.cloneNode(true); + clone.autoplay = false; + this.elements.original = clone; + + // 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; + + // Different setup based on type + switch (type) { + case 'div': + // Find the frame + iframe = this.media.querySelector('iframe'); + + //