PluginProbe
Elementor Website Builder – more than just a page builder / 3.16.0-dev1
Elementor Website Builder – more than just a page builder v3.16.0-dev1
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.16.0-dev1, at modules/styleguide/module.php

154 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 'release_status' => Experiments_Manager::RELEASE_STATUS_BETA,
63 'new_site' => [
64 'default_active' => true,
65 'minimum_installation_version' => '3.14',
66 ],
67 ];
68 }
69
70 /**
71 * Enqueue scripts.
72 *
73 * @return void
74 */
75 public function enqueue_main_scripts() {
76 wp_enqueue_script(
77 static::ASSETS_HANDLE,
78 $this->get_js_assets_url( static::ASSETS_SRC ),
79 [ 'elementor-editor' ],
80 ELEMENTOR_VERSION,
81 true
82 );
83
84 $kit_id = Plugin::$instance->kits_manager->get_active_id();
85
86 wp_localize_script( static::ASSETS_HANDLE, 'elementorStyleguideConfig', [
87 'activeKitId' => $kit_id,
88 ] );
89 }
90
91 public function enqueue_app_initiator( $is_preview = false ) {
92 $dependencies = [
93 'wp-i18n',
94 'react',
95 'react-dom',
96 ];
97
98 if ( ! $is_preview ) {
99 $dependencies[] = static::ASSETS_HANDLE;
100 }
101
102 wp_enqueue_script(
103 static::ASSETS_HANDLE . '-app-initiator',
104 $this->get_js_assets_url( static::ASSETS_SRC . '-app-initiator' ),
105 $dependencies,
106 ELEMENTOR_VERSION,
107 true
108 );
109 }
110
111 public function enqueue_styles() {
112 wp_enqueue_style(
113 static::ASSETS_HANDLE,
114 $this->get_css_assets_url( 'modules/' . static::ASSETS_SRC . '/' . static::ASSETS_SRC ),
115 [],
116 ELEMENTOR_VERSION
117 );
118 }
119
120 public function register_controls() {
121 $controls_manager = Plugin::$instance->controls_manager;
122
123 $controls_manager->register( new Switcher() );
124 }
125
126 /**
127 * Add the Enable Styleguide Preview controls to Global Colors and Global Fonts.
128 *
129 * @param $element
130 * @param string $section_id
131 * @param array $args
132 */
133 public function add_styleguide_enable_controls( $element, $section_id, $args ) {
134 if ( 'kit' !== $element->get_name() || ! in_array( $section_id, [ 'section_global_colors', 'section_text_style' ] ) ) {
135 return;
136 }
137
138 $control_name = str_replace( 'global-', '', $args['tab'] ) . '_enable_styleguide_preview';
139
140 $element->add_control(
141 $control_name,
142 [
143 'label' => esc_html__( 'Style Guide Preview', 'elementor' ),
144 'type' => Switcher::CONTROL_TYPE,
145 'description' => esc_html__( 'Switch between the content area and style guide to preview your changes to global colors.', 'elementor' ),
146 'separator' => 'after',
147 'label_off' => esc_html__( 'Off', 'elementor' ),
148 'label_on' => esc_html__( 'On', 'elementor' ),
149 'on_change_command' => true,
150 ]
151 );
152 }
153 }
154