Sfoglia il codice sorgente

:recycle: tweaking refactor of click setting

tags/1.0.1^2^2
J 3 anni fa
parent
commit
ac37adc59d
1 ha cambiato i file con 7 aggiunte e 8 eliminazioni
  1. 7
    8
      vue-theme/src/pages/single.vue

+ 7
- 8
vue-theme/src/pages/single.vue Vedi File

185
             this.loading = false
185
             this.loading = false
186
         },
186
         },
187
         _setClick(el, cb) {
187
         _setClick(el, cb) {
188
-            el.dataset.gallery = index
189
             if (el.addEventListener) {
188
             if (el.addEventListener) {
190
                 el.addEventListener('click', cb, false)
189
                 el.addEventListener('click', cb, false)
191
             } else {
190
             } else {
207
             if (!this.$el) return
206
             if (!this.$el) return
208
             const section = this.$el.children[0].querySelector('section')
207
             const section = this.$el.children[0].querySelector('section')
209
             await nextTick()
208
             await nextTick()
210
-            const galleries = section.querySelectorAll('.wp-block-gallery')
211
-            galleries.forEach((gallery, galleryIndex) => {
212
-                gallery.querySelectorAll('img').forEach(image =>
213
-                    this._setClick(image, galleryIndex, e => {
209
+            const galleryBlocks = section.querySelectorAll('.wp-block-gallery')
210
+            galleryBlocks.forEach((block, blockIndex) => {
211
+                block.querySelectorAll('img').forEach(image => {
212
+                    image.dataset.gallery = blockIndex
213
+                    this._setClick(image, e => {
214
                         this.activeGalleryIndex = e.target.dataset.gallery
214
                         this.activeGalleryIndex = e.target.dataset.gallery
215
-
216
                         const activeGallery =
215
                         const activeGallery =
217
                             post.galleries[this.activeGalleryIndex]
216
                             post.galleries[this.activeGalleryIndex]
218
 
217
 
228
                             `opening gallery: ${this.activeGalleryIndex}.${this.activeImageIndex}`,
227
                             `opening gallery: ${this.activeGalleryIndex}.${this.activeImageIndex}`,
229
                         )
228
                         )
230
                         console.log(e.target.dataset)
229
                         console.log(e.target.dataset)
231
-                    }),
232
-                )
230
+                    })
231
+                })
233
             })
232
             })
234
         },
233
         },
235
     },
234
     },

Loading…
Annulla
Salva