Skip to content

Commit fe550fa

Browse files
committed
Add open/close all button and a little styling.
1 parent b9c79fb commit fe550fa

5 files changed

Lines changed: 82 additions & 14 deletions

File tree

web/themes/custom/hoeringsportal/assets/css/hoeringsportal.scss

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
@import "custom-variables", "bootstrap-custom", "layout/aside",
2-
"layout/page-map", "layout/page-project", "base", "module/nav", "module/hero",
3-
"module/btn", "module/card", "module/footer", "module/content",
4-
"module/drupal", "module/underline", "module/timeline", "module/dialogue",
5-
"module/status-messages", "module/campaign", "module/splash", "module/lead",
6-
"module/line-clamp", "module/page-teaser",
7-
"module/responsive-image-as-background", "module/social-sharing-buttons",
8-
"module/form", "module/image-gallery", "module/spinner", "module/signup",
9-
"module/list", "module/pager", "module/paragraph-background-image",
10-
"module/paragraph-content-promotion", "module/paragraph-files",
11-
"module/paragraph-link", "module/info_box", "module/search",
12-
"module/search-page", "module/newsletter", "module/proposal",
13-
"module/animation", "module/header-v2", "module/animated-svg",
14-
"../../node_modules/slick-carousel/slick/slick";
1+
@import "custom-variables", "bootstrap-custom", "layout/aside", "layout/page-map", "layout/page-project", "base",
2+
"module/nav", "module/accordion", "module/hero", "module/btn", "module/card", "module/footer", "module/content",
3+
"module/drupal", "module/underline", "module/timeline", "module/dialogue", "module/status-messages",
4+
"module/campaign", "module/splash", "module/lead", "module/line-clamp", "module/page-teaser",
5+
"module/responsive-image-as-background", "module/social-sharing-buttons", "module/form", "module/image-gallery",
6+
"module/spinner", "module/signup", "module/list", "module/pager", "module/paragraph-background-image",
7+
"module/paragraph-content-promotion", "module/paragraph-files", "module/paragraph-link", "module/info_box",
8+
"module/search", "module/search-page", "module/newsletter", "module/proposal", "module/animation", "module/header-v2",
9+
"module/animated-svg", "../../node_modules/slick-carousel/slick/slick";
1510

1611
// We have an issue similar to https://www.drupal.org/project/bootstrap_barrio/issues/3228330#comment-14770789
1712
em.placeholder {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.accordion {
2+
--bs-accordion-border-radius: 6px;
3+
--accordion-border: 1px solid #333;
4+
--bs-accordion-btn-icon: url("data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 fill=%27none%27 stroke=%27%23008486%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3e%3cpath d=%27m2 5 6 6 6-6%27/%3e%3c/svg%3e");
5+
6+
.accordion-item {
7+
overflow: hidden;
8+
border-left: 0px;
9+
border-right: 0px;
10+
border-bottom: var(--accordion-border);
11+
}
12+
13+
.accordion-header {
14+
button {
15+
font-size: 1.1rem;
16+
font-weight: 700;
17+
18+
&:after {
19+
color: $primary;
20+
}
21+
}
22+
}
23+
24+
/* Add rounded corners to top and bottom elements*/
25+
.accordion-item:first-child {
26+
border-top: var(--accordion-border);
27+
}
28+
29+
/* Avoid shadow hanging around after opening accordion */
30+
button:focus:not(:focus-visible) {
31+
box-shadow: none;
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
document.addEventListener(
2+
"click",
3+
function (e) {
4+
const button = e.target.closest(".open-all");
5+
6+
if (button) {
7+
// Find the accordion container after the button
8+
const accordion = button.nextElementSibling;
9+
10+
if (accordion) {
11+
// Find all collapse elements within this accordion
12+
const collapseElements = accordion.querySelectorAll(".collapse");
13+
14+
// Check if any are currently hidden
15+
const anyCollapsed = Array.from(collapseElements).some(
16+
(el) => !el.classList.contains("show"),
17+
);
18+
19+
if (anyCollapsed) {
20+
// Open all using jQuery
21+
$(collapseElements).collapse("show");
22+
button.textContent = button.textContent.replace(
23+
"Open all",
24+
"Close all",
25+
);
26+
} else {
27+
// Close all using jQuery
28+
$(collapseElements).collapse("hide");
29+
button.textContent = button.textContent.replace(
30+
"Close all",
31+
"Open all",
32+
);
33+
}
34+
}
35+
}
36+
},
37+
false,
38+
);

web/themes/custom/hoeringsportal/assets/js/hoeringsportal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require("./icons.js");
2020
require("./modify-dialogue-form.js");
2121
require("./modify-dialogue-proposal-comments.js");
2222
require("./animated-svg.js");
23+
require("./accordion.js");
2324

2425
// Enable popovers.
2526
$(function () {

web/themes/custom/hoeringsportal/templates/paragraph/paragraph--accordion.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<div class="container my-2 my-lg-4">
4242
<div class="row">
4343
<div class="col-md-12">
44+
<button class="btn btn-link d-block ms-auto open-all">{{ 'Open all'|t }}</button>
4445
<div class="accordion" id="accordion-{{ paragraph.id() }}">
4546
{% block paragraph %}
4647
{% if content.field_paragraph_title['#items'] is not empty %}

0 commit comments

Comments
 (0)