|
|
@@ -13,7 +13,7 @@
|
|
13
|
13
|
li(v-for="(imageID, j) in post.galleries[block.gallery].ids" :class="`gallery-${i}--image-${j+1}`" :key="`block-${i}-${j}`")
|
|
14
|
14
|
img(@click="openGallery(i - 1, imageID)" :src="post.attached[imageID]['thumbnail']")
|
|
15
|
15
|
button(@click="openGallery(i - 1, imageID)") gallery: {{ i }} image: {{ imageID }}
|
|
16
|
|
- //- Fullscreen gallery
|
|
|
16
|
+ //- Fullscreen gallery component for every gallery block
|
|
17
|
17
|
gallery(
|
|
18
|
18
|
v-if="activeGalleryIndex == (i - 1)"
|
|
19
|
19
|
:activeImageIndex="activeImageIndex"
|
|
|
@@ -21,7 +21,7 @@
|
|
21
|
21
|
:images="imagesInGallery"
|
|
22
|
22
|
)
|
|
23
|
23
|
|
|
24
|
|
- //- Just a regular block
|
|
|
24
|
+ //- Just a regular block (html or img)
|
|
25
|
25
|
.block(v-else v-html="block")
|
|
26
|
26
|
|
|
27
|
27
|
sidebar(v-if="sidebar" :type="`${type}`")
|
|
|
@@ -40,22 +40,17 @@ import { convertTitleCase, typeFromRoute } from '@/utils/helpers'
|
|
40
|
40
|
|
|
41
|
41
|
export default {
|
|
42
|
42
|
props: {
|
|
43
|
|
- sidebar: {
|
|
44
|
|
- type: Boolean
|
|
45
|
|
- }
|
|
|
43
|
+ sidebar: { type: Boolean }
|
|
46
|
44
|
},
|
|
47
|
45
|
components: { sidebar, gallery },
|
|
48
|
46
|
data() {
|
|
49
|
47
|
return {
|
|
50
|
|
- images: [],
|
|
|
48
|
+ // Gallery control
|
|
51
|
49
|
activeGalleryIndex: -1,
|
|
52
|
50
|
activeImageID: -1
|
|
53
|
51
|
}
|
|
54
|
52
|
},
|
|
55
|
53
|
computed: {
|
|
56
|
|
- post() {
|
|
57
|
|
- return this.posts[this.$route.params.slug]
|
|
58
|
|
- },
|
|
59
|
54
|
...mapGetters({
|
|
60
|
55
|
allPages: 'allPages',
|
|
61
|
56
|
allPagesLoaded: 'allPagesLoaded',
|
|
|
@@ -72,6 +67,18 @@ export default {
|
|
72
|
67
|
type() { // Checks for type and fixes Episodes route edge case
|
|
73
|
68
|
return typeFromRoute(this.$route)
|
|
74
|
69
|
},
|
|
|
70
|
+
|
|
|
71
|
+ /**
|
|
|
72
|
+ * We get the actual post data using the slug
|
|
|
73
|
+ */
|
|
|
74
|
+ post() {
|
|
|
75
|
+ return this.posts[this.$route.params.slug]
|
|
|
76
|
+ },
|
|
|
77
|
+ /**
|
|
|
78
|
+ * We grab posts using the type derived from
|
|
|
79
|
+ * the route (See typeFromRoute() helper) and
|
|
|
80
|
+ * create a map keyed by post slug
|
|
|
81
|
+ */
|
|
75
|
82
|
posts() {
|
|
76
|
83
|
let type = convertTitleCase(this.type)
|
|
77
|
84
|
|
|
|
@@ -83,9 +90,19 @@ export default {
|
|
83
|
90
|
return postsMap
|
|
84
|
91
|
}, {})
|
|
85
|
92
|
},
|
|
|
93
|
+
|
|
|
94
|
+ /**
|
|
|
95
|
+ * We need a convenient way to get all the images
|
|
|
96
|
+ * broken down by gallery. We use the active gallery
|
|
|
97
|
+ * image IDs to create a map. We match the ID to the
|
|
|
98
|
+ * image size and url information returned by post.attached
|
|
|
99
|
+ */
|
|
86
|
100
|
imagesInGallery() {
|
|
87
|
101
|
if(!this.activeGalleryIndex < 0) return {}
|
|
88
|
|
-
|
|
|
102
|
+ // Create a map of images by their ID
|
|
|
103
|
+ // {
|
|
|
104
|
+ // imageId: { 'thumbnail': url, 'large': url }
|
|
|
105
|
+ // }
|
|
89
|
106
|
return this.post.galleries[this.activeGalleryIndex].ids.reduce((imageMap, id) => {
|
|
90
|
107
|
imageMap[id] = this.post.attached[id]
|
|
91
|
108
|
return imageMap
|
|
|
@@ -96,10 +113,25 @@ export default {
|
|
96
|
113
|
}
|
|
97
|
114
|
},
|
|
98
|
115
|
methods: {
|
|
|
116
|
+ /**
|
|
|
117
|
+ * We set the active gallery to the index.
|
|
|
118
|
+ * Everything kicks off when activeGallery
|
|
|
119
|
+ * is set. We also need to set the activeImageID
|
|
|
120
|
+ * to the image clicked
|
|
|
121
|
+ * @param {number} galleryIndex
|
|
|
122
|
+ * @param {string} imageID
|
|
|
123
|
+ */
|
|
99
|
124
|
openGallery(galleryIndex, imageID) {
|
|
100
|
125
|
this.activeGalleryIndex = galleryIndex
|
|
101
|
126
|
this.activeImageID = imageID ? imageID : 0
|
|
102
|
127
|
},
|
|
|
128
|
+
|
|
|
129
|
+ /**
|
|
|
130
|
+ * Everytime the posts object changes
|
|
|
131
|
+ * we use this to set a new HERO
|
|
|
132
|
+ * in vuex
|
|
|
133
|
+ * @param {object} posts
|
|
|
134
|
+ */
|
|
103
|
135
|
checkAndSetHero(posts) {
|
|
104
|
136
|
const post = posts[this.$route.params.slug]
|
|
105
|
137
|
if(!post || !post.hero) return
|
|
|
@@ -110,19 +142,19 @@ export default {
|
|
110
|
142
|
},
|
|
111
|
143
|
watch: {
|
|
112
|
144
|
posts(newVal, oldVal) {
|
|
113
|
|
- // Loads images from the DOM
|
|
114
|
|
- // this.checkForImages(newVal)
|
|
115
|
|
-
|
|
116
|
145
|
this.checkAndSetHero(newVal)
|
|
117
|
146
|
}
|
|
118
|
147
|
},
|
|
119
|
148
|
created() {
|
|
120
|
|
- let type = convertTitleCase(this.$route.params.type)
|
|
121
|
|
-
|
|
122
|
|
- if(!this[`all{type}Loaded`]) {
|
|
|
149
|
+ /**
|
|
|
150
|
+ * Conditionally load based on post type
|
|
|
151
|
+ * which is derived from the route
|
|
|
152
|
+ * !: posts watcher fires when this finishes
|
|
|
153
|
+ */
|
|
|
154
|
+ let type = convertTitleCase(this.type)
|
|
|
155
|
+ if(!this[`all${type}Loaded`]) {
|
|
123
|
156
|
// console.log('Retrieving...', type)
|
|
124
|
157
|
this.$store.dispatch(`getAll${type}`)
|
|
125
|
|
- // posts watcher will fire after this
|
|
126
|
158
|
}
|
|
127
|
159
|
}
|
|
128
|
160
|
}
|