PluginProbe
Canvas / 2.4.9
Canvas v2.4.9
2.5.5 2.5.4 trunk 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 All 54 releases
canvas / components / basic-elements / class-block-collapsibles.php

class-block-collapsibles.php in Canvas 2.4.9, at components/basic-elements/class-block-collapsibles.php

179 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Collapsibles Block.
4 *
5 * @package Canvas
6 */
7
8 /**
9 * Initialize Collapsibles block.
10 */
11 class CNVS_Block_Collapsibles {
12
13 /**
14 * Initialize
15 */
16 public function __construct() {
17 add_action( 'init', array( $this, 'init' ) );
18 add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
19 }
20
21 /**
22 * Enqueue the block's assets for the editor.
23 */
24 public function init() {
25 // Editor Scripts.
26 wp_register_script(
27 'canvas-block-collapsibles-editor-script',
28 plugins_url( 'block-collapsibles/block.js', __FILE__ ),
29 array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ),
30 filemtime( plugin_dir_path( __FILE__ ) . 'block-collapsibles/block.js' ),
31 true
32 );
33
34 wp_register_script(
35 'canvas-block-collapsible-editor-script',
36 plugins_url( 'block-collapsible/block.js', __FILE__ ),
37 array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor' ),
38 filemtime( plugin_dir_path( __FILE__ ) . 'block-collapsible/block.js' ),
39 true
40 );
41
42 // Editor Styles.
43 wp_register_style(
44 'canvas-block-collapsibles-editor-style',
45 plugins_url( 'block-collapsibles/block-editor.css', __FILE__ ),
46 array(),
47 filemtime( plugin_dir_path( __FILE__ ) . 'block-collapsibles/block-editor.css' )
48 );
49
50 wp_style_add_data( 'canvas-block-collapsibles-editor-style', 'rtl', 'replace' );
51
52 // Styles.
53 wp_register_style(
54 'canvas-block-collapsibles-style',
55 plugins_url( 'block-collapsibles/block.css', __FILE__ ),
56 array(),
57 filemtime( plugin_dir_path( __FILE__ ) . 'block-collapsibles/block.css' )
58 );
59
60 wp_style_add_data( 'canvas-block-collapsibles-style', 'rtl', 'replace' );
61
62 // Scripts.
63 wp_register_script( 'canvas-block-collapsibles-script', plugin_dir_url( __FILE__ ) . 'block-collapsibles/public-block-collapsibles.js', array( 'jquery' ), cnvs_get_setting( 'version' ), true );
64 }
65
66 /**
67 * Register block
68 *
69 * @param array $blocks all registered blocks.
70 * @return array
71 */
72 public function register_block_type( $blocks ) {
73 $blocks[] = array(
74 'name' => 'canvas/collapsibles',
75 'title' => esc_html__( 'Collapsibles', 'canvas' ),
76 'description' => '',
77 'category' => 'canvas',
78 'keywords' => array(),
79 'icon' => '
80 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
81 <path d="M19 15V17H5V15H19ZM21 5H3V7H21V5ZM21 9H3V11H21V9ZM21 13H3V19H21V13Z" />
82 </svg>
83 ',
84 'supports' => array(
85 'className' => true,
86 'anchor' => true,
87 'html' => false,
88 'canvasSpacings' => true,
89 'canvasBorder' => true,
90 'canvasResponsive' => true,
91 ),
92 'styles' => array(),
93 'location' => array(),
94
95 'sections' => array(
96 'general' => array(
97 'title' => esc_html__( 'Block Settings', 'canvas' ),
98 'priority' => 5,
99 'open' => true,
100 ),
101 ),
102 'layouts' => array(),
103
104 // Set fields just for add block attributes.
105 // Editor render for this block is custom JSX
106 // so we don't need to render fields automatically.
107 'fields' => array(
108 array(
109 'key' => 'count',
110 'label' => esc_html__( 'Collapsibles', 'canvas' ),
111 'type' => 'number',
112 'min' => 1,
113 'max' => 20,
114 'default' => 2,
115 'section' => 'general',
116 ),
117 ),
118 'template' => dirname( __FILE__ ) . '/block-collapsibles/render.php',
119
120 // enqueue registered scripts/styles.
121 'style' => 'canvas-block-collapsibles-style',
122 'script' => is_admin() ? '' : 'canvas-block-collapsibles-script',
123 'editor_script' => 'canvas-block-collapsibles-editor-script',
124 'editor_style' => 'canvas-block-collapsibles-editor-style',
125 );
126
127 $blocks[] = array(
128 'name' => 'canvas/collapsible',
129 'title' => esc_html__( 'Collapsible', 'canvas' ),
130 'description' => '',
131 'category' => 'canvas',
132 'keywords' => array(),
133 'icon' => '
134 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
135 <path d="M19 15V17H5V15H19ZM21 5H3V7H21V5ZM21 9H3V11H21V9ZM21 13H3V19H21V13Z" />
136 </svg>
137 ',
138 'supports' => array(
139 'inserter' => false,
140 'reusable' => false,
141 'className' => true,
142 'anchor' => true,
143 'canvasSpacings' => true,
144 'canvasBorder' => true,
145 'canvasResponsive' => true,
146 ),
147 'parent' => array(
148 'canvas/collapsibles',
149 ),
150 'styles' => array(),
151 'location' => array(),
152
153 'sections' => array(),
154 'layouts' => array(),
155 'fields' => array(
156 array(
157 'key' => 'title',
158 'type' => 'type-string',
159 'default' => '',
160 ),
161 array(
162 'key' => 'opened',
163 'label' => esc_html__( 'Opened', 'canvas' ),
164 'type' => 'toggle',
165 'default' => false,
166 ),
167 ),
168 'template' => dirname( __FILE__ ) . '/block-collapsible/render.php',
169
170 // enqueue registered scripts/styles.
171 'editor_script' => 'canvas-block-collapsible-editor-script',
172 );
173
174 return $blocks;
175 }
176 }
177
178 new CNVS_Block_Collapsibles();
179