templates
4 months ago
Accordion.php
4 months ago
Alerts_Box.php
4 months ago
Blog_Grid.php
4 months ago
Cheat_Sheet.php
4 months ago
Counter.php
4 months ago
Icon_Box.php
4 months ago
Integrations.php
4 months ago
List_Item.php
4 months ago
Tabs.php
4 months ago
Team_Carousel.php
4 months ago
Testimonial.php
4 months ago
Timeline.php
4 months ago
Video_Playlist.php
4 months ago
Video_Popup.php
4 months ago
Timeline.php
341 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Use namespace to avoid conflict |
| 4 | */ |
| 5 | |
| 6 | namespace SPEL\Widgets; |
| 7 | |
| 8 | use Elementor\Widget_Base; |
| 9 | use Elementor\Repeater; |
| 10 | use Elementor\Controls_Manager; |
| 11 | use Elementor\Group_Control_Typography; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; // Exit if accessed directly. |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Class Timeline |
| 19 | * @package spider\Widgets |
| 20 | */ |
| 21 | class Timeline extends Widget_Base { |
| 22 | |
| 23 | public function get_name(): string |
| 24 | { |
| 25 | return 'spe_timeline_widget'; // ID of the widget (Don't change this name) |
| 26 | } |
| 27 | |
| 28 | |
| 29 | public function get_title(): string |
| 30 | { |
| 31 | return esc_html__( 'Timeline', 'spider-elements' ); |
| 32 | } |
| 33 | |
| 34 | public function get_icon(): string |
| 35 | { |
| 36 | return 'eicon-time-line spel-icon'; |
| 37 | } |
| 38 | |
| 39 | public function get_categories(): array |
| 40 | { |
| 41 | return [ 'spider-elements' ]; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Name: get_style_depends() |
| 46 | * Desc: Register the required CSS dependencies for the frontend. |
| 47 | */ |
| 48 | public function get_style_depends(): array |
| 49 | { |
| 50 | return [ 'spel-main' ]; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Name: register_controls() |
| 56 | * Desc: Register controls for these widgets |
| 57 | * Params: no params |
| 58 | * Return: @void |
| 59 | * Since: @1.0.0 |
| 60 | * Package: @spider-elements |
| 61 | * Author: spider-themes |
| 62 | */ |
| 63 | protected function register_controls() { |
| 64 | $this->elementor_content_control(); |
| 65 | $this->elementor_style_control(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Name: elementor_content_control() |
| 70 | * Desc: Register the Content Tab output on the Elementor editor. |
| 71 | * Params: no params |
| 72 | * Return: @void |
| 73 | * Since: @1.0.0 |
| 74 | * Package: @spider-elements |
| 75 | * Author: spider-themes |
| 76 | */ |
| 77 | protected function elementor_content_control() { |
| 78 | |
| 79 | //=======================Timeline Content====================// |
| 80 | $this->start_controls_section( |
| 81 | 'section_timeline', |
| 82 | [ |
| 83 | 'label' => esc_html__( 'Timeline', 'spider-elements' ), |
| 84 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 85 | ] |
| 86 | ); |
| 87 | |
| 88 | $repeater = new Repeater(); |
| 89 | |
| 90 | $repeater->add_control( |
| 91 | 'timestamp', |
| 92 | [ |
| 93 | 'label' => esc_html__( 'Timestamp', 'spider-elements' ), |
| 94 | 'type' => Controls_Manager::TEXT, |
| 95 | 'default' => esc_html__( '11.05.2013', 'spider-elements' ), |
| 96 | 'label_block' => true, |
| 97 | ] |
| 98 | ); |
| 99 | |
| 100 | $repeater->add_control( |
| 101 | 'title', |
| 102 | [ |
| 103 | 'label' => esc_html__( 'Title', 'spider-elements' ), |
| 104 | 'type' => Controls_Manager::TEXT, |
| 105 | 'default' => esc_html__( 'Davidson College', 'spider-elements' ), |
| 106 | 'label_block' => true, |
| 107 | ] |
| 108 | ); |
| 109 | |
| 110 | $repeater->add_control( |
| 111 | 'location', |
| 112 | [ |
| 113 | 'label' => esc_html__( 'Location', 'spider-elements' ), |
| 114 | 'type' => Controls_Manager::TEXT, |
| 115 | 'default' => esc_html__( 'North Carolina', 'spider-elements' ), |
| 116 | 'label_block' => true, |
| 117 | ] |
| 118 | ); |
| 119 | |
| 120 | $repeater->add_control( |
| 121 | 'content', |
| 122 | [ |
| 123 | 'label' => esc_html__( 'Content', 'spider-elements' ), |
| 124 | 'type' => Controls_Manager::WYSIWYG, |
| 125 | 'default' => esc_html__( 'Vitae adipiscing turpis...', 'spider-elements' ), |
| 126 | 'show_label' => false, |
| 127 | ] |
| 128 | ); |
| 129 | |
| 130 | |
| 131 | $this->add_control( |
| 132 | 'timeline_items', |
| 133 | [ |
| 134 | 'label' => esc_html__( 'Timeline Items', 'spider-elements' ), |
| 135 | 'type' => Controls_Manager::REPEATER, |
| 136 | 'fields' => $repeater->get_controls(), |
| 137 | 'default' => [ |
| 138 | [ |
| 139 | 'timestamp' => esc_html__( '11.05.2013', 'spider-elements' ), |
| 140 | 'title' => esc_html__( 'Davidson College', 'spider-elements' ), |
| 141 | 'location' => esc_html__( 'North Carolina', 'spider-elements' ), |
| 142 | 'content' => esc_html__( 'Vitae adipiscing turpis...', 'spider-elements' ), |
| 143 | ], |
| 144 | // Add more default timeline items here... |
| 145 | ], |
| 146 | 'title_field' => '{{{ title }}}', |
| 147 | ] |
| 148 | ); |
| 149 | |
| 150 | |
| 151 | $this->add_group_control( |
| 152 | \Elementor\Group_Control_Background::get_type(), |
| 153 | [ |
| 154 | 'name' => 'background', |
| 155 | 'types' => [ 'classic', 'gradient', ], |
| 156 | 'separator'=> 'before', |
| 157 | 'selector' => '{{WRAPPER}} .timeline-wrapper .timeline-panel p::after', |
| 158 | ] |
| 159 | ); |
| 160 | |
| 161 | $this->end_controls_section(); //End Timeline Content |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /** |
| 166 | * Name: elementor_style_control() |
| 167 | * Desc: Register the Style Tab output on the Elementor editor. |
| 168 | * Params: no params |
| 169 | * Return: @void |
| 170 | * Since: @1.0.0 |
| 171 | * Package: @spider-elements |
| 172 | * Author: spider-themes |
| 173 | */ |
| 174 | public function elementor_style_control() { |
| 175 | |
| 176 | //============================= Timeline Content Style =============================// |
| 177 | $this->start_controls_section( |
| 178 | 'timeline_content_style', [ |
| 179 | 'label' => esc_html__( 'Timeline Content', 'spider-elements' ), |
| 180 | 'tab' => Controls_Manager::TAB_STYLE, |
| 181 | ] |
| 182 | ); |
| 183 | |
| 184 | //=== Timeline Title |
| 185 | $this->add_control( |
| 186 | 'timeline_title', [ |
| 187 | 'label' => esc_html__( 'Title', 'spider-elements' ), |
| 188 | 'type' => Controls_Manager::HEADING, |
| 189 | 'separator' => 'before', |
| 190 | ] |
| 191 | ); |
| 192 | |
| 193 | $this->add_control( |
| 194 | 'timeline', [ |
| 195 | 'label' => esc_html__( 'Text Color', 'spider-elements' ), |
| 196 | 'type' => Controls_Manager::COLOR, |
| 197 | 'selectors' => [ |
| 198 | '{{WRAPPER}} .timeline-wrapper .timeline-panel h3' => 'color: {{VALUE}};', |
| 199 | ], |
| 200 | ] |
| 201 | ); |
| 202 | |
| 203 | $this->add_group_control( |
| 204 | Group_Control_Typography::get_type(), [ |
| 205 | 'name' => 'timeline_title_typo', |
| 206 | 'selector' => '{{WRAPPER}} .timeline-wrapper .timeline-panel h3', |
| 207 | ] |
| 208 | ); //End TImeline Title |
| 209 | |
| 210 | |
| 211 | //=== Timeline Location |
| 212 | $this->add_control( |
| 213 | 'timeline_location', [ |
| 214 | 'label' => esc_html__( 'Location', 'spider-elements' ), |
| 215 | 'type' => Controls_Manager::HEADING, |
| 216 | 'separator' => 'before', |
| 217 | ] |
| 218 | ); |
| 219 | |
| 220 | $this->add_control( |
| 221 | 'timeline_location_color', [ |
| 222 | 'label' => esc_html__( 'Text Color', 'spider-elements' ), |
| 223 | 'type' => Controls_Manager::COLOR, |
| 224 | 'selectors' => [ |
| 225 | '{{WRAPPER}} .timeline-wrapper .timeline-panel span' => 'color: {{VALUE}};', |
| 226 | ], |
| 227 | ] |
| 228 | ); |
| 229 | |
| 230 | $this->add_group_control( |
| 231 | Group_Control_Typography::get_type(), [ |
| 232 | 'name' => 'timeline_location_typo', |
| 233 | 'selector' => '{{WRAPPER}} .timeline-wrapper .timeline-panel span', |
| 234 | ] |
| 235 | ); //End Timeline Location |
| 236 | |
| 237 | |
| 238 | //=== Timeline Content |
| 239 | $this->add_control( |
| 240 | 'timeline_content', [ |
| 241 | 'label' => esc_html__( 'Timeline Content', 'spider-elements' ), |
| 242 | 'type' => Controls_Manager::HEADING, |
| 243 | 'separator' => 'before', |
| 244 | ] |
| 245 | ); |
| 246 | |
| 247 | $this->add_control( |
| 248 | 'timeline_content_color', [ |
| 249 | 'label' => esc_html__( 'Text Color', 'spider-elements' ), |
| 250 | 'type' => Controls_Manager::COLOR, |
| 251 | 'selectors' => [ |
| 252 | '{{WRAPPER}} .timeline-wrapper .timeline-panel p' => 'color: {{VALUE}};', |
| 253 | ], |
| 254 | ] |
| 255 | ); |
| 256 | |
| 257 | $this->add_group_control( |
| 258 | Group_Control_Typography::get_type(), [ |
| 259 | 'name' => 'timeline_content_typo', |
| 260 | 'selector' => '{{WRAPPER}} .timeline-wrapper .timeline-panel p', |
| 261 | ] |
| 262 | ); //End Timeline content |
| 263 | |
| 264 | |
| 265 | //=== Timeline Date Option |
| 266 | $this->add_control( |
| 267 | 'timeline_date', [ |
| 268 | 'label' => esc_html__( 'Date', 'spider-elements' ), |
| 269 | 'type' => Controls_Manager::HEADING, |
| 270 | 'separator' => 'before', |
| 271 | ] |
| 272 | ); |
| 273 | |
| 274 | $this->add_group_control( |
| 275 | \Elementor\Group_Control_Background::get_type(), |
| 276 | [ |
| 277 | 'name' => 'timeline_date_bg_color', |
| 278 | 'types' => [ 'classic', 'gradient' ], |
| 279 | 'exclude' => [ 'image' ], |
| 280 | 'selector' => '{{WRAPPER}} .timeline-wrapper .timestamp' |
| 281 | ] |
| 282 | ); |
| 283 | |
| 284 | $this->add_control( |
| 285 | 'timeline_date_color', [ |
| 286 | 'label' => esc_html__( 'Text Color', 'spider-elements' ), |
| 287 | 'type' => Controls_Manager::COLOR, |
| 288 | 'selectors' => [ |
| 289 | '{{WRAPPER}} .timeline-wrapper .timestamp' => 'color: {{VALUE}};', |
| 290 | ], |
| 291 | ] |
| 292 | ); |
| 293 | |
| 294 | $this->add_group_control( |
| 295 | Group_Control_Typography::get_type(), [ |
| 296 | 'name' => 'timeline_meta_typo', |
| 297 | 'selector' => '{{WRAPPER}} .timeline-wrapper .timestamp', |
| 298 | ] |
| 299 | ); //End Timeline Date Option |
| 300 | |
| 301 | |
| 302 | $this->end_controls_section(); |
| 303 | |
| 304 | } //End Timeline Content Style |
| 305 | |
| 306 | |
| 307 | /** |
| 308 | * Name: elementor_render() |
| 309 | * Desc: Render the widget output on the frontend. |
| 310 | * Params: no params |
| 311 | * Return: @void |
| 312 | * Since: @1.0.0 |
| 313 | * Package: @spider-elements |
| 314 | * Author: spider-themes |
| 315 | */ |
| 316 | protected function render() { |
| 317 | $settings = $this->get_settings_for_display(); |
| 318 | |
| 319 | if ( !empty( $settings['timeline_items'] ) ) { |
| 320 | echo '<div class="timeline-widget">'; |
| 321 | $is_inverted = false; |
| 322 | foreach ( $settings[ 'timeline_items' ] as $item ) { |
| 323 | $timestamp = !empty($item[ 'timestamp' ]) ? $item[ 'timestamp' ] : ''; |
| 324 | $title = !empty($item[ 'title' ]) ? $item[ 'title' ] : ''; |
| 325 | $location = !empty($item[ 'location' ]) ? $item[ 'location' ] : ''; |
| 326 | $content = !empty($item[ 'content' ]) ? $item[ 'content' ] : ''; |
| 327 | echo '<div class="timeline-wrapper wow fadeInUp' . ($is_inverted ? ' timeline-inverted' : '') . '" data-wow-delay="0.1s">'; |
| 328 | echo '<div class="timestamp">' . esc_html($timestamp) . '</div>'; |
| 329 | echo '<div class="timeline-panel">'; |
| 330 | echo '<h3>' . esc_html($title) . '</h3>'; |
| 331 | echo '<span>' . esc_html($location) . '</span>'; |
| 332 | echo spel_kses_post(wpautop($content)); |
| 333 | echo '</div>'; |
| 334 | echo '</div>'; |
| 335 | $is_inverted = !$is_inverted; |
| 336 | } |
| 337 | echo '</div>'; |
| 338 | echo '</div>'; |
| 339 | } |
| 340 | } |
| 341 | } |