I have a theme that has a header component. That header is not an Elementor widget, but just a normal HTML/PHP component. Just like an Elementor widget it has some properties, e.g. transparent, overlayed...
I have added those properties to the Elementor Page Settings section via hook:
add_action('elementor/element/wp-page/document_settings/before_section_start', 'page_settings' );
function page_settings($controlStack){
$controlStack->start_controls_section(
'page_settings',
[
'label' => _x('Page Settings', 'elementor', 'theme'),
'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
]
);
$controlStack->add_control(
'header_overlayed',
[
'type' => \Elementor\Controls_Manager::SWITCHER,
'label' => _x('Header Overlayed', 'elementor', 'theme'),
'label_on' => __('True', 'theme'),
'label_off' => __('False', 'theme'),
'return_value' => true,
'default' => false,
]
);
$controlStack->add_control(
'header_transparent',
[
'type' => \Elementor\Controls_Manager::SWITCHER,
'label' => _x('Header Transparent', 'elementor', 'theme'),
'label_on' => __('True', 'theme'),
'label_off' => __('False', 'theme'),
'return_value' => true,
'default' => false,
]
);
$controlStack->end_controls_section();
}
Now the issue is that I want to see the changes in the preview of Elementor when I change any of the settings.
I tried hooking into elementor/editor/after_enqueue_scripts (any many other hooks) to execute custom JS and simulate preview. Unfortunately, I had no luck.
JavaScript code looked something like this:
var headerTransparency = function( newValue ){
if( newValue == 'true' ){
$('.header').addClass('header--transparent');
}else{
$('.header').removeClass('header--transparent');
}
}
elementor.settings.page.addChangeCallback( 'header_transparent', headerTransparency );
Is there any way to do it?