diff --git a/static/js/carousel.js b/assets/js/carousel.js similarity index 92% rename from static/js/carousel.js rename to assets/js/carousel.js index 78a51e438e..0e9ce894d2 100644 --- a/static/js/carousel.js +++ b/assets/js/carousel.js @@ -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; @@ -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 diff --git a/static/js/tutorials.js b/assets/js/tutorials.js similarity index 100% rename from static/js/tutorials.js rename to assets/js/tutorials.js diff --git a/docs/_index.md b/docs/_index.md index 85aeb00072..49af563d6f 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -216,5 +216,3 @@ sitemap: {{< card link="/tutorials/projects/integrating-viam-with-openai/" class="yellow">}} - - diff --git a/layouts/docs/tutorials.html b/layouts/docs/tutorials.html index 510d360579..34396c144d 100644 --- a/layouts/docs/tutorials.html +++ b/layouts/docs/tutorials.html @@ -80,7 +80,10 @@

Javascript

- + + {{ $jsTutorials := resources.Get "js/tutorials.js" }} + {{ $jsTutorials := $jsTutorials | minify }} + diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 4c7130420a..51a6ee9765 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,3 +1,10 @@ + +{{ $jsCarousel := resources.Get "js/carousel.js" }} +{{ $jsCarousel := $jsCarousel | minify }} +{{ if eq .Page.Title "Viam Documentation" }} + +{{ end }} + {{ $jsLozad := resources.Get "js/lozad.js" }} diff --git a/static/js/carousel-min.js b/static/js/carousel-min.js deleted file mode 100644 index b24bae2add..0000000000 --- a/static/js/carousel-min.js +++ /dev/null @@ -1 +0,0 @@ -document.addEventListener("DOMContentLoaded",function(){let e=document.querySelectorAll(".carousel");e.forEach(function(e){let t=e.querySelector("ul"),l=Math.round(t.offsetWidth/t.querySelector("li:nth-child(1)").offsetWidth),i=e.querySelectorAll("ol li"),r=e.querySelectorAll("ul li"),c=e.querySelector(".next"),n=e.querySelector(".prev");c.style.display="block",n.style.display="block",t.scrollLeft=0,i[0].classList.add("selected"),r[0].classList.add("selected"),l>1&&e.querySelectorAll("ol li:nth-last-child(-n + "+(l-1)+")").forEach(function(e){e.remove()});let o=function(){i.forEach(function(e){e.classList.remove("selected")}),r.forEach(function(e){e.classList.remove("selected")});let l=e.querySelector("ul li:nth-child(2)").offsetLeft-e.querySelector("ul li:nth-child(1)").offsetLeft,c=Math.round(t.scrollLeft/l+1);if(e.querySelector("ol li:nth-child("+c+")").classList.add("selected"),e.querySelector("ul li:nth-child("+c+")").classList.add("selected"),e.parentElement.parentElement.querySelector(".dynamictitle")){let n=e.querySelector("ul li:nth-child("+c+") img").getAttribute("title");n&&(e.parentElement.parentElement.querySelector(".dynamictitle").innerHTML=n)}},s=function(e){e.preventDefault(),t.scrollLeft=t.querySelector(this.getAttribute("href")).offsetLeft},d=function(){e.querySelector("ol li:last-child").classList.contains("selected")?e.querySelector("ol li:first-child a").click():e.querySelector("ol li.selected").nextElementSibling.querySelector("a").click()},a=function(){e.querySelector("ol li:first-child").classList.contains("selected")?e.querySelector("ol li:last-child a").click():e.querySelector("ol li.selected").previousElementSibling.querySelector("a").click()},u=function(){t.classList.add("interacted")};t.addEventListener("scroll",debounce(o)),t.addEventListener("touchstart",u),t.addEventListener("keydown",function(e){"ArrowLeft"==e.key&&t.classList.add("interacted"),"ArrowRight"==e.key&&t.classList.add("interacted")}),c.addEventListener("click",d),c.addEventListener("mousedown",u),c.addEventListener("touchstart",u),n.addEventListener("click",a),n.addEventListener("mousedown",u),n.addEventListener("touchstart",u),i.forEach(function(e){e.querySelector("a").addEventListener("click",s),e.addEventListener("mousedown",u),e.addEventListener("touchstart",u)}),e.getAttribute("duration")&&setInterval(function(){t!=document.querySelector(".carousel:hover ul")&&!1==t.classList.contains("interacted")&&c.click()},e.getAttribute("duration"));var f="@media (min-width:"+(100*r.length+400)+"px) {#board-carousel { padding: 0 !important; }#board-carousel div.prev, #board-carousel div.next {visibility: hidden;}}",h=document.createElement("style");h.innerText=f,document.head.appendChild(h)})});function debounce(e){let t;return function(){let l=this,i=arguments;t&&window.cancelAnimationFrame(t),t=window.requestAnimationFrame(function(){e.apply(l,i)})}} \ No newline at end of file