Merge branch 'MDL-84801-403' of https://github.com/HuongNV13/moodle into MOODLE_403_STABLE
This commit is contained in:
+1
-1
@@ -6,6 +6,6 @@ define("core_form/collapsesections",["exports","jquery","core/pending"],(functio
|
||||
* @copyright 2021 Bas Brands
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since 4.0
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_pending=_interopRequireDefault(_pending);const SELECTORS_FORM=".mform",SELECTORS_FORMHEADER=".fheader",SELECTORS_FORMCONTAINER="fieldset > .fcontainer",CLASSES_SHOW="show",CLASSES_COLLAPSED="collapsed",CLASSES_HIDDEN="d-none";_exports.init=collapsesections=>{const pendingPromise=new _pending.default("core_form/collapsesections"),collapsemenu=document.querySelector(collapsesections),formParent=collapsemenu.closest(SELECTORS_FORM),formContainers=formParent.querySelectorAll(SELECTORS_FORMCONTAINER);collapsemenu.addEventListener("keydown",(e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),collapsemenu.click())}));let formcontainercount=0,expandedcount=0;formContainers.forEach((container=>{container.parentElement.classList.contains(CLASSES_HIDDEN)||formcontainercount++,container.classList.contains(CLASSES_SHOW)&&expandedcount++})),formcontainercount===expandedcount&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0)),collapsemenu.addEventListener("click",(()=>{let action="hide";collapsemenu.classList.contains(CLASSES_COLLAPSED)&&(action="show"),formContainers.forEach((container=>(0,_jquery.default)(container).collapse(action)))}));const collapseElementIds=[...formParent.querySelectorAll(SELECTORS_FORMHEADER)].map(((element,index)=>(element.id=element.id||"collapseElement-".concat(index),element.id)));collapsemenu.setAttribute("aria-controls",collapseElementIds.join(" ")),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("hidden.bs.collapse",(()=>{[...formContainers].every((container=>!container.classList.contains(CLASSES_SHOW)))&&(collapsemenu.classList.add(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!1))})),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("shown.bs.collapse",(()=>{[...formContainers].every((container=>container.classList.contains(CLASSES_SHOW)))&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0))})),pendingPromise.resolve()}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_pending=_interopRequireDefault(_pending);const SELECTORS_FORM=".mform",SELECTORS_FORMHEADER=".fheader",SELECTORS_FORMCONTAINER="fieldset > .fcontainer",CLASSES_SHOW="show",CLASSES_COLLAPSED="collapsed",CLASSES_HIDDEN="d-none";_exports.init=collapsesections=>{const pendingPromise=new _pending.default("core_form/collapsesections"),collapsemenu=document.querySelector(collapsesections),formParent=collapsemenu.closest(SELECTORS_FORM),formContainers=formParent.querySelectorAll(SELECTORS_FORMCONTAINER);collapsemenu.addEventListener("keydown",(e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),collapsemenu.click())}));let formcontainercount=0,expandedcount=0;formContainers.forEach((container=>{container.parentElement.classList.contains(CLASSES_HIDDEN)||formcontainercount++,container.classList.contains(CLASSES_SHOW)&&expandedcount++})),formcontainercount===expandedcount&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0)),collapsemenu.addEventListener("click",(()=>{let action="hide";if(collapsemenu.classList.contains(CLASSES_COLLAPSED)&&(action="show"),formContainers.length){const pendingPromiseToggle=new _pending.default("core_form/collapsesections:toggle-"+action);formContainers.forEach(((container,index,array)=>{(0,_jquery.default)(container).collapse(action),index===array.length-1&&pendingPromiseToggle.resolve()}))}}));const collapseElementIds=[...formParent.querySelectorAll(SELECTORS_FORMHEADER)].map(((element,index)=>(element.id=element.id||"collapseElement-".concat(index),element.id)));collapsemenu.setAttribute("aria-controls",collapseElementIds.join(" ")),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("hidden.bs.collapse",(()=>{[...formContainers].every((container=>!container.classList.contains(CLASSES_SHOW)))&&(collapsemenu.classList.add(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!1))})),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("shown.bs.collapse",(()=>{[...formContainers].every((container=>container.classList.contains(CLASSES_SHOW)))&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0))})),pendingPromise.resolve()}}));
|
||||
|
||||
//# sourceMappingURL=collapsesections.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -82,7 +82,15 @@ export const init = collapsesections => {
|
||||
action = 'show';
|
||||
}
|
||||
|
||||
formContainers.forEach(container => $(container).collapse(action));
|
||||
if (formContainers.length) {
|
||||
const pendingPromiseToggle = new Pending('core_form/collapsesections:toggle-' + action);
|
||||
formContainers.forEach((container, index, array) => {
|
||||
$(container).collapse(action);
|
||||
if (index === array.length - 1) {
|
||||
pendingPromiseToggle.resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure collapse menu button adds aria-controls attribute referring to each collapsible element.
|
||||
|
||||
@@ -167,7 +167,7 @@ class behat_forms extends behat_base {
|
||||
|
||||
// Different try & catch as we can have expanded fieldsets with advanced fields on them.
|
||||
try {
|
||||
|
||||
$this->wait_for_pending_js();
|
||||
// Expand all fields xpath.
|
||||
$showmorexpath = "//a[normalize-space(.)='" . get_string('showmore', 'form') . "']" .
|
||||
"[contains(concat(' ', normalize-space(@class), ' '), ' moreless-toggler')]";
|
||||
@@ -177,22 +177,23 @@ class behat_forms extends behat_base {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getSession()->getDriver() instanceof \DMore\ChromeDriver\ChromeDriver) {
|
||||
// Chrome Driver produces unique xpaths for each element.
|
||||
foreach ($showmores as $showmore) {
|
||||
$showmore->click();
|
||||
$js = <<<EOF
|
||||
require(['core/pending'], function(Pending) {
|
||||
const query = document.evaluate("{$showmorexpath}", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
if (query.snapshotLength > 0) {
|
||||
const pendingPromise = new Pending('showmore:expand');
|
||||
for (let i = 0, length = query.snapshotLength; i < length; ++i) {
|
||||
query.snapshotItem(i).click();
|
||||
if (i === length - 1) {
|
||||
pendingPromise.resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Funny thing about this, with findAll() we specify a pattern and each element matching the pattern
|
||||
// is added to the array with of xpaths with a [0], [1]... sufix, but when we click on an element it
|
||||
// does not matches the specified xpath anymore (now is a "Show less..." link) so [1] becomes [0],
|
||||
// that's why we always click on the first XPath match, will be always the next one.
|
||||
$iterations = count($showmores);
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$showmores[0]->click();
|
||||
}
|
||||
}
|
||||
});
|
||||
EOF;
|
||||
|
||||
$this->execute_script($js);
|
||||
$this->wait_for_pending_js();
|
||||
} catch (ElementNotFoundException $e) {
|
||||
// We continue with the test.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user