From 5ccdf2c0e35ee57cc76425d8c092f0fdb94d457a Mon Sep 17 00:00:00 2001 From: Louis-Maxime Piton Date: Thu, 2 Jun 2022 13:23:56 +0200 Subject: [PATCH] fix(docs): don't display back-to-top when it is not needed (#1285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julien Déramond --- site/assets/js/application.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/site/assets/js/application.js b/site/assets/js/application.js index dec23635d3..f46d9d21c5 100644 --- a/site/assets/js/application.js +++ b/site/assets/js/application.js @@ -27,4 +27,24 @@ sidenav.scrollTop = viewportTop - (sidenavHeight / 2) + (sidenavActiveLinkHeight / 2) } } + + // Boosted mod: Remove back-to-top component from all pages when its not needed + ['load', 'resize'].forEach(event => { + window.addEventListener(event, () => { + const removeClass = 'd-none' + const html = document.querySelector('html') + const btt = document.querySelector('.back-to-top') + + // 100(px) comes from: + // - 40px of back-to-top component + // - 40px of navbar-minimized + // - 20px of 'security' + if (html.offsetHeight < window.innerHeight + 100) { + btt.classList.add(removeClass) + } else { + btt.classList.remove(removeClass) + } + }) + }) + // End mod })()