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,30 +1,33 @@
$(document).ready(function() { $(document).ready(function() {
var hash = decodeURIComponent(location.hash.substr(1)) 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 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 // Check if FAQ is a number and is not lower than 0
if (!faqId || faqId < 0) { if (isNaN(faqId) || faqId < 0) {
return return
} }
var selectedCollapse = $("#faqcollapse-heading-" + faqId) var selectedCollapse = $("#faqcollapse-heading-" + faqId)
// Check if element exists // Check if element exists
if (!selectedCollapse.length) { if (selectedCollapse.length) {
return // Toggle collapse
selectedCollapse.parent().find(".collapse").collapse({
toggle: true
})
// Scroll body
$("html,body").animate({
scrollTop: selectedCollapse.offset().top - 60
}, "slow")
} }
}
// Toggle collapse if (hash.startsWith("faq")) {
selectedCollapse.parent().find(".collapse").collapse({ displayFaq(hash)
toggle: true
})
// Scroll body
$("html,body").animate({
scrollTop: selectedCollapse.offset().top - 60
},"slow")
} }
$(".copy-faq-url").click(function (e) { $(".copy-faq-url").click(function (e) {