| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wdk\Elementor\Widgets; |
| 4 |
|
| 5 |
use Wdk\Elementor\Widgets\WdkElementorBase; |
| 6 |
use Elementor\Widget_Base; |
| 7 |
use Elementor\Controls_Manager; |
| 8 |
use Elementor\Utils; |
| 9 |
use Elementor\Typography; |
| 10 |
use Elementor\Editor; |
| 11 |
use Elementor\Plugin; |
| 12 |
use Elementor\Repeater; |
| 13 |
use Elementor\Core\Schemes; |
| 14 |
use Elementor\Icons_Manager; |
| 15 |
use Elementor\Group_Control_Typography; |
| 16 |
use Elementor\Group_Control_Border; |
| 17 |
use Elementor\Group_Control_Box_Shadow; |
| 18 |
|
| 19 |
if (!defined('ABSPATH')) |
| 20 |
exit; // Exit if accessed directly |
| 21 |
|
| 22 |
/** |
| 23 |
* @since 1.1.0 |
| 24 |
*/ |
| 25 |
class WdkTabs extends WdkElementorBase { |
| 26 |
|
| 27 |
public function __construct($data = array(), $args = null) { |
| 28 |
|
| 29 |
\Elementor\Controls_Manager::add_tab( |
| 30 |
'tab_conf', |
| 31 |
esc_html__('Settings', 'wpdirectorykit') |
| 32 |
); |
| 33 |
|
| 34 |
\Elementor\Controls_Manager::add_tab( |
| 35 |
'tab_layout', |
| 36 |
esc_html__('Layout', 'wpdirectorykit') |
| 37 |
); |
| 38 |
|
| 39 |
\Elementor\Controls_Manager::add_tab( |
| 40 |
'tab_content', |
| 41 |
esc_html__('Main', 'wpdirectorykit') |
| 42 |
); |
| 43 |
|
| 44 |
if ($this->is_edit_mode_load()) { |
| 45 |
$this->enqueue_styles_scripts(); |
| 46 |
} |
| 47 |
|
| 48 |
parent::__construct($data, $args); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Retrieve the widget name. |
| 53 |
* |
| 54 |
* @since 1.1.0 |
| 55 |
* |
| 56 |
* @access public |
| 57 |
* |
| 58 |
* @return string Widget name. |
| 59 |
*/ |
| 60 |
public function get_name() { |
| 61 |
return 'wdk-tabs'; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Retrieve the widget title. |
| 66 |
* |
| 67 |
* @since 1.1.0 |
| 68 |
* |
| 69 |
* @access public |
| 70 |
* |
| 71 |
* @return string Widget title. |
| 72 |
*/ |
| 73 |
public function get_title() { |
| 74 |
return esc_html__('Wdk Tabs', 'wpdirectorykit'); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Retrieve the widget icon. |
| 79 |
* |
| 80 |
* @since 1.1.0 |
| 81 |
* |
| 82 |
* @access public |
| 83 |
* |
| 84 |
* @return string Widget icon. |
| 85 |
*/ |
| 86 |
public function get_icon() { |
| 87 |
return 'eicon-tabs'; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Register the widget controls. |
| 92 |
* |
| 93 |
* Adds different input fields to allow the user to change and customize the widget settings. |
| 94 |
* |
| 95 |
* @since 1.1.0 |
| 96 |
* |
| 97 |
* @access protected |
| 98 |
*/ |
| 99 |
protected function register_controls() { |
| 100 |
$this->generate_controls_conf(); |
| 101 |
$this->generate_controls_layout(); |
| 102 |
$this->generate_controls_styles(); |
| 103 |
$this->generate_controls_content(); |
| 104 |
|
| 105 |
$this->insert_pro_message('1'); |
| 106 |
parent::register_controls(); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Render the widget output on the frontend. |
| 111 |
* |
| 112 |
* Written in PHP and used to generate the final HTML. |
| 113 |
* |
| 114 |
* @since 1.1.0 |
| 115 |
* |
| 116 |
* @access protected |
| 117 |
*/ |
| 118 |
protected function render() { |
| 119 |
parent::render(); |
| 120 |
$this->data['id_element'] = $this->get_id(); |
| 121 |
$this->data['settings'] = $this->get_settings(); |
| 122 |
|
| 123 |
|
| 124 |
$this->data['is_edit_mode'] = false; |
| 125 |
if(Plugin::$instance->editor->is_edit_mode()) { |
| 126 |
$this->data['is_edit_mode'] = true; |
| 127 |
} |
| 128 |
|
| 129 |
echo $this->view('wdk-tabs', $this->data); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
private function generate_controls_conf() { |
| 134 |
$this->start_controls_section( |
| 135 |
'section_config', |
| 136 |
[ |
| 137 |
'label' => __( 'Configuration', 'wpdirectorykit' ), |
| 138 |
] |
| 139 |
); |
| 140 |
|
| 141 |
|
| 142 |
$this->add_control( |
| 143 |
'important_note', |
| 144 |
[ |
| 145 |
'label' => '', |
| 146 |
'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 147 |
'raw' => wdk_sprintf(__( '<a href="%1$s" target="_blank">Have a question how to configure? Check our Guide</a>', 'wpdirectorykit' ), '//wpdirectorykit.com/wp/wpdirectorykit-elementor-element-wdk-tabs'), |
| 148 |
'content_classes' => 'wdk_elementor_hint', |
| 149 |
] |
| 150 |
); |
| 151 |
|
| 152 |
$this->add_control( |
| 153 |
'important_note_2', |
| 154 |
[ |
| 155 |
'label' => 'Guide:', |
| 156 |
'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 157 |
'raw' => '<span style="word-break: break-all;">'. |
| 158 |
'<br> 1. '.__( 'Create Tabs and set Tab Target', 'wpdirectorykit' ).''. |
| 159 |
'<br> 2. '.__( 'Tab Target, set in CSS Classes of tabs and also class "wdk_tab_mobile"', 'wpdirectorykit' ).''. |
| 160 |
'<br> 3. '.__( 'For choose first active tab, add for tab class "active"', 'wpdirectorykit' ).''. |
| 161 |
'</span>', |
| 162 |
'content_classes' => 'wdk_elementor_hint', |
| 163 |
] |
| 164 |
); |
| 165 |
|
| 166 |
|
| 167 |
$repeater = new Repeater(); |
| 168 |
$repeater->start_controls_tabs( 'custom_fields_repeat' ); |
| 169 |
|
| 170 |
$repeater->add_control( |
| 171 |
'tab_name', |
| 172 |
[ |
| 173 |
'label' => __( 'Tab Name', 'wpdirectorykit' ), |
| 174 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 175 |
'default' => '', |
| 176 |
] |
| 177 |
); |
| 178 |
|
| 179 |
$repeater->add_control( |
| 180 |
'tab_target', |
| 181 |
[ |
| 182 |
'description' => __( 'put name for css of css class, then set this class for tab', 'wpdirectorykit' ), |
| 183 |
'label' => __( 'Tab Target', 'wpdirectorykit' ), |
| 184 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 185 |
'default' => '', |
| 186 |
] |
| 187 |
); |
| 188 |
|
| 189 |
$repeater->add_control( |
| 190 |
'tab_css_class', |
| 191 |
[ |
| 192 |
'label' => __( 'Special Class for Tab', 'wpdirectorykit' ), |
| 193 |
'type' => \Elementor\Controls_Manager::TEXT, |
| 194 |
'default' => '', |
| 195 |
] |
| 196 |
); |
| 197 |
|
| 198 |
$repeater->add_control( |
| 199 |
'tab_icon', |
| 200 |
[ |
| 201 |
'label' => esc_html__('Icon', 'wpdirectorykit'), |
| 202 |
'type' => Controls_Manager::ICONS, |
| 203 |
'label_block' => true, |
| 204 |
] |
| 205 |
); |
| 206 |
|
| 207 |
$repeater->end_controls_tabs(); |
| 208 |
|
| 209 |
|
| 210 |
$this->add_control( |
| 211 |
'tabs', |
| 212 |
[ |
| 213 |
'type' => Controls_Manager::REPEATER, |
| 214 |
'fields' => $repeater->get_controls(), |
| 215 |
'label' => __( 'Field id', 'wpdirectorykit' ), |
| 216 |
'default' => [ |
| 217 |
[ |
| 218 |
'tab_name' => esc_html__('Tab 1', 'elementinvader-addons-for-elementor'), |
| 219 |
'tab_target' => 'tab_1', |
| 220 |
'tab_css_class' => '', |
| 221 |
'tab_icon' => 'fas fa-list', |
| 222 |
], |
| 223 |
[ |
| 224 |
'tab_name' => esc_html__('Tab 1', 'elementinvader-addons-for-elementor'), |
| 225 |
'tab_target' => 'tab_1', |
| 226 |
'tab_css_class' => '', |
| 227 |
'tab_icon' => 'fas fa-list', |
| 228 |
], |
| 229 |
], |
| 230 |
'title_field' => "{{{ tab_name }}}", |
| 231 |
] |
| 232 |
); |
| 233 |
|
| 234 |
$this->end_controls_section(); |
| 235 |
} |
| 236 |
|
| 237 |
private function generate_controls_layout() { |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
private function generate_controls_styles() { |
| 242 |
|
| 243 |
$items = [ |
| 244 |
[ |
| 245 |
'key'=>'wrapper', |
| 246 |
'label'=> esc_html__('Styles Wrapper', 'wpdirectorykit'), |
| 247 |
'selector'=>'{{WRAPPER}} .wdk-tabs', |
| 248 |
'options'=> ['margin','border','border_radius','padding','shadow','transition','background_group'], |
| 249 |
], |
| 250 |
[ |
| 251 |
'key'=>'btns', |
| 252 |
'label'=> esc_html__('Styles Buttons', 'wpdirectorykit'), |
| 253 |
'selector'=>'{{WRAPPER}} .wdk-tabs .tab', |
| 254 |
'selector_hover'=>'{{WRAPPER}} .wdk-tabs .tab%1$s', |
| 255 |
'options'=>['typo','color','border','border_radius','padding','shadow','transition','background_group'], |
| 256 |
], |
| 257 |
]; |
| 258 |
|
| 259 |
foreach ($items as $item) { |
| 260 |
$this->start_controls_section( |
| 261 |
$item['key'].'_section', |
| 262 |
[ |
| 263 |
'label' => $item['label'], |
| 264 |
'tab' => 'tab_form_styles', |
| 265 |
] |
| 266 |
); |
| 267 |
|
| 268 |
if(!empty($item['selector_hide'])) { |
| 269 |
$this->add_responsive_control( |
| 270 |
$item['key'].'_hide', |
| 271 |
[ |
| 272 |
'label' => esc_html__( 'Hide Element', 'wdk-svg-map' ), |
| 273 |
'type' => Controls_Manager::SWITCHER, |
| 274 |
'none' => esc_html__( 'Hide', 'wdk-svg-map' ), |
| 275 |
'block' => esc_html__( 'Show', 'wdk-svg-map' ), |
| 276 |
'return_value' => 'none', |
| 277 |
'default' => ($item['key'] == 'field_button_reset' ) ? 'none':'', |
| 278 |
'selectors' => [ |
| 279 |
$item['selector_hide'] => 'display: {{VALUE}};', |
| 280 |
], |
| 281 |
] |
| 282 |
); |
| 283 |
} |
| 284 |
|
| 285 |
$selectors = array(); |
| 286 |
if(!empty($item['selector'])) |
| 287 |
$selectors['normal'] = $item['selector']; |
| 288 |
|
| 289 |
if(!empty($item['selector_hover'])) |
| 290 |
$selectors['hover'] = $item['selector_hover']; |
| 291 |
|
| 292 |
if(!empty($item['selector_focus'])) |
| 293 |
$selectors['focus'] = $item['selector_hover']; |
| 294 |
|
| 295 |
$this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']); |
| 296 |
|
| 297 |
$this->end_controls_section(); |
| 298 |
/* END special for some elements */ |
| 299 |
} |
| 300 |
|
| 301 |
} |
| 302 |
|
| 303 |
private function generate_controls_content() { |
| 304 |
|
| 305 |
} |
| 306 |
|
| 307 |
public function enqueue_styles_scripts() { |
| 308 |
wp_enqueue_style( 'wdk-tabs'); |
| 309 |
wp_enqueue_script( 'wdk-tabs'); |
| 310 |
} |
| 311 |
} |
| 312 |
|