Build Beautiful Websites Faster with HT Mega Addons for Elementor Addons.
',
'placeholder' => __('Add Source Code Here...', 'htmega-pro'),
'condition' => [
'code_type!' => '',
],
]
);
$this->add_control(
'copy_button_show',
[
'label' => __('Copy Button Show?', 'htmega-pro'),
'type' => Controls_Manager::SWITCHER,
'return_value' => 'block',
'default' => 'block',
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button' => 'display:{{value}}',
],
'frontend_available' => true,
]
);
$this->add_control(
'copy_btn_text',
[
'label' => __('Copy Button Text', 'htmega-pro'),
'type' => Controls_Manager::TEXT,
'default' => __('Copy to clipboard', 'htmega-pro'),
'placeholder' => __('Copy Button Text', 'htmega-pro'),
'condition' => [
'copy_button_show' => 'block',
],
]
);
$this->add_control(
'copied_button_text',
[
'label' => __('After Copy Button Text', 'htmega-pro'),
'type' => Controls_Manager::TEXT,
'default' => __('Copied', 'htmega-pro'),
'placeholder' => __('Copied', 'htmega-pro'),
'condition' => [
'copy_button_show' => 'block',
],
]
);
$this->add_control(
'show_line_number',
[
'label' => __('Line Numbers Show?', 'htmega-pro'),
'type' => Controls_Manager::SWITCHER,
'return_value' => 'yes',
'default' => 'no',
]
);
$this->end_controls_section();
// Style
$this->start_controls_section(
'source_code_style_section',
array(
'label' => __( 'Box Style', 'htmega-pro' ),
'tab' => Controls_Manager::TAB_STYLE,
)
);
$this->add_control(
'box_height',
[
'label' => esc_html__( 'Max Height', 'htmega-pro' ),
'type' => Controls_Manager::NUMBER,
'default' => 500,
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'source_code_border',
'label' => __( 'Border', 'htmega-pro' ),
'selector' => '{{WRAPPER}} .htmega-source-code-wrap',
'separator' => 'before',
]
);
$this->add_responsive_control(
'source_code_border_radius',
[
'label' => __( 'Border Radius', 'htmega-pro' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .htmega-source-code-wrap' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'source_code_padding',
[
'label' => __( 'Padding', 'htmega-pro' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .htmega-source-code-wrap pre[class*=language-]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
],
]
);
// Custom theme option
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'source_code_background',
'label' => __( 'Background', 'htmega-pro' ),
'types' => [ 'classic', 'gradient' ],
'selector' => '{{WRAPPER}} .htmega-source-code-wrap pre[class*=language-]',
'condition' =>[
'theme' =>'custom',
]
]
);
$this->add_control(
'source_code_text_color',
[
'label' => __( 'Text Color', 'htmega-pro' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .htmega-source-code-wrap pre[class*=language-]' => 'color: {{VALUE}}',
],
'condition' =>[
'theme' =>'custom',
]
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'source_code_text_typography',
'label' => __( 'Typography', 'htmega-pro' ),
'selector' => '{{WRAPPER}} .htmega-source-code-wrap pre[class*=language-] code,{{WRAPPER}} .htmega-source-code-wrap pre[class*=language-] span',
]
);
$this->add_control(
'source_code_number_color',
[
'label' => __( 'Number Color', 'htmega-pro' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .line-numbers-rows > span:before' => 'color: {{VALUE}}',
],
'condition' =>[
'theme' =>'custom',
'show_line_number' =>'yes',
]
]
);
$this->add_control(
'source_code_bdrer_color',
[
'label' => __( 'Border Color', 'htmega-pro' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .line-numbers .line-numbers-rows' => 'border-color: {{VALUE}}',
],
'condition' =>[
'theme' =>'custom',
'show_line_number' =>'yes',
]
]
);
$this->end_controls_section();
// Style Copy button tab section
$this->start_controls_section(
'copy_style_section',
[
'label' => __( 'Copy Button', 'htmega-pro' ),
'tab' => Controls_Manager::TAB_STYLE,
'condition'=>[
'copy_button_show'=>'block',
'copy_btn_text!'=>'',
]
]
);
$this->start_controls_tabs('copy_style_tabs');
$this->start_controls_tab(
'copy_style_normal_tab',
[
'label' => __( 'Normal', 'htmega-pro' ),
]
);
$this->add_control(
'copy_color',
[
'label' => __( 'Color', 'htmega-pro' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button' => 'color: {{VALUE}}; border-bottom: 1px solid {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'copy_typography',
'label' => __( 'Typography', 'htmega-pro' ),
'selector' => '{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button',
]
);
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'copy_background',
'label' => __( 'Background', 'htmega-pro' ),
'types' => [ 'classic', 'gradient' ],
'selector' => '{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button',
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'copy_border',
'label' => __( 'Border', 'htmega-pro' ),
'selector' => '{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button',
]
);
$this->add_responsive_control(
'copy_border_radius',
[
'label' => esc_html__( 'Border Radius', 'htmega-pro' ),
'type' => Controls_Manager::DIMENSIONS,
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;',
],
]
);
$this->add_responsive_control(
'copy_padding',
[
'label' => __( 'Padding', 'htmega-pro' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'copy_button_position_toggle',
[
'type' =>Controls_Manager::POPOVER_TOGGLE,
'label' => esc_html__( 'Button Position', 'htmega-pro' ),
'label_off' => esc_html__( 'Default', 'htmega-pro' ),
'label_on' => esc_html__( 'Custom', 'htmega-pro' ),
'return_value' => 'yes',
]
);
$this->start_popover();
$this->add_responsive_control(
'position_vertical',
[
'label' => __( 'Vertical Position', 'htmega-pro' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 0,
'max' => 500,
'step' => 1,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button' => 'top: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'position_horizontal',
[
'label' => __( 'Horizontal Position', 'htmega-pro' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 0,
'max' => 100,
'step' => 1,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button' => 'right: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_popover();
$this->end_controls_tab(); // Normal Tab end
$this->start_controls_tab(
'copy_style_hover_tab',
[
'label' => __( 'Hover', 'htmega-pro' ),
]
);
$this->add_control(
'copy_hover_color',
[
'label' => __( 'Color', 'htmega-pro' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button:hover' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Background::get_type(),
[
'name' => 'copy_hover_background',
'label' => __( 'Background', 'htmega-pro' ),
'types' => [ 'classic', 'gradient' ],
'selector' => '{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button:hover',
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'copy_hover_border',
'label' => __( 'Border', 'htmega-pro' ),
'selector' => '{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button:hover',
]
);
$this->add_responsive_control(
'copy_hover_border_radius',
[
'label' => esc_html__( 'Border Radius', 'htmega-pro' ),
'type' => Controls_Manager::DIMENSIONS,
'selectors' => [
'{{WRAPPER}} .htmega-copy-btn .copy-to-clipboard-button:hover' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;',
],
]
);
$this->end_controls_tab(); // Hover Tab end
$this->end_controls_tabs();
$this->end_controls_section();
}
protected function render( $instance = [] ) {
$settings = $this->get_settings_for_display();
$theme = $settings['theme'];
$code_type = $settings['code_type'];
$this->add_render_attribute( 'source_code_wrapper', 'class', "htmega-source-code-wrap htmega-copy-btn htmega-source-{$theme}" );
$this->add_render_attribute( 'source_code_pre', 'class', "htmega-source-pre language-{$code_type}" );
$this->add_render_attribute( 'source_code_pre', 'data-htmega', esc_attr( $settings['box_height'] ) );
if( 'yes' == $settings['show_line_number'] ){
$this->add_render_attribute( 'source_code_pre', 'class', " line-numbers" );
}
$this->add_render_attribute( 'source_code_options', 'class', "language-{$code_type}" );
$this->add_render_attribute( 'source_code_options', 'data-lng-type', esc_attr( $code_type ) );
$this->add_render_attribute( 'source_code_options', 'data-prismjs-copy-timeout', "5000" );
if( 'block' == $settings['copy_button_show'] && !empty( $settings['copy_btn_text']) ){
$this->add_render_attribute( 'source_code_options', 'data-prismjs-copy', esc_html( $settings['copy_btn_text'] ) );
$this->add_render_attribute( 'source_code_options', 'data-prismjs-copy-success', esc_html( $settings['copied_button_text'] ) );
}
?>
get_render_attribute_string( 'source_code_wrapper' ); ?> >
get_render_attribute_string( 'source_code_pre' ); ?> >
get_render_attribute_string( 'source_code_options' ); ?> >