start_controls_section(
'section_premium_eq_height',
array(
'label' => sprintf( ' %s', __( 'Equal Height', 'premium-addons-for-elementor' ) ),
'tab' => Controls_Manager::TAB_ADVANCED,
)
);
$element->add_control(
'premium_eq_height_update',
array(
'label' => '
Update changes to page
',
'type' => Controls_Manager::RAW_HTML,
)
);
$element->add_control(
'premium_eq_height_switcher',
array(
'label' => __( 'Enable Equal Height', 'premium-addons-for-elementor' ),
'type' => Controls_Manager::SWITCHER,
'return_value' => 'yes',
'render_type' => 'template',
'prefix_class' => 'premium-equal-height-',
'frontend_available' => true,
)
);
$element->add_control(
'premium_eq_height_type',
array(
'label' => __( 'Apply on', 'premium-addons-for-elementor' ),
'type' => Controls_Manager::SELECT,
'default' => 'widget',
'options' => array(
'widget' => __( 'Widgets', 'premium-addons-for-elementor' ),
'custom' => __( 'Custom Selector', 'premium-addons-for-elementor' ),
),
'condition' => array(
'premium_eq_height_switcher' => 'yes',
),
)
);
$element->add_control(
'premium_eq_height_target',
array(
'label' => __( 'Widgets', 'premium-addons-for-elementor' ),
'type' => Premium_Select::TYPE,
'render_type' => 'template',
'label_block' => true,
'multiple' => true,
'frontend_available' => true,
'condition' => array(
'premium_eq_height_switcher' => 'yes',
'premium_eq_height_type' => 'widget',
),
)
);
$element->add_control(
'premium_eq_height_custom_target',
array(
'label' => __( 'Selectors', 'premium-addons-for-elementor' ),
'type' => Controls_Manager::TEXT,
'label_block' => true,
'placeholder' => __( '.class-name, .class-name2 .my-custom-class', 'premium-addons-for-elementor' ),
'description' => __( 'Enter selectors separated with \' , \' ', 'premium-addons-for-elementor' ),
'condition' => array(
'premium_eq_height_switcher' => 'yes',
'premium_eq_height_type' => 'custom',
),
)
);
$element->add_control(
'premium_eq_height_trigger',
array(
'label' => __( 'Trigger on', 'premium-addons-for-elementor' ),
'type' => Controls_Manager::SELECT,
'options' => array(
'load' => __( 'Page Load', 'premium-addons-for-elementor' ),
'scroll' => __( 'Scroll', 'premium-addons-for-elementor' ),
),
'default' => 'load',
'condition' => array(
'premium_eq_height_switcher' => 'yes',
),
)
);
$element->add_control(
'premium_eq_height_enable_on',
array(
'label' => __( 'Enable Equal Height on', 'premium-addons-for-elementor' ),
'type' => Controls_Manager::SELECT2,
'multiple' => true,
'options' => Helper_Functions::get_all_breakpoints(),
'label_block' => true,
'default' => Helper_Functions::get_all_breakpoints( 'keys' ),
'condition' => array(
'premium_eq_height_switcher' => 'yes',
),
)
);
$url = 'https://premiumaddons.com/docs/elementor-column-equal-height/';
$doc_url = Helper_Functions::get_campaign_link( $url, 'editor-page', 'wp-editor', 'get-support' );
$element->add_control(
'equal_height_notice',
array(
'type' => Controls_Manager::RAW_HTML,
'raw' => sprintf( '%s', $doc_url, __( 'How to use Premium Equal Height option ยป', 'premium-addons-for-elementor' ) ),
'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
)
);
$element->end_controls_section();
}
/**
* Render Premium Equal Height output in the editor.
*
* Written as a Backbone JavaScript template and used to generate the live preview.
*
* @since 4.2.5
* @access public
* @param object $template for current template.
* @param object $element for current element.
*/
public function _print_template( $template, $element ) {
if ( $element->get_name() !== 'section' && $element->get_name() !== 'container' ) {
return $template;
}
$old_template = $template;
ob_start();
?>
<# if( 'yes' === settings.premium_eq_height_switcher ) {
view.addRenderAttribute( 'eq_height', 'id', 'premium-temp-equal-height-' + view.getID() );
var targetType = settings.premium_eq_height_type,
target = 'custom' === targetType ? settings.premium_eq_height_custom_target.split(',') : settings.premium_eq_height_target,
addonSettings = {
'targetType': targetType,
'target': target,
'trigger':settings.premium_eq_height_trigger,
'enableOn':settings.premium_eq_height_enable_on
};
view.addRenderAttribute( 'equal_height', {
'id' : 'premium-temp-equal-height-' + view.getID(),
'data-pa-eq-height': JSON.stringify( addonSettings )
});
#>
<# } #>
get_settings_for_display();
if ( 'yes' === $settings['premium_eq_height_switcher'] ) {
$target_type = $settings['premium_eq_height_type'];
$target = ( 'custom' === $target_type ) ? explode( ',', $settings['premium_eq_height_custom_target'] ) : $settings['premium_eq_height_target'];
$addon_settings = array(
'targetType' => $target_type,
'target' => $target,
'trigger' => $settings['premium_eq_height_trigger'],
'enableOn' => $settings['premium_eq_height_enable_on'],
);
$element->add_render_attribute( '_wrapper', 'data-pa-eq-height', wp_json_encode( $addon_settings ) );
}
}
/**
* Check Script Enqueue
*
* Check if the script files should be loaded.
*
* @since 4.7.7
* @access public
*
* @param object $element for current element.
*/
public function check_script_enqueue( $element ) {
if ( self::$load_script ) {
return;
}
if ( 'yes' === $element->get_settings_for_display( 'premium_eq_height_switcher' ) ) {
$this->enqueue_scripts();
self::$load_script = true;
remove_action( 'elementor/frontend/section/before_render', array( $this, 'check_script_enqueue' ) );
remove_action( 'elementor/frontend/container/before_render', array( $this, 'check_script_enqueue' ) );
}
}
/**
* Creates and returns an instance of the class
*
* @since 4.2.5
* @access public
*
* @return object
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
}