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)
This commit is contained in:
Wruczek 2021-04-16 16:57:44 +02:00
parent aa431b3436
commit 223309c428
1 changed files with 16 additions and 13 deletions

View File

@ -1,21 +1,19 @@
$(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
@ -24,7 +22,12 @@ $(document).ready(function() {
// Scroll body
$("html,body").animate({
scrollTop: selectedCollapse.offset().top - 60
},"slow")
}, "slow")
}
}
if (hash.startsWith("faq")) {
displayFaq(hash)
}
$(".copy-faq-url").click(function (e) {