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 -199 2.0.83.0.2 View file →
@@ -1,199 +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 - 'popper',
28 - getwid_get_plugin_url( 'vendors/tippy.js/popper.min.js' ),
29 - [ 'jquery' ],
30 - '2.4.0',
31 - true
32 - );
33 -
34 - wp_register_script(
35 - 'tippy',
36 - getwid_get_plugin_url( 'vendors/tippy.js/tippy-bundle.umd.min.js' ),
37 - [ 'jquery', 'popper' ],
38 - '6.2.3',
39 - true
40 - );
41 -
42 - wp_register_script(
43 - 'waypoints',
44 - getwid_get_plugin_url( 'vendors/waypoints/lib/jquery.waypoints.min.js' ),
45 - [ 'jquery' ],
46 - '4.0.1',
47 - true
48 - );
49 -
50 - wp_register_script(
51 - 'unescape',
52 - getwid_get_plugin_url( 'vendors/lodash.unescape/unescape.min.js' ),
53 - [],
54 - '4.0.1',
55 - true
56 - );
57 -
58 - wp_register_style(
59 - 'tippy-themes',
60 - getwid_get_plugin_url( 'vendors/tippy.js/themes.css' ),
61 - [],
62 - '6.2.3'
63 - );
64 -
65 - wp_register_style(
66 - 'tippy-animation',
67 - getwid_get_plugin_url( 'vendors/tippy.js/animations.css' ),
68 - [],
69 - '6.2.3'
70 - );
71 - }
72 - }
73 -
74 - public function getLabel() {
75 - return __('Image Hotspot', 'getwid');
76 - }
77 -
78 - public function block_frontend_styles($styles) {
79 -
80 - //fontawesome
81 - $styles = getwid()->fontIconsManager()->enqueueFonts( $styles );
82 -
83 - //themes.css
84 - if ( is_admin() && ! in_array( 'tippy-themes', $styles ) ) {
85 - array_push( $styles, 'tippy-themes' );
86 - }
87 -
88 - //animation.css
89 - if ( is_admin() && ! in_array( 'tippy-animation', $styles ) ) {
90 - array_push( $styles, 'tippy-animation' );
91 - }
92 -
93 - return $styles;
94 - }
95 -
96 - public function block_editor_scripts($scripts) {
97 -
98 - //popper.min.js
99 - if ( ! in_array( 'popper', $scripts ) ) {
100 - array_push( $scripts, 'popper' );
101 - }
102 -
103 - //tippy-bundle.umd.min.js
104 - if ( ! in_array( 'tippy', $scripts ) ) {
105 - array_push( $scripts, 'tippy' );
106 - }
107 -
108 - return $scripts;
109 - }
110 -
111 - public function block_frontend_assets() {
112 -
113 - if ( is_admin() ) {
114 - return;
115 - }
116 -
117 - //popper.min.js
118 - if ( ! wp_script_is( 'popper', 'enqueued' ) ) {
119 - wp_enqueue_script('popper');
120 - }
121 -
122 - //tippy-bundle.umd.min.js
123 - if ( ! wp_script_is( 'tippy', 'enqueued' ) ) {
124 - wp_enqueue_script('tippy');
125 - }
126 -
127 - //jquery.waypoints.min.js
128 - if ( ! wp_script_is( 'waypoints', 'enqueued' ) ) {
129 - wp_enqueue_script('waypoints');
130 - }
131 -
132 - //unescape.min.js
133 - if ( ! wp_script_is( 'unescape', 'enqueued' ) ) {
134 - wp_enqueue_script( 'unescape' );
135 - }
136 -
137 - //themes.css
138 - if ( ! wp_style_is( 'tippy-themes', 'enqueued' ) ) {
139 - wp_enqueue_style( 'tippy-themes' );
140 - }
141 -
142 - //animation.css
143 - if ( ! wp_style_is( 'tippy-animation', 'enqueued' ) ) {
144 - wp_enqueue_style( 'tippy-animation' );
145 - }
146 -
147 - if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
148 - return;
149 - }
150 -
151 - $deps_css = [
152 - 'tippy-themes', 'tippy-animation'
153 - ];
154 -
155 - $deps_js = [ 'jquery', 'popper', 'tippy', 'waypoints', 'unescape' ];
156 -
157 - //fontawesome
158 - $deps_css = getwid()->fontIconsManager()->enqueueFonts( $deps_css );
159 -
160 - add_filter( 'getwid/optimize/assets',
161 - function ( $assets ) {
162 - $assets[] = getwid()->settings()->getPrefix() . '-blocks-common';
163 -
164 - return $assets;
165 - }
166 - );
167 -
168 - add_filter( 'getwid/optimize/should_load_common_css', '__return_true' );
169 -
170 - $rtl = is_rtl() ? '.rtl' : '';
171 -
172 - wp_enqueue_style(
173 - self::$blockName,
174 - getwid_get_plugin_url( 'assets/blocks/image-hotspot/style' . $rtl . '.css' ),
175 - $deps_css,
176 - getwid()->settings()->getVersion()
177 - );
178 -
179 - wp_enqueue_script(
180 - self::$blockName,
181 - getwid_get_plugin_url( 'assets/blocks/image-hotspot/frontend.js' ),
182 - $deps_js,
183 - getwid()->settings()->getVersion(),
184 - true
185 - );
186 -
187 - }
188 -
189 - public function render_callback( $attributes, $content ) {
190 -
191 - $this->block_frontend_assets();
192 -
193 - return $content;
194 - }
195 -}
196 -
197 -getwid()->blocksManager()->addBlock(
198 - new \Getwid\Blocks\ImageHotspot()
199 -);
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 +);