From 45553726fba750804113d8063d6eb4da14906240 Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Sat, 7 Oct 2023 19:10:20 +0200 Subject: [PATCH] Improve usersuite scrollspy JS --- sipa/static/js/usersuite_index.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/sipa/static/js/usersuite_index.js b/sipa/static/js/usersuite_index.js index 31e83fdb..5e2810e0 100644 --- a/sipa/static/js/usersuite_index.js +++ b/sipa/static/js/usersuite_index.js @@ -1,23 +1,14 @@ -$(function() { - var selector = '#usersuite-sidebar-nav'; - var $toc = $(selector); - var $parent = $toc.parent(); - var offset = 60; - var $body = $('body'); +document.addEventListener("DOMContentLoaded", () => { + const selector = '#usersuite-sidebar-nav'; + const $toc = $(selector); + const $parent = $toc.parent(); + const offset = 60; + const $body = $('body'); Toc.init($toc); - $body.scrollspy({ - target: selector, - offset: offset - }); + $body.scrollspy({target: selector, offset: offset}); $toc.affix({ - offset: { - top: function() { - return $parent.offset().top - offset; - } - } + offset: {top: () => $parent.offset().top - offset} }); // Handle window resize - $(window).resize(function(){ - $toc.affix('checkPosition'); - }); + $(window).resize(() => $toc.affix('checkPosition')); });