Admin
3 years ago
Api
3 years ago
Blocks
3 years ago
Hooks
3 years ago
AjaxController.php
3 years ago
BlocksController.php
3 years ago
ElementorController.php
3 years ago
GutenBergController.php
3 years ago
PageTemplateController.php
3 years ago
ScriptController.php
3 years ago
ShortcodeController.php
3 years ago
WidgetController.php
3 years ago
ScriptController.php
366 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 | 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_tpg.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 = isset( $this->settings['tpg_block_type'] ) ? $this->settings['tpg_block_type'] : 'default'; |
| 130 | wp_enqueue_script( 'jquery' ); |
| 131 | |
| 132 | if ( ! isset( $this->settings['tpg_load_script'] ) ) { |
| 133 | wp_enqueue_style( 'rt-fontawsome' ); |
| 134 | wp_enqueue_style( 'rt-flaticon' ); |
| 135 | |
| 136 | if ( 'default' === $block_type ) { |
| 137 | wp_enqueue_style( 'rt-tpg' ); |
| 138 | } |
| 139 | |
| 140 | if ( 'elementor' === $block_type ) { |
| 141 | wp_enqueue_style( 'rt-tpg-block' ); |
| 142 | } |
| 143 | |
| 144 | if ( 'shortcode' === $block_type ) { |
| 145 | wp_enqueue_style( 'rt-tpg-shortcode' ); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | $scriptBefore = isset( $this->settings['script_before_item_load'] ) ? stripslashes( $this->settings['script_before_item_load'] ) : null; |
| 150 | $scriptAfter = isset( $this->settings['script_after_item_load'] ) ? stripslashes( $this->settings['script_after_item_load'] ) : null; |
| 151 | $scriptLoaded = isset( $this->settings['script_loaded'] ) ? stripslashes( $this->settings['script_loaded'] ) : null; |
| 152 | |
| 153 | $script = "(function($){ |
| 154 | $('.rt-tpg-container').on('tpg_item_before_load', function(){{$scriptBefore}}); |
| 155 | $('.rt-tpg-container').on('tpg_item_after_load', function(){{$scriptAfter}}); |
| 156 | $('.rt-tpg-container').on('tpg_loaded', function(){{$scriptLoaded}}); |
| 157 | })(jQuery);"; |
| 158 | wp_add_inline_script( 'rt-tpg', $script ); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Header Scripts |
| 163 | * |
| 164 | * @return void |
| 165 | */ |
| 166 | public function header_scripts() { |
| 167 | |
| 168 | $tpg_logo = RT_THE_POST_GRID_PLUGIN_URL; |
| 169 | |
| 170 | ?> |
| 171 | |
| 172 | <script> |
| 173 | |
| 174 | jQuery(window).on('elementor/frontend/init', function () { |
| 175 | var previewIframe = jQuery('#elementor-preview-iframe').get(0); |
| 176 | |
| 177 | // Attach a load event listener to the preview iframe |
| 178 | jQuery(previewIframe).on('load', function () { |
| 179 | var tpg_selector = tpg_str_rev("nottub-tropmi-gpttr nottub-aera-noitces-dda-rotnemele"); |
| 180 | |
| 181 | var logo = "<?php echo esc_html( $tpg_logo ); ?>"; |
| 182 | var log_path = tpg_str_rev("gvs.04x04-noci/segami/stessa/"); |
| 183 | |
| 184 | |
| 185 | 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"); |
| 186 | |
| 187 | }); |
| 188 | |
| 189 | |
| 190 | /* |
| 191 | if ( elementorFrontend.isEditMode() ) { |
| 192 | elementorFrontend.hooks.addAction( 'elementor/frontend/init, function () { |
| 193 | var tpg_selector = tpg_str_rev("nottub-tropmi-gpttr nottub-aera-noitces-dda-rotnemele"); |
| 194 | |
| 195 | var logo = "<?php echo esc_html( $tpg_logo ); ?>"; |
| 196 | var log_path = tpg_str_rev("gvs.04x04-noci/segami/stessa/"); |
| 197 | console.log(logo+log_path) |
| 198 | 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"); |
| 199 | |
| 200 | |
| 201 | } ); |
| 202 | } |
| 203 | */ |
| 204 | |
| 205 | }); |
| 206 | </script> |
| 207 | <style> |
| 208 | :root { |
| 209 | --tpg-primary-color: <?php echo isset( $this->settings['tpg_primary_color_main'] ) ? sanitize_hex_color( $this->settings['tpg_primary_color_main'] ) : '#0d6efd'; ?>; |
| 210 | --tpg-secondary-color: <?php echo isset( $this->settings['tpg_secondary_color_main'] ) ? sanitize_hex_color( $this->settings['tpg_secondary_color_main'] ) : '#0654c4'; ?>; |
| 211 | --tpg-primary-light: #c4d0ff |
| 212 | } |
| 213 | |
| 214 | <?php if ( isset( $this->settings['tpg_loader_color'] ) ) : ?> |
| 215 | body .rt-tpg-container .rt-loading, |
| 216 | body #bottom-script-loader .rt-ball-clip-rotate { |
| 217 | color: <?php echo sanitize_hex_color( $this->settings['tpg_loader_color'] ); ?> !important; |
| 218 | } |
| 219 | |
| 220 | <?php endif; ?> |
| 221 | </style> |
| 222 | |
| 223 | <?php |
| 224 | if ( isset( $this->settings['tpg_load_script'] ) ) : |
| 225 | ?> |
| 226 | <style> |
| 227 | .rt-container-fluid { |
| 228 | position: relative; |
| 229 | } |
| 230 | |
| 231 | .rt-tpg-container .tpg-pre-loader { |
| 232 | position: relative; |
| 233 | overflow: hidden; |
| 234 | } |
| 235 | |
| 236 | .rt-tpg-container .rt-loading-overlay { |
| 237 | opacity: 0; |
| 238 | visibility: hidden; |
| 239 | position: absolute; |
| 240 | top: 0; |
| 241 | left: 0; |
| 242 | width: 100%; |
| 243 | height: 100%; |
| 244 | z-index: 1; |
| 245 | background-color: #fff; |
| 246 | } |
| 247 | |
| 248 | .rt-tpg-container .rt-loading { |
| 249 | color: var(--tpg-primary-color); |
| 250 | position: absolute; |
| 251 | top: 40%; |
| 252 | left: 50%; |
| 253 | margin-left: -16px; |
| 254 | z-index: 2; |
| 255 | opacity: 0; |
| 256 | visibility: hidden; |
| 257 | } |
| 258 | |
| 259 | .rt-tpg-container .tpg-pre-loader .rt-loading-overlay { |
| 260 | opacity: 0.8; |
| 261 | visibility: visible; |
| 262 | } |
| 263 | |
| 264 | .tpg-carousel-main .tpg-pre-loader .rt-loading-overlay { |
| 265 | opacity: 1; |
| 266 | } |
| 267 | |
| 268 | .rt-tpg-container .tpg-pre-loader .rt-loading { |
| 269 | opacity: 1; |
| 270 | visibility: visible; |
| 271 | } |
| 272 | |
| 273 | |
| 274 | #bottom-script-loader { |
| 275 | position: absolute; |
| 276 | width: calc(100% + 60px); |
| 277 | height: calc(100% + 60px); |
| 278 | z-index: 999; |
| 279 | background: rgba(255, 255, 255, 0.95); |
| 280 | margin: -30px; |
| 281 | } |
| 282 | |
| 283 | #bottom-script-loader .rt-ball-clip-rotate { |
| 284 | color: var(--tpg-primary-color); |
| 285 | position: absolute; |
| 286 | top: 80px; |
| 287 | left: 50%; |
| 288 | margin-left: -16px; |
| 289 | z-index: 2; |
| 290 | } |
| 291 | |
| 292 | .tpg-el-main-wrapper.loading { |
| 293 | min-height: 300px; |
| 294 | transition: 0.4s; |
| 295 | } |
| 296 | |
| 297 | .tpg-el-main-wrapper.loading::before { |
| 298 | width: 32px; |
| 299 | height: 32px; |
| 300 | display: inline-block; |
| 301 | float: none; |
| 302 | border: 2px solid currentColor; |
| 303 | background: transparent; |
| 304 | border-bottom-color: transparent; |
| 305 | border-radius: 100%; |
| 306 | -webkit-animation: ball-clip-rotate 0.75s linear infinite; |
| 307 | -moz-animation: ball-clip-rotate 0.75s linear infinite; |
| 308 | -o-animation: ball-clip-rotate 0.75s linear infinite; |
| 309 | animation: ball-clip-rotate 0.75s linear infinite; |
| 310 | left: 50%; |
| 311 | top: 50%; |
| 312 | position: absolute; |
| 313 | z-index: 9999999999; |
| 314 | color: red; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | .rt-tpg-container .slider-main-wrapper, |
| 319 | .tpg-el-main-wrapper .slider-main-wrapper { |
| 320 | opacity: 0; |
| 321 | } |
| 322 | |
| 323 | .md-modal { |
| 324 | visibility: hidden; |
| 325 | } |
| 326 | |
| 327 | .md-modal.md-show { |
| 328 | visibility: visible; |
| 329 | } |
| 330 | |
| 331 | .builder-content.content-invisible { |
| 332 | visibility: hidden; |
| 333 | } |
| 334 | |
| 335 | .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) { |
| 336 | opacity: 0; |
| 337 | } |
| 338 | |
| 339 | .rt-popup-content .rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper) { |
| 340 | opacity: 1; |
| 341 | } |
| 342 | |
| 343 | </style> |
| 344 | |
| 345 | <script> |
| 346 | jQuery(document).ready(function () { |
| 347 | setTimeout(function () { |
| 348 | jQuery('.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)').animate({"opacity": 1}); |
| 349 | }, 100); |
| 350 | }); |
| 351 | |
| 352 | jQuery(window).on('elementor/frontend/init', function () { |
| 353 | if (elementorFrontend.isEditMode()) { |
| 354 | elementorFrontend.hooks.addAction('frontend/element_ready/widget', function () { |
| 355 | jQuery('.rt-tpg-container > *:not(.bottom-script-loader, .slider-main-wrapper)').animate({"opacity": 1}); |
| 356 | }); |
| 357 | } |
| 358 | }); |
| 359 | </script> |
| 360 | <?php |
| 361 | endif; |
| 362 | |
| 363 | } |
| 364 | |
| 365 | } |
| 366 |