margin: 0 0 1.5rem;
}
-.collapse > a:first-child {
+.collapse div > a:first-child {
background: url(../images/open.svg) no-repeat 0 50%;
padding-left: 20px;
display: block;
transition: all 0.2s ease 0s;
}
-.collapse > a:first-child:hover {
+.collapse div > a:first-child:hover {
color: #195f8d;
}
-.collapse.close > a:first-child {
+.collapse.close div > a:first-child {
background: url(../images/close.svg) no-repeat 0 50%;
}
-.collapse.close > * {
+.collapse.close div > * {
display: none;
}
-.collapse.close > a:first-child {
+.collapse.close div > a:first-child {
margin: 0;
}
-.collapse *:last-child {
+.collapse div *:last-child {
margin-bottom: 0;
}
-.collapse .alert {
+.collapse div .alert {
margin: 0 0.5em 1.5rem;
}
for (let i = 0; i < collapsables.length; i++) {
collapsables[i].classList.add('close');
- const firstChild = collapsables[i].firstElementChild;
- if (firstChild) {
- firstChild.outerHTML = firstChild.outerHTML
- .replace(/<h2/gi, '<a href="#"')
- .replace(/<\/h2>/gi, '</a>');
- firstChild.addEventListener('click', (event: Event & { currentTarget: HTMLElement }) => {
- event.preventDefault();
- if (event.currentTarget.parentElement) {
- event.currentTarget.parentElement.classList.toggle('close');
- }
- });
+ const customBlockWrapper = collapsables[i].querySelector('.custom-block-body');
+ if (customBlockWrapper) {
+ let firstChild = customBlockWrapper.firstElementChild;
+ if (firstChild) {
+ firstChild.outerHTML = firstChild.outerHTML
+ .replace(/<h2/gi, '<a href="#"')
+ .replace(/<\/h2>/gi, '</a>');
+
+ // We changed the element. It's reference is no longer correct in some
+ // browsers. Fetch it again.
+ firstChild = customBlockWrapper.firstElementChild;
+ firstChild!.addEventListener('click', (event: Event & { currentTarget: HTMLElement }) => {
+ event.preventDefault();
+ if (
+ event.currentTarget.parentElement &&
+ event.currentTarget.parentElement.parentElement
+ ) {
+ event.currentTarget.parentElement.parentElement.classList.toggle('close');
+ }
+ });
+ }
}
}
}