PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 4.0.9
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v4.0.9
4.1.0 4.0.9 4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / gutenberg / block-api / class-dynamic-block-assets.php
superb-blocks / src / gutenberg / block-api Last commit date
class-author-box-controller.php 2 weeks ago class-dynamic-block-assets.php 2 weeks ago class-recent-posts-controller.php 2 weeks ago class-table-of-contents-controller.php 2 weeks ago
class-dynamic-block-assets.php
206 lines
1 <?php
2
3 namespace SuperbAddons\Gutenberg\BlocksAPI\Controllers;
4
5 use SuperbAddons\Data\Utils\ScriptTranslations;
6 use SuperbAddons\Gutenberg\Form\FormSettings;
7
8 defined('ABSPATH') || exit();
9
10 class DynamicBlockAssets
11 {
12 public static function EnqueueAnimatedHeader($attr, $content)
13 {
14 wp_enqueue_script(
15 'superbaddons-animated-heading',
16 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/animated-heading.js',
17 [],
18 SUPERBADDONS_VERSION,
19 true
20 );
21 return $content;
22 }
23
24 public static function EnqueueRevealButton($attr, $content)
25 {
26 wp_enqueue_script(
27 'superbaddons-reveal-button',
28 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/reveal-button.js',
29 [],
30 SUPERBADDONS_VERSION,
31 true
32 );
33 return $content;
34 }
35
36 public static function EnqueueAccordion($attr, $content)
37 {
38 wp_enqueue_script(
39 'superbaddons-accordion',
40 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/accordion.js',
41 [],
42 SUPERBADDONS_VERSION,
43 true
44 );
45 return $content;
46 }
47
48 public static function EnqueueCountdown($attr, $content)
49 {
50 wp_enqueue_script(
51 'superbaddons-countdown',
52 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/countdown.js',
53 [],
54 SUPERBADDONS_VERSION,
55 true
56 );
57
58 // Hide countdown until JS initializes to prevent flash of uninitialized state
59 $processor = new \WP_HTML_Tag_Processor($content);
60 if ($processor->next_tag()) {
61 $existing = $processor->get_attribute('style');
62 $existing = isset($existing) ? $existing : '';
63 if (!empty($existing) && substr($existing, -1) !== ';') {
64 $existing .= ';';
65 }
66 $processor->set_attribute('style', $existing . 'visibility:hidden;');
67 $content = $processor->get_updated_html();
68 }
69
70 return $content;
71 }
72
73 public static function EnqueueProgressBar($attr, $content)
74 {
75 wp_enqueue_script(
76 'superbaddons-progress-bar',
77 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/progress-bar.js',
78 [],
79 SUPERBADDONS_VERSION,
80 true
81 );
82
83 // Hide block until JS initializes to prevent flash of un-animated state
84 $processor = new \WP_HTML_Tag_Processor($content);
85 if ($processor->next_tag()) {
86 $existing = $processor->get_attribute('style');
87 if (!is_string($existing)) {
88 $existing = '';
89 }
90 if (!empty($existing) && substr($existing, -1) !== ';') {
91 $existing .= ';';
92 }
93 $processor->set_attribute('style', $existing . 'visibility:hidden;');
94 $content = $processor->get_updated_html();
95 }
96
97 return $content;
98 }
99
100 public static function EnqueueCarousel($attr, $content)
101 {
102 wp_enqueue_script(
103 'superbaddons-carousel',
104 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/carousel.js',
105 ['wp-i18n'],
106 SUPERBADDONS_VERSION,
107 true
108 );
109 ScriptTranslations::Set('superbaddons-carousel');
110 return $content;
111 }
112
113 public static function EnqueuePopup($attr, $content)
114 {
115 wp_enqueue_script(
116 'superbaddons-popup',
117 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/popup.js',
118 [],
119 SUPERBADDONS_VERSION,
120 true
121 );
122 return $content;
123 }
124
125 public static function EnqueueForm($attr, $content, $block = null)
126 {
127 if (!$block || empty($block->inner_blocks)) {
128 $isMultistep = $block && isset($block->name) && $block->name === 'superb-addons/multistep-form';
129 return $isMultistep
130 ? '<!-- Superb Multi-Step Form: not rendered because the form has no steps. Please add steps in the block editor. -->'
131 : '<!-- Superb Form: not rendered because the form has no fields. Please add fields in the block editor. -->';
132 }
133
134 wp_enqueue_script(
135 'superbaddons-form',
136 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/form.js',
137 array('wp-i18n'),
138 SUPERBADDONS_VERSION,
139 true
140 );
141 ScriptTranslations::Set('superbaddons-form');
142
143 /* Form-wide default message for empty required fields. */
144 if (!empty($attr['requiredMessage'])) {
145 $processor = new \WP_HTML_Tag_Processor($content);
146 if ($processor->next_tag('form')) {
147 $processor->set_attribute('data-required-message', sanitize_text_field($attr['requiredMessage']));
148 $content = $processor->get_updated_html();
149 }
150 }
151
152 static $localized = false;
153 if (!$localized) {
154 $localized = true;
155 $config = array('restUrl' => \get_rest_url(null, 'superbaddons/'));
156 $siteKeys = array(
157 'hcaptchaSiteKey' => FormSettings::Get(FormSettings::OPTION_HCAPTCHA_SITE_KEY),
158 'recaptchaSiteKey' => FormSettings::Get(FormSettings::OPTION_RECAPTCHA_SITE_KEY),
159 'turnstileSiteKey' => FormSettings::Get(FormSettings::OPTION_TURNSTILE_SITE_KEY),
160 );
161 foreach ($siteKeys as $key => $value) {
162 if (!empty($value)) {
163 $config[$key] = $value;
164 }
165 }
166 wp_localize_script('superbaddons-form', 'superbFormsConfig', $config);
167 }
168
169 return $content;
170 }
171
172 public static function EnqueueAddToCart($attr, $content = '')
173 {
174 if (!function_exists('WC')) {
175 return $content;
176 }
177
178 wp_enqueue_script(
179 'superbaddons-add-to-cart',
180 SUPERBADDONS_ASSETS_PATH . '/js/dynamic-blocks/add-to-cart.js',
181 array('wp-i18n'),
182 SUPERBADDONS_VERSION,
183 true
184 );
185 ScriptTranslations::Set('superbaddons-add-to-cart');
186
187 static $localized = false;
188 if (!$localized) {
189 $localized = true;
190 wp_localize_script('superbaddons-add-to-cart', 'superbAddToCartConfig', array(
191 'restUrl' => \get_rest_url(null, 'superbaddons/'),
192 'nonce' => wp_create_nonce('wp_rest'),
193 'cartUrl' => esc_url_raw((string) wc_get_cart_url()),
194 'checkoutUrl' => esc_url_raw((string) wc_get_checkout_url()),
195 'currencySymbol' => html_entity_decode(get_woocommerce_currency_symbol(), ENT_QUOTES, 'UTF-8'),
196 'currencyPosition' => (string) get_option('woocommerce_currency_pos', 'left'),
197 'decimalSeparator' => function_exists('wc_get_price_decimal_separator') ? (string) wc_get_price_decimal_separator() : '.',
198 'thousandSeparator' => function_exists('wc_get_price_thousand_separator') ? (string) wc_get_price_thousand_separator() : ',',
199 'decimals' => function_exists('wc_get_price_decimals') ? intval(wc_get_price_decimals()) : 2,
200 ));
201 }
202
203 return $content;
204 }
205 }
206