]> _ Git - c6-wordpress.git/commitdiff
WIP #2685 @7
authornael <nael@cubedesigners.com>
Mon, 6 May 2019 16:13:35 +0000 (18:13 +0200)
committernael <nael@cubedesigners.com>
Mon, 6 May 2019 16:13:35 +0000 (18:13 +0200)
wp-content/mu-plugins/cube/src/Elementor/Widgets/Timeline.php
wp-content/themes/c6/app/setup.php
wp-content/themes/c6/package.json
wp-content/themes/c6/resources/assets/config.json
wp-content/themes/c6/resources/assets/scripts/routes/common.js
wp-content/themes/c6/resources/assets/scripts/script.js [deleted file]
wp-content/themes/c6/resources/assets/scripts/timeline.js [new file with mode: 0644]
wp-content/themes/c6/resources/assets/styles/widgets/timeline.styl
wp-content/themes/c6/yarn.lock

index c0cc7cd27d630e9e238c0e1cfae2b93725ee8dbe..709efd3a964173cf035679468d2133160fe2747e 100644 (file)
@@ -44,7 +44,16 @@ class Timeline extends Widget_Base
      * @return array Widget scripts dependencies.
      */
     public function get_script_depends() {
-        return [];
+
+        wp_register_script(
+            'cube-timeline',
+            \App\asset_path('scripts/timeline.js'),
+            ['jquery'], // Dependencies
+            null, // Version
+            true // In footer?
+        );
+
+        return ['cube-timeline'];
     }
 
     /**
@@ -122,20 +131,20 @@ class Timeline extends Widget_Base
         $res = '<div class="timeline-wrapper">';
         $res .= '<div class="year">';
         $items = $this->get_settings('items');
-        $res .= '<ul>';
+        $res .= '<nav id="timeline-nav">';
         foreach ($items as $index => $item) {
 
             $arr = explode(' ', trim($item['title'])); // select the first word
-            $res .= '<li class="year-item" data-year="' . $index . '">' . $arr[0] . '</li>';
+            $res .= '<a class="year-item" href="#year-' . $index . '">' . $arr[0] . '</a>';
 
         }
-        $res .= '</ul>'; // .year-item
+        $res .= '</nav>';
         $res .= '</div>'; // .year
         $res .= '<div class="timeline">';
 
         foreach ($items as $index => $item) {
 
-            $res .= '<div id="#'.$index.'" class="timeline-item" data-timeline="' . $index . '">';
+            $res .= '<div id="year-'.$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 e4f8b9cbc0fcccf0051203d85370b8ea2785c036..e28f182121393989ddfb01c197c78d8ffaebbc0c 100644 (file)
@@ -15,7 +15,6 @@ add_action('wp_enqueue_scripts', function () {
     // is always loaded afterwards, allowing us to override the default styles. On 404 pages, this wasn't happening.
     wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), ['elementor-frontend'], null);
     wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true);
-    wp_enqueue_script('sage/script.js', asset_path('scripts/script.js'), ['jquery'], null, true);
 
     if (is_single() && comments_open() && get_option('thread_comments')) {
         wp_enqueue_script('comment-reply');
index a6f83422d543726d6c28555746fb866d85e3cf64..46a110e74d2a3e3faac3cf3913cc548f9b75962b 100644 (file)
@@ -65,6 +65,7 @@
     "rupture": "^0.7.1",
     "sass-loader": "~6.0",
     "sidr": "^2.2.1",
+    "simple-scrollspy": "^2.0.1",
     "style-loader": "^0.22.1",
     "stylelint": "^8.4.0",
     "stylelint-config-standard": "~18.2.0",
@@ -81,6 +82,8 @@
     "yargs": "~11.0.0"
   },
   "dependencies": {
-    "jquery": "^3.3.1"
+    "gumshoejs": "^5.1.1",
+    "jquery": "^3.3.1",
+    "smooth-scroll": "^16.0.3"
   }
 }
index 0e82b779613d7d092c27822e134e444b04f00b7d..873edffa9b1b03e40d8976b8950c8d01a9319508 100644 (file)
@@ -7,8 +7,8 @@
     "customizer": [
       "./scripts/customizer.js"
     ],
-    "script": [
-      "./scripts/script.js"
+    "timeline": [
+      "./scripts/timeline.js"
     ]
   },
   "publicPath": "/wp-content/themes/c6",
index 3acfc95119db40a79772a2e83a27fd1e9b3fb20f..2c599f5e75ca46d0e74a0376602f3d5d5916cbd7 100644 (file)
@@ -1,6 +1,12 @@
+import SmoothScroll from 'smooth-scroll';
+
 export default {
   init() {
     // JavaScript to be fired on all pages
+      new SmoothScroll('a[href*="#"]', {
+          speed: 300,
+          offset: 0,
+      });
   },
   finalize() {
     // JavaScript to be fired on all pages, after page specific JS is fired
diff --git a/wp-content/themes/c6/resources/assets/scripts/script.js b/wp-content/themes/c6/resources/assets/scripts/script.js
deleted file mode 100644 (file)
index a57a489..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-// import $ from 'jquery';
-
-// smooth scroll on click function
-$(document).ready(function () {
-    let timeline = $('.timeline-item'),
-        nav = $('.year-item'),
-        nav_height = nav.outerHeight(),
-        currentPosition = $(this).scrollTop();
-
-    console.log('current position : ' + currentPosition);
-
-    timeline.each(function () {
-        // on detecte le top et bottom de chaque section timeline
-        let top = $(this).offset().top - nav_height,
-            bottom = top + $(this).outerHeight();
-
-        console.log('top : ' + top + '  ----  ' + 'bottom : ' + bottom );
-
-        let thing = $(this);
-
-        nav.each(function () {
-            $(this).on('click',function () {
-                if (thing.data('timeline') === $(this).data('year')) {
-                    // alert(top);
-                    let scrollValue = top +2; // la valeur top est une valeur arrondie, on ajoute +1 pour que le scroll se synchonise avec la liste des années.
-                    $('html,body').animate(
-                    {
-                            scrollTop: scrollValue,
-                    },600);
-                }
-            });
-        })
-    });
-});
-
-$('.year-item:first').addClass('active');   // add class active to the first year-item
-
-// fonction scroll spy
-$(window).on('scroll', function () {
-    let timeline = $('.timeline-item'),
-        nav = $('.year-item'),
-        nav_height = nav.outerHeight(),
-        currentPosition = $(this).scrollTop();
-
-    console.log('current position : ' + currentPosition);
-
-    timeline.each(function () {
-        // on detecte le top et bottom de chaque section timeline
-        let top = $(this).offset().top - nav_height,
-            bottom = top + $(this).outerHeight();
-
-        // 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');
-            let thing = $(this);
-
-            // on attribut la class active a l'element ''year-item'' uniquement si les elements 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');
-                }
-            });
-        }
-    });
-});
\ No newline at end of file
diff --git a/wp-content/themes/c6/resources/assets/scripts/timeline.js b/wp-content/themes/c6/resources/assets/scripts/timeline.js
new file mode 100644 (file)
index 0000000..9231055
--- /dev/null
@@ -0,0 +1,7 @@
+import scrollSpy from 'simple-scrollspy';
+
+scrollSpy('#timeline-nav', {
+    offset: -200,
+    sectionClass: '.timeline-item',
+    menuActiveTarget: '.year-item',
+});
index 08ce8ff1c94582904f5d8a7d0abe5feeac1ab193..6503d1e8ebbbc3bbe64951ef347824bdd2bf989f 100644 (file)
@@ -6,21 +6,18 @@
 
 .year
   position: sticky
-  height: 0%
+  align-self flex-start
   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
-.year-item.active
-  font-size: $font-size-small
-  color: $colors.orange
+  @media (max-width: 425px)
+    display: none
+  &-item
+    display: block
+    margin-bottom: 24px
+    text-align: right
+    &.active
+      font-size: $font-size-small
+      color: $colors.orange
 
 .timeline
   display: flex
   &-item
     margin-bottom: 4em
     &-title
-      margin-top: 10px
+      margin-top: 15px
+      margin-bottom: 0,8888em
     &-subtitle
       font-size: $font-size-medium
-      margin: 48px 0
+      margin-bottom: 1.333em
     &-img
       margin-bottom: 48px
     &-body
       p
         max-width: 960px
-        margin-bottom: 48px
+        margin-bottom: 3em
       h4
         font-size: $font-size-small
         font-weight: lighter
@@ -49,7 +47,7 @@
         list-style none
         margin-left: 0.35em
         li
-          margin-bottom: 1em
+          margin-bottom: 1.8em
           max-width: 960px
           position: relative
           &::before
@@ -61,7 +59,5 @@
             position: absolute
             left: -1.6em
             top: 12px
-          &:first-of-type
-            margin-top: 1em
           &:last-of-type
             margin-bottom: 0
\ No newline at end of file
index 6edb26bb113d726076b1df4a0f32550c319ce7da..e2a3514d96467fe1fe50ed5e2779501d085c785d 100644 (file)
@@ -4171,6 +4171,11 @@ gulplog@^1.0.0:
   dependencies:
     glogg "^1.0.0"
 
+gumshoejs@^5.1.1:
+  version "5.1.1"
+  resolved "https://registry.yarnpkg.com/gumshoejs/-/gumshoejs-5.1.1.tgz#b67564fdec7bd8be8e2eaf02cc01f7c9fd7f8ce0"
+  integrity sha512-aQvXoMH/EbYGf7aRtpKhyvrYpBw7X+nMvdBg/dH3TOeqeM5BsDQKVaDRVsiv2AqLLj26h/WMBUsYgjT4oyIGKg==
+
 har-schema@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
@@ -8590,6 +8595,11 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
   resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
   integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
 
+simple-scrollspy@^2.0.1:
+  version "2.0.1"
+  resolved "https://registry.yarnpkg.com/simple-scrollspy/-/simple-scrollspy-2.0.1.tgz#9399290d1a96c58f13913f80ecfa3afbe9bb34df"
+  integrity sha512-fb/Ze/qnfK3/EABCsZXBWVVSlZkU+2bAM4g3cHJloOCZi9keufxIvoXvF6LtFcYezA9FJfGMMASAv2Z1ct6xoQ==
+
 simple-swizzle@^0.2.2:
   version "0.2.2"
   resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
@@ -8609,6 +8619,11 @@ slice-ansi@1.0.0:
   dependencies:
     is-fullwidth-code-point "^2.0.0"
 
+smooth-scroll@^16.0.3:
+  version "16.0.3"
+  resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-16.0.3.tgz#5914e0e4050a5313102d734140ddee0267526fd7"
+  integrity sha512-Wnhk3tWeqVJRrSUxeLQ4r7MNQvc9MNlswyWfKqAQ9cc37D8VqTco/CicWcdHzSFEC4/9/kPPK3uY6oyY+mdRYg==
+
 snapdragon-node@^2.0.1:
   version "2.1.1"
   resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"