Skip to content

Commit

Permalink
Merge branch 'MDL-75784-400' of https://github.com/JBThong/moodle int…
Browse files Browse the repository at this point in the history
…o MOODLE_400_STABLE
  • Loading branch information
andrewnicols committed Nov 4, 2022
2 parents dc02b1b + 744cd41 commit d0c489d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/form/amd/build/collapsesections.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/form/amd/build/collapsesections.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions lib/form/amd/src/collapsesections.js
Expand Up @@ -44,6 +44,7 @@ export const init = collapsesections => {
// All jQuery in this code can be replaced when MDL-71979 is integrated (move to Bootstrap 5).
const pendingPromise = new Pending('core_form/collapsesections');
const collapsemenu = document.querySelector(collapsesections);
const formParent = collapsemenu.closest('form');
collapsemenu.addEventListener('keydown', e => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
Expand Down Expand Up @@ -71,7 +72,7 @@ export const init = collapsesections => {
action = 'show';
}

document.querySelectorAll(SELECTORS.FORMCONTAINER).forEach((collapsecontainer) => {
formParent.querySelectorAll(SELECTORS.FORMCONTAINER).forEach((collapsecontainer) => {
$(collapsecontainer).collapse(action);
});
});
Expand All @@ -85,26 +86,29 @@ export const init = collapsesections => {
collapsemenu.setAttribute('aria-controls', collapseElementIds.join(' '));

$(SELECTORS.FORMCONTAINER).on('hidden.bs.collapse', () => {
let allcollapsed = true;
$(SELECTORS.FORMCONTAINER).each((_, collapsecontainer) => {
let allCollapsed = true;

formParent.querySelectorAll(SELECTORS.FORMCONTAINER).forEach((collapsecontainer) => {
if (collapsecontainer.classList.contains(CLASSES.SHOW)) {
allcollapsed = false;
allCollapsed = false;
}
});
if (allcollapsed) {

if (allCollapsed) {
collapsemenu.classList.add(CLASSES.COLLAPSED);
collapsemenu.setAttribute('aria-expanded', false);
}
});
$(SELECTORS.FORMCONTAINER).on('shown.bs.collapse', () => {
var allexpanded = true;
$(SELECTORS.FORMCONTAINER).each((_, collapsecontainer) => {
let allExpanded = true;

formParent.querySelectorAll(SELECTORS.FORMCONTAINER).forEach((collapsecontainer) => {
if (!collapsecontainer.classList.contains(CLASSES.SHOW)) {
allexpanded = false;
allExpanded = false;
}
});

if (allexpanded) {
if (allExpanded) {
collapsemenu.classList.remove(CLASSES.COLLAPSED);
collapsemenu.setAttribute('aria-expanded', true);
}
Expand Down

0 comments on commit d0c489d

Please sign in to comment.