mirror of
https://github.com/proelements/proelements.git
synced 2026-05-13 12:35:02 +00:00
v4.0.4
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
namespace ElementorPro\Modules\Interactions;
|
||||
|
||||
use ElementorPro\Plugin;
|
||||
use ElementorPro\Core\Utils as ProUtils;
|
||||
use Elementor\Utils;
|
||||
use Elementor\Modules\Interactions\Module as InteractionsModule;
|
||||
use Elementor\Modules\Interactions\Presets;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
@@ -38,10 +41,13 @@ class Hooks {
|
||||
}
|
||||
|
||||
private function replace_core_handlers() {
|
||||
add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'replace_frontend_handlers' ], 20 );
|
||||
// Run after core's print_interactions_data (priority 1). If core enqueued its script
|
||||
// it means the page has interactions — swap it for the pro script. If core didn't
|
||||
// enqueue anything (no interactions), we skip too, preserving the load optimization.
|
||||
add_action( 'wp_footer', [ $this, 'replace_frontend_handlers' ], 2 );
|
||||
|
||||
add_action( 'elementor/preview/enqueue_scripts', function() {
|
||||
$core_module = Plugin::elementor()->modules_manager->get_modules( 'e-interactions' );
|
||||
$core_module = Plugin::elementor()->modules_manager->get_modules( ProUtils::get_class_constant( InteractionsModule::class, 'MODULE_NAME', 'e-interactions' ) );
|
||||
if ( $core_module && method_exists( $core_module, 'enqueue_preview_scripts' ) ) {
|
||||
remove_action( 'elementor/preview/enqueue_scripts', [ $core_module, 'enqueue_preview_scripts' ] );
|
||||
}
|
||||
@@ -53,73 +59,77 @@ class Hooks {
|
||||
}
|
||||
|
||||
public function register_frontend_scripts() {
|
||||
$suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min';
|
||||
|
||||
wp_register_script(
|
||||
'elementor-interactions-pro',
|
||||
$this->get_js_assets_url( 'interactions-pro' ),
|
||||
[ 'motion-js' ],
|
||||
[
|
||||
ProUtils::get_class_constant( InteractionsModule::class, 'HANDLE_MOTION_JS', 'motion-js' ),
|
||||
ProUtils::get_class_constant( InteractionsModule::class, 'HANDLE_SHARED_UTILS', 'elementor-interactions-shared-utils' ),
|
||||
],
|
||||
ELEMENTOR_PRO_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function register_editor_scripts() {
|
||||
$suffix = ( Utils::is_script_debug() || Utils::is_elementor_tests() ) ? '' : '.min';
|
||||
|
||||
wp_register_script(
|
||||
'elementor-editor-interactions-pro',
|
||||
$this->get_js_assets_url( 'editor-interactions-pro' ),
|
||||
[ 'motion-js' ],
|
||||
[
|
||||
ProUtils::get_class_constant( InteractionsModule::class, 'HANDLE_MOTION_JS', 'motion-js' ),
|
||||
ProUtils::get_class_constant( InteractionsModule::class, 'HANDLE_SHARED_UTILS', 'elementor-interactions-shared-utils' ),
|
||||
],
|
||||
ELEMENTOR_PRO_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function replace_frontend_handlers() {
|
||||
wp_dequeue_script( 'elementor-interactions' );
|
||||
wp_deregister_script( 'elementor-interactions' );
|
||||
$handle_frontend = ProUtils::get_class_constant( InteractionsModule::class, 'HANDLE_FRONTEND', 'elementor-interactions' );
|
||||
|
||||
// Core only enqueues its script when the page has interactions.
|
||||
// If it didn't enqueue, there's nothing to replace — skip to preserve the load optimization.
|
||||
if ( ! wp_script_is( $handle_frontend, 'enqueued' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_dequeue_script( $handle_frontend );
|
||||
wp_deregister_script( $handle_frontend );
|
||||
|
||||
wp_enqueue_script( 'elementor-interactions-pro' );
|
||||
|
||||
$config = $this->get_config();
|
||||
wp_localize_script(
|
||||
'elementor-interactions-pro',
|
||||
'ElementorInteractionsConfig',
|
||||
$config
|
||||
ProUtils::get_class_constant( InteractionsModule::class, 'JS_CONFIG_OBJECT', 'ElementorInteractionsConfig' ),
|
||||
$this->get_config()
|
||||
);
|
||||
}
|
||||
|
||||
public function replace_preview_handlers() {
|
||||
wp_dequeue_script( 'elementor-editor-interactions' );
|
||||
wp_deregister_script( 'elementor-editor-interactions' );
|
||||
$handle_editor = ProUtils::get_class_constant( InteractionsModule::class, 'HANDLE_EDITOR', 'elementor-editor-interactions' );
|
||||
wp_dequeue_script( $handle_editor );
|
||||
wp_deregister_script( $handle_editor );
|
||||
|
||||
wp_enqueue_script( 'elementor-editor-interactions-pro' );
|
||||
|
||||
$config = $this->get_config();
|
||||
wp_localize_script(
|
||||
'elementor-editor-interactions-pro',
|
||||
'ElementorInteractionsConfig',
|
||||
$config
|
||||
ProUtils::get_class_constant( InteractionsModule::class, 'JS_CONFIG_OBJECT', 'ElementorInteractionsConfig' ),
|
||||
$this->get_config()
|
||||
);
|
||||
}
|
||||
|
||||
private function get_config() {
|
||||
$interactions_module = Plugin::elementor()->modules_manager->get_modules( 'e-interactions' );
|
||||
|
||||
if ( $interactions_module && method_exists( $interactions_module, 'get_config' ) ) {
|
||||
return $interactions_module->get_config();
|
||||
if ( class_exists( 'Elementor\\Modules\\Interactions\\Module' ) ) {
|
||||
$module = \Elementor\Modules\Interactions\Module::instance();
|
||||
if ( $module && is_callable( [ $module, 'get_config' ] ) ) {
|
||||
return $module->get_config();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'constants' => [
|
||||
'defaultDuration' => 300,
|
||||
'defaultDelay' => 0,
|
||||
'slideDistance' => 100,
|
||||
'scaleStart' => 0,
|
||||
'easing' => 'linear',
|
||||
],
|
||||
'animationOptions' => [],
|
||||
'constants' => class_exists( Presets::class ) ? ( new Presets() )->defaults() : [],
|
||||
'breakpoints' => [],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user