| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Property Actions Widget. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
*/ |
| 7 |
class Elementor_Property_Actions_Widget extends \Elementor\Widget_Base { |
| 8 |
|
| 9 |
public function get_name() { |
| 10 |
return 'property-actions'; |
| 11 |
} |
| 12 |
|
| 13 |
public function get_title() { |
| 14 |
return __( 'Actions', 'propertyhive' ); |
| 15 |
} |
| 16 |
|
| 17 |
public function get_icon() { |
| 18 |
return 'eicon-button'; |
| 19 |
} |
| 20 |
|
| 21 |
public function get_categories() { |
| 22 |
return [ 'property-hive' ]; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_keywords() { |
| 26 |
return [ 'property hive', 'propertyhive', 'property', 'actions', 'buttons', 'enquiry' ]; |
| 27 |
} |
| 28 |
|
| 29 |
protected function register_controls() { |
| 30 |
|
| 31 |
$this->start_controls_section( |
| 32 |
'style_section', |
| 33 |
[ |
| 34 |
'label' => __( 'Actions', 'propertyhive' ), |
| 35 |
'tab' => \Elementor\Controls_Manager::TAB_STYLE, |
| 36 |
] |
| 37 |
); |
| 38 |
|
| 39 |
$this->add_control( |
| 40 |
'display', |
| 41 |
[ |
| 42 |
'label' => __( 'Display As', 'propertyhive' ), |
| 43 |
'type' => \Elementor\Controls_Manager::CHOOSE, |
| 44 |
'options' => [ |
| 45 |
'list' => [ |
| 46 |
'title' => __( 'List', 'propertyhive' ), |
| 47 |
'icon' => 'eicon-editor-list-ul', |
| 48 |
], |
| 49 |
'buttons' => [ |
| 50 |
'title' => __( 'Buttons', 'propertyhive' ), |
| 51 |
'icon' => 'eicon-button', |
| 52 |
], |
| 53 |
], |
| 54 |
'default' => 'list', |
| 55 |
'toggle' => false, |
| 56 |
] |
| 57 |
); |
| 58 |
|
| 59 |
$this->add_responsive_control( |
| 60 |
'button_layout', |
| 61 |
[ |
| 62 |
'label' => __( 'Button Layout', 'propertyhive' ), |
| 63 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 64 |
'options' => [ |
| 65 |
'inline' => __( 'Inline', 'propertyhive' ), |
| 66 |
'equal' => __( 'Equal Width', 'propertyhive' ), |
| 67 |
'fixed' => __( 'Fixed Width', 'propertyhive' ), |
| 68 |
], |
| 69 |
'default' => 'inline', |
| 70 |
'toggle' => false, |
| 71 |
'condition' => [ |
| 72 |
'display' => 'buttons', |
| 73 |
], |
| 74 |
] |
| 75 |
); |
| 76 |
|
| 77 |
$this->add_responsive_control( |
| 78 |
'fixed_button_width', |
| 79 |
[ |
| 80 |
'label' => __( 'Button Width', 'propertyhive' ), |
| 81 |
'type' => \Elementor\Controls_Manager::SLIDER, |
| 82 |
'size_units' => [ 'px', '%' ], |
| 83 |
'range' => [ |
| 84 |
'px' => [ |
| 85 |
'min' => 40, |
| 86 |
'max' => 600, |
| 87 |
], |
| 88 |
'%' => [ |
| 89 |
'min' => 5, |
| 90 |
'max' => 100, |
| 91 |
], |
| 92 |
], |
| 93 |
'condition' => [ |
| 94 |
'display' => 'buttons', |
| 95 |
'button_layout' => 'fixed', |
| 96 |
], |
| 97 |
] |
| 98 |
); |
| 99 |
|
| 100 |
$this->start_controls_tabs( 'button_style_tabs' ); |
| 101 |
|
| 102 |
// Normal tab |
| 103 |
$this->start_controls_tab( |
| 104 |
'button_style_normal', |
| 105 |
[ |
| 106 |
'label' => __( 'Normal', 'propertyhive' ), |
| 107 |
'condition' => [ |
| 108 |
'display' => 'buttons', |
| 109 |
], |
| 110 |
] |
| 111 |
); |
| 112 |
|
| 113 |
$this->add_control( |
| 114 |
'button_background_color', |
| 115 |
[ |
| 116 |
'label' => __( 'Background Colour', 'propertyhive' ), |
| 117 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 118 |
'selectors' => [ |
| 119 |
'{{WRAPPER}} .property_actions ul li a' => 'background-color: {{VALUE}};', |
| 120 |
], |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$this->add_control( |
| 125 |
'button_text_color', |
| 126 |
[ |
| 127 |
'label' => __( 'Text Colour', 'propertyhive' ), |
| 128 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 129 |
'selectors' => [ |
| 130 |
'{{WRAPPER}} .property_actions ul li a' => 'color: {{VALUE}};', |
| 131 |
], |
| 132 |
] |
| 133 |
); |
| 134 |
|
| 135 |
$this->end_controls_tab(); |
| 136 |
|
| 137 |
// Hover tab |
| 138 |
$this->start_controls_tab( |
| 139 |
'button_style_hover', |
| 140 |
[ |
| 141 |
'label' => __( 'Hover', 'propertyhive' ), |
| 142 |
'condition' => [ |
| 143 |
'display' => 'buttons', |
| 144 |
], |
| 145 |
] |
| 146 |
); |
| 147 |
|
| 148 |
$this->add_control( |
| 149 |
'button_background_hover_color', |
| 150 |
[ |
| 151 |
'label' => __( 'Background Colour', 'propertyhive' ), |
| 152 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 153 |
'selectors' => [ |
| 154 |
'{{WRAPPER}} .property_actions ul li a:hover' => 'background-color: {{VALUE}};', |
| 155 |
], |
| 156 |
] |
| 157 |
); |
| 158 |
|
| 159 |
$this->add_control( |
| 160 |
'button_text_hover_color', |
| 161 |
[ |
| 162 |
'label' => __( 'Text Colour', 'propertyhive' ), |
| 163 |
'type' => \Elementor\Controls_Manager::COLOR, |
| 164 |
'selectors' => [ |
| 165 |
'{{WRAPPER}} .property_actions ul li a:hover' => 'color: {{VALUE}};', |
| 166 |
], |
| 167 |
] |
| 168 |
); |
| 169 |
|
| 170 |
$this->end_controls_tab(); |
| 171 |
|
| 172 |
$this->add_control( |
| 173 |
'button_padding', |
| 174 |
[ |
| 175 |
'label' => __( 'Button Padding', 'propertyhive' ), |
| 176 |
'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 177 |
'size_units' => [ 'px' ], |
| 178 |
'selectors' => [ |
| 179 |
'{{WRAPPER}} .property_actions ul li a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 180 |
], |
| 181 |
'default' => [ |
| 182 |
'top' => 5, |
| 183 |
'right' => 5, |
| 184 |
'bottom' => 5, |
| 185 |
'left' => 5, |
| 186 |
'isLinked' => true, |
| 187 |
], |
| 188 |
'condition' => [ |
| 189 |
'display' => 'buttons' |
| 190 |
], |
| 191 |
] |
| 192 |
); |
| 193 |
|
| 194 |
$this->add_control( |
| 195 |
'button_margin', |
| 196 |
[ |
| 197 |
'label' => __( 'Button Margin', 'propertyhive' ), |
| 198 |
'type' => \Elementor\Controls_Manager::DIMENSIONS, |
| 199 |
'size_units' => [ 'px' ], |
| 200 |
'selectors' => [ |
| 201 |
'{{WRAPPER}} .property_actions ul li' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 202 |
], |
| 203 |
'default' => [ |
| 204 |
'top' => 0, |
| 205 |
'right' => 0, |
| 206 |
'bottom' => 0, |
| 207 |
'left' => 0, |
| 208 |
'isLinked' => true, |
| 209 |
], |
| 210 |
'condition' => [ |
| 211 |
'display' => 'buttons' |
| 212 |
], |
| 213 |
] |
| 214 |
); |
| 215 |
|
| 216 |
$this->end_controls_section(); |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
protected function render() { |
| 221 |
|
| 222 |
global $property; |
| 223 |
|
| 224 |
$settings = $this->get_settings_for_display(); |
| 225 |
|
| 226 |
if ( !isset($property->id) ) { |
| 227 |
return; |
| 228 |
} |
| 229 |
|
| 230 |
if ( isset( $settings['display'] ) && 'buttons' === $settings['display'] ) |
| 231 |
{ |
| 232 |
$breakpoints = \Elementor\Plugin::$instance->breakpoints->get_active_breakpoints(); |
| 233 |
|
| 234 |
$tablet_breakpoint = isset($breakpoints['tablet']) ? $breakpoints['tablet']->get_value() : 1024; |
| 235 |
$mobile_breakpoint = isset($breakpoints['mobile']) ? $breakpoints['mobile']->get_value() : 767; |
| 236 |
|
| 237 |
echo '<style type="text/css">'; |
| 238 |
echo '.property_actions ul { display:flex; flex-wrap:wrap; list-style:none; margin:0; padding:0; }'; |
| 239 |
echo '.property_actions ul li { float:none }'; |
| 240 |
echo '.property_actions ul li a { display:block; width:100%; box-sizing:border-box; text-align:center; }'; |
| 241 |
|
| 242 |
// Desktop |
| 243 |
$this->output_layout_css( $settings, '' ); |
| 244 |
|
| 245 |
// Tablet |
| 246 |
echo '@media (max-width: ' . $tablet_breakpoint . 'px) {'; |
| 247 |
$this->output_layout_css( $settings, '_tablet' ); |
| 248 |
echo '}'; |
| 249 |
|
| 250 |
// Mobile |
| 251 |
echo '@media (max-width: ' . $mobile_breakpoint . 'px) {'; |
| 252 |
$this->output_layout_css( $settings, '_mobile' ); |
| 253 |
echo '}'; |
| 254 |
echo '</style>'; |
| 255 |
} |
| 256 |
|
| 257 |
propertyhive_template_single_actions(); |
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
protected function output_layout_css( $settings, $suffix = '' ) { |
| 262 |
|
| 263 |
$layout_key = 'button_layout' . $suffix; |
| 264 |
$width_key = 'fixed_button_width' . $suffix; |
| 265 |
|
| 266 |
$layout = isset( $settings[ $layout_key ] ) ? $settings[ $layout_key ] : ''; |
| 267 |
|
| 268 |
if ( ! $layout && '' !== $suffix && isset( $settings['button_layout'] ) ) { |
| 269 |
$layout = $settings['button_layout']; |
| 270 |
} |
| 271 |
|
| 272 |
switch ( $layout ) { |
| 273 |
case 'equal': |
| 274 |
echo '.property_actions ul li { flex:1 1 0; }'; |
| 275 |
break; |
| 276 |
|
| 277 |
case 'fixed': |
| 278 |
$size = isset( $settings[ $width_key ]['size'] ) ? $settings[ $width_key ]['size'] : ''; |
| 279 |
$unit = isset( $settings[ $width_key ]['unit'] ) ? $settings[ $width_key ]['unit'] : 'px'; |
| 280 |
|
| 281 |
if ( $size ) { |
| 282 |
echo '.property_actions ul li { flex:0 0 ' . esc_attr( $size . $unit ) . '; max-width:' . esc_attr( $size . $unit ) . '; }'; |
| 283 |
} else { |
| 284 |
echo '.property_actions ul li { flex:0 0 auto; }'; |
| 285 |
} |
| 286 |
break; |
| 287 |
|
| 288 |
case 'inline': |
| 289 |
default: |
| 290 |
echo '.property_actions ul li { flex:0 0 auto; }'; |
| 291 |
break; |
| 292 |
} |
| 293 |
} |
| 294 |
} |