mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-72530-master' of git://github.com/mihailges/moodle
This commit is contained in:
commit
b984315b38
2
lib/amd/build/moremenu.min.js
vendored
2
lib/amd/build/moremenu.min.js
vendored
@ -1,2 +1,2 @@
|
||||
define ("core/moremenu",["exports","jquery","core/menu_navigation"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var f={regions:{moredropdown:"[data-region=\"moredropdown\"]",morebutton:"[data-region=\"morebutton\"]"},classes:{dropdownitem:"dropdown-item",dropdownmoremenu:"dropdownmoremenu",hidden:"d-none",active:"active",nav:"nav",navlink:"nav-link",observed:"observed"},attributes:{menu:"[role=\"menu\"]",dropdowntoggle:"[data-toggle=\"dropdown\"]"}},g=function(a){var b=a.parentNode.offsetHeight+1,c=a.querySelector(f.regions.moredropdown),d=a.querySelector(f.regions.morebutton);if(a.offsetHeight>b){d.classList.remove(f.classes.hidden);var e=Array.from(a.children).reverse();e.forEach(function(c){if(!c.classList.contains(f.classes.dropdownmoremenu)){if(a.offsetHeight>b){var d=a.removeChild(c);h(a,d,!0)}}})}else{if("children"in c){var j=Array.from(c.children);j.forEach(function(d){if(a.offsetHeight<b&&"true"!==d.dataset.forceintomoremenu){var e=c.removeChild(d);i(a,e)}});if(0===j.length){d.classList.add(f.classes.hidden)}}if(a.offsetHeight>b){g(a)}}a.parentNode.classList.add(f.classes.observed)},h=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!1,d=a.querySelector(f.regions.moredropdown),e=a.querySelector(f.attributes.dropdowntoggle),g=b.querySelector("."+f.classes.navlink);if(g.classList.contains(f.classes.active)){e.classList.add(f.classes.active)}g.classList.remove(f.classes.navlink);g.classList.add(f.classes.dropdownitem);if(c){d.prepend(b)}else{d.append(b)}},i=function(a,b){var c=a.querySelector(f.regions.morebutton),d=a.querySelector(f.attributes.dropdowntoggle),e=b.querySelector("."+f.classes.dropdownitem);if(e.classList.contains(f.classes.active)){d.classList.remove(f.classes.active)}e.classList.remove(f.classes.dropdownitem);e.classList.add(f.classes.navlink);a.insertBefore(b,c)},j=function(a){a.firstElementChild.querySelector("[role=\"menuitem\"]").setAttribute("tabindex","0");if("children"in a){var d=a.querySelector(f.regions.morebutton),e=Array.from(a.children);e.forEach(function(b){if(!b.classList.contains(f.classes.dropdownmoremenu)&&"true"===b.dataset.forceintomoremenu){h(a,b,!1);if(d.classList.contains(f.classes.hidden)){d.classList.remove(f.classes.hidden)}}})}g(a);(0,c.default)(a);window.addEventListener("resize",function(){g(a);(0,c.default)(a)});var i=function(a){var b=a.target.parentNode.querySelector(f.attributes.menu);if(b){b.classList.toggle("show")}a.stopPropagation()};(0,b.default)("."+f.classes.dropdownmoremenu).on("show.bs.dropdown",function(){var b=a.querySelector(f.regions.moredropdown);b.querySelectorAll(".dropdown").forEach(function(a){a.removeEventListener("click",i,!0);a.addEventListener("click",i,!0)})})};a.default=j;return a.default});
|
||||
define ("core/moremenu",["exports","jquery","core/menu_navigation"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;b=d(b);c=d(c);function d(a){return a&&a.__esModule?a:{default:a}}var f={regions:{moredropdown:"[data-region=\"moredropdown\"]",morebutton:"[data-region=\"morebutton\"]"},classes:{dropdownitem:"dropdown-item",dropdownmoremenu:"dropdownmoremenu",hidden:"d-none",active:"active",nav:"nav",navlink:"nav-link",observed:"observed"},attributes:{menu:"[role=\"menu\"]",dropdowntoggle:"[data-toggle=\"dropdown\"]"}},g=function(a){var b=a.parentNode.offsetHeight+1,c=a.querySelector(f.regions.moredropdown),d=a.querySelector(f.regions.morebutton);if(a.offsetHeight>b){d.classList.remove(f.classes.hidden);var e=Array.from(a.children).reverse();e.forEach(function(c){if(!c.classList.contains(f.classes.dropdownmoremenu)){if(a.offsetHeight>b){var d=a.removeChild(c);h(a,d,!0)}}})}else{if("children"in c){Array.from(c.children).forEach(function(d){if(a.offsetHeight<b&&"true"!==d.dataset.forceintomoremenu){var e=c.removeChild(d);i(a,e)}});if(0===Array.from(c.children).length){d.classList.add(f.classes.hidden)}}if(a.offsetHeight>b){g(a)}}a.parentNode.classList.add(f.classes.observed)},h=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:!1,d=a.querySelector(f.regions.moredropdown),e=a.querySelector(f.attributes.dropdowntoggle),g=b.querySelector("."+f.classes.navlink);if(g.classList.contains(f.classes.active)){e.classList.add(f.classes.active)}g.classList.remove(f.classes.navlink);g.classList.add(f.classes.dropdownitem);if(c){d.prepend(b)}else{d.append(b)}},i=function(a,b){var c=a.querySelector(f.regions.morebutton),d=a.querySelector(f.attributes.dropdowntoggle),e=b.querySelector("."+f.classes.dropdownitem);if(e.classList.contains(f.classes.active)){d.classList.remove(f.classes.active)}e.classList.remove(f.classes.dropdownitem);e.classList.add(f.classes.navlink);a.insertBefore(b,c)},j=function(a){a.firstElementChild.querySelector("[role=\"menuitem\"]").setAttribute("tabindex","0");if("children"in a){var d=a.querySelector(f.regions.morebutton),e=Array.from(a.children);e.forEach(function(b){if(!b.classList.contains(f.classes.dropdownmoremenu)&&"true"===b.dataset.forceintomoremenu){h(a,b,!1);if(d.classList.contains(f.classes.hidden)){d.classList.remove(f.classes.hidden)}}})}g(a);(0,c.default)(a);window.addEventListener("resize",function(){g(a);(0,c.default)(a)});var i=function(a){var b=a.target.parentNode.querySelector(f.attributes.menu);if(b){b.classList.toggle("show")}a.stopPropagation()};(0,b.default)("."+f.classes.dropdownmoremenu).on("show.bs.dropdown",function(){var b=a.querySelector(f.regions.moredropdown);b.querySelectorAll(".dropdown").forEach(function(a){a.removeEventListener("click",i,!0);a.addEventListener("click",i,!0)})})};a.default=j;return a.default});
|
||||
//# sourceMappingURL=moremenu.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -62,7 +62,6 @@ const autoCollapse = menu => {
|
||||
// If the menu items wrap and the menu height is larger than the height of the
|
||||
// parent then start pushing navlinks into the moreDropdown.
|
||||
if (menu.offsetHeight > maxHeight) {
|
||||
|
||||
moreButton.classList.remove(Selectors.classes.hidden);
|
||||
|
||||
const menuNodes = Array.from(menu.children).reverse();
|
||||
@ -79,10 +78,9 @@ const autoCollapse = menu => {
|
||||
});
|
||||
} else {
|
||||
// If the menu height is smaller than the height of the parent, then try returning navlinks to the menu.
|
||||
|
||||
if ('children' in moreDropdown) {
|
||||
const menuNodes = Array.from(moreDropdown.children);
|
||||
menuNodes.forEach(item => {
|
||||
// Iterate through the nodes within the more dropdown menu.
|
||||
Array.from(moreDropdown.children).forEach(item => {
|
||||
// Don't move the node to the more menu if it is explicitly defined that
|
||||
// this node should be displayed in the more dropdown menu at all times.
|
||||
if (menu.offsetHeight < maxHeight && item.dataset.forceintomoremenu !== 'true') {
|
||||
@ -91,9 +89,8 @@ const autoCollapse = menu => {
|
||||
moveOutOfMoreDropdown(menu, lastNode);
|
||||
}
|
||||
});
|
||||
|
||||
// If there are no more menuNodes in the dropdown we can hide the moreButton.
|
||||
if (menuNodes.length === 0) {
|
||||
// If there are no more nodes in the more dropdown menu we can hide the moreButton.
|
||||
if (Array.from(moreDropdown.children).length === 0) {
|
||||
moreButton.classList.add(Selectors.classes.hidden);
|
||||
}
|
||||
}
|
||||
|
@ -152,6 +152,7 @@ class secondary extends view {
|
||||
$context = $this->context;
|
||||
$this->headertitle = get_string('menu');
|
||||
$defaultmoremenunodes = [];
|
||||
$maxdisplayednodes = self::MAX_DISPLAYED_NAV_NODES;
|
||||
|
||||
switch ($context->contextlevel) {
|
||||
case CONTEXT_COURSE:
|
||||
@ -173,6 +174,12 @@ class secondary extends view {
|
||||
case CONTEXT_SYSTEM:
|
||||
$this->headertitle = get_string('homeheader');
|
||||
$this->load_admin_navigation();
|
||||
// If the site administration navigation was generated after load_admin_navigation().
|
||||
if ($this->has_children()) {
|
||||
// Do not explicitly limit the number of navigation nodes displayed in the site administration
|
||||
// navigation menu.
|
||||
$maxdisplayednodes = null;
|
||||
}
|
||||
$defaultmoremenunodes = $this->get_default_admin_more_menu_nodes();
|
||||
break;
|
||||
}
|
||||
@ -183,8 +190,8 @@ class secondary extends view {
|
||||
if ($this->children->count() == 1) {
|
||||
$this->children->remove('modulepage');
|
||||
}
|
||||
|
||||
$this->force_nodes_into_more_menu($defaultmoremenunodes);
|
||||
// Force certain navigation nodes to be displayed in the "more" menu.
|
||||
$this->force_nodes_into_more_menu($defaultmoremenunodes, $maxdisplayednodes);
|
||||
// Search and set the active node.
|
||||
$this->scan_for_active_node($this);
|
||||
$this->initialised = true;
|
||||
@ -345,8 +352,9 @@ class secondary extends view {
|
||||
*
|
||||
* @param array $defaultmoremenunodes Array with navigation node keys of the pre-defined nodes that
|
||||
* should be added into the "more" menu by default
|
||||
* @param int|null $maxdisplayednodes The maximum limit of navigation nodes displayed in the secondary navigation
|
||||
*/
|
||||
protected function force_nodes_into_more_menu(array $defaultmoremenunodes = []) {
|
||||
protected function force_nodes_into_more_menu(array $defaultmoremenunodes = [], ?int $maxdisplayednodes = null) {
|
||||
// Counter of the navigation nodes that are initially displayed in the secondary nav
|
||||
// (excludes the nodes from the "more" menu).
|
||||
$displayednodescount = 0;
|
||||
@ -356,8 +364,9 @@ class secondary extends view {
|
||||
continue;
|
||||
}
|
||||
// If the navigation node is in the pre-defined list of nodes that should be added by default in the
|
||||
// "more" menu or the maximum limit of displayed navigation nodes has been reached.
|
||||
if (in_array($child->key, $defaultmoremenunodes) || $displayednodescount >= self::MAX_DISPLAYED_NAV_NODES) {
|
||||
// "more" menu or the maximum limit of displayed navigation nodes has been reached (if defined).
|
||||
if (in_array($child->key, $defaultmoremenunodes) ||
|
||||
(!is_null($maxdisplayednodes) && $displayednodescount >= $maxdisplayednodes)) {
|
||||
// Force the node and its children into the "more" menu.
|
||||
$child->set_force_into_more_menu(true);
|
||||
continue;
|
||||
|
@ -247,12 +247,13 @@ class secondary_test extends \advanced_testcase {
|
||||
* @param array $secondarynavnodesdata The array which contains the data used to generate the secondary navigation
|
||||
* @param array $defaultmoremenunodes The array containing the keys of the navigation nodes which should be added
|
||||
* to the "more" menu by default
|
||||
* @param int|null $maxdisplayednodes The maximum limit of navigation nodes displayed in the secondary navigation
|
||||
* @param array $expecedmoremenunodes The array containing the keys of the expected navigation nodes which are
|
||||
* forced into the "more" menu
|
||||
* @dataProvider test_force_nodes_into_more_menu_provider
|
||||
*/
|
||||
public function test_force_nodes_into_more_menu(array $secondarynavnodesdata, array $defaultmoremenunodes,
|
||||
array $expecedmoremenunodes) {
|
||||
?int $maxdisplayednodes, array $expecedmoremenunodes) {
|
||||
global $PAGE;
|
||||
|
||||
// Create a dummy secondary navigation.
|
||||
@ -263,7 +264,7 @@ class secondary_test extends \advanced_testcase {
|
||||
|
||||
$method = new ReflectionMethod('core\navigation\views\secondary', 'force_nodes_into_more_menu');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($secondary, $defaultmoremenunodes);
|
||||
$method->invoke($secondary, $defaultmoremenunodes, $maxdisplayednodes);
|
||||
|
||||
$actualmoremenunodes = [];
|
||||
foreach ($secondary->children as $node) {
|
||||
@ -300,6 +301,7 @@ class secondary_test extends \advanced_testcase {
|
||||
'navnode2',
|
||||
'navnode4',
|
||||
],
|
||||
5,
|
||||
[
|
||||
'navnode2',
|
||||
'navnode4',
|
||||
@ -321,6 +323,27 @@ class secondary_test extends \advanced_testcase {
|
||||
'navnode2',
|
||||
'navnode4',
|
||||
],
|
||||
5,
|
||||
[
|
||||
'navnode2',
|
||||
'navnode4',
|
||||
],
|
||||
],
|
||||
'The max display limit of navigation nodes is not defined; ' .
|
||||
'navnode2 and navnode4 are forced into "more" menu by default.' =>
|
||||
[
|
||||
[
|
||||
[ 'text' => 'Navigation node 1', 'key' => 'navnode1'],
|
||||
[ 'text' => 'Navigation node 2', 'key' => 'navnode2'],
|
||||
[ 'text' => 'Navigation node 3', 'key' => 'navnode3'],
|
||||
[ 'text' => 'Navigation node 4', 'key' => 'navnode4'],
|
||||
[ 'text' => 'Navigation node 5', 'key' => 'navnode5'],
|
||||
],
|
||||
[
|
||||
'navnode2',
|
||||
'navnode4',
|
||||
],
|
||||
null,
|
||||
[
|
||||
'navnode2',
|
||||
'navnode4',
|
||||
@ -340,6 +363,7 @@ class secondary_test extends \advanced_testcase {
|
||||
[ 'text' => 'Navigation node 8', 'key' => 'navnode8'],
|
||||
],
|
||||
[],
|
||||
5,
|
||||
[
|
||||
'navnode6',
|
||||
'navnode7',
|
||||
@ -358,10 +382,26 @@ class secondary_test extends \advanced_testcase {
|
||||
[ 'text' => 'Navigation node 6', 'key' => 'navnode6'],
|
||||
],
|
||||
[],
|
||||
5,
|
||||
[
|
||||
'navnode6',
|
||||
],
|
||||
],
|
||||
'The max display limit of navigation nodes is not defined; ' .
|
||||
'no forced navigation nodes into "more" menu by default.' =>
|
||||
[
|
||||
[
|
||||
[ 'text' => 'Navigation node 1', 'key' => 'navnode1'],
|
||||
[ 'text' => 'Navigation node 2', 'key' => 'navnode2'],
|
||||
[ 'text' => 'Navigation node 3', 'key' => 'navnode3'],
|
||||
[ 'text' => 'Navigation node 4', 'key' => 'navnode4'],
|
||||
[ 'text' => 'Navigation node 5', 'key' => 'navnode5'],
|
||||
[ 'text' => 'Navigation node 6', 'key' => 'navnode6'],
|
||||
],
|
||||
[],
|
||||
null,
|
||||
[],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user