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() { $(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 // Toggle collapse
selectedCollapse.parent().find(".collapse").collapse({ selectedCollapse.parent().find(".collapse").collapse({
toggle: true toggle: true
@ -26,6 +24,11 @@ $(document).ready(function() {
scrollTop: selectedCollapse.offset().top - 60 scrollTop: selectedCollapse.offset().top - 60
}, "slow") }, "slow")
} }
}
if (hash.startsWith("faq")) {
displayFaq(hash)
}
$(".copy-faq-url").click(function (e) { $(".copy-faq-url").click(function (e) {
e.preventDefault() e.preventDefault()