From 9c63e8cb3e05f2061bc463fe72e4b17ceea0f298 Mon Sep 17 00:00:00 2001 From: Yoni Date: Sat, 21 Aug 2021 14:00:10 +0300 Subject: [PATCH] Fix issues caused by missing gttBtn when enableGoToTop is false --- layouts/partials/head/scripts.html | 74 +++++++++++++++++------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html index dba8cde..9159e98 100644 --- a/layouts/partials/head/scripts.html +++ b/layouts/partials/head/scripts.html @@ -243,33 +243,35 @@ // ========================= go to top ========================= - var gttBtn = document.getElementById("gtt"); - gttBtn.style.display = "none"; - gttBtn.addEventListener('click', function () { - if (window.document.documentMode) { - document.documentElement.scrollTop = 0; - } else { - scrollToTop(250); - } - }); - - function scrollToTop(scrollDuration) { - var scrollStep = -window.scrollY / (scrollDuration / 15); - var scrollInterval = setInterval(function () { - if (window.scrollY != 0) { - window.scrollBy(0, scrollStep); + {{ if $.Param "enableGoToTop" }} + var gttBtn = document.getElementById("gtt"); + gttBtn.style.display = "none"; + gttBtn.addEventListener('click', function () { + if (window.document.documentMode) { + document.documentElement.scrollTop = 0; + } else { + scrollToTop(250); } - else clearInterval(scrollInterval); - }, 15); - } + }); - var scrollFunction = function () { - if (document.body.scrollTop > 250 || document.documentElement.scrollTop > 250) { - gttBtn.style.display = "block"; - } else { - gttBtn.style.display = "none"; + function scrollToTop(scrollDuration) { + var scrollStep = -window.scrollY / (scrollDuration / 15); + var scrollInterval = setInterval(function () { + if (window.scrollY != 0) { + window.scrollBy(0, scrollStep); + } + else clearInterval(scrollInterval); + }, 15); } - } + + var scrollFunction = function () { + if (document.body.scrollTop > 250 || document.documentElement.scrollTop > 250) { + gttBtn.style.display = "block"; + } else { + gttBtn.style.display = "none"; + } + } + {{ end }} // ============================================================ @@ -347,15 +349,19 @@ window.onscroll = function () { - scrollFunction(); + {{ if $.Param "enableGoToTop" }} + scrollFunction(); + {{ end }} var st = window.pageYOffset || document.documentElement.scrollTop; if (st > lastScrollTop) { // scroll down - if (st < 250) { - gttBtn.style.display = "none"; - } else { - gttBtn.style.display = "block"; - } + {{ if $.Param "enableGoToTop" }} + if (st < 250) { + gttBtn.style.display = "none"; + } else { + gttBtn.style.display = "block"; + } + {{ end }} if (st < 45) { return null; @@ -429,9 +435,11 @@ } } } else { // scroll up - if (st < 250) { - gttBtn.style.display = "none"; - } + {{ if $.Param "enableGoToTop" }} + if (st < 250) { + gttBtn.style.display = "none"; + } + {{ end }} if (navbar.classList.contains('scrolling')) { if (navbar.classList.contains('navbar--hide')) {