This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
forked from CloudCannon/base-jekyll-template
-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.html
71 lines (63 loc) · 2.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
---
<section class="faq">
<div class="accordion" id="accordionFaq">
<div class="card">
{% assign sorted = site.faq | where:"lang",site.active_lang | sort: 'weight' | reverse %}
{% for item in sorted %}
{% assign question = item.path | replace:'_faq/','' | replace:'en/','' | replace:'.html','' | replace:'.md','' %}
<div class="card-header" id="heading{{ forloop.index }}">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapse{{ forloop.index }}" aria-expanded="true" aria-controls="collapse{{ forloop.index }}" data-slug="{{ item.anchor }}">
{{question}}
</button>
</h5>
</div>
<div id="collapse{{ forloop.index }}" class="collapse {% if forloop.last == true %}{{ "collapse-item-last" }}{% endif %}" aria-labelledby="heading{{ forloop.index }}" data-parent="#accordionFaq">
<div class="card-body">
{{ item | markdownify }}
</div>
</div>
{% endfor %}
</div>
</div>
</section>
<script>
//init collapse state according to URL #param
var currentURL = window.location.href;
if (currentURL.indexOf("#") > -1)
{
var slug = currentURL.substr(currentURL.indexOf("#")+1);
var toUnCollapse = document.querySelector("button[data-slug="+slug+"]");
var toUnCollapseTarget = toUnCollapse.getAttribute('data-target');
document.querySelector(toUnCollapseTarget).classList.add('show');
var sectionContainer = document.querySelector('section.content');
window.scrollTo({
left: 0,
top: toUnCollapse.offsetTop + document.querySelector('header').offsetHeight,
behavior: 'smooth'
});
//console.log("scrolled to");
//console.log(toUnCollapse.offsetTop + document.querySelector('header').offsetHeight);
}
//handles button click and append/remove slug to URL
var buttons = document.querySelectorAll("button.btn-link");
buttons.forEach((button) => {
button.addEventListener("click", function(e)
{
//wait for the animation to complete
setTimeout(() => {
if( this.getAttribute("aria-expanded") == "true" )
{
var appendix = "#" + e.target.dataset.slug;
window.history.replaceState(null, null, appendix);
}
else
{
var loc = window.location;
window.history.pushState("", document.title, loc.pathname + loc.search);
}
}, 500);
});
});
</script>