From 516ba47609610bb9510bff1df6dd9133d8eed8be Mon Sep 17 00:00:00 2001 From: RJ Spiker Date: Thu, 6 Dec 2018 12:17:35 -0700 Subject: [PATCH] website: fix carousel bugs --- .../source/assets/javascripts/application.js | 5 ++ .../javascripts/consul-connect/carousel.js | 87 +++++++++++-------- website/source/configuration.html.erb | 9 +- website/source/discovery.html.erb | 9 +- 4 files changed, 58 insertions(+), 52 deletions(-) diff --git a/website/source/assets/javascripts/application.js b/website/source/assets/javascripts/application.js index 98ee102687..98baefa2de 100644 --- a/website/source/assets/javascripts/application.js +++ b/website/source/assets/javascripts/application.js @@ -4,6 +4,11 @@ //= require hashicorp/mega-nav //= require hashicorp/sidebar //= require hashicorp/analytics + +//= require consul-connect/vendor/object-fit-images.min.js +//= require consul-connect/vendor/siema.min.js +//= require consul-connect/carousel + //= require analytics //= require gsap-custom //= require animations diff --git a/website/source/assets/javascripts/consul-connect/carousel.js b/website/source/assets/javascripts/consul-connect/carousel.js index 805e419fab..66e0202864 100644 --- a/website/source/assets/javascripts/consul-connect/carousel.js +++ b/website/source/assets/javascripts/consul-connect/carousel.js @@ -1,44 +1,55 @@ -objectFitImages() +document.addEventListener('turbolinks:load', function () { + var qs = document.querySelector.bind(document) + var qsa = document.querySelectorAll.bind(document) + var carousel = qs('.siema') -var qs = document.querySelector.bind(document) -var qsa = document.querySelectorAll.bind(document) + if (carousel) { + objectFitImages() -// siema carousels -var dots = qsa('.g-carousel .pagination li') -var carousel = new Siema({ - selector: '.siema', - duration: 200, - easing: 'ease-out', - perPage: 1, - startIndex: 0, - draggable: true, - multipleDrag: true, - threshold: 20, - loop: true, - rtl: false, - onChange: function() { + // siema carousels + var dots = qsa('.g-carousel .pagination li') + var siema = new Siema({ + selector: carousel, + duration: 200, + easing: 'ease-out', + perPage: 1, + startIndex: 0, + draggable: true, + multipleDrag: true, + threshold: 20, + loop: true, + rtl: false, + onChange: function() { + for (var i = 0; i < dots.length; i++) { + dots[i].classList.remove('active') + } + dots[siema.currentSlide].classList.add('active') + } + }) + + // on previous button click + qs('.g-carousel .prev') + .addEventListener('click', function() { + siema.prev() + }) + + // on next button click + qs('.g-carousel .next') + .addEventListener('click', function() { + siema.next() + }) + + // on dot click for (var i = 0; i < dots.length; i++) { - dots[i].classList.remove('active') + dots[i].addEventListener('click', function() { + siema.goTo(this.dataset.index) + }) } - dots[carousel.currentSlide].classList.add('active') - } + + document.addEventListener('turbolinks:before-cache', function() { + siema.goTo(0) // reset pagination + siema.destroy(true) + }); + } }) -// on previous button click -qs('.g-carousel .prev') - .addEventListener('click', function() { - carousel.prev() - }) - -// on next button click -qs('.g-carousel .next') - .addEventListener('click', function() { - carousel.next() - }) - -// on dot click -for (var i = 0; i < dots.length; i++) { - dots[i].addEventListener('click', function() { - carousel.goTo(i) - }) -} diff --git a/website/source/configuration.html.erb b/website/source/configuration.html.erb index 60175ad9f2..9e8ae01401 100644 --- a/website/source/configuration.html.erb +++ b/website/source/configuration.html.erb @@ -242,8 +242,8 @@ description: |- @@ -269,8 +269,3 @@ description: |- - -<% content_for :scripts do %> - - -<% end %> diff --git a/website/source/discovery.html.erb b/website/source/discovery.html.erb index 920f98a192..a4891d8bee 100644 --- a/website/source/discovery.html.erb +++ b/website/source/discovery.html.erb @@ -263,8 +263,8 @@ $ curl http://localhost:8500/v1/catalog/nodes?dc=dc2 @@ -290,8 +290,3 @@ $ curl http://localhost:8500/v1/catalog/nodes?dc=dc2 - -<% content_for :scripts do %> - - -<% end %>