Преглед на файлове

feat: finds images on single page and puts into images prop

tags/0.9.0
John Maeda преди 6 години
родител
ревизия
22913132bd

+ 3
- 0
plugins/cia-endpoints/includes/class.make-endpoint.php Целия файл

61
         $filtered[content] = $item->post_content;
61
         $filtered[content] = $item->post_content;
62
         $filtered[blocks] = get_rearrange_blocks($item->blocks);
62
         $filtered[blocks] = get_rearrange_blocks($item->blocks);
63
         
63
         
64
+        // Log the request with PHP Console
65
+        if ( class_exists( 'PC' ) ) PC::debug( $item, 'Blocks' );
66
+        
64
         return $filtered;
67
         return $filtered;
65
         // return $item;
68
         // return $item;
66
     }
69
     }

+ 1
- 0
plugins/cia-endpoints/includes/reformat-blocks.php Целия файл

1
 <?php
1
 <?php
2
     function get_rearrange_blocks($blocks) {
2
     function get_rearrange_blocks($blocks) {
3
         $parsed_blocks = array();
3
         $parsed_blocks = array();
4
+
4
         foreach( $blocks as $block ) {
5
         foreach( $blocks as $block ) {
5
             if(sizeof($block[innerBlocks]) < 1 && $block[innerHTML] !== "\n\n") {
6
             if(sizeof($block[innerBlocks]) < 1 && $block[innerHTML] !== "\n\n") {
6
                 array_push($parsed_blocks, $block[innerHTML]);
7
                 array_push($parsed_blocks, $block[innerHTML]);

+ 0
- 1
plugins/cia-post-types/cia-post-types.php Целия файл

65
     $icon = get_icon($type);
65
     $icon = get_icon($type);
66
     add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
66
     add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
67
 endforeach;
67
 endforeach;
68
-

+ 32
- 9
vue-theme/src/components/gallery.vue Целия файл

2
 .gallery.f-col.center(v-if="fullscreengallery")
2
 .gallery.f-col.center(v-if="fullscreengallery")
3
     button(@click="hideGallery") hide
3
     button(@click="hideGallery") hide
4
     ul
4
     ul
5
-        li
6
-            h1 hello world
7
-        li
8
-            h1 hello world again
5
+        li(v-for="(image, i) of images" :class="{ active: i === selected }")
6
+            .image-wrapper.f-row.center
7
+                img(:src="image")
9
     .controls.f-row
8
     .controls.f-row
10
-        button(@click="hideGallery") <<<
11
-        button(@click="hideGallery") >>>
9
+        button(@click="prev") <
10
+        .f-grow
11
+        button(@click="next") >
12
 </template>
12
 </template>
13
 
13
 
14
 <script>
14
 <script>
15
 export default {
15
 export default {
16
     props: {
16
     props: {
17
+        images: { type: Array },
17
         fullscreengallery: { type: Boolean }
18
         fullscreengallery: { type: Boolean }
18
     },
19
     },
20
+    data() { 
21
+        return {
22
+            selected: 0
23
+        }
24
+    },
19
     methods: {
25
     methods: {
26
+        prev() {
27
+            this.selected > 0 ? this.selected-- : this.selected = this.images.length - 1
28
+        },
29
+        next() {
30
+            this.selected < this.images.length - 1 ? this.selected++ : this.selected = 0
31
+        },
20
         hideGallery() {
32
         hideGallery() {
21
             this.$emit('close')
33
             this.$emit('close')
22
         }
34
         }
30
     top: 0
42
     top: 0
31
     left: 0
43
     left: 0
32
     width: 100%
44
     width: 100%
33
-    height: 100vw
45
+    height: 100%
34
     background-color: blue
46
     background-color: blue
35
     opacity: 75%
47
     opacity: 75%
36
     z-index: 1001
48
     z-index: 1001
40
         z-index: 1011
52
         z-index: 1011
41
     ul
53
     ul
42
         list-style: none
54
         list-style: none
43
-        h1
44
-            color: green
55
+        li
56
+            display: none
57
+            &.active
58
+                display: block
59
+            .image-wrapper
60
+                height: 100%
61
+                width: 50vw
62
+                background-color: yellow
63
+            h1
64
+                color: green
65
+    .controls
66
+        position: absolute
67
+        bottom: 5em
45
 </style>
68
 </style>

+ 29
- 3
vue-theme/src/pages/single.vue Целия файл

1
 <template lang="pug">
1
 <template lang="pug">
2
-.page--single.f-row.between
3
-    gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = false")
2
+.page--single.f-row.between(v-if="$route.params.slug")
3
+    gallery(v-if="images.length" :fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = false" :images="images")
4
     article.f-grow.shadow
4
     article.f-grow.shadow
5
         header
5
         header
6
             h1 {{ type }}:{{ $route.params.slug }} single
6
             h1 {{ type }}:{{ $route.params.slug }} single
7
             button(@click="fullscreengallery = true") fullscreen
7
             button(@click="fullscreengallery = true") fullscreen
8
-        section
8
+        section(v-if="posts[$route.params.slug]")
9
             h4 {{ posts[$route.params.slug].title }}
9
             h4 {{ posts[$route.params.slug].title }}
10
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
10
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
11
     sidebar(v-if="sidebar" :type="`${type}`")
11
     sidebar(v-if="sidebar" :type="`${type}`")
32
     },
32
     },
33
     data() {
33
     data() {
34
         return {
34
         return {
35
+            images: [], 
35
             fullscreengallery: false
36
             fullscreengallery: false
36
         }
37
         }
37
     },
38
     },
62
             }, {})
63
             }, {})
63
         },
64
         },
64
     },
65
     },
66
+    methods: {
67
+        checkForImages(post) {
68
+            const allBlocks = post[this.$route.params.slug].blocks.map(block => {
69
+                if(block) return block
70
+            })
71
+            allBlocks.forEach(block => {
72
+                if(!block) return
73
+
74
+                const domparser = new DOMParser()
75
+                const doc = domparser.parseFromString(block, 'text/html')
76
+
77
+                const gallery = doc.querySelectorAll('.blocks-gallery-item img')
78
+                if(gallery) {
79
+                    this.images = [].slice.call(gallery).map(item => { return item.src })
80
+                }
81
+            })
82
+        }
83
+    },
84
+    watch: {
85
+        posts(newVal, oldVal) {
86
+            this.checkForImages(newVal)
87
+        }
88
+    },
65
     mounted() {
89
     mounted() {
66
         // TODO: this should be conditional after checking vuex state
90
         // TODO: this should be conditional after checking vuex state
67
         let type = this.$route.params.type
91
         let type = this.$route.params.type
68
         type = type.charAt(0).toUpperCase() + type.slice(1)
92
         type = type.charAt(0).toUpperCase() + type.slice(1)
69
         this.$store.dispatch(`getAll${type}`)
93
         this.$store.dispatch(`getAll${type}`)
94
+        
95
+        console.log(this.images)
70
     }
96
     }
71
 }
97
 }
72
 </script>
98
 </script>

Loading…
Отказ
Запис