Replace switch in source.js with destructuring
This commit is contained in:
parent
d522e40594
commit
2aa967aba9
@ -8,6 +8,7 @@ import media from './media';
|
|||||||
import support from './support';
|
import support from './support';
|
||||||
import ui from './ui';
|
import ui from './ui';
|
||||||
import { createElement, insertElement, removeElement } from './utils/elements';
|
import { createElement, insertElement, removeElement } from './utils/elements';
|
||||||
|
import { getDeep } from './utils/objects';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
|
|
||||||
const source = {
|
const source = {
|
||||||
@ -27,7 +28,7 @@ const source = {
|
|||||||
// Update source
|
// Update source
|
||||||
// Sources are not checked for support so be careful
|
// Sources are not checked for support so be careful
|
||||||
change(input) {
|
change(input) {
|
||||||
if (!is.object(input) || !('sources' in input) || !input.sources.length) {
|
if (!getDeep(input, 'sources.length')) {
|
||||||
this.debug.warn('Invalid source format');
|
this.debug.warn('Invalid source format');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -52,32 +53,19 @@ const source = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the type and provider
|
// Set the type and provider
|
||||||
this.type = input.type;
|
const { sources, type } = input;
|
||||||
this.provider = !is.empty(input.sources[0].provider) ? input.sources[0].provider : providers.html5;
|
const [{ provider = providers.html5, src }] = sources;
|
||||||
|
const tagName = provider === 'html5' ? type : 'div';
|
||||||
|
const attributes = provider === 'html5' ? {} : { src };
|
||||||
|
|
||||||
// Check for support
|
Object.assign(this, {
|
||||||
this.supported = support.check(this.type, this.provider, this.config.playsinline);
|
provider,
|
||||||
|
type,
|
||||||
// Create new markup
|
// Check for support
|
||||||
switch (`${this.provider}:${this.type}`) {
|
supported: support.check(type, provider, this.config.playsinline),
|
||||||
case 'html5:video':
|
// Create new element
|
||||||
this.media = createElement('video');
|
media: createElement(tagName, attributes),
|
||||||
break;
|
});
|
||||||
|
|
||||||
case 'html5:audio':
|
|
||||||
this.media = createElement('audio');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'youtube:video':
|
|
||||||
case 'vimeo:video':
|
|
||||||
this.media = createElement('div', {
|
|
||||||
src: input.sources[0].src,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inject the new element
|
// Inject the new element
|
||||||
this.elements.container.appendChild(this.media);
|
this.elements.container.appendChild(this.media);
|
||||||
@ -114,7 +102,7 @@ const source = {
|
|||||||
|
|
||||||
// Set new sources for html5
|
// Set new sources for html5
|
||||||
if (this.isHTML5) {
|
if (this.isHTML5) {
|
||||||
source.insertElements.call(this, 'source', input.sources);
|
source.insertElements.call(this, 'source', sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set video title
|
// Set video title
|
||||||
|
Loading…
x
Reference in New Issue
Block a user