PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
← All changes | includes/blocks/image-hotspot.php +33 -217 1.9.13.0.2 View file →
@@ -1,217 +1,33 @@
1 -<?php
2 -
3 -namespace Getwid\Blocks;
4 -
5 -class ImageHotspot extends \Getwid\Blocks\AbstractBlock {
6 -
7 - protected static $blockName = 'getwid/image-hotspot';
8 -
9 - public function __construct() {
10 -
11 - parent::__construct( self::$blockName );
12 -
13 - register_block_type(
14 - 'getwid/image-hotspot',
15 - array(
16 - 'render_callback' => [ $this, 'render_callback' ]
17 - )
18 - );
19 -
20 - if ( $this->isEnabled() ) {
21 -
22 - add_filter( 'getwid/editor_blocks_js/dependencies', [ $this, 'block_editor_scripts'] );
23 - add_filter( 'getwid/blocks_style_css/dependencies', [ $this, 'block_frontend_styles' ] );
24 -
25 - //Register JS/CSS assets
26 - wp_register_script(
27 - 'draggabilly',
28 - getwid_get_plugin_url( 'vendors/draggabilly/draggabilly.pkgd.min.js' ),
29 - [ 'jquery' ],
30 - '2.2.0',
31 - true
32 - );
33 -
34 - wp_register_script(
35 - 'popper',
36 - getwid_get_plugin_url( 'vendors/tippy.js/popper.min.js' ),
37 - [ 'jquery' ],
38 - '2.4.0',
39 - true
40 - );
41 -
42 - wp_register_script(
43 - 'tippy',
44 - getwid_get_plugin_url( 'vendors/tippy.js/tippy-bundle.umd.min.js' ),
45 - [ 'jquery', 'popper' ],
46 - '6.2.3',
47 - true
48 - );
49 -
50 - wp_register_script(
51 - 'waypoints',
52 - getwid_get_plugin_url( 'vendors/waypoints/lib/jquery.waypoints.min.js' ),
53 - [ 'jquery' ],
54 - '4.0.1',
55 - true
56 - );
57 -
58 - wp_register_script(
59 - 'unescape',
60 - getwid_get_plugin_url( 'vendors/lodash.unescape/unescape.min.js' ),
61 - [],
62 - '4.0.1',
63 - true
64 - );
65 -
66 - wp_register_style(
67 - 'tippy-themes',
68 - getwid_get_plugin_url( 'vendors/tippy.js/themes.css' ),
69 - [],
70 - '6.2.3'
71 - );
72 -
73 - wp_register_style(
74 - 'tippy-animation',
75 - getwid_get_plugin_url( 'vendors/tippy.js/animations.css' ),
76 - [],
77 - '6.2.3'
78 - );
79 - }
80 - }
81 -
82 - public function getLabel() {
83 - return __('Image Hotspot', 'getwid');
84 - }
85 -
86 - public function block_frontend_styles($styles) {
87 -
88 - //fontawesome
89 - $styles = getwid()->fontIconsManager()->enqueueFonts( $styles );
90 -
91 - //themes.css
92 - if ( is_admin() && ! in_array( 'tippy-themes', $styles ) ) {
93 - array_push( $styles, 'tippy-themes' );
94 - }
95 -
96 - //animation.css
97 - if ( is_admin() && ! in_array( 'tippy-animation', $styles ) ) {
98 - array_push( $styles, 'tippy-animation' );
99 - }
100 -
101 - return $styles;
102 - }
103 -
104 - public function block_editor_scripts($scripts) {
105 -
106 - //imagesloaded.min.js
107 - if ( ! in_array( 'imagesloaded', $scripts ) ) {
108 - array_push( $scripts, 'imagesloaded' );
109 - }
110 -
111 - //draggabilly.pkgd.min.js
112 - if ( ! in_array( 'draggabilly', $scripts ) ) {
113 - array_push( $scripts, 'draggabilly' );
114 - }
115 -
116 - //popper.min.js
117 - if ( ! in_array( 'popper', $scripts ) ) {
118 - array_push( $scripts, 'popper' );
119 - }
120 -
121 - //tippy-bundle.umd.min.js
122 - if ( ! in_array( 'tippy', $scripts ) ) {
123 - array_push( $scripts, 'tippy' );
124 - }
125 -
126 - return $scripts;
127 - }
128 -
129 - public function block_frontend_assets() {
130 -
131 - if ( is_admin() ) {
132 - return;
133 - }
134 -
135 - //popper.min.js
136 - if ( ! wp_script_is( 'popper', 'enqueued' ) ) {
137 - wp_enqueue_script('popper');
138 - }
139 -
140 - //tippy-bundle.umd.min.js
141 - if ( ! wp_script_is( 'tippy', 'enqueued' ) ) {
142 - wp_enqueue_script('tippy');
143 - }
144 -
145 - //jquery.waypoints.min.js
146 - if ( ! wp_script_is( 'waypoints', 'enqueued' ) ) {
147 - wp_enqueue_script('waypoints');
148 - }
149 -
150 - //unescape.min.js
151 - if ( ! wp_script_is( 'unescape', 'enqueued' ) ) {
152 - wp_enqueue_script( 'unescape' );
153 - }
154 -
155 - //themes.css
156 - if ( ! wp_style_is( 'tippy-themes', 'enqueued' ) ) {
157 - wp_enqueue_style( 'tippy-themes' );
158 - }
159 -
160 - //animation.css
161 - if ( ! wp_style_is( 'tippy-animation', 'enqueued' ) ) {
162 - wp_enqueue_style( 'tippy-animation' );
163 - }
164 -
165 - if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
166 - return;
167 - }
168 -
169 - $deps_css = [
170 - 'tippy-themes', 'tippy-animation'
171 - ];
172 -
173 - $deps_js = [ 'jquery', 'popper', 'tippy', 'waypoints', 'unescape' ];
174 -
175 - //fontawesome
176 - $deps_css = getwid()->fontIconsManager()->enqueueFonts( $deps_css );
177 -
178 - add_filter( 'getwid/optimize/assets',
179 - function ( $assets ) {
180 - $assets[] = getwid()->settings()->getPrefix() . '-blocks-common';
181 -
182 - return $assets;
183 - }
184 - );
185 -
186 - add_filter( 'getwid/optimize/should_load_common_css', '__return_true' );
187 -
188 - $rtl = is_rtl() ? '.rtl' : '';
189 -
190 - wp_enqueue_style(
191 - self::$blockName,
192 - getwid_get_plugin_url( 'assets/blocks/image-hotspot/style' . $rtl . '.css' ),
193 - $deps_css,
194 - getwid()->settings()->getVersion()
195 - );
196 -
197 - wp_enqueue_script(
198 - self::$blockName,
199 - getwid_get_plugin_url( 'assets/blocks/image-hotspot/frontend.js' ),
200 - $deps_js,
201 - getwid()->settings()->getVersion(),
202 - true
203 - );
204 -
205 - }
206 -
207 - public function render_callback( $attributes, $content ) {
208 -
209 - $this->block_frontend_assets();
210 -
211 - return $content;
212 - }
213 -}
214 -
215 -getwid()->blocksManager()->addBlock(
216 - new \Getwid\Blocks\ImageHotspot()
217 -);
1 +<?php
2 +
3 +namespace Getwid\Blocks;
4 +
5 +class ImageHotspot extends AbstractBlock {
6 +
7 + public function __construct() {
8 +
9 + parent::__construct( 'getwid/image-hotspot' );
10 +
11 + register_block_type(
12 + getwid_get_plugin_path( 'assets/blocks/image-hotspot' )
13 + );
14 +
15 + add_action( 'enqueue_block_assets', array( $this, 'add_block_assets' ) );
16 + }
17 +
18 + public function get_label() {
19 + return __( 'Image Hotspot', 'getwid' );
20 + }
21 +
22 + public function add_block_assets() {
23 + if ( ! is_admin() ) {
24 + return;
25 + }
26 +
27 + wp_enqueue_script( 'tippy' );
28 + }
29 +}
30 +
31 +getwid()->blocksManager()->addBlock(
32 + new ImageHotspot()
33 +);