Skip to content

Commit

Permalink
review fixes pt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
bozatko committed Jan 7, 2025
1 parent 88c29a3 commit 349a81f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/bundle/Resources/config/bazinga_js_translation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ active_domains:
- 'ibexa_user_invitation'
- 'ibexa_content_type'
- 'ibexa_dropdown'
- 'ibexa_collapse'
- 'messages'
19 changes: 10 additions & 9 deletions src/bundle/Resources/public/js/scripts/core/collapse.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(function (global, doc, bootstrap, Translator) {
let toggleAllTimeout;
const TOGGLE_TIMEOUT = 200;
const toggleAllBtns = [...doc.querySelectorAll(`[data-multi-collapse-btn-id]`)];
const toggleMultiCollapseBtn = (btn, changeToCollapseAll) => {
const displayedText = changeToCollapseAll
? /*@Desc("Collapse all)*/ 'product_type.edit.section.attribute_collapse_all'
: /*@Desc("Expand all)*/ 'product_type.edit.section.attribute_expand_all';
? /*@Desc("Collapse all sections)*/ 'collapse.collapse_all'
: /*@Desc("Expand all sections)*/ 'collapse.expand_all';

btn.innerText = Translator.trans(displayedText, {}, 'ibexa_product_catalog');
btn.innerText = Translator.trans(displayedText, {}, 'ibexa_collapse');
btn.classList.toggle('ibexa-multi-collapse__btn--expand-all-label', !changeToCollapseAll);
};

Expand Down Expand Up @@ -42,16 +43,16 @@
section.addEventListener('click', () => {
const currentCollapsibleBtns = [...multiCollapseNode.querySelectorAll('[data-bs-toggle]')];

window.clearTimeout(toggleAllTimeout);
global.clearTimeout(toggleAllTimeout);

toggleAllTimeout = window.setTimeout(() => {
toggleAllTimeout = global.setTimeout(() => {
const collapsedCount = currentCollapsibleBtns.filter((btn) => btn.classList.contains('collapsed')).length;
const shouldBeToggled = collapsedCount === currentCollapsibleBtns.length || collapsedCount === 0;

if (shouldBeToggled) {
toggleMultiCollapseBtn(currentToggleAllBtn, collapsedCount === 0);
}
}, 200);
}, TOGGLE_TIMEOUT);
});
};

Expand Down Expand Up @@ -83,14 +84,14 @@

const multiCollapseBodyNode = doc.querySelector(`[data-multi-collapse-body="${collapseId}"]`);

window.clearTimeout(toggleAllTimeout);
global.clearTimeout(toggleAllTimeout);

toggleAllTimeout = window.setTimeout(() => {
toggleAllTimeout = global.setTimeout(() => {
const isExpandingAction = btn.classList.contains('ibexa-multi-collapse__btn--expand-all-label');

handleCollapseAction(multiCollapseBodyNode, isExpandingAction);
toggleMultiCollapseBtn(btn, isExpandingAction);
}, 200);
}, TOGGLE_TIMEOUT);
});
};
toggleAllBtns.forEach(attachAllElementsToggler);
Expand Down
21 changes: 21 additions & 0 deletions src/bundle/Resources/translations/ibexa_collapse.en.xliff
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
</header>
<body>
<trans-unit id="4436e5415672ea41ee48dbda15f8cb25baae6c64" resname="collapse.collapse_all">
<source>Collapse all sections</source>
<target state="new">Collapse all sections</target>
<note>key: collapse.collapse_all</note>
</trans-unit>
<trans-unit id="5f80091b211b46190856ec877c535d63aee17627" resname="collapse.expand_all">
<source>Expand all sections</source>
<target state="new">Expand all sections</target>
<note>key: collapse.expand_all</note>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 349a81f

Please sign in to comment.