Skip to content

Commit

Permalink
Smart menu JS included to the page based on menus existence.
Browse files Browse the repository at this point in the history
- Fix #357, UN-231
  • Loading branch information
prasanna-lmsace authored and abias committed Sep 26, 2023
1 parent 6ec2175 commit 8d2a3f4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2023-09-22 - Improvement: Smartmenus.js is only be added to the page if smart menus are really used, solves #357
* 2023-09-22 - Bugfix: Smart menu language restriction did not respect switching language with the language switcher, solves #358.
* 2023-09-26 - Bugfix: The smart menu third level arrow was broken, solves #402.
* 2023-09-22 - Make codechecker happier
Expand Down
6 changes: 6 additions & 0 deletions classes/output/navigation/primary.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,19 @@ public function export_for_template(?renderer_base $output = null): array {
$usermenu = $this->get_user_menu($output);
$this->build_usermenus($usermenu, $locationusermenus);

// 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));

return [
'mobileprimarynav' => $mobileprimarynav,
'moremenu' => $moremenu->export_for_template($output),
'menubar' => isset($menubarmoremenu) ? $menubarmoremenu->export_for_template($output) : false,
'lang' => !isloggedin() || isguestuser() ? $languagemenu->export_for_template($output) : [],
'user' => $usermenu ?? [],
'bottombar' => $bottombardata ?? false,
'includesmartmenu' => $includesmartmenu ? true : false
];
}

Expand Down
4 changes: 4 additions & 0 deletions layout/includes/smartmenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
// Add smart menu elements to template context.
$templatecontext['menubar'] = $primarymenu['menubar'] ?? [];
$templatecontext['bottombar'] = $primarymenu['bottombar'] ?? [];

// Add smart menu flag if the smart menu contains any menus to show.
$includesmartmenu = (isset($primarymenu['includesmartmenu']) && !empty($primarymenu['includesmartmenu']));
$templatecontext['includesmartmenu'] = $includesmartmenu ? true : false;
4 changes: 2 additions & 2 deletions templates/theme_boost/columns2.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
</html>
{{#js}}
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader', 'theme_boost/drawer', 'theme_boost_union/smartmenu'], function(Loader, Drawer, SmartMenu) {
require(['theme_boost/loader', 'theme_boost/drawer'{{#includesmartmenu}}, 'theme_boost_union/smartmenu'{{/includesmartmenu}}], function(Loader, Drawer{{#includesmartmenu}}, SmartMenu{{/includesmartmenu}}) {
Drawer.init();
M.util.js_complete('theme_boost/loader');
SmartMenu.init();
{{#includesmartmenu}}SmartMenu.init();{{/includesmartmenu}}
});
{{/js}}
4 changes: 2 additions & 2 deletions templates/theme_boost/drawers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@
</html>
{{#js}}
M.util.js_pending('theme_boost/loader');
require(['theme_boost/loader', 'theme_boost/drawer'{{#regions.offcanvas.hasblocks}},'theme_boost_union/offcanvas'{{/regions.offcanvas.hasblocks}}, 'theme_boost_union/smartmenu'], function(Loader, Drawer{{#regions.offcanvas.hasblocks}},OffCanvas{{/regions.offcanvas.hasblocks}}, SmartMenu) {
require(['theme_boost/loader', 'theme_boost/drawer'{{#regions.offcanvas.hasblocks}},'theme_boost_union/offcanvas'{{/regions.offcanvas.hasblocks}}{{#includesmartmenu}}, 'theme_boost_union/smartmenu'{{/includesmartmenu}}], function(Loader, Drawer{{#regions.offcanvas.hasblocks}},OffCanvas{{/regions.offcanvas.hasblocks}}{{#includesmartmenu}}, SmartMenu{{/includesmartmenu}}) {
Drawer.init();
M.util.js_complete('theme_boost/loader');
{{#regions.offcanvas.hasblocks}}OffCanvas.init();{{/regions.offcanvas.hasblocks}}
SmartMenu.init();
{{#includesmartmenu}}SmartMenu.init();{{/includesmartmenu}}
});
{{/js}}

0 comments on commit 8d2a3f4

Please sign in to comment.