Quellcode durchsuchen

feat: working youtube embeds from custom field

tags/0.9.0
J vor 6 Jahren
Ursprung
Commit
c2dbec3831
1 geänderte Dateien mit 28 neuen und 11 gelöschten Zeilen
  1. 28
    11
      vue-theme/src/components/hero.vue

+ 28
- 11
vue-theme/src/components/hero.vue Datei anzeigen

1
 <template lang="pug">
1
 <template lang="pug">
2
 .hero.f-col(v-if="showHero")
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
 </template>
12
 </template>
6
 
13
 
7
 <script>
14
 <script>
10
 export default {
17
 export default {
11
     data() {
18
     data() {
12
         return {
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
     methods: {
35
     methods: {
22
         onResize() {
36
         onResize() {
23
-            this.heroHeight = this.$el.offsetWidth / 2.33
37
+            this.heroHeight = this.$el.offsetWidth / 1.8
24
         }
38
         }
25
     },
39
     },
26
     mounted() {
40
     mounted() {
27
-        this.heroHeight = this.$el.offsetWidth / 2.33
41
+        this.heroHeight = this.$el.offsetWidth / 1.8
28
         this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
42
         this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
29
     },
43
     },
30
     watch: {
44
     watch: {
42
 <style lang="postcss">
56
 <style lang="postcss">
43
 .hero
57
 .hero
44
     background-color: rebeccapurple
58
     background-color: rebeccapurple
45
-    min-height: 30%
59
+    min-height: 35%
46
     width: 100%
60
     width: 100%
61
+    .embedded
62
+        height: 100%
63
+        width: 100%
47
 </style>
64
 </style>

Laden…
Abbrechen
Speichern