| 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 |
use RT\ThePostGrid\Helpers\Fns; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit( 'This script cannot be accessed directly.' ); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Script Controller class. |
| 19 |
*/ |
| 20 |
class ScriptController { |
| 21 |
/** |
| 22 |
* Version |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
private $version; |
| 27 |
|
| 28 |
/** |
| 29 |
* Settings |
| 30 |
* |
| 31 |
* @var array |
| 32 |
*/ |
| 33 |
private $settings; |
| 34 |
|
| 35 |
/** |
| 36 |
* Class construct |
| 37 |
*/ |
| 38 |
public function __construct() { |
| 39 |
$this->version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : RT_THE_POST_GRID_VERSION; |
| 40 |
add_action( 'wp_head', [ $this, 'header_scripts' ] ); |
| 41 |
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue' ] ); |
| 42 |
add_action( 'init', [ $this, 'init' ] ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Init |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function init() { |
| 51 |
|
| 52 |
$current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; |
| 53 |
|
| 54 |
if ( 'rttpg_settings' === $current_page ) { |
| 55 |
wp_enqueue_style( 'wp-color-picker' ); |
| 56 |
wp_enqueue_script( 'wp-color-picker' ); |
| 57 |
} |
| 58 |
|
| 59 |
// register scripts. |
| 60 |
$scripts = []; |
| 61 |
$styles = []; |
| 62 |
|
| 63 |
$scripts[] = [ |
| 64 |
'handle' => 'rt-isotope-js', |
| 65 |
'src' => rtTPG()->get_assets_uri( 'vendor/isotope/isotope.pkgd.min.js' ), |
| 66 |
'deps' => [ 'jquery' ], |
| 67 |
'footer' => true, |
| 68 |
]; |
| 69 |
|
| 70 |
$scripts[] = [ |
| 71 |
'handle' => 'rt-tpg', |
| 72 |
'src' => rtTPG()->get_assets_uri( 'js/rttpg.js' ), |
| 73 |
'deps' => [ 'jquery' ], |
| 74 |
'footer' => true, |
| 75 |
]; |
| 76 |
|
| 77 |
// register acf styles. |
| 78 |
$styles['rt-fontawsome'] = rtTPG()->get_assets_uri( 'vendor/font-awesome/css/font-awesome.min.css' ); |
| 79 |
|
| 80 |
if ( Fns::tpg_option('tpg_icon_font') === 'flaticon' ) { |
| 81 |
$styles['rt-flaticon'] = rtTPG()->get_assets_uri( 'vendor/flaticon/flaticon_the_post_grid.css' ); |
| 82 |
} |
| 83 |
|
| 84 |
// Plugin specific css. |
| 85 |
$styles['rt-tpg'] = rtTPG()->tpg_can_be_rtl( 'css/thepostgrid' ); |
| 86 |
$styles['rt-tpg-block'] = rtTPG()->tpg_can_be_rtl( 'css/tpg-block' ); |
| 87 |
$styles['rt-tpg-shortcode'] = rtTPG()->tpg_can_be_rtl( 'css/tpg-shortcode' ); |
| 88 |
|
| 89 |
if ( is_admin() ) { |
| 90 |
$scripts[] = [ |
| 91 |
'handle' => 'rt-select2', |
| 92 |
'src' => rtTPG()->get_assets_uri( 'vendor/select2/select2.min.js' ), |
| 93 |
'deps' => [ 'jquery' ], |
| 94 |
'footer' => false, |
| 95 |
]; |
| 96 |
$scripts[] = [ |
| 97 |
'handle' => 'rt-tpg-admin', |
| 98 |
'src' => rtTPG()->get_assets_uri( 'js/admin.js' ), |
| 99 |
'deps' => [ 'jquery', 'wp-color-picker', 'jquery-ui-sortable' ], |
| 100 |
'footer' => true, |
| 101 |
]; |
| 102 |
$scripts[] = [ |
| 103 |
'handle' => 'rt-tpg-admin-preview', |
| 104 |
'src' => rtTPG()->get_assets_uri( 'js/admin-preview.js' ), |
| 105 |
'deps' => [ 'jquery' ], |
| 106 |
'footer' => true, |
| 107 |
]; |
| 108 |
|
| 109 |
$styles['rt-select2'] = rtTPG()->get_assets_uri( 'vendor/select2/select2.min.css' ); |
| 110 |
$styles['rt-tpg-admin'] = rtTPG()->get_assets_uri( 'css/admin/admin.css' ); |
| 111 |
$styles['rt-tpg-admin-preview'] = rtTPG()->get_assets_uri( 'css/admin/admin-preview.css' ); |
| 112 |
} |
| 113 |
|
| 114 |
foreach ( $scripts as $script ) { |
| 115 |
wp_register_script( $script['handle'], $script['src'], $script['deps'], isset( $script['version'] ) ? $script['version'] : $this->version, $script['footer'] ); |
| 116 |
} |
| 117 |
|
| 118 |
foreach ( $styles as $k => $v ) { |
| 119 |
wp_register_style( $k, $v, false, isset( $script['version'] ) ? $script['version'] : $this->version ); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Enqueue scripts. |
| 125 |
* |
| 126 |
* @return void |
| 127 |
*/ |
| 128 |
public function enqueue() { |
| 129 |
$block_type = Fns::tpg_option('tpg_block_type', 'default'); |
| 130 |
$load_script_type = Fns::tpg_option('tpg_load_script'); |
| 131 |
|
| 132 |
wp_enqueue_script( 'jquery' ); |
| 133 |
|
| 134 |
if ( ! $load_script_type ) { |
| 135 |
wp_enqueue_style( 'rt-fontawsome' ); |
| 136 |
wp_enqueue_style( 'rt-flaticon' ); |
| 137 |
|
| 138 |
if ( 'default' === $block_type ) { |
| 139 |
wp_enqueue_style( 'rt-tpg' ); |
| 140 |
} |
| 141 |
|
| 142 |
if ( 'elementor' === $block_type ) { |
| 143 |
wp_enqueue_style( 'rt-tpg-block' ); |
| 144 |
} |
| 145 |
|
| 146 |
if ( 'shortcode' === $block_type ) { |
| 147 |
wp_enqueue_style( 'rt-tpg-shortcode' ); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
$scriptBefore = isset( $this->settings['script_before_item_load'] ) ? stripslashes( $this->settings['script_before_item_load'] ) : null; |
| 152 |
$scriptAfter = isset( $this->settings['script_after_item_load'] ) ? stripslashes( $this->settings['script_after_item_load'] ) : null; |
| 153 |
$scriptLoaded = isset( $this->settings['script_loaded'] ) ? stripslashes( $this->settings['script_loaded'] ) : null; |
| 154 |
|
| 155 |
$script = "(function($){ |
| 156 |
$('.rt-tpg-container').on('tpg_item_before_load', function(){{$scriptBefore}}); |
| 157 |
$('.rt-tpg-container').on('tpg_item_after_load', function(){{$scriptAfter}}); |
| 158 |
$('.rt-tpg-container').on('tpg_loaded', function(){{$scriptLoaded}}); |
| 159 |
})(jQuery);"; |
| 160 |
wp_add_inline_script( 'rt-tpg', $script ); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Header Scripts |
| 165 |
* |
| 166 |
* @return void |
| 167 |
*/ |
| 168 |
public function header_scripts() { |
| 169 |
|
| 170 |
$tpg_logo = RT_THE_POST_GRID_PLUGIN_URL; |
| 171 |
|
| 172 |
?> |
| 173 |
|
| 174 |
<script> |
| 175 |
|
| 176 |
jQuery(window).on('elementor/frontend/init', function () { |
| 177 |
var previewIframe = jQuery('#elementor-preview-iframe').get(0); |
| 178 |
|
| 179 |
// Attach a load event listener to the preview iframe |
| 180 |
jQuery(previewIframe).on('load', function () { |
| 181 |
var tpg_selector = tpg_str_rev("nottub-tropmi-gpttr nottub-aera-noitces-dda-rotnemele"); |
| 182 |
|
| 183 |
var logo = "<?php echo esc_html( $tpg_logo ); ?>"; |
| 184 |
var log_path = tpg_str_rev("gvs.04x04-noci/segami/stessa/"); |
| 185 |
|
| 186 |
jQuery('<div class="' + tpg_selector + '" style="vertical-align: bottom;margin-left: 5px;"><img src="' + logo + log_path + '" alt="TPG"/></div>').insertBefore(".elementor-add-section-drag-title"); |
| 187 |
}); |
| 188 |
|
| 189 |
}); |
| 190 |
</script> |
| 191 |
<style> |
| 192 |
:root { |
| 193 |
--tpg-primary-color: <?php echo isset( $this->settings['tpg_primary_color_main'] ) ? sanitize_hex_color( $this->settings['tpg_primary_color_main'] ) : '#0d6efd'; ?>; |
| 194 |
--tpg-secondary-color: <?php echo isset( $this->settings['tpg_secondary_color_main'] ) ? sanitize_hex_color( $this->settings['tpg_secondary_color_main'] ) : '#0654c4'; ?>; |
| 195 |
--tpg-primary-light: #c4d0ff |
| 196 |
} |
| 197 |
|
| 198 |
<?php if ( isset( $this->settings['tpg_loader_color'] ) ) : ?> |
| 199 |
body .rt-tpg-container .rt-loading, |
| 200 |
body #bottom-script-loader .rt-ball-clip-rotate { |
| 201 |
color: <?php echo sanitize_hex_color( $this->settings['tpg_loader_color'] ); ?> !important; |
| 202 |
} |
| 203 |
|
| 204 |
<?php endif; ?> |
| 205 |
</style> |
| 206 |
|
| 207 |
<?php |
| 208 |
if ( isset( $this->settings['tpg_load_script'] ) ) : |
| 209 |
?> |
| 210 |
<style> |
| 211 |
.rt-container-fluid { |
| 212 |
position: relative; |
| 213 |
} |
| 214 |
|
| 215 |
.rt-tpg-container .tpg-pre-loader { |
| 216 |
position: relative; |
| 217 |
overflow: hidden; |
| 218 |
} |
| 219 |
|
| 220 |
.rt-tpg-container .rt-loading-overlay { |
| 221 |
opacity: 0; |
| 222 |
visibility: hidden; |
| 223 |
position: absolute; |
| 224 |
top: 0; |
| 225 |
left: 0; |
| 226 |
width: 100%; |
| 227 |
height: 100%; |
| 228 |
z-index: 1; |
| 229 |
background-color: #fff; |
| 230 |
} |
| 231 |
|
| 232 |
.rt-tpg-container .rt-loading { |
| 233 |
color: var(--tpg-primary-color); |
| 234 |
position: absolute; |
| 235 |
top: 40%; |
| 236 |
left: 50%; |
| 237 |
margin-left: -16px; |
| 238 |
z-index: 2; |
| 239 |
opacity: 0; |
| 240 |
visibility: hidden; |
| 241 |
} |
| 242 |
|
| 243 |
.rt-tpg-container .tpg-pre-loader .rt-loading-overlay { |
| 244 |
opacity: 0.8; |
| 245 |
visibility: visible; |
| 246 |
} |
| 247 |
|
| 248 |
.tpg-carousel-main .tpg-pre-loader .rt-loading-overlay { |
| 249 |
opacity: 1; |
| 250 |
} |
| 251 |
|
| 252 |
.rt-tpg-container .tpg-pre-loader .rt-loading { |
| 253 |
opacity: 1; |
| 254 |
visibility: visible; |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
#bottom-script-loader { |
| 259 |
position: absolute; |
| 260 |
width: calc(100% + 60px); |
| 261 |
height: calc(100% + 60px); |
| 262 |
z-index: 999; |
| 263 |
background: rgba(255, 255, 255, 0.95); |
| 264 |
margin: -30px; |
| 265 |
} |
| 266 |
|
| 267 |
#bottom-script-loader .rt-ball-clip-rotate { |
| 268 |
color: var(--tpg-primary-color); |
| 269 |
position: absolute; |
| 270 |
top: 80px; |
| 271 |
left: 50%; |
| 272 |
margin-left: -16px; |
| 273 |
z-index: 2; |
| 274 |
} |
| 275 |
|
| 276 |
.tpg-el-main-wrapper.loading { |
| 277 |
min-height: 300px; |
| 278 |
transition: 0.4s; |
| 279 |
} |
| 280 |
|
| 281 |
.tpg-el-main-wrapper.loading::before { |
| 282 |
width: 32px; |
| 283 |
height: 32px; |
| 284 |
display: inline-block; |
| 285 |
float: none; |
| 286 |
border: 2px solid currentColor; |
| 287 |
background: transparent; |
| 288 |
border-bottom-color: transparent; |
| 289 |
border-radius: 100%; |
| 290 |
-webkit-animation: ball-clip-rotate 0.75s linear infinite; |
| 291 |
-moz-animation: ball-clip-rotate 0.75s linear infinite; |
| 292 |
-o-animation: ball-clip-rotate 0.75s linear infinite; |
| 293 |
animation: ball-clip-rotate 0.75s linear infinite; |
| 294 |
left: 50%; |
| 295 |
top: 50%; |
| 296 |
position: absolute; |
| 297 |
z-index: 9999999999; |
| 298 |
color: red; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
.rt-tpg-container .slider-main-wrapper, |
| 303 |
.tpg-el-main-wrapper .slider-main-wrapper { |
| 304 |
opacity: 0; |
| 305 |
} |
| 306 |
|
| 307 |
.md-modal { |
| 308 |
visibility: hidden; |
| 309 |
} |
| 310 |
|
| 311 |
.md-modal.md-show { |
| 312 |
visibility: visible; |
| 313 |
} |
| 314 |
|
| 315 |
.builder-content.content-invisible { |
| 316 |
visibility: hidden; |
| 317 |
} |
| 318 |
|
| 319 |
.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) { |
| 320 |
opacity: 0; |
| 321 |
} |
| 322 |
|
| 323 |
.rt-popup-content .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) { |
| 324 |
opacity: 1; |
| 325 |
} |
| 326 |
|
| 327 |
</style> |
| 328 |
|
| 329 |
<script> |
| 330 |
jQuery(document).ready(function () { |
| 331 |
setTimeout(function () { |
| 332 |
jQuery('.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)').animate({"opacity": 1}); |
| 333 |
}, 100); |
| 334 |
}); |
| 335 |
|
| 336 |
jQuery(window).on('elementor/frontend/init', function () { |
| 337 |
if (elementorFrontend.isEditMode()) { |
| 338 |
elementorFrontend.hooks.addAction('frontend/element_ready/widget', function () { |
| 339 |
jQuery('.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)').animate({"opacity": 1}); |
| 340 |
}); |
| 341 |
} |
| 342 |
}); |
| 343 |
</script> |
| 344 |
<?php |
| 345 |
endif; |
| 346 |
|
| 347 |
} |
| 348 |
|
| 349 |
} |
| 350 |
|