Przeglądaj źródła

feat: added gallery keyboard event listen

tags/0.9.0
John Maeda 6 lat temu
rodzic
commit
806c4e1eb9

+ 28
- 5
vue-theme/src/components/gallery.vue Wyświetl plik

@@ -1,9 +1,9 @@
1 1
 <template lang="pug">
2 2
 .gallery.f-col.center(v-if="fullscreengallery")
3
-    button(@click="hideGallery") hide
3
+    button(@click="hideGallery").hide hide
4 4
     ul
5 5
         li(v-for="(image, i) of images" :class="{ active: i === selected }")
6
-            .image-wrapper.f-row.center
6
+            .image-wrapper.f-col.center
7 7
                 img(:src="image")
8 8
     .controls.f-row
9 9
         button(@click="prev") <
@@ -31,7 +31,26 @@ export default {
31 31
         },
32 32
         hideGallery() {
33 33
             this.$emit('close')
34
+        },
35
+        interpretKeypress(e) {
36
+            switch (e.key) {
37
+                case 'ArrowRight':
38
+                    this.next()
39
+                    break
40
+                case 'ArrowLeft':
41
+                    this.prev()
42
+                    break
43
+                case 'Escape':
44
+                    this.hideGallery()
45
+                    break
46
+            }
34 47
         }
48
+    },
49
+    mounted() {
50
+        window.addEventListener('keydown', this.interpretKeypress)
51
+    },
52
+    destroyed() {
53
+        window.removeEventListener('keydown', this.interpretKeypress)
35 54
     }
36 55
 }
37 56
 </script>
@@ -43,13 +62,14 @@ export default {
43 62
     left: 0
44 63
     width: 100%
45 64
     height: 100%
46
-    background-color: blue
47
-    opacity: 75%
65
+    background-color: black
48 66
     z-index: 1001
49 67
     > *
50 68
         opacity: 100%
51 69
         position: relative
52 70
         z-index: 1011
71
+    button.hide
72
+        z-index: 1100
53 73
     ul
54 74
         list-style: none
55 75
         li
@@ -64,5 +84,8 @@ export default {
64 84
                 color: green
65 85
     .controls
66 86
         position: absolute
67
-        bottom: 5em
87
+        width: 100vw
88
+        button
89
+            height: 100vw
90
+            padding: 1vw
68 91
 </style>

+ 7
- 8
vue-theme/src/pages/single.vue Wyświetl plik

@@ -64,8 +64,8 @@ export default {
64 64
         },
65 65
     },
66 66
     methods: {
67
-        checkForImages(post) {
68
-            const allBlocks = post[this.$route.params.slug].blocks.map(block => {
67
+        checkForImages(posts) {
68
+            const allBlocks = posts[this.$route.params.slug].blocks.map(block => {
69 69
                 if(block) return block
70 70
             })
71 71
             allBlocks.forEach(block => {
@@ -87,12 +87,11 @@ export default {
87 87
         }
88 88
     },
89 89
     mounted() {
90
-        // TODO: this should be conditional after checking vuex state
91
-        let type = this.$route.params.type
92
-        type = type.charAt(0).toUpperCase() + type.slice(1)
93
-        this.$store.dispatch(`getAll${type}`)
94
-        
95
-        console.log(this.images)
90
+        if(!this.posts[this.$route.params.slug]) {
91
+            let type = this.$route.params.type
92
+            type = type.charAt(0).toUpperCase() + type.slice(1)
93
+            this.$store.dispatch(`getAll${type}`)
94
+        }
96 95
     }
97 96
 }
98 97
 </script>

+ 0
- 1
vue-theme/src/store/modules/artist.js Wyświetl plik

@@ -17,7 +17,6 @@ const getters = {
17 17
     artistContent: state => id => {
18 18
         let field = typeof id === 'number' ? 'id' : 'slug'
19 19
         let artist = state.all.filter(artist => artist[field] === id)
20
-
21 20
         return (artist[0]) ? artist[0].content.rendered : false
22 21
     },
23 22
     someArtists: state => limit => {

Ładowanie…
Anuluj
Zapisz