Bläddra i källkod

loading images based on index

tags/0.9.0
J 6 år sedan
förälder
incheckning
0861703562
2 ändrade filer med 11 tillägg och 13 borttagningar
  1. 6
    5
      vue-theme/src/components/gallery.vue
  2. 5
    8
      vue-theme/src/pages/single.vue

+ 6
- 5
vue-theme/src/components/gallery.vue Visa fil

@@ -1,5 +1,5 @@
1 1
 <template lang="pug">
2
-.gallery.f-col.center(v-if="fullscreengallery")
2
+.gallery.f-col.center(v-if="fullscreengallery + 1 > 0")
3 3
     button(@click="hideGallery").hide hide
4 4
     ul
5 5
         li(v-for="(image, i) of images" :class="{ active: i === selected }")
@@ -15,8 +15,7 @@
15 15
 export default {
16 16
     props: {
17 17
         images: { type: Array },
18
-        fullscreengallery: { type: Boolean },
19
-        startwith: { type: Number }
18
+        fullscreengallery: { type: Number },
20 19
     },
21 20
     data() { 
22 21
         return {
@@ -47,8 +46,10 @@ export default {
47 46
             }
48 47
         }
49 48
     },
50
-    created() {
51
-        this.selected = this.startwith
49
+    watch: {
50
+        fullscreengallery(newVal, oldVal) { 
51
+            this.selected = newVal
52
+        }
52 53
     },
53 54
     mounted() {
54 55
         window.addEventListener('keydown', this.interpretKeypress)

+ 5
- 8
vue-theme/src/pages/single.vue Visa fil

@@ -1,10 +1,9 @@
1 1
 <template lang="pug">
2 2
 .page--single.f-row.between(v-if="$route.params.slug")
3
-    gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = false" :images="images" :startwith="lastImageClicked")
3
+    gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = -1" :images="images")
4 4
     article.f-grow.shadow
5 5
         header
6 6
             h1 {{ type }}:{{ $route.params.slug }} single
7
-            button(@click="fullscreengallery = true") fullscreen
8 7
         section(v-if="posts[$route.params.slug]")
9 8
             h4 {{ posts[$route.params.slug].title }}
10 9
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
@@ -33,8 +32,7 @@ export default {
33 32
     data() {
34 33
         return {
35 34
             images: [], 
36
-            fullscreengallery: false,
37
-            lastImageClicked: 0
35
+            fullscreengallery: -1
38 36
         }
39 37
     },
40 38
     computed: {
@@ -85,9 +83,7 @@ export default {
85 83
             const gallery = document.querySelectorAll('.blocks-gallery-item figure, figure.wp-block-image')
86 84
             gallery.forEach((item, i) => {
87 85
                 item.addEventListener('click', () => {
88
-                    this.lastImageClicked = i
89
-                    console.log('yeah!', this.lastImageClicked)
90
-                    this.fullscreengallery = true
86
+                    this.fullscreengallery = i
91 87
                 })
92 88
             })
93 89
         }
@@ -96,7 +92,6 @@ export default {
96 92
         posts(newVal, oldVal) { 
97 93
             // Loads images from the DOM
98 94
             this.checkForImages(newVal)
99
-            this.wrapImagesWithLink()
100 95
         }
101 96
     },
102 97
     mounted() {
@@ -104,6 +99,8 @@ export default {
104 99
         let type = this.$route.params.type
105 100
         type = type.charAt(0).toUpperCase() + type.slice(1)
106 101
         this.$store.dispatch(`getAll${type}`)
102
+
103
+        this.wrapImagesWithLink()
107 104
     }
108 105
 }
109 106
 </script>

Laddar…
Avbryt
Spara