Explorar el Código

:sparkles: galleries fixed for new endpoints

tags/0.9.0
j hace 5 años
padre
commit
2ea4000e72
Se han modificado 2 ficheros con 79 adiciones y 85 borrados
  1. 42
    43
      vue-theme/src/components/gallery.vue
  2. 37
    42
      vue-theme/src/pages/single.vue

+ 42
- 43
vue-theme/src/components/gallery.vue Ver fichero

@@ -1,6 +1,8 @@
1 1
 <template lang="pug">
2
-.gallery.f-col.center(v-if="showGallery")
2
+.gallery.active.f-col.center
3 3
     button(@click="hideGallery").hide hide
4
+    p {{ imageIds }}
5
+    p image: {{ imageIds[selected] }}
4 6
     ul
5 7
         li(v-for="(image, i) of images" :class="{ active: i === selected }")
6 8
             .image-wrapper.f-col.center
@@ -14,25 +16,21 @@
14 16
 <script>
15 17
 export default {
16 18
     props: {
17
-        images: { type: Array },
18
-        fullscreengallery: { type: Number },
19
+        imageIds: { type: Array, required: true },
20
+        activeImageIndex: { type: Number, default: 0 },
21
+        activeGalleryIndex: { type: Number },
19 22
     },
20 23
     data() { 
21 24
         return {
22 25
             selected: -1
23 26
         }
24 27
     },
25
-    computed: {
26
-        showGallery() {
27
-            return this.fullscreengallery + 1 > 0
28
-        }
29
-    },
30 28
     methods: {
31 29
         prev() {
32
-            this.selected > 0 ? this.selected-- : this.selected = this.images.length - 1
30
+            this.selected > 0 ? this.selected-- : this.selected = this.imageIds.length - 1
33 31
         },
34 32
         next() {
35
-            this.selected < this.images.length - 1 ? this.selected++ : this.selected = 0
33
+            this.selected < this.imageIds.length - 1 ? this.selected++ : this.selected = 0
36 34
         },
37 35
         hideGallery() {
38 36
             this.$emit('close')
@@ -52,13 +50,13 @@ export default {
52 50
         }
53 51
     },
54 52
     watch: {
55
-        fullscreengallery(newVal, oldVal) {
53
+        activeImageIndex(newVal, oldVal) {
56 54
             this.selected = newVal
57 55
         }
58 56
     },
59 57
     mounted() {
60 58
         // Set the first selection
61
-        this.selected = this.fullscreengallery
59
+        this.selected = this.activeImageIndex
62 60
 
63 61
         window.addEventListener('keydown', this.interpretKeypress)
64 62
     },
@@ -70,35 +68,36 @@ export default {
70 68
 
71 69
 <style lang="postcss">
72 70
 .gallery
73
-    position: fixed
74
-    top: 0
75
-    left: 0
76
-    width: 100%
77
-    height: 100%
78
-    background-color: black
79
-    z-index: 1001
80
-    > *
81
-        opacity: 100%
82
-        position: relative
83
-        z-index: 1011
84
-    button.hide
85
-        z-index: 1100
86
-    ul
87
-        list-style: none
88
-        li
89
-            display: none
90
-            &.active
91
-                display: block
92
-            .image-wrapper
93
-                height: 100%
94
-                width: 50vw
95
-                background-color: yellow
96
-            h1
97
-                color: green
98
-    .controls
99
-        position: absolute
100
-        width: 100vw
101
-        button
102
-            height: 100vw
103
-            padding: 1vw
71
+    &.active
72
+        position: fixed
73
+        top: 0
74
+        left: 0
75
+        width: 100%
76
+        height: 100%
77
+        background-color: black
78
+        z-index: 1001
79
+        > *
80
+            opacity: 100%
81
+            position: relative
82
+            z-index: 1011
83
+        button.hide
84
+            z-index: 1100
85
+        ul
86
+            list-style: none
87
+            li
88
+                display: none
89
+                &.active
90
+                    display: block
91
+                .image-wrapper
92
+                    height: 100%
93
+                    width: 50vw
94
+                    background-color: yellow
95
+                h1
96
+                    color: green
97
+        .controls
98
+            position: absolute
99
+            width: 100vw
100
+            button
101
+                height: 100vw
102
+                padding: 1vw
104 103
 </style>

+ 37
- 42
vue-theme/src/pages/single.vue Ver fichero

@@ -1,27 +1,38 @@
1 1
 <template lang="pug">
2 2
 .page--single.f-row.between
3
-    gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = -1" :images="images")
4
-    
5 3
     article.f-grow.shadow
6 4
         header
7 5
             h1 {{ type }}:{{ $route.params.slug }} single
8
-            p {{galleries}}
9 6
             p categories: 
10
-                span(v-for="category in posts[$route.params.slug].categories") {{ category }}&nbsp;
11
-        section(v-if="posts[$route.params.slug]")
12
-            h4 {{ posts[$route.params.slug].title }}
13
-            .block-wrapper(v-for="block in posts[$route.params.slug].blocks")
14
-                    .block(v-if="typeof block === 'object'")
15
-                        p gallery {{ block.gallery + 1 }}: 
7
+                span(v-for="category in post.categories") {{ category }}&nbsp;
8
+
9
+        section(v-if="post")
10
+            h4 {{ post.title }}
11
+            p {{ activeGalleryIndex }}
12
+            .block-wrapper(v-for="(block, i) in post.blocks")
13
+                    //- ?: are objects are always gallery blocks
14
+                    .gallery.block(v-if="typeof block === 'object'")
15
+                        p gallery number: {{ i }}
16 16
                         ul
17
-                            li(v-for="imageID in posts[$route.params.slug].galleries[block.gallery].ids") image: {{ imageID }}
17
+                            li(v-for="(imageID, j) in post.galleries[block.gallery].ids") 
18
+                                button(@click="openGallery(i - 1, j)") gallery: {{ i }} image: {{ imageID }}
19
+                        //- Fullscreen gallery
20
+                        gallery(
21
+                            v-if="activeGalleryIndex == (i - 1)"
22
+                            :activeGalleryIndex="activeGalleryIndex"
23
+                            :image-ids="post.galleries[block.gallery].ids"
24
+                            :activeImageIndex="activeImageIndex"
25
+                            v-on:close="activeGalleryIndex = -1"
26
+                        )
27
+
28
+                    //- Just a regular block
18 29
                     .block(v-else v-html="block")
19 30
 
20
-    sidebar(v-if="sidebar" :type="`${type}`")
21
-        .shadow
22
-            h1.t-up single slot
23
-            div
24
-                p body whatever
31
+    //- sidebar(v-if="sidebar" :type="`${type}`")
32
+    //-     .shadow
33
+    //-         h1.t-up single slot
34
+    //-         div
35
+    //-             p body whatever
25 36
 </template>
26 37
 
27 38
 <script>
@@ -41,10 +52,14 @@ export default {
41 52
     data() {
42 53
         return {
43 54
             images: [], 
44
-            fullscreengallery: -1
55
+            activeGalleryIndex: -1,
56
+            activeImageIndex: -1
45 57
         }
46 58
     },
47 59
     computed: {
60
+        post() {
61
+            return this.posts[this.$route.params.slug]
62
+        },
48 63
         ...mapGetters({
49 64
             allPages: 'allPages',
50 65
             allPagesLoaded: 'allPagesLoaded',
@@ -61,10 +76,6 @@ export default {
61 76
         type() { // Checks for type and fixes Episodes route edge case 
62 77
             return typeFromRoute(this.$route)
63 78
         },
64
-        galleries() {
65
-            if(!this.posts || !this.$route || !this.posts[this.$route.params.slug]) return
66
-            return this.posts[this.$route.params.slug].galleries[block.gallery].ids
67
-        },
68 79
         posts() {
69 80
             let type = convertTitleCase(this.type)
70 81
             
@@ -78,25 +89,10 @@ export default {
78 89
         }
79 90
     },
80 91
     methods: {
81
-        pageBlocks(posts) {
82
-            if(!posts || !posts[this.$route.params.slug] || !posts[this.$route.params.slug].blocks ) return []
83
-            
84
-            return posts[this.$route.params.slug].blocks.map(block => {
85
-                if(block) return block
86
-            })
87
-        },
88
-        checkForImages(posts) {
89
-            if(Object.keys(posts).length == 0) return
90
-            this.pageBlocks(posts).forEach(block => {
91
-                const doc = new DOMParser().parseFromString(block, 'text/html')
92
-                const gallery = doc.querySelectorAll('.blocks-gallery-item img')
93
-
94
-                if(!gallery || gallery.length < 1) return
95
-
96
-                this.images = [].slice.call(gallery).map(item => { 
97
-                    return item.src
98
-                })
99
-            })
92
+        openGallery(galleryIndex, imageID) {
93
+            this.activeGalleryIndex = galleryIndex
94
+            this.activeImageIndex = imageID ? imageID : 0
95
+            // console.log(this.post.galleries[galleryIndex])
100 96
         },
101 97
         checkAndSetHero(posts) {
102 98
             const post = posts[this.$route.params.slug]
@@ -109,15 +105,14 @@ export default {
109 105
     watch: {
110 106
         posts(newVal, oldVal) {
111 107
             // Loads images from the DOM
112
-            this.checkForImages(newVal)
108
+            // this.checkForImages(newVal)
113 109
             
114 110
             this.checkAndSetHero(newVal)
115
-            console.log(this.galleries)
116 111
         }
117 112
     },
118 113
     created() {
119 114
         let type = convertTitleCase(this.$route.params.type)
120
-
115
+        this.$store.dispatch(`getMediaById`, [7])
121 116
         if(!this[`all{type}Loaded`]) {
122 117
             // console.log('Retrieving...', type)
123 118
             this.$store.dispatch(`getAll${type}`)

Loading…
Cancelar
Guardar