MDL-75555 core_courseformat: Remove duplicate section collapse requests

Previously, by simulating a click, the section toggle listener
was invoked again. Instead, it now uses the bootstrap collapse
function directly.
This commit is contained in:
Justus Dieckmann
2022-08-25 23:20:06 +02:00
parent 17ee072693
commit b3e97db59c
3 changed files with 23 additions and 5 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+20 -2
View File
@@ -31,6 +31,8 @@ import CmItem from 'core_courseformat/local/content/section/cmitem';
import courseActions from 'core_course/actions';
import DispatchActions from 'core_courseformat/local/content/actions';
import * as CourseEvents from 'core_course/events';
// The jQuery module is only used for interacting with Boostrap 4. It can we removed when MDL-71979 is integrated.
import jQuery from 'jquery';
export default class Component extends BaseComponent {
@@ -232,7 +234,10 @@ export default class Component extends BaseComponent {
}
/**
* Update section collapsed.
* Update section collapsed state via bootstrap 4 if necessary.
*
* Formats that do not use bootstrap 4 must override this method in order to keep the section
* toggling working.
*
* @param {object} args
* @param {Object} args.state The state data
@@ -248,7 +253,20 @@ export default class Component extends BaseComponent {
const isCollapsed = toggler?.classList.contains(this.classes.COLLAPSED) ?? false;
if (element.contentcollapsed !== isCollapsed) {
toggler.click();
let collapsibleId = toggler.dataset.target ?? toggler.getAttribute("href");
if (!collapsibleId) {
return;
}
collapsibleId = collapsibleId.replace('#', '');
const collapsible = document.getElementById(collapsibleId);
if (!collapsible) {
return;
}
// Course index is based on Bootstrap 4 collapsibles. To collapse them we need jQuery to
// interact with collapsibles methods. Hopefully, this will change in Bootstrap 5 because
// it does not require jQuery anymore (when MDL-71979 is integrated).
jQuery(collapsible).collapse(element.contentcollapsed ? 'hide' : 'show');
}
this._refreshAllSectionsToggler(state);