Browse Source

feat: working youtube embeds from custom field

tags/0.9.0
J 6 years ago
parent
commit
c2dbec3831
1 changed files with 28 additions and 11 deletions
  1. 28
    11
      vue-theme/src/components/hero.vue

+ 28
- 11
vue-theme/src/components/hero.vue View File

@@ -1,7 +1,14 @@
1 1
 <template lang="pug">
2 2
 .hero.f-col(v-if="showHero")
3
-    h3(v-if="heroText") {{ heroText }}
4
-    button(v-if="showPlaybutton") play
3
+    iframe(
4
+        v-if="isPlaying"
5
+        :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
6
+        frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope"
7
+        allowfullscreen
8
+    ).embedded
9
+    .blank.f-col(v-else)
10
+        h3(v-if="heroText") {{ heroText }}
11
+        button(v-if="showPlaybutton" @click="isPlaying = true") play
5 12
 </template>
6 13
 
7 14
 <script>
@@ -10,21 +17,28 @@ import { mapState } from 'vuex'
10 17
 export default {
11 18
     data() {
12 19
         return {
13
-            heroHeight: 0
20
+            heroHeight: 0,
21
+            isPlaying: false
22
+        }
23
+    },
24
+    computed: {
25
+        ...mapState({
26
+            showHero: state => state.hero.url,
27
+            heroText: state => state.hero.text,
28
+            showPlaybutton: state => state.hero.playbutton,
29
+        }),
30
+        heroIdFromUrl() {
31
+            const url = this.showHero.split('/')
32
+            return url.pop()
14 33
         }
15 34
     },
16
-    computed: mapState({
17
-        showHero: state => state.hero.url,
18
-        heroText: state => state.hero.text,
19
-        showPlaybutton: state => state.hero.playbutton,
20
-    }),
21 35
     methods: {
22 36
         onResize() {
23
-            this.heroHeight = this.$el.offsetWidth / 2.33
37
+            this.heroHeight = this.$el.offsetWidth / 1.8
24 38
         }
25 39
     },
26 40
     mounted() {
27
-        this.heroHeight = this.$el.offsetWidth / 2.33
41
+        this.heroHeight = this.$el.offsetWidth / 1.8
28 42
         this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
29 43
     },
30 44
     watch: {
@@ -42,6 +56,9 @@ export default {
42 56
 <style lang="postcss">
43 57
 .hero
44 58
     background-color: rebeccapurple
45
-    min-height: 30%
59
+    min-height: 35%
46 60
     width: 100%
61
+    .embedded
62
+        height: 100%
63
+        width: 100%
47 64
 </style>

Loading…
Cancel
Save