Skip to content

Commit

Permalink
Fix carousel javascript error (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Sep 8, 2023
1 parent 5619013 commit ee07bb2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
8 changes: 5 additions & 3 deletions static/js/carousel.js → assets/js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ document.addEventListener('DOMContentLoaded', function() {
});
const scrolllength = carousel.querySelector('ul li:nth-child(2)').offsetLeft - carousel.querySelector('ul li:nth-child(1)').offsetLeft;
const nthchild = (Math.round((ele.scrollLeft/scrolllength)+1));
carousel.querySelector('ol li:nth-child('+nthchild+')').classList.add('selected');
carousel.querySelector('ul li:nth-child('+nthchild+')').classList.add('selected');
let ol_elem = carousel.querySelector('ol li:nth-child('+nthchild+')');
let ul_elem = carousel.querySelector('ul li:nth-child('+nthchild+')');
if (ol_elem) { ol_elem.classList.add('selected'); }
if (ul_elem) { ul_elem.classList.add('selected'); }
if(carousel.parentElement.parentElement.querySelector('.dynamictitle')) {
const title = carousel.querySelector('ul li:nth-child('+nthchild+') img').getAttribute('title');
if(title) carousel.parentElement.parentElement.querySelector('.dynamictitle').innerHTML = title;
Expand Down Expand Up @@ -97,7 +99,7 @@ document.addEventListener('DOMContentLoaded', function() {
}

// Add CSS to hide arrows when all elements visible
var styles = "@media (min-width:" + (slides.length * 100 + 400) "px) {#board-carousel { padding: 0 !important; }#board-carousel div.prev, #board-carousel div.next {visibility: hidden;}}"
var styles = "@media (min-width:" + (slides.length * 100 + 400) + "px) {#board-carousel { padding: 0 !important; }#board-carousel div.prev, #board-carousel div.next {visibility: hidden;}}"

var styleSheet = document.createElement("style")
styleSheet.innerText = styles
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,3 @@ sitemap:
{{< card link="/tutorials/projects/integrating-viam-with-openai/" class="yellow">}}
</div>
</div>

<script type="text/javascript" src="js/carousel-min.js"></script>
5 changes: 4 additions & 1 deletion layouts/docs/tutorials.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ <h4 class="alert-heading">Javascript</h4>
<script src="https://cdn.jsdelivr.net/npm/typesense-instantsearch-adapter@2/dist/typesense-instantsearch-adapter.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="../js/tutorials.js"></script>

{{ $jsTutorials := resources.Get "js/tutorials.js" }}
{{ $jsTutorials := $jsTutorials | minify }}
<script type="text/javascript" src="{{ $jsTutorials.RelPermalink }}" crossorigin="anonymous"></script>

</body>
</html>
7 changes: 7 additions & 0 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

{{ $jsCarousel := resources.Get "js/carousel.js" }}
{{ $jsCarousel := $jsCarousel | minify }}
{{ if eq .Page.Title "Viam Documentation" }}
<script type="text/javascript" src="{{$jsCarousel.RelPermalink}}" crossorigin="anonymous"></script>
{{ end }}

<!-- START script for lazy loading -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lozad/dist/lozad.min.js"></script>
{{ $jsLozad := resources.Get "js/lozad.js" }}
Expand Down
1 change: 0 additions & 1 deletion static/js/carousel-min.js

This file was deleted.

0 comments on commit ee07bb2

Please sign in to comment.