|
5 | 5 | toc: false |
6 | 6 | --- |
7 | 7 |
|
8 | | -<div class="faq-accordion"> |
9 | | - {%- for category in site.data.faq %} |
10 | | - {%- assign data = category | first %} |
11 | | - <div class="faq-category"> |
12 | | - <h3>{{ data | first | capitalize }}</h3> |
13 | | - <div class="accordion"> |
14 | | - {%- assign pairs = data | last %} |
15 | | - {%- for item in pairs %} |
16 | | - {%- assign question_id = item.question | strip_html | downcase | replace: ' ', '-' | replace_regex : '[^a-z0-9-]', '' %} |
17 | | - <div class="accordion-item"> |
18 | | - <button class="accordion-button" aria-expanded="false" id="{{ question_id }}"> |
19 | | - {{ item.question | markdownify }} |
20 | | - </button> |
21 | | - <div class="accordion-content"> |
22 | | - {{ item.response | markdownify }} |
23 | | - </div> |
24 | | - </div> |
25 | | - {%- endfor %} |
26 | | - </div> |
| 8 | +{%- for category in site.data.faq %} |
| 9 | + {%- assign data = category | first %} |
| 10 | + <div class="faq-category"> |
| 11 | + <h3>{{ data | first | capitalize }}</h3> |
| 12 | + {%- assign pairs = data | last %} |
| 13 | + <div> |
| 14 | + {%- for item in pairs %} |
| 15 | + {%- assign question_id = item.question | strip_html | downcase | replace: ' ', '-' | replace_regex : '[^a-z0-9-]', '' %} |
| 16 | + <details class="faq-item" id="{{ question_id }}" name="lineage-faq"> |
| 17 | + <summary> |
| 18 | + {{ item.question | markdownify }} |
| 19 | + </summary> |
| 20 | + <div class="faq-content"> |
| 21 | + {{ item.response | markdownify }} |
| 22 | + </div> |
| 23 | + </details> |
| 24 | + {%- endfor %} |
27 | 25 | </div> |
28 | | - {%- endfor %} |
29 | | -</div> |
| 26 | + </div> |
| 27 | +{%- endfor %} |
30 | 28 |
|
31 | 29 | <style> |
32 | | -.faq-accordion .faq-category h3 { |
33 | | - margin-top: 20px; |
| 30 | +.faq-category h3 { |
| 31 | + margin-top: 1rem; |
34 | 32 | border-bottom: 1px solid var(--theme-border); |
35 | | - padding-bottom: 5px; |
| 33 | + transition: all var(--transition-speed); |
| 34 | + padding-bottom: 0rem; |
36 | 35 | } |
37 | 36 |
|
38 | | -.accordion-item { |
39 | | - margin-bottom: 0.5rem; |
40 | | - border: 1px solid var(--theme-border); |
41 | | - border-radius: 0.5rem; |
| 37 | +.faq-item { |
42 | 38 | overflow: hidden; |
| 39 | + border-radius: 0.25rem; |
| 40 | + margin-bottom: 0.25rem; |
43 | 41 | transition: all var(--transition-speed); |
| 42 | + background-color: var(--theme-bg-surface); |
44 | 43 | } |
45 | 44 |
|
46 | | -.accordion-button { |
47 | | - color: var(--theme-text); |
48 | | - background-color: var(--theme-bg-neutral); |
49 | | - transition: background-color 0.6s ease; |
50 | | - padding: 10px 15px; |
51 | | - width: 100%; |
52 | | - text-align: left; |
53 | | - border: none; |
54 | | - cursor: pointer; |
55 | | - display: flex; |
56 | | - justify-content: space-between; |
57 | | - align-items: center; |
58 | | - transition: all var(--transition-speed); |
| 45 | +.faq-item:first-child, .faq-item[open] { |
| 46 | + border-top-left-radius: 1rem; |
| 47 | + border-top-right-radius: 1rem; |
59 | 48 | } |
60 | 49 |
|
61 | | -.accordion-button::after { |
62 | | - content: '+'; |
63 | | - font-size: 1.2em; |
64 | | - font-family: monospace; |
| 50 | +.faq-item:last-child, .faq-item[open] { |
| 51 | + border-bottom-left-radius: 1rem; |
| 52 | + border-bottom-right-radius: 1rem; |
65 | 53 | } |
66 | 54 |
|
67 | | -html { |
68 | | - scroll-padding-top: 80px; |
| 55 | +.faq-item::details-content { |
| 56 | + height: 0; |
| 57 | + opacity: 0; |
| 58 | + interpolate-size: allow-keywords; |
| 59 | + transition: height var(--transition-speed), opacity var(--transition-speed); |
| 60 | +} |
| 61 | + |
| 62 | +.faq-item[open]::details-content { |
| 63 | + height: auto; |
| 64 | + opacity: 1; |
| 65 | + padding: 0rem 1rem 1rem 1rem; |
69 | 66 | } |
70 | 67 |
|
71 | | -.accordion-button[aria-expanded="true"]::after { |
72 | | - content: '-'; |
| 68 | +.faq-content p { |
| 69 | + margin: 0; |
73 | 70 | } |
74 | 71 |
|
75 | | -.accordion-button p { |
76 | | - margin: 0px; |
| 72 | +.faq-content ul { |
| 73 | + padding-left: 1rem; |
| 74 | + margin-bottom: 0; |
77 | 75 | } |
78 | 76 |
|
79 | | -.accordion-content { |
80 | | - padding: 1rem; |
81 | | - background-color: var(--theme-bg); |
82 | | - display: none; /* Initially hidden */ |
| 77 | +summary { |
| 78 | + display: flex; |
| 79 | + justify-content: space-between; |
| 80 | + align-items: center; |
| 81 | + cursor: pointer; |
| 82 | + list-style: none; |
| 83 | + background-color: var(--theme-bg-surface); |
83 | 84 | transition: background-color var(--transition-speed); |
| 85 | + font-weight: bolder; |
| 86 | +} |
| 87 | +summary::-webkit-details-marker { display: none; } |
| 88 | + |
| 89 | +summary::after { |
| 90 | + content: "+"; |
| 91 | + font-size: 1.2rem; |
| 92 | + font-weight: bold; |
| 93 | + transition: transform 0.3s ease; |
| 94 | + margin-right: 1rem; |
84 | 95 | } |
85 | 96 |
|
86 | | -.accordion-content p:last-child, .accordion-content ul { |
87 | | - margin-bottom: 0; |
| 97 | +summary p { |
| 98 | + margin: 10px 15px !important; |
| 99 | + flex-grow: 1; |
| 100 | +} |
| 101 | + |
| 102 | +details[open] summary::after { |
| 103 | + content: "−"; |
| 104 | + transform: rotate(180deg); |
| 105 | +} |
| 106 | + |
| 107 | +html { |
| 108 | + scroll-padding-top: 80px; |
88 | 109 | } |
89 | 110 | </style> |
90 | 111 |
|
91 | 112 | <script> |
92 | | -$(window).on("load", function() { |
93 | | - const accordionItems = document.querySelectorAll('.accordion-item'); |
94 | | - |
95 | | - accordionItems.forEach(item => { |
96 | | - const button = item.querySelector('.accordion-button'); |
97 | | - const content = item.querySelector('.accordion-content'); |
98 | | - |
99 | | - button.addEventListener('click', () => { |
100 | | - const isExpanded = button.getAttribute('aria-expanded') === 'true' || false; |
101 | | - button.setAttribute('aria-expanded', !isExpanded); |
102 | | - content.style.display = isExpanded ? 'none' : 'block'; |
103 | | - if (!isExpanded) { |
104 | | - window.location.hash = button.id; |
105 | | - } |
106 | | - }); |
107 | | - }); |
108 | | - |
109 | | - // Check the URL hash on page load |
110 | | - if (window.location.hash) { |
111 | | - const targetId = window.location.hash.substring(1); // Remove the '#' |
112 | | - expandAccordion(targetId); |
| 113 | +const handleFaqNavigation = () => { |
| 114 | + const hash = window.location.hash; |
| 115 | + if (hash) { |
| 116 | + const target = document.querySelector(hash); |
| 117 | + if (target && target.tagName === 'DETAILS') { |
| 118 | + target.open = true; |
| 119 | + target.scrollIntoView({ behavior: 'smooth' }); |
| 120 | + } |
113 | 121 | } |
114 | | -}); |
115 | | - |
116 | | -function expandAccordion(questionId) { |
117 | | - const buttonToExpand = document.getElementById(questionId); |
118 | | - if (buttonToExpand) { |
119 | | - const accordionItem = buttonToExpand.closest('.accordion-item'); |
120 | | - const content = accordionItem.querySelector('.accordion-content'); |
121 | | - buttonToExpand.setAttribute('aria-expanded', 'true'); |
122 | | - content.style.display = 'block'; |
| 122 | +}; |
| 123 | + |
| 124 | +window.addEventListener('load', handleFaqNavigation); |
| 125 | +window.addEventListener('hashchange', handleFaqNavigation); |
| 126 | + |
| 127 | +document.addEventListener('toggle', (event) => { |
| 128 | + var target = event.target; |
| 129 | + if (target.tagName === 'DETAILS' && target.open) { |
| 130 | + const id = target.id; |
| 131 | + if (id && `#${id}` !== window.location.hash) { |
| 132 | + history.replaceState(null, null, `#${id}`); |
| 133 | + } |
| 134 | + target.scrollIntoView({ behavior: 'smooth' }); |
123 | 135 | } |
124 | | -} |
125 | | - |
126 | | -$(window).on("hashchange", function(e) { |
127 | | - const targetId = window.location.hash.substring(1); // Remove the '#' |
128 | | - expandAccordion(targetId); |
129 | | -}); |
| 136 | +}, true); |
130 | 137 | </script> |
131 | | - |
|
0 commit comments