]
);
- // items with repeater
-// $this->add_control(
-// 'items',
-// [
-// 'label' => __('Items', 'cube'),
-// 'type' => Controls_Manager::REPEATER,
-// 'fields' => [
-// [
-// 'name' => 'title',
-// 'label' => __('Title', 'elementor'),
-// 'type' => Controls_Manager::TEXTAREA,
-// 'placeholder' => __('Enter your title', 'elementor'),
-// 'default' => '',
-// ],
-// [
-// 'name' => 'subtitle',
-// 'label' => __('Subtitle', 'cube'),
-// 'type' => Controls_Manager::TEXT,
-// 'default' => '',
-// ],
-// [
-// 'name' => 'image',
-// 'label' => __( 'Image', 'elementor' ),
-// 'type' => Controls_Manager::MEDIA,
-// 'default' => [
-// 'url' => Utils::get_placeholder_image_src(),
-// ],
-// ],
-// [
-// 'name' => 'body',
-// 'label' => __('Body', 'cube'),
-// 'type' => Controls_Manager::WYSIWYG,
-// 'default' => '',
-// ],
-// 'title_field' => '{{{ title }}}',
-// ],
-//
-// ]
-// );
-
+ // all the items with REPEATER
$this->add_control(
'items',
[
- 'label' => __( 'Items', 'cube' ),
+ 'label' => __('Items', 'cube'),
'type' => Controls_Manager::REPEATER,
'fields' => [
[
'name' => 'title',
- 'label' => __( 'Title', 'cube' ),
+ 'label' => __('Title', 'cube'),
'type' => Controls_Manager::TEXT,
'label_block' => true,
'default' => '',
],
[
'name' => 'subtitle',
- 'label' => __( 'subtitle', 'cube' ),
+ 'label' => __('subtitle', 'cube'),
'type' => Controls_Manager::TEXT,
'label_block' => true,
'default' => '',
*/
protected function render() {
-// $subtitle = $this->get_settings('subtitle');
-// $title = $this->get_settings('title');
-//
-// $body = $this->parse_text_editor($this->get_settings('body'));
-// // Inline Editing settings
-// $this->add_inline_editing_attributes('subtitle', 'none');
-// $this->add_inline_editing_attributes('title', 'none');
-//
-// $this->add_inline_editing_attributes('body', 'advanced');
-//
-// // CSS Classes for elements
-// $this->add_render_attribute('subtitle', 'class', ['timeline-item-subtitle']);
-// $this->add_render_attribute('title', 'class', ['timeline-item-title']);
-// $this->add_render_attribute('body', 'class', ['timeline-item-body']);
-//
-// $settings = $this->get_settings_for_display();
-
- // Rendered content
- $res = '<div class="timeline">';
-
- $items = $this->get_settings('items');
-
- foreach ($items as $item) {
-
- $res .= '<div class="timeline-item">';
- $res .= '<h2 class="timeline-item-title">'. $item['title'] .'</h2>';
- $res .= '<h3 class="timeline-item-subtitle">'. $item['subtitle'] .'</h3>';
- $res .= wp_get_attachment_image($item['image']['id'], 'large', false, ['class' => 'timeline-item-img']);
- $res .= '<div class="timeline-item-body">'.$item['body'].'</div>';
- $res .= '</div>'; // .timeline-item
+ // Rendered content
+ $res = '<div class="timeline-wrapper">';
+ $res .= '<div class="year">';
+ $items = $this->get_settings('items');
+ $res .= '<ul>';
+ foreach ($items as $index => $item) {
- }
+ $arr = explode(' ', trim($item['title'])); // select the first word
+ $res .= '<li class="year-item" data-year="' . $index . '"><a>' . $arr[0] . '</a></li>';
- $res .= '</div>'; // .timeline
- echo $res;
-// if (!empty($title)) {
-// echo "<h2 {$this->get_render_attribute_string('title')}>$title</h2>";
-// }
-//
-// if (!empty($subtitle)) {
-// echo "<h3 {$this->get_render_attribute_string('subtitle')}>$subtitle</h3>";
-// }
-//
-// // Get image by id
-// echo wp_get_attachment_image( $settings['image']['id'], 'large' );
-//
-// if (!empty($body)) echo "<div {$this->get_render_attribute_string('body')}>$body</div>";
+ }
+ $res .= '</ul>'; // .year-item
+ $res .= '</div>'; // .year
+ $res .= '<div class="timeline">';
+ foreach ($items as $index => $item) {
-}
+ $res .= '<div class="timeline-item" data-timeline="' . $index . '">';
+ $res .= '<h2 class="timeline-item-title">' . $item['title'] . '</h2>';
+ $res .= '<h3 class="timeline-item-subtitle">' . $item['subtitle'] . '</h3>';
+ $res .= wp_get_attachment_image($item['image']['id'], 'large', false, ['class' => 'timeline-item-img']);
+ $res .= '<div class="timeline-item-body">' . $item['body'] . '</div>';
+ $res .= '</div>'; // .timeline-item
+
+ }
+
+ $res .= '</div>'; // .timeline
+ $res .= '</div>'; // .timeline-wrapper
+ echo $res;
+
+ }
}
--- /dev/null
+// import $ from 'jquery';
+
+// console.log('wesh');
+
+let link = $('.year-item');
+
+link.on('click', function() {
+ let target = $(this).data('year');
+
+ alert(target);
+});
+
+$(window).on('scroll', function () {
+ var sections = $('.timeline-item')
+ , nav = $('.year-item')
+ , nav_height = nav.outerHeight()
+ , cur_pos = $(this).scrollTop();
+ sections.each(function() {
+ var top = $(this).offset().top - nav_height,
+ bottom = top + $(this).outerHeight();
+
+ if (cur_pos >= top && cur_pos <= bottom) {
+ nav.find('a').removeClass('active');
+ sections.removeClass('active');
+
+ $(this).addClass('active');
+ // nav.data('year').addClass('active');
+ }
+ });
+});
\ No newline at end of file