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
  • Loading branch information
prasanna-lmsace committed Sep 16, 2023
1 parent c41310c commit 5112546
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion classes/output/navigation/primary.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ public function export_for_template(?renderer_base $output = null): array {
$usermenu = $this->get_user_menu($output);
$this->build_usermenus($usermenu, $locationusermenus);

// Verify any of the smartmenus are going to include in the page.
$includesmartmenus = (!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
'bottombar' => $bottombardata ?? false,
'includesmartmenu' => $includesmartmenus ? true : false
];
}

Expand Down
3 changes: 3 additions & 0 deletions layout/includes/smartmenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
// Add smart menu elements to template context.
$templatecontext['menubar'] = $primarymenu['menubar'] ?? [];
$templatecontext['bottombar'] = $primarymenu['bottombar'] ?? [];
// Verify the smart menu contains any menus to show.
$smartmenuincluded = (isset($primarymenu['includesmartmenu']) && !empty($primarymenu['includesmartmenu']));
$templatecontext['includesmartmenu'] = $smartmenuincluded ? 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 5112546

Please sign in to comment.