Skip to content

Commit

Permalink
fixup! MDL-81768 subsection: Display all-sections toggler on section …
Browse files Browse the repository at this point in the history
…pages
  • Loading branch information
laurentdavid committed Nov 26, 2024
1 parent 69402d5 commit 2c7ffa1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion course/format/amd/build/local/content.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion course/format/amd/build/local/content.min.js.map

Large diffs are not rendered by default.

46 changes: 19 additions & 27 deletions course/format/amd/src/local/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,15 @@ export default class Component extends BaseComponent {

const target = event.target.closest(this.selectors.TOGGLEALL);
const isAllCollapsed = target.classList.contains(this.classes.COLLAPSED);

// Find collapsible sections.
let sectionIsCollapsible = {};
const togglerDoms = this.element.querySelectorAll(this.selectors.SECTION_ITEM + " " + this.selectors.COLLAPSE);
for (let togglerDom of togglerDoms) {
sectionIsCollapsible[togglerDom.closest(this.selectors.SECTION).dataset.id] = true;
}

// Filter section list by collapsibility.
const course = this.reactive.get('course');
const sectionCollapsibleList = (course.sectionlist ?? []).filter(section => sectionIsCollapsible[section]);

// Toggle sections' collapse states.
// Sections that are visible on this page and have a collapse button.
const visibleSections = course.sectionlist.filter((sectionId) => {
const sectionElement = this.getElement(this.selectors.SECTION, sectionId);
return sectionElement && sectionElement.querySelector(this.selectors.COLLAPSE);
});
this.reactive.dispatch(
'sectionContentCollapsed',
sectionCollapsibleList,
visibleSections ?? [],
!isAllCollapsed
);
}
Expand Down Expand Up @@ -341,22 +334,21 @@ export default class Component extends BaseComponent {
}
}
);

// Refresh all-sections toggler.
if (allexpanded && allcollapsed) {
// No collapsible sections.
target.style.visibility = "hidden";
if (allcollapsed) {
target.classList.add(this.classes.COLLAPSED);
target.setAttribute('aria-expanded', false);
}
if (allexpanded) {
target.classList.remove(this.classes.COLLAPSED);
target.setAttribute('aria-expanded', true);
}
// This will hide the collapsible button if there are no sections to collapse.
if (!Object.values(sectionIsCollapsible).length) {
target.classList.add('d-none');
} else {
if (allcollapsed) {
target.classList.add(this.classes.COLLAPSED);
target.setAttribute('aria-expanded', false);
}
if (allexpanded) {
target.classList.remove(this.classes.COLLAPSED);
target.setAttribute('aria-expanded', true);
}
target.style.visibility = "visible";
target.classList.remove('d-none');
}

}

/**
Expand Down
12 changes: 4 additions & 8 deletions course/format/classes/output/local/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,10 @@ protected function add_format_data(stdClass &$data, array $haspartials, renderer
$format = $this->format;

$data->iscoursedisplaymultipage = ($format->get_course_display() == COURSE_DISPLAY_MULTIPAGE);

if (
($data->num === 0 || $data->id == $format->get_sectionid()) &&
!$data->iscoursedisplaymultipage &&
empty($section->component)
) {
$data->collapsemenu = true;
}
$hascollapsemenu = $data->num === 0 || $data->id == $format->get_sectionid(); // We are on a section page or general page.
$hascollapsemenu = $hascollapsemenu && !$data->iscoursedisplaymultipage; // We are not in multipage mode.
$hascollapsemenu = $hascollapsemenu && !$section->is_delegated(); // The section is not delegated.
$data->collapsemenu = $hascollapsemenu;

$data->contentcollapsed = $this->is_section_collapsed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
aria-expanded="true"
role="button"
data-toggle="toggleall"
style="visibility: hidden;"
>
<span class="collapseall text-nowrap">{{#str}}collapseall{{/str}}</span>
<span class="expandall text-nowrap">{{#str}}expandall{{/str}}</span>
Expand Down

0 comments on commit 2c7ffa1

Please sign in to comment.