Moved to provider + type to make it cleaner in future, fix for multiple players

This commit is contained in:
Sam Potts
2017-11-23 17:35:35 +11:00
parent de6f0f1b77
commit 921cefd212
22 changed files with 199 additions and 215 deletions

View File

@ -2,7 +2,7 @@
// Plyr source update
// ==========================================================================
import types from './types';
import { providers } from './types';
import utils from './utils';
import media from './media';
import ui from './ui';
@ -48,35 +48,25 @@ const source = {
this.elements.container.removeAttribute('class');
}
// Set the type
if ('type' in input) {
this.type = input.type;
// Get child type for video (it might be an embed)
if (this.type === 'video') {
const firstSource = input.sources[0];
if ('type' in firstSource && types.embed.includes(firstSource.type)) {
this.type = firstSource.type;
}
}
}
// Set the type and provider
this.type = input.type;
this.provider = !utils.is.empty(input.sources[0].provider) ? input.sources[0].provider : providers.html5;
// Check for support
this.supported = support.check(this.type, this.config.inline);
this.supported = support.check(this.type, this.provider, this.config.inline);
// Create new markup
switch (this.type) {
case 'video':
switch (`${this.provider}:${this.type}`) {
case 'html5:video':
this.media = utils.createElement('video');
break;
case 'audio':
case 'html5:audio':
this.media = utils.createElement('audio');
break;
case 'youtube':
case 'vimeo':
case 'youtube:video':
case 'vimeo:video':
this.media = utils.createElement('div');
this.embedId = input.sources[0].src;
break;
@ -117,7 +107,6 @@ const source = {
// Restore class hooks
utils.toggleClass(this.elements.container, this.config.classNames.captions.active, this.supported.ui && this.captions.enabled);
ui.addStyleHook.call(this);
// Set new sources for html5