From 223309c428991714bc0b8b3c4e0622a62a901f68 Mon Sep 17 00:00:00 2001 From: Wruczek Date: Fri, 16 Apr 2021 16:57:44 +0200 Subject: [PATCH] FAQ page bug fixes - link to the first question didnt worked (first question has ID of 0, which was treated as false) - sometimes the copy button didnt worked (was returning from the script without being in a function) --- src/js/faq.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/js/faq.js b/src/js/faq.js index a020fbb..ff5a18f 100644 --- a/src/js/faq.js +++ b/src/js/faq.js @@ -1,30 +1,33 @@ $(document).ready(function() { var hash = decodeURIComponent(location.hash.substr(1)) - if (hash.startsWith("faq")) { + // use an function so we can return early + function displayFaq(hash) { var faqId = parseInt(hash.substr(3)) - 1 // IDs in faq start from 0 // Check if FAQ is a number and is not lower than 0 - if (!faqId || faqId < 0) { + if (isNaN(faqId) || faqId < 0) { return } var selectedCollapse = $("#faqcollapse-heading-" + faqId) // Check if element exists - if (!selectedCollapse.length) { - return + if (selectedCollapse.length) { + // Toggle collapse + selectedCollapse.parent().find(".collapse").collapse({ + toggle: true + }) + + // Scroll body + $("html,body").animate({ + scrollTop: selectedCollapse.offset().top - 60 + }, "slow") } + } - // Toggle collapse - selectedCollapse.parent().find(".collapse").collapse({ - toggle: true - }) - - // Scroll body - $("html,body").animate({ - scrollTop: selectedCollapse.offset().top - 60 - },"slow") + if (hash.startsWith("faq")) { + displayFaq(hash) } $(".copy-faq-url").click(function (e) {