| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\EditorOne\Components; |
| 4 |
|
| 5 |
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 6 |
use Elementor\Utils; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
class Top_Bar_Handler { |
| 13 |
|
| 14 |
private Menu_Data_Provider $menu_data_provider; |
| 15 |
|
| 16 |
public function __construct() { |
| 17 |
$this->menu_data_provider = Menu_Data_Provider::instance(); |
| 18 |
$this->register_actions(); |
| 19 |
} |
| 20 |
|
| 21 |
private function register_actions(): void { |
| 22 |
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); |
| 23 |
add_action( 'in_admin_header', [ $this, 'render_top_bar_container' ] ); |
| 24 |
} |
| 25 |
|
| 26 |
public function enqueue_assets(): void { |
| 27 |
if ( ! $this->menu_data_provider->is_elementor_editor_page() ) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
$min_suffix = Utils::is_script_debug() ? '' : '.min'; |
| 32 |
|
| 33 |
wp_enqueue_style( |
| 34 |
'elementor-one-top-bar', |
| 35 |
ELEMENTOR_ASSETS_URL . 'css/modules/editor-one/top-bar' . $min_suffix . '.css', |
| 36 |
[], |
| 37 |
ELEMENTOR_VERSION |
| 38 |
); |
| 39 |
|
| 40 |
wp_enqueue_script( |
| 41 |
'editor-one-top-bar', |
| 42 |
ELEMENTOR_ASSETS_URL . 'js/editor-one-top-bar' . $min_suffix . '.js', |
| 43 |
[ |
| 44 |
'react', |
| 45 |
'react-dom', |
| 46 |
'elementor-common', |
| 47 |
'elementor-v2-ui', |
| 48 |
'elementor-v2-icons', |
| 49 |
], |
| 50 |
ELEMENTOR_VERSION, |
| 51 |
true |
| 52 |
); |
| 53 |
|
| 54 |
wp_localize_script( |
| 55 |
'editor-one-top-bar', |
| 56 |
'elementorOneTopBarConfig', |
| 57 |
[ |
| 58 |
'version' => ELEMENTOR_VERSION, |
| 59 |
'title' => __( 'website builder', 'elementor' ), |
| 60 |
'environment' => apply_filters( 'elementor/environment', 'production' ), |
| 61 |
] |
| 62 |
); |
| 63 |
} |
| 64 |
|
| 65 |
public function render_top_bar_container(): void { |
| 66 |
echo '<div id="editor-one-top-bar"></div>'; |
| 67 |
} |
| 68 |
} |
| 69 |
|