... |
... |
@@ -1,11 +1,11 @@ |
1 |
1 |
{ |
2 |
|
- // Animation parameters for opening and closing the expandable element |
|
2 |
+ // Animation parameters for expanding and collapsing the expandable element |
3 |
3 |
const animationDurationMillis = 300; |
4 |
4 |
const animationEasing = 'ease-in-out'; |
5 |
5 |
|
6 |
6 |
// CSS class names |
7 |
7 |
const expandableBaseClass = 'xw-expandable'; |
8 |
|
- const expandableOpenClass = 'xw-expandable_open'; |
|
8 |
+ const expandableExpandedClass = 'xw-expandable_expanded'; |
9 |
9 |
const expandableHeaderClass = 'xw-expandable_header'; |
10 |
10 |
const expandableCaretClass = 'xw-expandable_caret'; |
11 |
11 |
const expandableContentClass = 'xw-expandable_content'; |
... |
... |
@@ -12,7 +12,7 @@ |
12 |
12 |
|
13 |
13 |
let ignoreEvents = false; // Indicates to ignore click and keypress events while animating |
14 |
14 |
|
15 |
|
- // Event handler when the opening or closing of the expandable element has been triggered. |
|
15 |
+ // Event handler when the expanding or collapsing of the expandable element has been triggered. |
16 |
16 |
// Argument `toggleEvent` is a `CustomEvent` that contains the causing click or keypress event |
17 |
17 |
// as "detail" property. |
18 |
18 |
// It will be dispatched on `document` as event type "internal:expandable-toggle" whenever a |
... |
... |
@@ -38,9 +38,9 @@ |
38 |
38 |
ignoreEvents = true; |
39 |
39 |
const expandableElem = ev.currentTarget.parentNode; |
40 |
40 |
|
41 |
|
- (expandableElem.classList.contains(expandableOpenClass) |
42 |
|
- ? closeExpandable(expandableElem) |
43 |
|
- : openExpandable(expandableElem) |
|
41 |
+ (expandableElem.classList.contains(expandableExpandedClass) |
|
42 |
+ ? collapseExpandable(expandableElem) |
|
43 |
+ : expandExpandable(expandableElem) |
44 |
44 |
).then(() => (ignoreEvents = false)); |
45 |
45 |
} |
46 |
46 |
|
... |
... |
@@ -52,8 +52,8 @@ |
52 |
52 |
return expandableElem.querySelector(`& > .${expandableContentClass}`); |
53 |
53 |
} |
54 |
54 |
|
55 |
|
- async function openExpandable(expandableElem) { |
56 |
|
- expandableElem.classList.add(expandableOpenClass); |
|
55 |
+ async function expandExpandable(expandableElem) { |
|
56 |
+ expandableElem.classList.add(expandableExpandedClass); |
57 |
57 |
const contentElem = getExpandableContent(expandableElem); |
58 |
58 |
const caretElem = getExpandableCaret(expandableElem); |
59 |
59 |
|
... |
... |
@@ -67,12 +67,12 @@ |
67 |
67 |
{ transform: 'rotate(90deg)' }, |
68 |
68 |
]); |
69 |
69 |
|
70 |
|
- closeOtherExpandablesOfAccordionIfRequired(expandableElem); |
|
70 |
+ collapseOtherExpandablesOfAccordionIfRequired(expandableElem); |
71 |
71 |
await Promise.any([animateContent, animateCaret]); |
72 |
72 |
} |
73 |
73 |
|
74 |
|
- async function closeExpandable(expandableElem) { |
75 |
|
- if (!expandableElem.classList.contains(expandableOpenClass)) { |
|
74 |
+ async function collapseExpandable(expandableElem) { |
|
75 |
+ if (!expandableElem.classList.contains(expandableExpandedClass)) { |
76 |
76 |
return; |
77 |
77 |
} |
78 |
78 |
|
... |
... |
@@ -90,7 +90,7 @@ |
90 |
90 |
]); |
91 |
91 |
|
92 |
92 |
await Promise.any([animateContent, animateCaret]); |
93 |
|
- expandableElem.classList.remove(expandableOpenClass); |
|
93 |
+ expandableElem.classList.remove(expandableExpandedClass); |
94 |
94 |
} |
95 |
95 |
|
96 |
96 |
async function animate(elem, keyframes) { |
... |
... |
@@ -136,18 +136,18 @@ |
136 |
136 |
return accordionExpandables; |
137 |
137 |
} |
138 |
138 |
|
139 |
|
- function closeOtherExpandablesOfAccordionIfRequired(expandableElem) { |
|
139 |
+ function collapseOtherExpandablesOfAccordionIfRequired(expandableElem) { |
140 |
140 |
const expandablesOfAccordion = getAccordionExpandables(expandableElem); |
141 |
141 |
|
142 |
|
- const closingOfOtherExpandablesRequired = expandablesOfAccordion.some((elem) => |
|
142 |
+ const collapsingOfOtherExpandablesRequired = expandablesOfAccordion.some((elem) => |
143 |
143 |
elem.hasAttribute('data-force-exclusive-accordion'), |
144 |
144 |
); |
145 |
145 |
|
146 |
|
- if (!closingOfOtherExpandablesRequired) { |
|
146 |
+ if (!collapsingOfOtherExpandablesRequired) { |
147 |
147 |
return; |
148 |
148 |
} |
149 |
149 |
|
150 |
|
- expandablesOfAccordion.filter((it) => it !== expandableElem).forEach(closeExpandable); |
|
150 |
+ expandablesOfAccordion.filter((it) => it !== expandableElem).forEach(collapseExpandable); |
151 |
151 |
} |
152 |
152 |
|
153 |
153 |
// Whenever a `click` or `keypress`event is dispatched on the header of an expandable element |