PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.2.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.2.0
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / ScriptController.php
the-post-grid / app / Controllers Last commit date
Admin 3 years ago Hooks 3 years ago AjaxController.php 3 years ago ElementorController.php 3 years ago GutenBergController.php 3 years ago ScriptController.php 3 years ago ShortcodeController.php 3 years ago WidgetController.php 3 years ago
ScriptController.php
321 lines
1 <?php
2 /**
3 * Script Controller class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 /**
16 * Script Controller class.
17 */
18 class ScriptController {
19 /**
20 * Version
21 *
22 * @var string
23 */
24 private $version;
25
26 /**
27 * Settings
28 *
29 * @var array
30 */
31 private $settings;
32
33 /**
34 * Class construct
35 */
36 public function __construct() {
37 $this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION;
38
39 add_action( 'wp_head', [ &$this, 'header_scripts' ] );
40 add_action( 'wp_enqueue_scripts', [ &$this, 'enqueue' ] );
41 add_action( 'init', [ $this, 'init' ] );
42 }
43
44 /**
45 * Init
46 *
47 * @return void
48 */
49 public function init() {
50 $this->settings = get_option( rtTPG()->options['settings'] );
51 $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
52
53 if ( 'rttpg_settings' === $current_page ) {
54 wp_enqueue_style( 'wp-color-picker' );
55 wp_enqueue_script( 'wp-color-picker' );
56 }
57
58 // register scripts.
59 $scripts = [];
60 $styles = [];
61
62 $scripts[] = [
63 'handle' => 'rt-isotope-js',
64 'src' => rtTPG()->get_assets_uri( 'vendor/isotope/isotope.pkgd.min.js' ),
65 'deps' => [ 'jquery' ],
66 'footer' => true,
67 ];
68
69 $scripts[] = [
70 'handle' => 'rt-tpg',
71 'src' => rtTPG()->get_assets_uri( 'js/rttpg.js' ),
72 'deps' => [ 'jquery' ],
73 'footer' => true,
74 ];
75
76 // register acf styles.
77 $styles['rt-fontawsome'] = rtTPG()->get_assets_uri( 'vendor/font-awesome/css/font-awesome.min.css' );
78
79 // Plugin specific css.
80 $styles['rt-tpg'] = rtTPG()->tpg_can_be_rtl( 'css/thepostgrid' );
81 $styles['rt-tpg-elementor'] = rtTPG()->tpg_can_be_rtl( 'css/tpg-elementor' );
82 $styles['rt-tpg-shortcode'] = rtTPG()->tpg_can_be_rtl( 'css/tpg-shortcode' );
83
84 if ( is_admin() ) {
85 $scripts[] = [
86 'handle' => 'rt-select2',
87 'src' => rtTPG()->get_assets_uri( 'vendor/select2/select2.min.js' ),
88 'deps' => [ 'jquery' ],
89 'footer' => false,
90 ];
91 $scripts[] = [
92 'handle' => 'rt-tpg-admin',
93 'src' => rtTPG()->get_assets_uri( 'js/admin.js' ),
94 'deps' => [ 'jquery', 'wp-color-picker' ],
95 'footer' => true,
96 ];
97 $scripts[] = [
98 'handle' => 'rt-tpg-admin-preview',
99 'src' => rtTPG()->get_assets_uri( 'js/admin-preview.js' ),
100 'deps' => [ 'jquery' ],
101 'footer' => true,
102 ];
103
104 $styles['rt-select2'] = rtTPG()->get_assets_uri( 'vendor/select2/select2.min.css' );
105 $styles['rt-tpg-admin'] = rtTPG()->get_assets_uri( 'css/admin/admin.css' );
106 $styles['rt-tpg-admin-preview'] = rtTPG()->get_assets_uri( 'css/admin/admin-preview.css' );
107 }
108
109 foreach ( $scripts as $script ) {
110 wp_register_script( $script['handle'], $script['src'], $script['deps'], isset( $script['version'] ) ? $script['version'] : $this->version, $script['footer'] );
111 }
112
113 foreach ( $styles as $k => $v ) {
114 wp_register_style( $k, $v, false, isset( $script['version'] ) ? $script['version'] : $this->version );
115 }
116 }
117
118 /**
119 * Enqueue scripts.
120 *
121 * @return void
122 */
123 public function enqueue() {
124 $block_type = isset( $this->settings['tpg_block_type'] ) ? $this->settings['tpg_block_type'] : 'default';
125
126 wp_enqueue_script( 'jquery' );
127
128 if ( ! isset( $this->settings['tpg_load_script'] ) ) {
129 wp_enqueue_style( 'rt-fontawsome' );
130
131 if ( 'default' === $block_type ) {
132 wp_enqueue_style( 'rt-tpg' );
133 }
134
135 if ( 'elementor' === $block_type ) {
136 wp_enqueue_style( 'rt-tpg-elementor' );
137 }
138
139 if ( 'shortcode' === $block_type ) {
140 wp_enqueue_style( 'rt-tpg-shortcode' );
141 }
142 }
143
144 $scriptBefore = isset( $this->settings['script_before_item_load'] ) ? stripslashes( $this->settings['script_before_item_load'] ) : null;
145 $scriptAfter = isset( $this->settings['script_after_item_load'] ) ? stripslashes( $this->settings['script_after_item_load'] ) : null;
146 $scriptLoaded = isset( $this->settings['script_loaded'] ) ? stripslashes( $this->settings['script_loaded'] ) : null;
147
148 $script = "(function($){
149 $('.rt-tpg-container').on('tpg_item_before_load', function(){{$scriptBefore}});
150 $('.rt-tpg-container').on('tpg_item_after_load', function(){{$scriptAfter}});
151 $('.rt-tpg-container').on('tpg_loaded', function(){{$scriptLoaded}});
152 })(jQuery);";
153 wp_add_inline_script( 'rt-tpg', $script );
154 }
155
156 /**
157 * Header Scripts
158 *
159 * @return void
160 */
161 public function header_scripts() {
162 ?>
163 <style>
164 :root {
165 --tpg-primary-color: <?php echo isset( $this->settings['tpg_primary_color_main'] ) ? sanitize_hex_color( $this->settings['tpg_primary_color_main'] ) : '#0d6efd'; ?>;
166 --tpg-secondary-color: <?php echo isset( $this->settings['tpg_secondary_color_main'] ) ? sanitize_hex_color( $this->settings['tpg_secondary_color_main'] ) : '#0654c4'; ?>;
167 --tpg-primary-light: #c4d0ff
168 }
169
170 <?php if ( isset( $this->settings['tpg_loader_color'] ) ) : ?>
171 body .rt-tpg-container .rt-loading,
172 body #bottom-script-loader .rt-ball-clip-rotate {
173 color: <?php echo sanitize_hex_color( $this->settings['tpg_loader_color'] ); ?> !important;
174 }
175
176 <?php endif; ?>
177 </style>
178
179 <?php
180 if ( isset( $this->settings['tpg_load_script'] ) ) :
181 ?>
182 <style>
183 .rt-container-fluid {
184 position: relative;
185 }
186
187 .rt-tpg-container .tpg-pre-loader {
188 position: relative;
189 overflow: hidden;
190 }
191
192 .rt-tpg-container .rt-loading-overlay {
193 opacity: 0;
194 visibility: hidden;
195 position: absolute;
196 top: 0;
197 left: 0;
198 width: 100%;
199 height: 100%;
200 z-index: 1;
201 background-color: #fff;
202 }
203
204 .rt-tpg-container .rt-loading {
205 color: var(--tpg-primary-color);
206 position: absolute;
207 top: 40%;
208 left: 50%;
209 margin-left: -16px;
210 z-index: 2;
211 opacity: 0;
212 visibility: hidden;
213 }
214
215 .rt-tpg-container .tpg-pre-loader .rt-loading-overlay {
216 opacity: 0.8;
217 visibility: visible;
218 }
219
220 .tpg-carousel-main .tpg-pre-loader .rt-loading-overlay {
221 opacity: 1;
222 }
223
224 .rt-tpg-container .tpg-pre-loader .rt-loading {
225 opacity: 1;
226 visibility: visible;
227 }
228
229
230 #bottom-script-loader {
231 position: absolute;
232 width: calc(100% + 60px);
233 height: calc(100% + 60px);
234 z-index: 999;
235 background: rgba(255, 255, 255, 0.95);
236 margin: -30px;
237 }
238
239 #bottom-script-loader .rt-ball-clip-rotate {
240 color: var(--tpg-primary-color);
241 position: absolute;
242 top: 80px;
243 left: 50%;
244 margin-left: -16px;
245 z-index: 2;
246 }
247
248 .tpg-el-main-wrapper.loading {
249 min-height: 300px;
250 transition: 0.4s;
251 }
252
253 .tpg-el-main-wrapper.loading::before {
254 width: 32px;
255 height: 32px;
256 display: inline-block;
257 float: none;
258 border: 2px solid currentColor;
259 background: transparent;
260 border-bottom-color: transparent;
261 border-radius: 100%;
262 -webkit-animation: ball-clip-rotate 0.75s linear infinite;
263 -moz-animation: ball-clip-rotate 0.75s linear infinite;
264 -o-animation: ball-clip-rotate 0.75s linear infinite;
265 animation: ball-clip-rotate 0.75s linear infinite;
266 left: 50%;
267 top: 50%;
268 position: absolute;
269 z-index: 9999999999;
270 color: red;
271 }
272
273
274 .rt-tpg-container .slider-main-wrapper,
275 .tpg-el-main-wrapper .slider-main-wrapper {
276 opacity: 0;
277 }
278
279 .md-modal {
280 visibility: hidden;
281 }
282 .md-modal.md-show {
283 visibility: visible;
284 }
285
286 .builder-content.content-invisible {
287 visibility: hidden;
288 }
289
290 .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) {
291 opacity: 0;
292 }
293
294 .rt-popup-content .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) {
295 opacity: 1;
296 }
297
298 </style>
299
300 <script>
301 jQuery( document ).ready( function () {
302 setTimeout( function () {
303 jQuery( '.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)' ).animate( { "opacity": 1 } );
304 }, 100 );
305 } );
306
307 jQuery( window ).on( 'elementor/frontend/init', function () {
308 if ( elementorFrontend.isEditMode() ) {
309 elementorFrontend.hooks.addAction( 'frontend/element_ready/widget', function () {
310 jQuery( '.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)' ).animate( { "opacity": 1 } );
311 } );
312 }
313 } );
314 </script>
315 <?php
316 endif;
317
318 }
319
320 }
321