fields-errors
4 years ago
base-module.php
4 years ago
general-style-functions.php
4 years ago
general-style.php
4 years ago
general-style-functions.php
113 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Blocks\Modules; |
| 5 | |
| 6 | trait General_Style_Functions { |
| 7 | |
| 8 | private $namespace = 'jet-form-builder'; |
| 9 | |
| 10 | public function maybe_add_controls_type( $type ) { |
| 11 | if ( ! in_array( $type, $this->general_style_unregister() ) ) { |
| 12 | |
| 13 | if ( is_callable( $this->general_controls_callbacks()[ $type ] ) ) { |
| 14 | $this->general_controls_callbacks()[ $type ](); |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public function additional_selectors_for_controls() { |
| 20 | return array(); |
| 21 | } |
| 22 | |
| 23 | public function get_additional_styles( $id ) { |
| 24 | $styles = $this->additional_selectors_for_controls(); |
| 25 | |
| 26 | return isset( $styles[ $id ] ) ? $styles[ $id ] : array(); |
| 27 | } |
| 28 | |
| 29 | public function selector( $selector = '', $prefix_base = '', $additional = '' ) { |
| 30 | $base = $prefix_base . ".$this->namespace"; |
| 31 | |
| 32 | if ( $selector && isset( $this->css_scheme[ $selector ] ) ) { |
| 33 | $selector = $this->css_scheme[ $selector ]; |
| 34 | } |
| 35 | |
| 36 | $result = "{{WRAPPER}} $base" . sprintf( $selector, $this->namespace ); |
| 37 | |
| 38 | if ( $additional ) { |
| 39 | $result .= $additional; |
| 40 | } |
| 41 | |
| 42 | return $result; |
| 43 | } |
| 44 | |
| 45 | public function selector_no_space( $selector = '' ) { |
| 46 | return ( '{{WRAPPER}}' . sprintf( $selector, $this->namespace ) ); |
| 47 | } |
| 48 | |
| 49 | public function button_selector( $selector, $additional = '' ) { |
| 50 | return $this->selector( $selector, 'button', $additional ); |
| 51 | } |
| 52 | |
| 53 | public function div_selector( $selector, $additional = '' ) { |
| 54 | return $this->selector( $selector, 'div', $additional ); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | public function get_default_margin_control( $selector ) { |
| 59 | return array( |
| 60 | 'type' => 'dimensions', |
| 61 | 'label' => __( 'Margin', 'jet-form-builder' ), |
| 62 | 'units' => array( 'px', '%' ), |
| 63 | 'css_selector' => array( |
| 64 | '{{WRAPPER}} ' . $selector => 'margin: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', |
| 65 | ), |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | public function get_default_padding_control( $selector ) { |
| 70 | return array( |
| 71 | 'type' => 'dimensions', |
| 72 | 'label' => __( 'Padding', 'jet-form-builder' ), |
| 73 | 'units' => array( 'px', '%' ), |
| 74 | 'css_selector' => array( |
| 75 | $selector => 'padding: {{TOP}} {{RIGHT}} {{BOTTOM}} {{LEFT}};', |
| 76 | ), |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | public function add_margin_padding( $selector, $control_options ) { |
| 81 | if ( isset( $control_options['margin'] ) ) { |
| 82 | |
| 83 | $options = $this->merge_controls_or_add_id( |
| 84 | $this->get_default_margin_control( $selector ), |
| 85 | $control_options['margin'] |
| 86 | ); |
| 87 | $this->controls_manager->add_control( $options ); |
| 88 | } |
| 89 | |
| 90 | if ( isset( $control_options['padding'] ) ) { |
| 91 | |
| 92 | $options = $this->merge_controls_or_add_id( |
| 93 | $this->get_default_padding_control( $selector ), |
| 94 | $control_options['padding'] |
| 95 | ); |
| 96 | $this->controls_manager->add_control( $options ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | public function merge_controls_or_add_id( $control, $options ) { |
| 101 | if ( is_array( $options ) ) { |
| 102 | return array_merge( $control, $options ); |
| 103 | |
| 104 | } elseif ( is_string( $options ) ) { |
| 105 | |
| 106 | $control['id'] = $options; |
| 107 | |
| 108 | return $control; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | } |
| 113 |