|
|
@ -1,4 +1,4 @@ |
|
|
import Component from './ComponentImage'; |
|
|
import ComponentImage from './ComponentImage'; |
|
|
import { toLowerCase } from 'utils/mixins'; |
|
|
import { toLowerCase } from 'utils/mixins'; |
|
|
|
|
|
|
|
|
const type = 'video'; |
|
|
const type = 'video'; |
|
|
@ -8,10 +8,10 @@ const ytnc = 'ytnc'; |
|
|
|
|
|
|
|
|
const hasParam = value => value && value !== '0'; |
|
|
const hasParam = value => value && value !== '0'; |
|
|
|
|
|
|
|
|
export default Component.extend( |
|
|
export default class ComponentVideo extends ComponentImage { |
|
|
{ |
|
|
get defaults() { |
|
|
defaults: { |
|
|
return { |
|
|
...Component.prototype.defaults, |
|
|
...super.defaults, |
|
|
type, |
|
|
type, |
|
|
tagName: type, |
|
|
tagName: type, |
|
|
videoId: '', |
|
|
videoId: '', |
|
|
@ -31,331 +31,329 @@ export default Component.extend( |
|
|
modestbranding: 0, // YT modest branding
|
|
|
modestbranding: 0, // YT modest branding
|
|
|
sources: [], |
|
|
sources: [], |
|
|
attributes: { allowfullscreen: 'allowfullscreen' }, |
|
|
attributes: { allowfullscreen: 'allowfullscreen' }, |
|
|
}, |
|
|
}; |
|
|
|
|
|
} |
|
|
initialize(o, opt) { |
|
|
|
|
|
this.em = opt.em; |
|
|
|
|
|
if (this.get('src')) this.parseFromSrc(); |
|
|
|
|
|
this.updateTraits(); |
|
|
|
|
|
this.listenTo(this, 'change:provider', this.updateTraits); |
|
|
|
|
|
this.listenTo(this, 'change:videoId change:provider', this.updateSrc); |
|
|
|
|
|
Component.prototype.initialize.apply(this, arguments); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Update traits by provider |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
updateTraits() { |
|
|
|
|
|
const prov = this.get('provider'); |
|
|
|
|
|
let tagName = 'iframe'; |
|
|
|
|
|
let traits; |
|
|
|
|
|
|
|
|
|
|
|
switch (prov) { |
|
|
initialize(o, opt) { |
|
|
case yt: |
|
|
this.em = opt.em; |
|
|
case ytnc: |
|
|
if (this.get('src')) this.parseFromSrc(); |
|
|
traits = this.getYoutubeTraits(); |
|
|
this.updateTraits(); |
|
|
break; |
|
|
this.listenTo(this, 'change:provider', this.updateTraits); |
|
|
case vi: |
|
|
this.listenTo(this, 'change:videoId change:provider', this.updateSrc); |
|
|
traits = this.getVimeoTraits(); |
|
|
ComponentImage.prototype.initialize.apply(this, arguments); |
|
|
break; |
|
|
} |
|
|
default: |
|
|
|
|
|
tagName = 'video'; |
|
|
|
|
|
traits = this.getSourceTraits(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.set({ tagName }, { silent: 1 }); // avoid break in view
|
|
|
/** |
|
|
this.set({ traits }); |
|
|
* Update traits by provider |
|
|
this.em.trigger('component:toggled'); |
|
|
* @private |
|
|
}, |
|
|
*/ |
|
|
|
|
|
updateTraits() { |
|
|
|
|
|
const prov = this.get('provider'); |
|
|
|
|
|
let tagName = 'iframe'; |
|
|
|
|
|
let traits; |
|
|
|
|
|
|
|
|
/** |
|
|
switch (prov) { |
|
|
* Set attributes by src string |
|
|
case yt: |
|
|
*/ |
|
|
case ytnc: |
|
|
parseFromSrc() { |
|
|
traits = this.getYoutubeTraits(); |
|
|
const prov = this.get('provider'); |
|
|
break; |
|
|
const uri = this.parseUri(this.get('src')); |
|
|
case vi: |
|
|
const qr = uri.query; |
|
|
traits = this.getVimeoTraits(); |
|
|
switch (prov) { |
|
|
break; |
|
|
case yt: |
|
|
default: |
|
|
case ytnc: |
|
|
tagName = 'video'; |
|
|
case vi: |
|
|
traits = this.getSourceTraits(); |
|
|
this.set('videoId', uri.pathname.split('/').pop()); |
|
|
} |
|
|
qr.list && this.set('list', qr.list); |
|
|
|
|
|
hasParam(qr.autoplay) && this.set('autoplay', 1); |
|
|
|
|
|
hasParam(qr.loop) && this.set('loop', 1); |
|
|
|
|
|
parseInt(qr.controls) === 0 && this.set('controls', 0); |
|
|
|
|
|
hasParam(qr.color) && this.set('color', qr.color); |
|
|
|
|
|
qr.rel === '0' && this.set('rel', 0); |
|
|
|
|
|
qr.modestbranding === '1' && this.set('modestbranding', 1); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
this.set({ tagName }, { silent: 1 }); // avoid break in view
|
|
|
* Update src on change of video ID |
|
|
this.set({ traits }); |
|
|
* @private |
|
|
this.em.trigger('component:toggled'); |
|
|
*/ |
|
|
} |
|
|
updateSrc() { |
|
|
|
|
|
const prov = this.get('provider'); |
|
|
|
|
|
let src = ''; |
|
|
|
|
|
|
|
|
|
|
|
switch (prov) { |
|
|
/** |
|
|
case yt: |
|
|
* Set attributes by src string |
|
|
src = this.getYoutubeSrc(); |
|
|
*/ |
|
|
break; |
|
|
parseFromSrc() { |
|
|
case ytnc: |
|
|
const prov = this.get('provider'); |
|
|
src = this.getYoutubeNoCookieSrc(); |
|
|
const uri = this.parseUri(this.get('src')); |
|
|
break; |
|
|
const qr = uri.query; |
|
|
case vi: |
|
|
switch (prov) { |
|
|
src = this.getVimeoSrc(); |
|
|
case yt: |
|
|
break; |
|
|
case ytnc: |
|
|
} |
|
|
case vi: |
|
|
|
|
|
this.set('videoId', uri.pathname.split('/').pop()); |
|
|
|
|
|
qr.list && this.set('list', qr.list); |
|
|
|
|
|
hasParam(qr.autoplay) && this.set('autoplay', 1); |
|
|
|
|
|
hasParam(qr.loop) && this.set('loop', 1); |
|
|
|
|
|
parseInt(qr.controls) === 0 && this.set('controls', 0); |
|
|
|
|
|
hasParam(qr.color) && this.set('color', qr.color); |
|
|
|
|
|
qr.rel === '0' && this.set('rel', 0); |
|
|
|
|
|
qr.modestbranding === '1' && this.set('modestbranding', 1); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.set({ src }); |
|
|
/** |
|
|
}, |
|
|
* Update src on change of video ID |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
updateSrc() { |
|
|
|
|
|
const prov = this.get('provider'); |
|
|
|
|
|
let src = ''; |
|
|
|
|
|
|
|
|
/** |
|
|
switch (prov) { |
|
|
* Returns object of attributes for HTML |
|
|
case yt: |
|
|
* @return {Object} |
|
|
src = this.getYoutubeSrc(); |
|
|
* @private |
|
|
break; |
|
|
*/ |
|
|
case ytnc: |
|
|
getAttrToHTML(...args) { |
|
|
src = this.getYoutubeNoCookieSrc(); |
|
|
var attr = Component.prototype.getAttrToHTML.apply(this, args); |
|
|
break; |
|
|
var prov = this.get('provider'); |
|
|
case vi: |
|
|
switch (prov) { |
|
|
src = this.getVimeoSrc(); |
|
|
case yt: |
|
|
break; |
|
|
case ytnc: |
|
|
} |
|
|
case vi: |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
if (this.get('loop')) attr.loop = 'loop'; |
|
|
|
|
|
if (this.get('autoplay')) attr.autoplay = 'autoplay'; |
|
|
|
|
|
if (this.get('controls')) attr.controls = 'controls'; |
|
|
|
|
|
} |
|
|
|
|
|
return attr; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Listen provider change and switch traits, in TraitView listen traits change
|
|
|
this.set({ src }); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Return the provider trait |
|
|
* Returns object of attributes for HTML |
|
|
* @return {Object} |
|
|
* @return {Object} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getProviderTrait() { |
|
|
getAttrToHTML(...args) { |
|
|
return { |
|
|
var attr = Component.prototype.getAttrToHTML.apply(this, args); |
|
|
type: 'select', |
|
|
var prov = this.get('provider'); |
|
|
label: 'Provider', |
|
|
switch (prov) { |
|
|
name: 'provider', |
|
|
case yt: |
|
|
changeProp: 1, |
|
|
case ytnc: |
|
|
options: [ |
|
|
case vi: |
|
|
{ value: 'so', name: 'HTML5 Source' }, |
|
|
break; |
|
|
{ value: yt, name: 'Youtube' }, |
|
|
default: |
|
|
{ value: ytnc, name: 'Youtube (no cookie)' }, |
|
|
if (this.get('loop')) attr.loop = 'loop'; |
|
|
{ value: vi, name: 'Vimeo' }, |
|
|
if (this.get('autoplay')) attr.autoplay = 'autoplay'; |
|
|
], |
|
|
if (this.get('controls')) attr.controls = 'controls'; |
|
|
}; |
|
|
} |
|
|
}, |
|
|
return attr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// Listen provider change and switch traits, in TraitView listen traits change
|
|
|
* Return traits for the source provider |
|
|
|
|
|
* @return {Array<Object>} |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
getSourceTraits() { |
|
|
|
|
|
return [ |
|
|
|
|
|
this.getProviderTrait(), |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'Source', |
|
|
|
|
|
name: 'src', |
|
|
|
|
|
placeholder: 'eg. ./media/video.mp4', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'Poster', |
|
|
|
|
|
name: 'poster', |
|
|
|
|
|
placeholder: 'eg. ./media/image.jpg', |
|
|
|
|
|
// changeProp: 1
|
|
|
|
|
|
}, |
|
|
|
|
|
this.getAutoplayTrait(), |
|
|
|
|
|
this.getLoopTrait(), |
|
|
|
|
|
this.getControlsTrait(), |
|
|
|
|
|
]; |
|
|
|
|
|
}, |
|
|
|
|
|
/** |
|
|
|
|
|
* Return traits for the source provider |
|
|
|
|
|
* @return {Array<Object>} |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
getYoutubeTraits() { |
|
|
|
|
|
return [ |
|
|
|
|
|
this.getProviderTrait(), |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'Video ID', |
|
|
|
|
|
name: 'videoId', |
|
|
|
|
|
placeholder: 'eg. jNQXAC9IVRw', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
this.getAutoplayTrait(), |
|
|
|
|
|
this.getLoopTrait(), |
|
|
|
|
|
this.getControlsTrait(), |
|
|
|
|
|
{ |
|
|
|
|
|
type: 'checkbox', |
|
|
|
|
|
label: 'Related', |
|
|
|
|
|
name: 'rel', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
type: 'checkbox', |
|
|
|
|
|
label: 'Modest', |
|
|
|
|
|
name: 'modestbranding', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
]; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Return traits for the source provider |
|
|
* Return the provider trait |
|
|
* @return {Array<Object>} |
|
|
* @return {Object} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getVimeoTraits() { |
|
|
getProviderTrait() { |
|
|
return [ |
|
|
return { |
|
|
this.getProviderTrait(), |
|
|
type: 'select', |
|
|
{ |
|
|
label: 'Provider', |
|
|
label: 'Video ID', |
|
|
name: 'provider', |
|
|
name: 'videoId', |
|
|
changeProp: 1, |
|
|
placeholder: 'eg. 123456789', |
|
|
options: [ |
|
|
changeProp: 1, |
|
|
{ value: 'so', name: 'HTML5 Source' }, |
|
|
}, |
|
|
{ value: yt, name: 'Youtube' }, |
|
|
{ |
|
|
{ value: ytnc, name: 'Youtube (no cookie)' }, |
|
|
label: 'Color', |
|
|
{ value: vi, name: 'Vimeo' }, |
|
|
name: 'color', |
|
|
], |
|
|
placeholder: 'eg. FF0000', |
|
|
}; |
|
|
changeProp: 1, |
|
|
} |
|
|
}, |
|
|
|
|
|
this.getAutoplayTrait(), |
|
|
|
|
|
this.getLoopTrait(), |
|
|
|
|
|
]; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Return object trait |
|
|
* Return traits for the source provider |
|
|
* @return {Object} |
|
|
* @return {Array<Object>} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getAutoplayTrait() { |
|
|
getSourceTraits() { |
|
|
return { |
|
|
return [ |
|
|
|
|
|
this.getProviderTrait(), |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'Source', |
|
|
|
|
|
name: 'src', |
|
|
|
|
|
placeholder: 'eg. ./media/video.mp4', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'Poster', |
|
|
|
|
|
name: 'poster', |
|
|
|
|
|
placeholder: 'eg. ./media/image.jpg', |
|
|
|
|
|
// changeProp: 1
|
|
|
|
|
|
}, |
|
|
|
|
|
this.getAutoplayTrait(), |
|
|
|
|
|
this.getLoopTrait(), |
|
|
|
|
|
this.getControlsTrait(), |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
|
|
|
* Return traits for the source provider |
|
|
|
|
|
* @return {Array<Object>} |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
getYoutubeTraits() { |
|
|
|
|
|
return [ |
|
|
|
|
|
this.getProviderTrait(), |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'Video ID', |
|
|
|
|
|
name: 'videoId', |
|
|
|
|
|
placeholder: 'eg. jNQXAC9IVRw', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
this.getAutoplayTrait(), |
|
|
|
|
|
this.getLoopTrait(), |
|
|
|
|
|
this.getControlsTrait(), |
|
|
|
|
|
{ |
|
|
type: 'checkbox', |
|
|
type: 'checkbox', |
|
|
label: 'Autoplay', |
|
|
label: 'Related', |
|
|
name: 'autoplay', |
|
|
name: 'rel', |
|
|
changeProp: 1, |
|
|
changeProp: 1, |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Return object trait |
|
|
|
|
|
* @return {Object} |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
getLoopTrait() { |
|
|
|
|
|
return { |
|
|
|
|
|
type: 'checkbox', |
|
|
type: 'checkbox', |
|
|
label: 'Loop', |
|
|
label: 'Modest', |
|
|
name: 'loop', |
|
|
name: 'modestbranding', |
|
|
changeProp: 1, |
|
|
changeProp: 1, |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Return object trait |
|
|
* Return traits for the source provider |
|
|
* @return {Object} |
|
|
* @return {Array<Object>} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getControlsTrait() { |
|
|
getVimeoTraits() { |
|
|
return { |
|
|
return [ |
|
|
type: 'checkbox', |
|
|
this.getProviderTrait(), |
|
|
label: 'Controls', |
|
|
{ |
|
|
name: 'controls', |
|
|
label: 'Video ID', |
|
|
|
|
|
name: 'videoId', |
|
|
|
|
|
placeholder: 'eg. 123456789', |
|
|
changeProp: 1, |
|
|
changeProp: 1, |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
|
|
|
label: 'Color', |
|
|
|
|
|
name: 'color', |
|
|
|
|
|
placeholder: 'eg. FF0000', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}, |
|
|
|
|
|
this.getAutoplayTrait(), |
|
|
|
|
|
this.getLoopTrait(), |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Returns url to youtube video |
|
|
* Return object trait |
|
|
* @return {string} |
|
|
* @return {Object} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getYoutubeSrc() { |
|
|
getAutoplayTrait() { |
|
|
const id = this.get('videoId'); |
|
|
return { |
|
|
let url = this.get('ytUrl'); |
|
|
type: 'checkbox', |
|
|
const list = this.get('list'); |
|
|
label: 'Autoplay', |
|
|
url += id + (id.indexOf('?') < 0 ? '?' : ''); |
|
|
name: 'autoplay', |
|
|
url += list ? `&list=${list}` : ''; |
|
|
changeProp: 1, |
|
|
url += this.get('autoplay') ? '&autoplay=1' : ''; |
|
|
}; |
|
|
url += !this.get('controls') ? '&controls=0&showinfo=0' : ''; |
|
|
} |
|
|
// Loop works only with playlist enabled
|
|
|
|
|
|
// https://stackoverflow.com/questions/25779966/youtube-iframe-loop-doesnt-work
|
|
|
|
|
|
url += this.get('loop') ? `&loop=1&playlist=${id}` : ''; |
|
|
|
|
|
url += this.get('rel') ? '' : '&rel=0'; |
|
|
|
|
|
url += this.get('modestbranding') ? '&modestbranding=1' : ''; |
|
|
|
|
|
return url; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Returns url to youtube no cookie video |
|
|
* Return object trait |
|
|
* @return {string} |
|
|
* @return {Object} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getYoutubeNoCookieSrc() { |
|
|
getLoopTrait() { |
|
|
let url = this.getYoutubeSrc(); |
|
|
return { |
|
|
url = url.replace(this.get('ytUrl'), this.get('ytncUrl')); |
|
|
type: 'checkbox', |
|
|
return url; |
|
|
label: 'Loop', |
|
|
}, |
|
|
name: 'loop', |
|
|
|
|
|
changeProp: 1, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Returns url to vimeo video |
|
|
* Return object trait |
|
|
* @return {string} |
|
|
* @return {Object} |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
getVimeoSrc() { |
|
|
getControlsTrait() { |
|
|
var url = this.get('viUrl'); |
|
|
return { |
|
|
url += this.get('videoId') + '?'; |
|
|
type: 'checkbox', |
|
|
url += this.get('autoplay') ? '&autoplay=1' : ''; |
|
|
label: 'Controls', |
|
|
url += this.get('loop') ? '&loop=1' : ''; |
|
|
name: 'controls', |
|
|
url += !this.get('controls') ? '&title=0&portrait=0&badge=0' : ''; |
|
|
changeProp: 1, |
|
|
url += this.get('color') ? '&color=' + this.get('color') : ''; |
|
|
}; |
|
|
return url; |
|
|
} |
|
|
}, |
|
|
|
|
|
}, |
|
|
/** |
|
|
{ |
|
|
* Returns url to youtube video |
|
|
/** |
|
|
* @return {string} |
|
|
* Detect if the passed element is a valid component. |
|
|
* @private |
|
|
* In case the element is valid an object abstracted |
|
|
*/ |
|
|
* from the element will be returned |
|
|
getYoutubeSrc() { |
|
|
* @param {HTMLElement} |
|
|
const id = this.get('videoId'); |
|
|
* @return {Object} |
|
|
let url = this.get('ytUrl'); |
|
|
* @private |
|
|
const list = this.get('list'); |
|
|
*/ |
|
|
url += id + (id.indexOf('?') < 0 ? '?' : ''); |
|
|
isComponent(el) { |
|
|
url += list ? `&list=${list}` : ''; |
|
|
let result = ''; |
|
|
url += this.get('autoplay') ? '&autoplay=1' : ''; |
|
|
const { tagName, src } = el; |
|
|
url += !this.get('controls') ? '&controls=0&showinfo=0' : ''; |
|
|
const isYtProv = /youtube\.com\/embed/.test(src); |
|
|
// Loop works only with playlist enabled
|
|
|
const isYtncProv = /youtube-nocookie\.com\/embed/.test(src); |
|
|
// https://stackoverflow.com/questions/25779966/youtube-iframe-loop-doesnt-work
|
|
|
const isViProv = /player\.vimeo\.com\/video/.test(src); |
|
|
url += this.get('loop') ? `&loop=1&playlist=${id}` : ''; |
|
|
const isExtProv = isYtProv || isYtncProv || isViProv; |
|
|
url += this.get('rel') ? '' : '&rel=0'; |
|
|
if (toLowerCase(tagName) == type || (toLowerCase(tagName) == 'iframe' && isExtProv)) { |
|
|
url += this.get('modestbranding') ? '&modestbranding=1' : ''; |
|
|
result = { type: 'video' }; |
|
|
return url; |
|
|
if (src) result.src = src; |
|
|
} |
|
|
if (isExtProv) { |
|
|
|
|
|
if (isYtProv) result.provider = yt; |
|
|
/** |
|
|
else if (isYtncProv) result.provider = ytnc; |
|
|
* Returns url to youtube no cookie video |
|
|
else if (isViProv) result.provider = vi; |
|
|
* @return {string} |
|
|
} |
|
|
* @private |
|
|
} |
|
|
*/ |
|
|
return result; |
|
|
getYoutubeNoCookieSrc() { |
|
|
}, |
|
|
let url = this.getYoutubeSrc(); |
|
|
|
|
|
url = url.replace(this.get('ytUrl'), this.get('ytncUrl')); |
|
|
|
|
|
return url; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Returns url to vimeo video |
|
|
|
|
|
* @return {string} |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
getVimeoSrc() { |
|
|
|
|
|
var url = this.get('viUrl'); |
|
|
|
|
|
url += this.get('videoId') + '?'; |
|
|
|
|
|
url += this.get('autoplay') ? '&autoplay=1' : ''; |
|
|
|
|
|
url += this.get('loop') ? '&loop=1' : ''; |
|
|
|
|
|
url += !this.get('controls') ? '&title=0&portrait=0&badge=0' : ''; |
|
|
|
|
|
url += this.get('color') ? '&color=' + this.get('color') : ''; |
|
|
|
|
|
return url; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
|
|
|
* Detect if the passed element is a valid component. |
|
|
|
|
|
* In case the element is valid an object abstracted |
|
|
|
|
|
* from the element will be returned |
|
|
|
|
|
* @param {HTMLElement} |
|
|
|
|
|
* @return {Object} |
|
|
|
|
|
* @private |
|
|
|
|
|
*/ |
|
|
|
|
|
ComponentVideo.isComponent = el => { |
|
|
|
|
|
let result = ''; |
|
|
|
|
|
const { tagName, src } = el; |
|
|
|
|
|
const isYtProv = /youtube\.com\/embed/.test(src); |
|
|
|
|
|
const isYtncProv = /youtube-nocookie\.com\/embed/.test(src); |
|
|
|
|
|
const isViProv = /player\.vimeo\.com\/video/.test(src); |
|
|
|
|
|
const isExtProv = isYtProv || isYtncProv || isViProv; |
|
|
|
|
|
if (toLowerCase(tagName) == type || (toLowerCase(tagName) == 'iframe' && isExtProv)) { |
|
|
|
|
|
result = { type: 'video' }; |
|
|
|
|
|
if (src) result.src = src; |
|
|
|
|
|
if (isExtProv) { |
|
|
|
|
|
if (isYtProv) result.provider = yt; |
|
|
|
|
|
else if (isYtncProv) result.provider = ytnc; |
|
|
|
|
|
else if (isViProv) result.provider = vi; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
); |
|
|
return result; |
|
|
|
|
|
}; |
|
|
|