|
|
@@ -60,47 +60,54 @@ export default {
|
|
60
|
60
|
postsMap[post.slug] = post
|
|
61
|
61
|
return postsMap
|
|
62
|
62
|
}, {})
|
|
63
|
|
- },
|
|
|
63
|
+ }
|
|
64
|
64
|
},
|
|
65
|
65
|
methods: {
|
|
66
|
|
- checkForImages(posts) {
|
|
67
|
|
- const allBlocks = posts[this.$route.params.slug].blocks.map(block => {
|
|
|
66
|
+ pageBlocks(posts) {
|
|
|
67
|
+ return posts[this.$route.params.slug].blocks.map(block => {
|
|
68
|
68
|
if(block) return block
|
|
69
|
69
|
})
|
|
70
|
|
- allBlocks.forEach(block => {
|
|
|
70
|
+ },
|
|
|
71
|
+ checkForImages(posts) {
|
|
|
72
|
+ this.pageBlocks(posts).forEach(block => {
|
|
71
|
73
|
if(!block) return
|
|
72
|
74
|
const doc = new DOMParser().parseFromString(block, 'text/html')
|
|
73
|
75
|
const gallery = doc.querySelectorAll('.blocks-gallery-item img')
|
|
74
|
76
|
// add captions
|
|
75
|
|
- if(gallery) {
|
|
|
77
|
+ if(gallery.length) {
|
|
76
|
78
|
this.images = [].slice.call(gallery).map(
|
|
77
|
79
|
item => { return item.src }
|
|
78
|
80
|
)
|
|
79
|
81
|
}
|
|
80
|
82
|
})
|
|
81
|
|
- },
|
|
82
|
|
- wrapImagesWithLink() {
|
|
83
|
|
- const gallery = document.querySelectorAll('.blocks-gallery-item figure, figure.wp-block-image')
|
|
84
|
|
- gallery.forEach((item, i) => {
|
|
85
|
|
- item.addEventListener('click', () => {
|
|
86
|
|
- this.fullscreengallery = i
|
|
87
|
|
- })
|
|
88
|
|
- })
|
|
89
|
83
|
}
|
|
90
|
84
|
},
|
|
91
|
85
|
watch: {
|
|
92
|
86
|
posts(newVal, oldVal) {
|
|
93
|
87
|
// Loads images from the DOM
|
|
94
|
88
|
this.checkForImages(newVal)
|
|
|
89
|
+
|
|
|
90
|
+ // Gottas be on the next render tick
|
|
|
91
|
+ this.$nextTick(() => {
|
|
|
92
|
+ let gallery
|
|
|
93
|
+ this.pageBlocks(newVal).forEach(block => {
|
|
|
94
|
+ if(!block) return
|
|
|
95
|
+ gallery = document.querySelectorAll('.blocks-gallery-item figure')
|
|
|
96
|
+ })
|
|
|
97
|
+
|
|
|
98
|
+ if(gallery.length < 1) return
|
|
|
99
|
+
|
|
|
100
|
+ gallery.forEach((item, i) => {
|
|
|
101
|
+ item.addEventListener('mouseup', event => { this.fullscreengallery = i })
|
|
|
102
|
+ })
|
|
|
103
|
+ })
|
|
95
|
104
|
}
|
|
96
|
105
|
},
|
|
97
|
|
- mounted() {
|
|
|
106
|
+ created() {
|
|
98
|
107
|
// TODO: Only makes req if this hasn't been loaded yet
|
|
99
|
108
|
let type = this.$route.params.type
|
|
100
|
109
|
type = type.charAt(0).toUpperCase() + type.slice(1)
|
|
101
|
110
|
this.$store.dispatch(`getAll${type}`)
|
|
102
|
|
-
|
|
103
|
|
- this.wrapImagesWithLink()
|
|
104
|
111
|
}
|
|
105
|
112
|
}
|
|
106
|
113
|
</script>
|