Просмотр исходного кода

loading images based on index

tags/0.9.0
J 6 лет назад
Родитель
Сommit
0861703562
2 измененных файлов: 11 добавлений и 13 удалений
  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 Просмотреть файл

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

+ 5
- 8
vue-theme/src/pages/single.vue Просмотреть файл

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

Загрузка…
Отмена
Сохранить