Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Apr 16, 2024
1 parent 49ebe24 commit c397763
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 53 deletions.
7 changes: 2 additions & 5 deletions amd/src/submenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Theme Boost Union - Initializes and handles events of the sub menus in smart menu.
* Theme Boost Union - JS code to initialize and handle events of the sub menus in smart menu.
*
* @module theme_boost_union/submenu
* @copyright 2023 bdecent GmbH <https://bdecent.de>
* @copyright 2024 bdecent GmbH <https://bdecent.de>
* @copyright based on code from core/usermenu by Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down Expand Up @@ -241,9 +241,7 @@ const moreMenuCardItem = () => {
innerMenu.style.right = 0;
}
}

};

};

/**
Expand All @@ -260,7 +258,6 @@ const init = () => {

// Calculate and setup the card menus width and positions inside the more menu.
moreMenuCardItem();

};

export default {
Expand Down
70 changes: 35 additions & 35 deletions classes/output/navigation/primary.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,50 +96,49 @@ public function export_for_template(?renderer_base $output = null): array {
return parent::export_for_template($output);
}

// Get the menus for the main menu.
$mainmenu = smartmenu::get_menus_forlocation(smartmenu::LOCATION_MAIN, $smartmenus);

// Convert the children menu items into submenus.
$primarymenu = $this->convert_submenus($mainmenu);

// Separate the menus for the menubar.
$menubarmenus = smartmenu::get_menus_forlocation(smartmenu::LOCATION_MENU, $smartmenus);

// Convert the children menu items into submenus.
$menubarmenus = $this->convert_submenus($menubarmenus);

// Separate the menus for the user menus.
// Get the menus for the main menu loation.
// And convert the children menu items into submenus.
$locationmainmenu = smartmenu::get_menus_forlocation(smartmenu::LOCATION_MAIN, $smartmenus);
$locationmainmenuconverted = $this->convert_submenus($locationmainmenu);

// Separate the menus for the menubar location.
// And convert the children menu items into submenus.
$locationmenubarmenu = smartmenu::get_menus_forlocation(smartmenu::LOCATION_MENU, $smartmenus);
$locationmenubarmenuconverted = $this->convert_submenus($locationmenubarmenu);

// Separate the menus for the usermenu location.
// (There is no need to concert the submenus in this case).
$locationusermenus = smartmenu::get_menus_forlocation(smartmenu::LOCATION_USER, $smartmenus);

// Separate the menus for the bottom menu.
$locationbottom = smartmenu::get_menus_forlocation(smartmenu::LOCATION_BOTTOM, $smartmenus);

// Convert the children menu items of bottom bar into submenus.
$locationbottomsubmenu = $this->convert_submenus($locationbottom);
// Separate the menus for the bottom menu location.
// And convert the children menu items into submenus.
$locationbottommenu = smartmenu::get_menus_forlocation(smartmenu::LOCATION_BOTTOM, $smartmenus);
$locationbottommenuconverted = $this->convert_submenus($locationbottommenu);

// Primary menu.
// Merge the smart menu nodes which contain the main menu location with the primary and custom menu nodes.
$menudata = array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $primarymenu);
$moremenu = new \core\navigation\output\more_menu((object) $menudata, 'navbar-nav', false);
$mainmenudata = array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $locationmainmenuconverted);
$moremenu = new \core\navigation\output\more_menu((object) $mainmenudata, 'navbar-nav', false);

// Menubar.
// Items of menus only added in the menubar.
// Removed the menu nodes from menubar, each item will be displayed as menu in menubar.
if (!empty($menubarmenus)) {
$menubarmoremenu = new \core\navigation\output\more_menu((object) $menubarmenus, 'navbar-nav-menu-bar', false);
if (!empty($locationmenubarmenuconverted)) {
$menubarmoremenu = new \core\navigation\output\more_menu((object) $locationmenubarmenuconverted,
'navbar-nav-menu-bar', false);
}

// Bottom bar.
// Include the menu navigation menus to the mobile menu when the bottom bar doesn't have any menus.
$mobileprimarynav = (!empty($locationbottom))
? array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $locationbottom)
: array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $mainmenu);
$mobileprimarynav = (!empty($locationbottommenu))
? array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $locationbottommenu)
: array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $locationmainmenu);

if (!empty($locationbottom)) {
$mobilemenudata = array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $locationbottomsubmenu);
if (!empty($locationbottommenu)) {
$mobilemenudata = array_merge($this->get_primary_nav(), $this->get_custom_menu($output), $locationbottommenuconverted);
$bottombar = new \core\navigation\output\more_menu((object) $mobilemenudata, 'navbar-nav-bottom-bar', false);
$bottombardata = $bottombar->export_for_template($output);
$bottombardata['drawer'] = (!empty($locationbottom)) ? true : false;
$bottombardata['drawer'] = (!empty($locationbottommenu)) ? true : false;
}

// Usermenu.
Expand All @@ -151,7 +150,7 @@ public function export_for_template(?renderer_base $output = null): array {
// Check if any of the smartmenus are going to be included on the page.
// This is used as flag to include the smart menu's JS file in mustache templates later
// as well as for controlling the smart menu SCSS.
$includesmartmenu = (!empty($mainmenu) || !empty($menubarmenus) || !empty($locationusermenus) || !empty($locationbottom));
$includesmartmenu = (!empty($locationmainmenu) || !empty($locationmenubarmenu) || !empty($locationusermenus) || !empty($locationbottommenu));

return [
'mobileprimarynav' => $mobileprimarynav,
Expand Down Expand Up @@ -240,33 +239,33 @@ public function get_user_menu(renderer_base $output): array {
*
* @param array $usermenu
* @param array $menus
* @param bool $forusermenu If false the divider and logout nodes are unchanged.
* @param bool $forusermenu If false, the divider and logout nodes are unchanged.
* @return void
*/
public function build_usermenus(&$usermenu, $menus, $forusermenu=true) {
public function build_usermenus(&$usermenu, $menus, $forusermenu = true) {

if (empty($menus)) {
return [];
}

$logout = !empty($usermenu['items']) ? array_pop($usermenu['items']) : '';
foreach ($menus as $menu) {

// Cast the menu to an object, if needed.
$menu = !is_object($menu) ? (object) $menu : $menu;

// Menu with empty childrens.
if (!isset($menu->children)) {
$menu->submenulink = false;
$menu->link = !(isset($menu->divider) && $menu->divider);
$menu->submenulink = false;
$usermenu['items'][] = $menu;
continue;
}

// Menu with children, split the children and push them into submenus.
if (isset($menu->submenuid)) {
$children = $menu->children;

$menu->link = false;
$menu->submenulink = true;
$children = $menu->children;

// Add the second level menus list before the course list to the user menu.
// This will have the effect that, when opening the third level submenus, the transition will go to the right.
Expand Down Expand Up @@ -315,6 +314,7 @@ public function build_usermenus(&$usermenu, $menus, $forusermenu=true) {
}
}

// If the menu is to be used as user menu.
if ($forusermenu) {
// Include the divider after smart menus items to make difference from logout.
$divider = [
Expand Down
16 changes: 3 additions & 13 deletions templates/smartmenus-moremenu-children.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
This is a modified version of core/moremenu_children.
Modifications compared to the original template:
* Added the carousel-target data to the li item.
* Main items are wrapped with carousel-item.
* Second-level submenus are rendered as separate carousel items.
* Added the carousel-target data to the li item.
* Main items are wrapped with carousel-item.
* Second-level submenus are rendered as separate carousel items.
Example context (json):
{
Expand All @@ -48,12 +48,9 @@
{{{text}}}
</a>
<div class="dropdown-menu boost-union-moremenu" role="menu" id="drop-down-menu-{{moremenuid}}" aria-labelledby="drop-down-{{moremenuid}}">

<div data-toggle="smartmenu-carousel" class="carousel slide" data-touch="false" data-interval="false" data-keyboard="false">
<div class="carousel-inner">

{{#children}}

{{! Smart menus }}
{{#submenuid}}
<div id="carousel-item-main" class="carousel-item active" role="menu" tabindex="-1">
Expand All @@ -63,7 +60,6 @@
{{#belowhelptext}}{{#helptext}}<div class="menu-description">{{{helptext}}}</div>{{/helptext}}{{/belowhelptext}}
</div>
{{/submenuid}}

{{! Moodle core menus }}
{{^items}}
{{^divider}}
Expand All @@ -83,20 +79,16 @@
<a class="dropdown-item {{#itemdata.classes}}{{.}} {{/itemdata.classes}}" role="menuitem" href="{{{url}}}{{{action}}}" {{#isactive}}aria-current="true"{{/isactive}} tabindex="-1"
{{#tooltip}}title="{{.}}" data-toggle="tooltip"{{/tooltip}}{{^tooltip}}{{#title}}title="{{.}}"{{/title}}{{/tooltip}}
{{#attributes}}{{name}}="{{value}}" {{/attributes}}

>
{{{text}}}
</a>
{{/is_action_link}}

{{/divider}}
{{#divider}}
<div class="dropdown-divider"></div>
{{/divider}}
{{/items}}

{{/children}}

{{#submenus}}
<div id="carousel-item-{{id}}" role="menu" class="carousel-item submenu" tabindex="-1" aria-label="{{title}}">
<div class="d-flex flex-column h-100">
Expand All @@ -114,9 +106,7 @@
</div>
</div>
{{/submenus}}

</div>

</div>
</div>
</li>
Expand Down

0 comments on commit c397763

Please sign in to comment.