PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.1.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.1.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 4 years ago Hooks 4 years ago AjaxController.php 4 years ago ElementorController.php 4 years ago GutenBergController.php 4 years ago ScriptController.php 4 years ago ShortcodeController.php 4 years ago WidgetController.php 4 years ago
ScriptController.php
279 lines
1 <?php
2
3 namespace RT\ThePostGrid\Controllers;
4
5 class ScriptController {
6
7 private $version;
8 private $settings;
9
10 public function __construct() {
11 $this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION;
12 add_action( 'wp_head', [ &$this, 'header_scripts' ] );
13 add_action( 'wp_enqueue_scripts', [ &$this, 'enqueue' ] );
14 add_action( 'init', [ $this, 'init' ] );
15
16 }
17
18 public function init() {
19
20 $this->settings = get_option( rtTPG()->options['settings'] );
21
22 $current_page = isset( $_GET["page"] ) ? $_GET["page"] : '';
23 if ( 'rttpg_settings' == $current_page ) {
24 wp_enqueue_style( 'wp-color-picker' );
25 wp_enqueue_script( 'wp-color-picker' );
26 }
27
28 // register scripts
29 $scripts = [];
30 $styles = [];
31
32
33 $scripts[] = [
34 'handle' => 'rt-isotope-js',
35 'src' => rtTPG()->get_assets_uri( "vendor/isotope/isotope.pkgd.min.js" ),
36 'deps' => [ 'jquery' ],
37 'footer' => true,
38 ];
39
40 $scripts[] = [
41 'handle' => 'rt-tpg',
42 'src' => rtTPG()->get_assets_uri( 'js/rttpg.js' ),
43 'deps' => [ 'jquery' ],
44 'footer' => true,
45 ];
46
47 // register acf styles
48 $styles['rt-fontawsome'] = rtTPG()->get_assets_uri( 'vendor/font-awesome/css/font-awesome.min.css' );
49
50
51 //Plugin specific css
52 $styles['rt-tpg'] = rtTPG()->tpg_can_be_rtl( 'css/thepostgrid' );
53 $styles['rt-tpg-elementor'] = rtTPG()->tpg_can_be_rtl( 'css/tpg-elementor' );
54 $styles['rt-tpg-shortcode'] = rtTPG()->tpg_can_be_rtl( 'css/tpg-shortcode' );
55
56
57 if ( is_admin() ) {
58 $scripts[] = [
59 'handle' => 'rt-select2',
60 'src' => rtTPG()->get_assets_uri( 'vendor/select2/select2.min.js' ),
61 'deps' => [ 'jquery' ],
62 'footer' => false,
63 ];
64 $scripts[] = [
65 'handle' => 'rt-tpg-admin',
66 'src' => rtTPG()->get_assets_uri( 'js/admin.js' ),
67 'deps' => [ 'jquery', 'wp-color-picker' ],
68 'footer' => true,
69 ];
70 $scripts[] = [
71 'handle' => 'rt-tpg-admin-preview',
72 'src' => rtTPG()->get_assets_uri( 'js/admin-preview.js' ),
73 'deps' => [ 'jquery' ],
74 'footer' => true,
75 ];
76 $styles['rt-select2'] = rtTPG()->get_assets_uri( 'vendor/select2/select2.min.css' );
77 $styles['rt-tpg-admin'] = rtTPG()->get_assets_uri( 'css/admin/admin.css' );
78 $styles['rt-tpg-admin-preview'] = rtTPG()->get_assets_uri( 'css/admin/admin-preview.css' );
79 }
80
81 foreach ( $scripts as $script ) {
82 wp_register_script( $script['handle'], $script['src'], $script['deps'], isset( $script['version'] ) ? $script['version'] : $this->version, $script['footer'] );
83 }
84
85 foreach ( $styles as $k => $v ) {
86 wp_register_style( $k, $v, false, isset( $script['version'] ) ? $script['version'] : $this->version );
87 }
88 }
89
90 public function enqueue() {
91 wp_enqueue_script( 'jquery' );
92 $block_type = isset( $this->settings['tpg_block_type'] ) ? $this->settings['tpg_block_type'] : 'default';
93
94 if ( ! isset( $this->settings['tpg_load_script'] ) ) {
95 wp_enqueue_style( 'rt-fontawsome' );
96 if ( 'default' == $block_type ) {
97 wp_enqueue_style( 'rt-tpg' );
98 }
99 if ( 'elementor' == $block_type ) {
100 wp_enqueue_style( 'rt-tpg-elementor' );
101 }
102 if ( 'shortcode' == $block_type ) {
103 wp_enqueue_style( 'rt-tpg-shortcode' );
104 }
105 }
106
107 $scriptBefore = isset( $this->settings['script_before_item_load'] ) ? stripslashes( $this->settings['script_before_item_load'] ) : null;
108 $scriptAfter = isset( $this->settings['script_after_item_load'] ) ? stripslashes( $this->settings['script_after_item_load'] ) : null;
109 $scriptLoaded = isset( $this->settings['script_loaded'] ) ? stripslashes( $this->settings['script_loaded'] ) : null;
110 $script = "(function($){
111 $('.rt-tpg-container').on('tpg_item_before_load', function(){{$scriptBefore}});
112 $('.rt-tpg-container').on('tpg_item_after_load', function(){{$scriptAfter}});
113 $('.rt-tpg-container').on('tpg_loaded', function(){{$scriptLoaded}});
114 })(jQuery);";
115 wp_add_inline_script( 'rt-tpg', $script );
116 }
117
118 /**
119 * Header Scripts
120 */
121 public function header_scripts() {
122
123 ?>
124 <style>
125 :root {
126 --tpg-primary-color: <?php echo isset( $this->settings['tpg_primary_color_main'] ) ? $this->settings['tpg_primary_color_main'] : '#0d6efd'?>;
127 --tpg-secondary-color: <?php echo isset( $this->settings['tpg_secondary_color_main'] ) ? $this->settings['tpg_secondary_color_main'] : '#0654c4'?>;
128 --tpg-primary-light: #c4d0ff
129 }
130
131 <?php if( isset( $this->settings['tpg_loader_color'] ) ) : ?>
132 body .rt-tpg-container .rt-loading,
133 body #bottom-script-loader .rt-ball-clip-rotate {
134 color: <?php echo esc_attr($this->settings['tpg_loader_color']) ?> !important;
135 }
136
137 <?php endif; ?>
138 </style>
139
140 <?php
141 if ( isset( $this->settings['tpg_load_script'] ) ) : ?>
142 <style>
143 .rt-container-fluid {
144 position: relative;
145 }
146
147 .rt-tpg-container .tpg-pre-loader {
148 position: relative;
149 overflow: hidden;
150 }
151
152 .rt-tpg-container .rt-loading-overlay {
153 opacity: 0;
154 visibility: hidden;
155 position: absolute;
156 top: 0;
157 left: 0;
158 width: 100%;
159 height: 100%;
160 z-index: 1;
161 background-color: #fff;
162 }
163
164 .rt-tpg-container .rt-loading {
165 color: var(--tpg-primary-color);
166 position: absolute;
167 top: 40%;
168 left: 50%;
169 margin-left: -16px;
170 z-index: 2;
171 opacity: 0;
172 visibility: hidden;
173 }
174
175 .rt-tpg-container .tpg-pre-loader .rt-loading-overlay {
176 opacity: 0.8;
177 visibility: visible;
178 }
179
180 .tpg-carousel-main .tpg-pre-loader .rt-loading-overlay {
181 opacity: 1;
182 }
183
184 .rt-tpg-container .tpg-pre-loader .rt-loading {
185 opacity: 1;
186 visibility: visible;
187 }
188
189
190 #bottom-script-loader {
191 position: absolute;
192 width: calc(100% + 60px);
193 height: calc(100% + 60px);
194 z-index: 999;
195 background: rgba(255, 255, 255, 0.95);
196 margin: -30px;
197 }
198
199 #bottom-script-loader .rt-ball-clip-rotate {
200 color: var(--tpg-primary-color);
201 position: absolute;
202 top: 80px;
203 left: 50%;
204 margin-left: -16px;
205 z-index: 2;
206 }
207
208 .tpg-el-main-wrapper.loading {
209 min-height: 300px;
210 transition: 0.4s;
211 }
212
213 .tpg-el-main-wrapper.loading::before {
214 width: 32px;
215 height: 32px;
216 display: inline-block;
217 float: none;
218 border: 2px solid currentColor;
219 background: transparent;
220 border-bottom-color: transparent;
221 border-radius: 100%;
222 -webkit-animation: ball-clip-rotate 0.75s linear infinite;
223 -moz-animation: ball-clip-rotate 0.75s linear infinite;
224 -o-animation: ball-clip-rotate 0.75s linear infinite;
225 animation: ball-clip-rotate 0.75s linear infinite;
226 left: 50%;
227 top: 50%;
228 position: absolute;
229 z-index: 9999999999;
230 color: red;
231 }
232
233
234 .rt-tpg-container .slider-main-wrapper,
235 .tpg-el-main-wrapper .slider-main-wrapper {
236 opacity: 0;
237 }
238
239 .md-modal {
240 visibility: hidden;
241 }
242 .md-modal.md-show {
243 visibility: visible;
244 }
245
246 .builder-content.content-invisible {
247 visibility: hidden;
248 }
249
250 .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) {
251 opacity: 0;
252 }
253
254 .rt-popup-content .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) {
255 opacity: 1;
256 }
257
258 </style>
259
260 <script>
261 jQuery( document ).ready( function () {
262 setTimeout( function () {
263 jQuery( '.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)' ).animate( { "opacity": 1 } );
264 }, 100 );
265 } );
266
267 jQuery( window ).on( 'elementor/frontend/init', function () {
268 if ( elementorFrontend.isEditMode() ) {
269 elementorFrontend.hooks.addAction( 'frontend/element_ready/widget', function () {
270 jQuery( '.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)' ).animate( { "opacity": 1 } );
271 } );
272 }
273 } );
274 </script>
275 <?php endif;
276
277 }
278
279 }