forked from EnergySage/es-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EsVideo.vue
93 lines (89 loc) · 2.31 KB
/
EsVideo.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div>
<b-embed
v-if="showVideo"
allowfullscreen
aspect="16by9"
:src="autoplayUrl"
:title="altText"
type="iframe" />
<es-card
v-else
class="EsVideo-button bg-transparent overflow-hidden p-0 position-relative w-100"
variant="interactive"
@click="showVideo = true">
<slot
v-if="hasImage"
name="image" />
<b-img
v-else-if="coverImageUrl"
:alt="altText"
sizes="md:530px sm:275px"
class="EsVideo-image d-block w-100"
:src="coverImageUrl" />
<icon-video-play
class="EsVideo-icon position-absolute"
width="74px"
height="54px" />
</es-card>
</div>
</template>
<script lang="js">
import { BImg, BEmbed } from 'bootstrap-vue';
import EsCard from './EsCard.vue';
import IconVideoPlay from '../lib-icons/icon-video-play.vue';
export default ({
name: 'EsVideo',
components: {
BImg,
BEmbed,
EsCard,
IconVideoPlay,
},
props: {
altText: {
type: String,
required: true,
},
coverImageUrl: {
type: String,
default: '',
},
embedUrl: {
type: String,
required: true,
},
},
data() {
return {
showVideo: false,
};
},
computed: {
hasImage() {
return !!this.$slots.image;
},
autoplayUrl() {
const pieces = this.embedUrl.split('?');
// "&cc_load_policy=1&cc_lang_pref=en" turns closed captions on by default
// https://support.google.com/youtube/answer/171780?hl=en#zippy=%2Cadd-captions-to-an-embedded-video
// but requires that the video owner upload non-auto-generated captions
return `${pieces[0]}?rel=0&autoplay=1&cc_load_policy=1&cc_lang_pref=en`;
},
},
});
</script>
<style lang="scss" scoped>
.EsVideo {
&-button,
&-image {
height: auto;
}
&-icon {
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
z-index: 2;
}
}
</style>