]> _ Git - c6-wordpress.git/commitdiff
WIP #2685 @7
authornael <nael@cubedesigners.com>
Mon, 29 Apr 2019 16:15:36 +0000 (18:15 +0200)
committernael <nael@cubedesigners.com>
Mon, 29 Apr 2019 16:15:36 +0000 (18:15 +0200)
wp-content/mu-plugins/cube/src/Elementor/Widgets/Timeline.php
wp-content/themes/c6/resources/assets/scripts/script.js
wp-content/themes/c6/resources/assets/styles/widgets/timeline.styl

index 2ab95ffbf4693fca71696394be132693fa0b0d4f..a0afed8a7166047163bda15ce991cb5e0e81615d 100644 (file)
@@ -126,7 +126,7 @@ class Timeline extends Widget_Base
         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 .= '<li class="year-item" data-year="' . $index . '"><a href="#'.$index.'">' . $arr[0] . '</a></li>';
 
         }
         $res .= '</ul>'; // .year-item
@@ -135,7 +135,7 @@ class Timeline extends Widget_Base
 
         foreach ($items as $index => $item) {
 
-            $res .= '<div class="timeline-item" data-timeline="' . $index . '">';
+            $res .= '<div id="#'.$index.'" 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']);
index 4fdd9db1d816dba65493925a9bba6db974b622df..9ec8062afd7b1780770cd9d954c54a96af12ce81 100644 (file)
@@ -1,30 +1,75 @@
 // import $ from 'jquery';
 
-// console.log('wesh');
+// let navigation = $('.year-item');
 
-let link = $('.year-item');
+// navigation.on('click',function(e){
+//     e.preventDefault();
+//     var target = $($(this).attr('href'));
+//     if(target.length){
+//         var scrollTo = target.offset().top;
+//         $('body, html').animate({scrollTop: scrollTo+'px'}, 800);
+//     }
+// });
 
-link.on('click', function() {
-    let target = $(this).data('year');
+// //TODO : ON CLICK REDIRECT TO THE RIGHT SECTION
+// navigation.on('click', function() {
+//     let target = $(this).data('year');
+//     alert(target);
+//     // $('html, body').animate({
+//     //     scrollTop: $(target).offset().top(),
+//     // },'slow');
+// });
 
-    alert(target);
+
+// smoothscroll on click bug
+$('.year-item ').on('click', function() {
+    let hash = $(this).data('year');
+    let $toElement = $('a[href=#'+hash+']');
+    let toPosition = $toElement.offset().top;
+    $('html,body').animate(
+    {
+            scrollTop: toPosition,
+    },500);
+    console.log(toPosition);
 });
 
+
+$('.year-item:first').addClass('active');   // add class active to the first year-item
+
+// fonction scroll spy
 $(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,
+    let timeline = $('.timeline-item'),
+        nav = $('.year-item'),
+        nav_height = nav.outerHeight(),
+        currentPosition = $(this).scrollTop();
+
+    // see the current position on scroll
+    console.log('current position : ' + currentPosition);
+
+    // pour chaque element timeline
+    timeline.each(function () {
+        // on detecte le top et bottom de chaque section timeline
+        let 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');
+        console.log('top : ' + top + '  ----  ' + 'bottom : ' + bottom);
+
+        // si la position actuel est supérieur ou egale au top ET inferieur ou egale au bottom alors on ajoute la class active sur l"élément timeline-item en question
+        if (currentPosition >= top && currentPosition <= bottom) {
 
+            timeline.removeClass('active');
             $(this).addClass('active');
-            // nav.data('year').addClass('active');
+
+            let thing = $(this);
+            // on attribut la class active a l'element ''year-item'' uniquement si les element data attribute de timeline-item ET year-item ont la meme valeur
+            nav.each(function () {
+
+                if (thing.data('timeline') === $(this).data('year')) {
+                    nav.removeClass('active');
+                    $(this).addClass('active');
+                }
+            });
+            // console.log($(this).data('timeline'));
         }
     });
 });
\ No newline at end of file
index 633ae0b23c2ae8c93eceb5619f1b2b3147680037..08ce8ff1c94582904f5d8a7d0abe5feeac1ab193 100644 (file)
@@ -7,17 +7,20 @@
 .year
   position: sticky
   height: 0%
-  padding: 1rem 5.375rem
-  top: 0
+  padding: 0 5.375rem
+  top: 149px
   ul
     list-style: none
     li
       margin-bottom: 24px
       cursor: pointer
       text-align: right
-      &:first-of-type
-        font-size: $font-size-small
-        color: $colors.orange
+      //&:first-of-type
+      //  font-size: $font-size-small
+      //  color: $colors.orange
+.year-item.active
+  font-size: $font-size-small
+  color: $colors.orange
 
 .timeline
   display: flex
@@ -27,7 +30,7 @@
   &-item
     margin-bottom: 4em
     &-title
-      margin: 0
+      margin-top: 10px
     &-subtitle
       font-size: $font-size-medium
       margin: 48px 0