PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.2.1
Easy Elements for Elementor – Addons & Website Templates v1.2.1
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / offcanvas / offcanvas.php

offcanvas.php in Easy Elements for Elementor – Addons & Website Templates 1.2.1, at widgets/offcanvas/offcanvas.php

466 lines 13.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use Elementor\Controls_Manager;
3 use Elementor\Widget_Base;
4 use Elementor\Group_Control_Typography;
5 use Elementor\Group_Control_Background;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 class Easyel_Offcanvas_Widget extends Widget_Base {
12
13 public function get_style_depends() {
14 $handle = 'eel-offcanvas-style';
15 $css_path = plugin_dir_path( __FILE__ ) . 'css/offcanvas.min.css';
16
17 if ( ! wp_style_is( $handle, 'registered' ) && file_exists( $css_path ) ) {
18 wp_register_style(
19 $handle,
20 plugins_url( 'css/offcanvas.min.css', __FILE__ ),
21 [],
22 defined( 'WP_DEBUG' ) && WP_DEBUG ? filemtime( $css_path ) : EASYELEMENTS_VER
23 );
24 }
25 return [ $handle ];
26 }
27
28 public function get_script_depends() {
29 $handle = 'eel-offcanvas-script';
30 $js_path = plugin_dir_path( __FILE__ ) . 'js/offcanvas.js';
31
32 if ( ! wp_script_is( $handle, 'registered' ) && file_exists( $js_path ) ) {
33 wp_register_script( $handle, plugins_url( 'js/offcanvas.js', __FILE__ ), [ 'jquery' ], filemtime( $js_path ), true );
34 }
35
36 return [ $handle ];
37 }
38 public function get_name() {
39 return 'eel-offcanvas';
40 }
41
42 public function get_title() {
43 return __( 'Offcanvas', 'easy-elements' );
44 }
45
46 public function get_icon() {
47 return 'easyicon easyelIcon-canvas';
48 }
49
50 public function get_categories() {
51 return [ 'easyelements_category' ];
52 }
53
54 public function get_keywords() {
55 return [ 'offcanvas', 'text', 'link', 'image' ];
56 }
57 protected function register_controls() {
58 $this->start_controls_section(
59 'section_offcanvas',
60 [
61 'label' => __( 'Offcanvas Settings', 'easy-elements' ),
62 ]
63 );
64
65 $this->add_control(
66 'offcanvas_layout',
67 [
68 'label' => __( 'Offcanvas Layout', 'easy-elements' ),
69 'type' => Controls_Manager::SELECT,
70 'default' => 'classic',
71 'options' => [
72 'classic' => __( 'Classic', 'easy-elements' ),
73 'modern' => __( 'Modern', 'easy-elements' ),
74 ],
75 ]
76 );
77
78 $this->add_control(
79 'menu_text',
80 [
81 'label' => __( 'Canvas Menu', 'easy-elements' ),
82 'type' => Controls_Manager::TEXT,
83 'default' => __( 'Menu', 'easy-elements' ),
84 ]
85 );
86
87 $this->add_control(
88 'btn_icon',
89 [
90 'label' => esc_html__('Menu Icon', 'easy-elements'),
91 'type' => Controls_Manager::ICONS,
92 'default' => [
93 'value' => '',
94 'library' => '',
95 ],
96 ]
97 );
98
99 $this->add_control(
100 'position_offcanvas',
101 [
102 'label' => __( 'Open Position', 'easy-elements' ),
103 'type' => Controls_Manager::SELECT,
104 'default' => 'eel-offcanvas-right',
105 'options' => [
106 'eel-offcanvas-left' => __( 'Left', 'easy-elements' ),
107 'eel-offcanvas-right' => __( 'Right', 'easy-elements' ),
108 ],
109 'condition' => [
110 'offcanvas_layout' => 'classic',
111 ],
112 ]
113 );
114
115 $this->add_responsive_control(
116 'offcanvas_width',
117 [
118 'label' => __( 'Canvas Width', 'easy-elements' ),
119 'type' => \Elementor\Controls_Manager::SLIDER,
120 'size_units' => [ 'px', '%' ],
121 'range' => [
122 'px' => [
123 'min' => 200,
124 'max' => 800,
125 ],
126 '%' => [
127 'min' => 20,
128 'max' => 100,
129 ],
130 ],
131 'default' => [
132 'unit' => 'px',
133 'size' => 380,
134 ],
135 'selectors' => [
136 '.eel-offcanvas' => 'width: {{SIZE}}{{UNIT}} !important;',
137 ],
138 'condition' => [
139 'offcanvas_layout' => ['classic', 'modern'],
140 ],
141 ]
142 );
143
144 $this->add_control(
145 'content_template',
146 [
147 'label' => esc_html__( 'Select Template', 'easy-elements' ),
148 'type' => \Elementor\Controls_Manager::SELECT,
149 'options' => $this->get_eligible_canvas_templates(),
150 ]
151 );
152
153 $this->add_control(
154 'edit_template_button',
155 [
156 'type' => \Elementor\Controls_Manager::RAW_HTML,
157 'raw' => sprintf(
158 '<a href="%s" class="elementor-button elementor-button-primary" target="_blank">%s</a>
159 <p style="margin-top:5px; font-size:13px; color:#555;">%s</p>',
160 admin_url( 'edit.php?post_type=easy-offcanvas' ),
161 esc_html__( 'Edit Offcanvas Templates', 'easy-elements' ),
162 esc_html__( 'All your offcanvas content can be managed here in the Easy Offcanvas post type.', 'easy-elements' )
163 ),
164 'separator' => 'before',
165 ]
166 );
167
168 $this->add_control(
169 'close_icon',
170 [
171 'label' => esc_html__('Close Icon', 'easy-elements'),
172 'type' => Controls_Manager::ICONS,
173 'default' => [
174 'value' => '',
175 'library' => '',
176 ],
177 ]
178 );
179
180 $this->add_control(
181 'need_blur_effect',
182 [
183 'label' => esc_html__( 'Enable Blur', 'easy-elements' ),
184 'type' => \Elementor\Controls_Manager::SWITCHER,
185 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
186 'label_off' => esc_html__( 'No', 'easy-elements' ),
187 'return_value' => 'yes',
188 'default' => 'no',
189 ]
190 );
191 $this->end_controls_section();
192
193 // Style
194 $this->start_controls_section(
195 'style_section',
196 [
197 'label' => esc_html__( 'Style', 'easy-elements' ),
198 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
199 ]
200 );
201 $this->add_control(
202 'open_icon_options',
203 [
204 'label' => esc_html__( 'Opener Icon', 'easy-elements' ),
205 'type' => \Elementor\Controls_Manager::HEADING,
206 'separator' => 'after',
207 ]
208 );
209 $this->add_control(
210 'offcanvas_opener_text_color',
211 [
212 'label' => esc_html__( 'Text Color', 'easy-elements' ),
213 'type' => \Elementor\Controls_Manager::COLOR,
214 'selectors' => [
215 '{{WRAPPER}} .eel-offcanvas-toggle-text .eel-icon-text' => 'color: {{VALUE}};',
216 ],
217 'condition' => [
218 'menu_text!' => '',
219 ],
220 ]
221 );
222 $this->add_group_control(
223 \Elementor\Group_Control_Typography::get_type(),
224 [
225 'name' => 'offcanvas_opener_text_typography',
226 'label' => esc_html__('Typography', 'easy-elements' ),
227 'selector' => '{{WRAPPER}} .eel-offcanvas-toggle-text .eel-icon-text',
228 'separator' => 'after',
229 'condition' => [
230 'menu_text!' => '',
231 ],
232 ]
233 );
234 $this->add_control(
235 'offcanvas_opener_icon_color',
236 [
237 'label' => esc_html__( 'Hamburger Color', 'easy-elements' ),
238 'type' => \Elementor\Controls_Manager::COLOR,
239 'selectors' => [
240 '{{WRAPPER}} .eel-offcanvas-toggle-text svg' => 'fill: {{VALUE}};',
241 '{{WRAPPER}} .eel-offcanvas-toggle-text i' => 'color: {{VALUE}};',
242 '{{WRAPPER}} .eel-icon-menu' => 'border-bottom-color: {{VALUE}};',
243 ],
244 'condition' => [
245 'offcanvas_layout' => 'classic',
246 ],
247 ]
248 );
249 $this->add_control(
250 'offcanvas_opener_icon_humburger_color',
251 [
252 'label' => esc_html__( 'Hamburger Color', 'easy-elements' ),
253 'type' => \Elementor\Controls_Manager::COLOR,
254 'selectors' => [
255 '.modern.eel-offcanvas-wrapper label span' => 'background: {{VALUE}} !important;',
256
257 ],
258 'condition' => [
259 'offcanvas_layout' => 'modern',
260 ],
261 ]
262 );
263 $this->add_responsive_control(
264 'offcanvas_opener_icon_size',
265 [
266 'label' => __( 'Hamburger Size', 'easy-elements' ),
267 'type' => \Elementor\Controls_Manager::SLIDER,
268 'size_units' => [ 'px', '%' ],
269 'selectors' => [
270 '{{WRAPPER}} .eel-offcanvas-toggle-text svg' => 'width: {{SIZE}}{{UNIT}} !important; height: {{SIZE}}{{UNIT}} !important;',
271 '{{WRAPPER}} .eel-offcanvas-toggle-text i' => 'font-size: {{SIZE}}{{UNIT}} !important;',
272 ],
273 'condition' => [
274 'offcanvas_layout' => 'classic',
275 ],
276 ]
277 );
278 $this->add_responsive_control(
279 'offcanvas_opener_icon_size_morden',
280 [
281 'label' => __( 'Hamburger Size', 'easy-elements' ),
282 'type' => \Elementor\Controls_Manager::SLIDER,
283 'size_units' => [ 'px', '%' ],
284 'selectors' => [
285 '{{WRAPPER}} .modern.eel-offcanvas-wrapper label' => 'width: {{SIZE}}{{UNIT}};',
286 ],
287 'condition' => [
288 'offcanvas_layout' => 'modern',
289 ],
290 ]
291 );
292 $this->add_control(
293 'closing_icon_options',
294 [
295 'label' => esc_html__( 'Closing Icon', 'easy-elements' ),
296 'type' => \Elementor\Controls_Manager::HEADING,
297 'separator' => 'after',
298 ]
299 );
300
301 $this->add_control(
302 'offcanvas_closing_icon_color',
303 [
304 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
305 'type' => \Elementor\Controls_Manager::COLOR,
306 'selectors' => [
307 '.eel-offcanvas-close' => 'color: {{VALUE}} !important;',
308 ],
309 'condition' => [
310 'offcanvas_layout' => 'classic',
311 ],
312 ]
313 );
314
315 $this->add_control(
316 'offcanvas_closing_icon_morden_color',
317 [
318 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
319 'type' => \Elementor\Controls_Manager::COLOR,
320 'selectors' => [
321 '.eel-modern-close-toggle span, .modern.eel-offcanvas-wrapper label.eel-modern-close-toggle span' => 'background: {{VALUE}} !important;',
322 ],
323 'condition' => [
324 'offcanvas_layout' => 'modern',
325 ],
326 ]
327 );
328
329 $this->add_responsive_control(
330 'offcanvas_closing_icon_size',
331 [
332 'label' => __( 'Icon Size', 'easy-elements' ),
333 'type' => \Elementor\Controls_Manager::SLIDER,
334 'size_units' => [ 'px', '%' ],
335 'selectors' => [
336 '.eel-offcanvas-close' => 'font-size: {{SIZE}}{{UNIT}} !important;',
337 ],
338 'condition' => [
339 'offcanvas_layout' => 'classic',
340 ],
341 ]
342 );
343 $this->add_control(
344 'offcanvas_item',
345 [
346 'label' => esc_html__( 'OffCanvas Item', 'easy-elements' ),
347 'type' => \Elementor\Controls_Manager::HEADING,
348 'separator' => 'after',
349 ]
350 );
351 $this->add_control(
352 'offcanvas_bg',
353 [
354 'label' => esc_html__( 'OffCanvas Background', 'easy-elements' ),
355 'type' => \Elementor\Controls_Manager::COLOR,
356 'selectors' => [
357 'body .eel-offcanvas' => 'background: {{VALUE}} !important;',
358 ],
359 ]
360 );
361 $this->add_responsive_control(
362 'offcanvas_padding',
363 [
364 'label' => esc_html__('OffCanvas Padding', 'easy-elements'),
365 'type' => \Elementor\Controls_Manager::DIMENSIONS,
366 'size_units' => [ 'px', 'em', '%' ],
367 'selectors' => [
368 'body .eel-offcanvas' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
369 ],
370 ]
371 );
372 $this->end_controls_section();
373 }
374
375 private function get_eligible_canvas_templates() {
376 $templates = [];
377
378 $posts = get_posts([
379 'post_type' => 'easy-offcanvas',
380 'posts_per_page' => -1,
381 'post_status' => 'publish',
382 ]);
383
384 foreach ( $posts as $post ) {
385 $templates[ $post->ID ] = $post->post_title;
386 }
387
388 return $templates;
389 }
390
391 protected function render() {
392 $settings = $this->get_settings_for_display();
393 $position = $settings['position_offcanvas'];
394 $btn_text = ! empty( $settings['menu_text'] ) ? $settings['menu_text'] : '';
395 $content_template = ! empty( $settings['content_template'] ) ? $settings['content_template'] : '';
396 $blur = ( isset( $settings['need_blur_effect'] ) && $settings['need_blur_effect'] === 'yes' ) ? 'eel-blur-effect' : '';
397 $unique_id = 'eel-offcanvas-' . $this->get_id();
398 ?>
399
400 <div class="eel-offcanvas-wrapper <?php echo esc_attr($settings['offcanvas_layout']); ?>">
401 <div class="eel-offcanvas-toggle" data-target="#<?php echo esc_attr($unique_id); ?>">
402 <span class="eel-offcanvas-toggle-text">
403 <?php if (!empty($btn_text)) : ?>
404 <em class="eel-icon-text"><?php echo esc_html($btn_text); ?></em>
405 <?php endif; ?>
406
407 <?php if ($settings['offcanvas_layout'] === 'classic') : ?>
408 <?php
409 if (!empty($settings['btn_icon']['value'])) {
410 \Elementor\Icons_Manager::render_icon($settings['btn_icon'], ['aria-hidden' => 'true']);
411 } else { ?>
412 <div class="eel-icon-menu-wrap">
413 <em class="eel-icon-menu"></em>
414 <em class="eel-icon-menu"></em>
415 </div>
416 <?php } ?>
417 <?php else : ?>
418 <label>
419 <span></span><span></span><span></span>
420 </label>
421 <?php endif; ?>
422 </span>
423 </div>
424
425 <?php
426 if (!\Elementor\Plugin::$instance->editor->is_edit_mode()) {
427 add_action('wp_footer', function() use ($settings, $unique_id, $blur) { ?>
428 <div id="<?php echo esc_attr($unique_id); ?>" class="eel-offcanvas <?php echo esc_attr($blur . ' ' . $settings['position_offcanvas'] . ' ' . $settings['offcanvas_layout']); ?>">
429 <div class="eel-offcanvas-overlay"></div>
430 <div class="eel-offcanvas-panel">
431 <?php if ($settings['offcanvas_layout'] === 'classic') { ?>
432 <span class="eel-offcanvas-close eel-offcanvas-toggle" data-target="#<?php echo esc_attr($unique_id); ?>">
433 <?php
434 if (!empty($settings['close_icon']['value'])) {
435 \Elementor\Icons_Manager::render_icon($settings['close_icon'], ['aria-hidden' => 'true']);
436 } else {
437 echo '<i class="unicon-close"></i>';
438 }
439 ?>
440 </span>
441 <?php } else { ?>
442 <span class="eel-offcanvas-close eel-offcanvas-toggle eel-modern-close" data-target="#<?php echo esc_attr($unique_id); ?>">
443 <label class="eel-modern-close-toggle">
444 <span></span><span></span><span></span>
445 </label>
446 </span>
447 <?php } ?>
448
449 <div class="eel-offcanvas-content">
450 <?php
451 if (!empty($settings['content_template'])) {
452 // phpcs:ignore WordPress.Security.EscapeOutput
453 echo \Elementor\Plugin::$instance->frontend->get_builder_content_for_display($settings['content_template']);
454 }
455 ?>
456 </div>
457 </div>
458 </div>
459 <?php });
460 }
461 ?>
462 </div>
463 <?php
464 }
465 }
466 ?>