EduardET

Untitled

Jul 4th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.82 KB | None | 0 0
  1. <?php
  2.  
  3. class WPC_ET_Builder_Module_Toggle extends ET_Builder_Module {
  4.     function init() {
  5.         $this->name                       = esc_html__( 'WPC Toggle', 'et_builder' );
  6.         $this->slug                       = 'wpc_et_pb_toggle';
  7.         $this->vb_support                 = false;
  8.         $this->additional_shortcode_slugs = array( 'wpc_et_pb_accordion_item' );
  9.         $this->main_css_element = '%%order_class%%.et_pb_toggle';
  10.  
  11.         $this->settings_modal_toggles = array(
  12.             'general'  => array(
  13.                 'toggles' => array(
  14.                     'main_content' => esc_html__( 'Text', 'et_builder' ),
  15.                     'state'        => esc_html__( 'State', 'et_builder' ),
  16.                 ),
  17.             ),
  18.             'advanced' => array(
  19.                 'toggles' => array(
  20.                     'icon' => esc_html__( 'Icon', 'et_builder' ),
  21.                     'text' => array(
  22.                         'title'    => esc_html__( 'Text', 'et_builder' ),
  23.                         'priority' => 49,
  24.                     ),
  25.                     'toggle' => esc_html__( 'Toggle', 'et_builder' ),
  26.                 ),
  27.             ),
  28.         );
  29.  
  30.         $this->advanced_fields = array(
  31.             'borders'               => array(
  32.                 'default' => array(
  33.                     'css'      => array(
  34.                         'main' => array(
  35.                             'border_radii'  => ".et_pb_module{$this->main_css_element}",
  36.                             'border_styles' => ".et_pb_module{$this->main_css_element}",
  37.                         )
  38.                     ),
  39.                     'defaults' => array(
  40.                         'border_radii' => 'on||||',
  41.                         'border_styles' => array(
  42.                             'width' => '1px',
  43.                             'color' => '#d9d9d9',
  44.                             'style' => 'solid',
  45.                         ),
  46.                     )
  47.                 ),
  48.             ),
  49.             'box_shadow'            => array(
  50.                 'default' => array(
  51.                     'css' => array(
  52.                         'important' => true,
  53.                     ),
  54.                 ),
  55.             ),
  56.             'fonts'                 => array(
  57.                 'title' => array(
  58.                     'label'    => esc_html__( 'Title', 'et_builder' ),
  59.                     'css'      => array(
  60.                         'main' => "{$this->main_css_element} h5, {$this->main_css_element} h1.et_pb_toggle_title, {$this->main_css_element} h2.et_pb_toggle_title, {$this->main_css_element} h3.et_pb_toggle_title, {$this->main_css_element} h4.et_pb_toggle_title, {$this->main_css_element} h6.et_pb_toggle_title",
  61.                         'important' => 'plugin_only',
  62.                     ),
  63.                     'header_level' => array(
  64.                         'default' => 'h5',
  65.                     ),
  66.                 ),
  67.                 'body'   => array(
  68.                     'label'    => esc_html__( 'Body', 'et_builder' ),
  69.                     'css'      => array(
  70.                         'main'        => "{$this->main_css_element}",
  71.                         'plugin_main' => "{$this->main_css_element}, {$this->main_css_element} p",
  72.                         'line_height' => "{$this->main_css_element} p",
  73.                         'text_shadow' => "{$this->main_css_element} .et_pb_toggle_content",
  74.                     ),
  75.                 ),
  76.             ),
  77.             'background'            => array(
  78.                 'settings' => array(
  79.                     'color' => 'alpha',
  80.                 ),
  81.             ),
  82.             'margin_padding' => array(
  83.                 'css' => array(
  84.                     'important' => 'all',
  85.                 ),
  86.             ),
  87.             'button'                => false,
  88.         );
  89.  
  90.         $this->custom_css_fields = array(
  91.             'open_toggle' => array(
  92.                 'label'    => esc_html__( 'Open Toggle', 'et_builder' ),
  93.                 'selector' => '.et_pb_toggle.et_pb_toggle_open',
  94.                 'no_space_before_selector' => true,
  95.             ),
  96.             'toggle_title' => array(
  97.                 'label'    => esc_html__( 'Toggle Title', 'et_builder' ),
  98.                 'selector' => '.et_pb_toggle_title',
  99.             ),
  100.             'toggle_icon' => array(
  101.                 'label'    => esc_html__( 'Toggle Icon', 'et_builder' ),
  102.                 'selector' => '.et_pb_toggle_title:before',
  103.             ),
  104.             'toggle_content' => array(
  105.                 'label'    => esc_html__( 'Toggle Content', 'et_builder' ),
  106.                 'selector' => '.et_pb_toggle_content',
  107.             ),
  108.         );
  109.  
  110.         $this->help_videos = array(
  111.             array(
  112.                 'id'   => esc_html( 'hFgp_A_u7mg' ),
  113.                 'name' => esc_html__( 'An introduction to the Toggle module', 'et_builder' ),
  114.             ),
  115.         );
  116.     }
  117.  
  118.     function get_fields() {
  119.         $fields = array(
  120.             'title' => array(
  121.                 'label'           => esc_html__( 'Title', 'et_builder' ),
  122.                 'type'            => 'text',
  123.                 'option_category' => 'basic_option',
  124.                 'description'     => esc_html__( 'The title will appear above the content and when the toggle is closed.', 'et_builder' ),
  125.                 'toggle_slug'     => 'main_content',
  126.             ),
  127.             'sub_title' => array(
  128.                 'label'           => esc_html__( 'Sub Title', 'et_builder' ),
  129.                 'type'            => 'text',
  130.                 'option_category' => 'basic_option',
  131.                 'description'     => esc_html__( 'The sub title will appear above the content and when the toggle is closed.', 'et_builder' ),
  132.                 'toggle_slug'     => 'main_content',
  133.             ),
  134.             'open' => array(
  135.                 'label'           => esc_html__( 'State', 'et_builder' ),
  136.                 'type'            => 'select',
  137.                 'option_category' => 'basic_option',
  138.                 'options'         => array(
  139.                     'off' => esc_html__( 'Close', 'et_builder' ),
  140.                     'on'  => esc_html__( 'Open', 'et_builder' ),
  141.                 ),
  142.                 'default_on_front' => 'off',
  143.                 'toggle_slug'     => 'state',
  144.                 'description'     => esc_html__( 'Choose whether or not this toggle should start in an open or closed state.', 'et_builder' ),
  145.             ),
  146.             'content' => array(
  147.                 'label'             => esc_html__( 'Content', 'et_builder' ),
  148.                 'type'              => 'tiny_mce',
  149.                 'option_category'   => 'basic_option',
  150.                 'description'       => esc_html__( 'Input the main text content for your module here.', 'et_builder' ),
  151.                 'toggle_slug'       => 'main_content',
  152.             ),
  153.             'open_toggle_text_color' => array(
  154.                 'label'             => esc_html__( 'Open Toggle Text Color', 'et_builder' ),
  155.                 'type'              => 'color-alpha',
  156.                 'custom_color'      => true,
  157.                 'tab_slug'          => 'advanced',
  158.                 'toggle_slug'       => 'toggle',
  159.             ),
  160.             'open_toggle_background_color' => array(
  161.                 'label'             => esc_html__( 'Open Toggle Background Color', 'et_builder' ),
  162.                 'type'              => 'color-alpha',
  163.                 'custom_color'      => true,
  164.                 'tab_slug'          => 'advanced',
  165.                 'toggle_slug'       => 'toggle',
  166.             ),
  167.             'closed_toggle_text_color' => array(
  168.                 'label'             => esc_html__( 'Closed Toggle Text Color', 'et_builder' ),
  169.                 'type'              => 'color-alpha',
  170.                 'custom_color'      => true,
  171.                 'tab_slug'          => 'advanced',
  172.                 'toggle_slug'       => 'toggle',
  173.             ),
  174.             'closed_toggle_background_color' => array(
  175.                 'label'             => esc_html__( 'Closed Toggle Background Color', 'et_builder' ),
  176.                 'type'              => 'color-alpha',
  177.                 'custom_color'      => true,
  178.                 'tab_slug'          => 'advanced',
  179.                 'toggle_slug'       => 'toggle',
  180.             ),
  181.             'icon_color' => array(
  182.                 'label'             => esc_html__( 'Icon Color', 'et_builder' ),
  183.                 'type'              => 'color-alpha',
  184.                 'custom_color'      => true,
  185.                 'tab_slug'          => 'advanced',
  186.                 'toggle_slug'       => 'icon',
  187.             ),
  188.         );
  189.         return $fields;
  190.     }
  191.  
  192.     function render( $attrs, $content = null, $render_slug ) {
  193.         $title                                  = $this->props['title'];
  194.         $sub_title                          = $this->props['sub_title'];
  195.         $open                                   = $this->props['open'];
  196.         $open_toggle_background_color           = $this->props['open_toggle_background_color'];
  197.         $closed_toggle_background_color         = $this->props['closed_toggle_background_color'];
  198.         $icon_color                             = $this->props['icon_color'];
  199.         $closed_toggle_text_color               = $this->props['closed_toggle_text_color'];
  200.         $open_toggle_text_color                 = $this->props['open_toggle_text_color'];
  201.         $header_level                           = $this->props['title_level'];
  202.  
  203.         if ( '' !== $open_toggle_background_color ) {
  204.             ET_Builder_Element::set_style( $render_slug, array(
  205.                 'selector'    => '%%order_class%%.et_pb_toggle.et_pb_toggle_open',
  206.                 'declaration' => sprintf(
  207.                     'background-color: %1$s;',
  208.                     esc_html( $open_toggle_background_color )
  209.                 ),
  210.             ) );
  211.         }
  212.  
  213.         if ( '' !== $closed_toggle_background_color ) {
  214.             ET_Builder_Element::set_style( $render_slug, array(
  215.                 'selector'    => '%%order_class%%.et_pb_toggle.et_pb_toggle_close',
  216.                 'declaration' => sprintf(
  217.                     'background-color: %1$s;',
  218.                     esc_html( $closed_toggle_background_color )
  219.                 ),
  220.             ) );
  221.         }
  222.  
  223.         if ( '' !== $icon_color ) {
  224.             ET_Builder_Element::set_style( $render_slug, array(
  225.                 'selector'    => '%%order_class%% .et_pb_toggle_title:before',
  226.                 'priority'    => ET_Builder_Element::DEFAULT_PRIORITY + 1,
  227.                 'declaration' => sprintf(
  228.                     'color: %1$s;',
  229.                     esc_html( $icon_color )
  230.                 ),
  231.             ) );
  232.         }
  233.  
  234.         if ( '' !== $closed_toggle_text_color ) {
  235.             ET_Builder_Element::set_style( $render_slug, array(
  236.                 'selector'    => '%%order_class%%.et_pb_toggle.et_pb_toggle_close h5.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_close h1.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_close h2.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_close h3.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_close h4.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_close h6.et_pb_toggle_title',
  237.                 'declaration' => sprintf(
  238.                     'color: %1$s !important;',
  239.                     esc_html( $closed_toggle_text_color )
  240.                 ),
  241.             ) );
  242.         }
  243.  
  244.         if ( '' !== $open_toggle_text_color ) {
  245.             ET_Builder_Element::set_style( $render_slug, array(
  246.                 'selector'    => '%%order_class%%.et_pb_toggle.et_pb_toggle_open h5.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_open h1.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_open h2.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_open h3.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_open h4.et_pb_toggle_title, %%order_class%%.et_pb_toggle.et_pb_toggle_open h6.et_pb_toggle_title',
  247.                 'declaration' => sprintf(
  248.                     'color: %1$s !important;',
  249.                     esc_html( $open_toggle_text_color )
  250.                 ),
  251.             ) );
  252.         }
  253.  
  254.         if ( 'et_pb_accordion_item' === $render_slug ) {
  255.             global $et_pb_accordion_item_number, $et_pb_accordion_header_level;
  256.  
  257.             $open = 1 === $et_pb_accordion_item_number ? 'on' : 'off';
  258.  
  259.             $et_pb_accordion_item_number++;
  260.  
  261.             $header_level = $et_pb_accordion_header_level;
  262.  
  263.             $this->add_classname( 'et_pb_accordion_item' );
  264.         }
  265.  
  266.         // Adding "_item" class for toggle module for customizer targetting. There's no proper selector
  267.         // for toggle module styles since both accordion and toggle module use the same selector
  268.         if( 'et_pb_toggle' === $render_slug ){
  269.             $this->add_classname( 'et_pb_toggle_item' );
  270.         }
  271.  
  272.         $video_background = $this->video_background();
  273.         $parallax_image_background = $this->get_parallax_image_background();
  274.  
  275.         $heading = sprintf( '<%1$s class="et_pb_toggle_title">%2$s<span class="wpc-sub-title">%3$s</span></%1$s>', et_pb_process_header_level( $header_level, 'h5' ), esc_html( $title ), $sub_title );
  276.  
  277.         // Module classnames
  278.         $this->add_classname( array(
  279.             $this->get_text_orientation_classname(),
  280.         ) );
  281.  
  282.         if ( 'on' === $open ) {
  283.             $this->add_classname( 'et_pb_toggle_open' );
  284.         } else {
  285.             $this->add_classname( 'et_pb_toggle_close' );
  286.         }
  287.  
  288.         $output = sprintf(
  289.             '<div%4$s class="%2$s et_pb_toggle">
  290.                 %6$s
  291.                 %5$s
  292.                 %1$s
  293.                 <div class="et_pb_toggle_content clearfix">
  294.                     %3$s
  295.                 </div> <!-- .et_pb_toggle_content -->
  296.             </div> <!-- .et_pb_toggle -->',
  297.             $heading,
  298.             $this->module_classname( $render_slug ),
  299.             $this->content,
  300.             $this->module_id(),
  301.             $video_background,
  302.             $parallax_image_background
  303.         );
  304.  
  305.         return $output;
  306.     }
  307. }
  308.  
  309. new WPC_ET_Builder_Module_Toggle;
Advertisement
Add Comment
Please, Sign In to add comment