/
widget.php
386 lines (367 loc) · 13.3 KB
/
widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
/**
* Material Cards Widget Class
*
* @package WpacMaterialCards
* @author Mian Shahzad Raza
* @copyright 2021 WP Academy
* @license GPL-2.0-or-later
*/
class WPAC_Material_Cards extends \Elementor\Widget_Base {
/**
* Get widget name.
*
* Retrieve Material Cards widget name.
*
* @since 1.0.0
* @access public
*
* @return string Widget name.
*/
public function get_name() {
return 'wpacmc';
}
/**
* Get widget title.
*
* Retrieve Material Cards widget title.
*
* @since 1.0.0
* @access public
*
* @return string Widget title.
*/
public function get_title() {
return __( 'Material Cards', 'wpac-material-cards' );
}
/**
* Get widget icon.
*
* Retrieve Material Cards widget icon.
*
* @since 1.0.0
* @access public
*
* @return string Widget icon.
*/
public function get_icon() {
return 'fa fa-address-card';
}
/**
* Get widget categories.
*
* Retrieve the list of categories the Material Cards widget belongs to.
*
* @since 1.0.0
* @access public
*
* @return array Widget categories.
*/
public function get_categories() {
return [ 'general' ];
}
/**
* Register Material Cards widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
* @access protected
*/
protected function _register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => __( 'Content', 'wpac-material-cards' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'btn_icon',
[
'label' => __( 'Button Icon', 'text-domain' ),
'type' => \Elementor\Controls_Manager::ICONS,
'default' => [
'value' => 'fas fa-bars',
'library' => 'solid',
],
]
);
$this->add_control(
'btn_icon_clicked',
[
'label' => __( 'Button Icon (Clicked)', 'text-domain' ),
'type' => \Elementor\Controls_Manager::ICONS,
'default' => [
'value' => 'fas fa-times',
'library' => 'solid',
],
]
);
$repeater = new \Elementor\Repeater();
$repeater->add_control(
'image',
[
'label' => __( 'Choose Image', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::MEDIA,
'default' => [
'url' => \Elementor\Utils::get_placeholder_image_src(),
],
]
);
$repeater->add_control(
'card_title',
[
'label' => __( 'Title', 'wpac-material-cards' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => __( 'John Doe.', 'wpac-material-cards' ),
'placeholder' => __( 'Type your title here', 'wpac-material-cards' ),
]
);
$repeater->add_control(
'card_subtitle',
[
'label' => __( 'Sub Title', 'wpac-material-cards' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => __( 'Web Designer', 'wpac-material-cards' ),
'placeholder' => __( 'Type sub title here.', 'wpac-material-cards' ),
]
);
$repeater->add_control(
'card_description',
[
'label' => __( 'Description', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::TEXTAREA,
'rows' => 10,
'default' => __( 'He has appeared in more than 100 films and television shows, including The Deer Hunter, Annie Hall, The Prophecy trilogy, The Dogs of War ...', 'plugin-domain' ),
'placeholder' => __( 'Type your description here', 'plugin-domain' ),
]
);
$repeater->add_control(
'card_color',
[
'label' => __( 'Card Color', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'Red',
'options' => [
'Red' => __( 'Red', 'plugin-domain' ),
'Pink' => __( 'Pink', 'plugin-domain' ),
'Purple' => __( 'Purple', 'plugin-domain' ),
'Deep-Purple' => __( 'Deep-Purple', 'plugin-domain' ),
'Indigo' => __( 'Indigo', 'plugin-domain' ),
'Blue' => __( 'Blue', 'plugin-domain' ),
'Light-Blue' => __( 'Light-Blue', 'plugin-domain' ),
'Cyan' => __( 'Cyan', 'plugin-domain' ),
'Teal' => __( 'Teal', 'plugin-domain' ),
'Green' => __( 'Green', 'plugin-domain' ),
'Light-Green' => __( 'Light-Green', 'plugin-domain' ),
'Lime' => __( 'Lime', 'plugin-domain' ),
'Yellow' => __( 'Yellow', 'plugin-domain' ),
'Amber' => __( 'Amber', 'plugin-domain' ),
'Orange' => __( 'Orange', 'plugin-domain' ),
'Deep-Orange' => __( 'Deep-Orange', 'plugin-domain' ),
'Brown' => __( 'Brown', 'plugin-domain' ),
'Grey' => __( 'Grey', 'plugin-domain' ),
'Blue-Grey' => __( 'Blue-Grey', 'plugin-domain' ),
],
]
);
$repeater->add_control(
'link_facebook',
[
'label' => __( 'Facebook', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => __( 'https://facebook.com', 'plugin-domain' ),
'show_external' => true,
'default' => [
'url' => 'https://facebook.com',
'is_external' => true,
'nofollow' => true,
],
]
);
$repeater->add_control(
'link_twitter',
[
'label' => __( 'Twitter', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => __( 'https://twitter.com', 'plugin-domain' ),
'show_external' => true,
'default' => [
'url' => 'https://twitter.com',
'is_external' => true,
'nofollow' => true,
],
]
);
$repeater->add_control(
'link_linkedin',
[
'label' => __( 'LinkedIn', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => __( 'https://linkedin.com', 'plugin-domain' ),
'show_external' => true,
'default' => [
'url' => 'https://linkedin.com',
'is_external' => true,
'nofollow' => true,
],
]
);
$repeater->add_control(
'link_instagram',
[
'label' => __( 'Instagram', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => __( 'https://instagram.com', 'plugin-domain' ),
'show_external' => true,
'default' => [
'url' => 'https://instagram.com',
'is_external' => true,
'nofollow' => true,
],
]
);
$this->add_control(
'material_card',
[
'label' => __( 'Cards List', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'card_title' => __( 'John Doe.', 'plugin-domain' ),
'card_subtitle' => __( 'Web Designer', 'plugin-domain' ),
'card_description' => __( 'He has appeared in more than 100 films and television shows, including The Deer Hunter, Annie Hall, The Prophecy trilogy, The Dogs of War ...', 'plugin-domain' ),
],
[
'card_title' => __( 'John Doe.', 'plugin-domain' ),
'card_subtitle' => __( 'Web Designer', 'plugin-domain' ),
'card_description' => __( 'He has appeared in more than 100 films and television shows, including The Deer Hunter, Annie Hall, The Prophecy trilogy, The Dogs of War ...', 'plugin-domain' ),
],
],
'title_field' => '{{{ card_title }}}',
]
);
$this->end_controls_section();
$this->start_controls_section(
'typography_section',
[
'label' => __( 'Typography Controls', 'plugin-name' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typo',
'label' => __( 'Title', 'plugin-domain' ),
'scheme' => Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
'selector' => '{{WRAPPER}} .material-card h2 .main-title',
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'subtitle_typo',
'label' => __( 'Sub-Title', 'plugin-domain' ),
'scheme' => Elementor\Core\Schemes\Typography::TYPOGRAPHY_2,
'selector' => '{{WRAPPER}} .material-card h2 .sub-title',
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'desc_typo',
'label' => __( 'Description', 'plugin-domain' ),
'scheme' => Elementor\Core\Schemes\Typography::TYPOGRAPHY_2,
'selector' => '{{WRAPPER}} .material-card .mc-description',
]
);
$this->end_controls_section();
}
/**
* Render Material Cards widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
* @access protected
*/
protected function render() {
$settings = $this->get_settings_for_display();
if ( $settings['material_card'] ) {
echo '<div class="row active-with-click">';
foreach ( $settings['material_card'] as $item ) { ?>
<div class="col-md-4 col-sm-6 col-xs-12 elementor-repeater-item-<?php echo $item['_id'] ?>">
<article class="material-card <?php echo $item['card_color'] ?>">
<h2>
<span class="main-title"><?php echo $item['card_title'] ?></span>
<span class="sub-title">
<?php echo $item['card_subtitle'] ?>
</span>
</h2>
<div class="mc-content">
<div class="img-container">
<img class="img-responsive" src="<?php echo $item['image']['url'] ?>">
</div>
<div class="mc-description">
<?php echo $item['card_description'] ?>
</div>
</div>
<a class="mc-btn-action">
<i class="fa fa-bars"></i>
</a>
<div class="mc-footer">
<h4>
Social
</h4>
<?php
$target_fb = $item['link_facebook']['is_external'] ? ' target="_blank"' : '';
$target_tw = $item['link_twitter']['is_external'] ? ' target="_blank"' : '';
$target_in = $item['link_linkedin']['is_external'] ? ' target="_blank"' : '';
$target_insta = $item['link_instagram']['is_external'] ? ' target="_blank"' : '';
$nofollow_fb = $item['link_facebook']['nofollow'] ? ' rel="nofollow"' : '';
$nofollow_tw = $item['link_twitter']['nofollow'] ? ' rel="nofollow"' : '';
$nofollow_in = $item['link_linkedin']['nofollow'] ? ' rel="nofollow"' : '';
$nofollow_insta = $item['link_instagram']['nofollow'] ? ' rel="nofollow"' : '';
?>
<a href="<?php echo $item['link_facebook']['url'] ?>" class="wpacmc-social-icon text-center" <?php echo $target_fb . $nofollow_fb ?>>
<i class="fa fa-facebook"></i>
</a>
<a href="<?php echo $item['link_twitter']['url'] ?>" class="wpacmc-social-icon text-center" <?php echo $target_tw . $nofollow_tw ?>>
<i class="fa fa-twitter"></i>
</a>
<a href="<?php echo $item['link_linkedin']['url'] ?>" class="wpacmc-social-icon text-center" <?php echo $target_in . $nofollow_in ?>>
<i class="fa fa-linkedin"></i>
</a>
<a href="<?php echo $item['link_instagram']['url'] ?>" class="wpacmc-social-icon text-center" <?php echo $target_insta . $nofollow_insta ?>>
<i class="fa fa-instagram"></i>
</a>
</div>
</article>
</div>
<?php }
echo '</div>';
}
?>
<script>
jQuery(function() {
jQuery('.material-card').materialCard({
icon_close: '<?php echo $settings['btn_icon_clicked']['value'] ?>',
icon_open: '<?php echo $settings['btn_icon']['value'] ?>',
icon_spin: 'fa-spin-fast',
card_activator: 'click'
});
// $('.active-with-click .material-card').materialCard();
window.setTimeout(function() {
jQuery('.material-card:eq(1)').materialCard('open');
}, 2000);
jQuery('.material-card').on('shown.material-card show.material-card hide.material-card hidden.material-card', function (event) {
console.log(event.type, event.namespace, jQuery(this));
});
});
</script>
<?php
}
}