PluginProbe
Elementor Website Builder – more than just a page builder / 3.18.2
Elementor Website Builder – more than just a page builder v3.18.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / styleguide / module.php

module.php in Elementor Website Builder – more than just a page builder 3.18.2, at modules/styleguide/module.php

151 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\Styleguide;
3
4 use Elementor\Core\Base\Module as Base_Module;
5 use Elementor\Core\Experiments\Manager as Experiments_Manager;
6 use Elementor\Plugin;
7 use Elementor\Modules\Styleguide\Controls\Switcher;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 class Module extends Base_Module {
14
15 const ASSETS_HANDLE = 'elementor-styleguide';
16 const ASSETS_SRC = 'styleguide';
17
18 const EXPERIMENT_NAME = 'e_global_styleguide';
19
20 /**
21 * Initialize the Container-Converter module.
22 *
23 * @return void
24 */
25 public function __construct() {
26 parent::__construct();
27 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_main_scripts' ] );
28 add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_styles' ] );
29
30 add_action( 'elementor/frontend/after_register_scripts', function () {
31 $is_preview = Plugin::$instance->preview->is_preview();
32
33 if ( ! $is_preview ) {
34 return;
35 }
36
37 $this->enqueue_app_initiator( $is_preview );
38 } );
39
40 add_action( 'elementor/controls/register', [ $this, 'register_controls' ] );
41 add_action( 'elementor/element/after_section_start', [ $this, 'add_styleguide_enable_controls' ], 10, 3 );
42 }
43
44 /**
45 * Retrieve the module name.
46 *
47 * @return string
48 */
49 public function get_name() {
50 return 'styleguide';
51 }
52
53 public static function is_active() {
54 return Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME );
55 }
56
57 public static function get_experimental_data() {
58 return [
59 'name' => static::EXPERIMENT_NAME,
60 'title' => esc_html__( 'Global Style Guide', 'elementor' ),
61 'description' => esc_html__( 'Display a live preview of changes to global colors and fonts in a sleek style guide from the site’s settings. You will be able to toggle between the style guide and the page to see your changes in action.', 'elementor' ),
62 'default' => Experiments_Manager::STATE_ACTIVE,
63 'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE,
64 ];
65 }
66
67 /**
68 * Enqueue scripts.
69 *
70 * @return void
71 */
72 public function enqueue_main_scripts() {
73 wp_enqueue_script(
74 static::ASSETS_HANDLE,
75 $this->get_js_assets_url( static::ASSETS_SRC ),
76 [ 'elementor-editor' ],
77 ELEMENTOR_VERSION,
78 true
79 );
80
81 $kit_id = Plugin::$instance->kits_manager->get_active_id();
82
83 wp_localize_script( static::ASSETS_HANDLE, 'elementorStyleguideConfig', [
84 'activeKitId' => $kit_id,
85 ] );
86 }
87
88 public function enqueue_app_initiator( $is_preview = false ) {
89 $dependencies = [
90 'wp-i18n',
91 'react',
92 'react-dom',
93 ];
94
95 if ( ! $is_preview ) {
96 $dependencies[] = static::ASSETS_HANDLE;
97 }
98
99 wp_enqueue_script(
100 static::ASSETS_HANDLE . '-app-initiator',
101 $this->get_js_assets_url( static::ASSETS_SRC . '-app-initiator' ),
102 $dependencies,
103 ELEMENTOR_VERSION,
104 true
105 );
106 }
107
108 public function enqueue_styles() {
109 wp_enqueue_style(
110 static::ASSETS_HANDLE,
111 $this->get_css_assets_url( 'modules/' . static::ASSETS_SRC . '/' . static::ASSETS_SRC ),
112 [],
113 ELEMENTOR_VERSION
114 );
115 }
116
117 public function register_controls() {
118 $controls_manager = Plugin::$instance->controls_manager;
119
120 $controls_manager->register( new Switcher() );
121 }
122
123 /**
124 * Add the Enable Styleguide Preview controls to Global Colors and Global Fonts.
125 *
126 * @param $element
127 * @param string $section_id
128 * @param array $args
129 */
130 public function add_styleguide_enable_controls( $element, $section_id, $args ) {
131 if ( 'kit' !== $element->get_name() || ! in_array( $section_id, [ 'section_global_colors', 'section_text_style' ] ) ) {
132 return;
133 }
134
135 $control_name = str_replace( 'global-', '', $args['tab'] ) . '_enable_styleguide_preview';
136
137 $element->add_control(
138 $control_name,
139 [
140 'label' => esc_html__( 'Style Guide Preview', 'elementor' ),
141 'type' => Switcher::CONTROL_TYPE,
142 'description' => esc_html__( 'Switch between the content area and style guide to preview your changes to global colors.', 'elementor' ),
143 'separator' => 'after',
144 'label_off' => esc_html__( 'Off', 'elementor' ),
145 'label_on' => esc_html__( 'On', 'elementor' ),
146 'on_change_command' => true,
147 ]
148 );
149 }
150 }
151