diff --git a/lib/navigationlib.php b/lib/navigationlib.php index f56a6ef65c7..09cfc188f1e 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -116,6 +116,8 @@ class navigation_node implements renderable { public $forceopen = false; /** @var array An array of CSS classes for the node */ public $classes = array(); + /** @var array An array of HTML attributes for the node */ + public $attributes = []; /** @var navigation_node_collection An array of child nodes */ public $children = array(); /** @var bool If set to true the node will be recognised as active */ @@ -559,6 +561,16 @@ class navigation_node implements renderable { return true; } + /** + * Adds an HTML attribute to this node. + * + * @param string $name + * @param string $value + */ + public function add_attribute(string $name, string $value): void { + $this->attributes[] = ['name' => $name, 'value' => $value]; + } + /** * Removes a CSS class from this node. * @@ -2290,6 +2302,7 @@ class global_navigation extends navigation_node { null, $section->id, new pix_icon('i/section', '')); $sectionnode->nodetype = navigation_node::NODETYPE_BRANCH; $sectionnode->hidden = (!$section->visible || !$section->available); + $sectionnode->add_attribute('data-section-name-for', $section->id); if ($this->includesectionnum !== false && $this->includesectionnum == $section->section) { $this->load_section_activities($sectionnode, $section->section, $activities); } diff --git a/lib/templates/navbar.mustache b/lib/templates/navbar.mustache index c1834d84c19..6e94273bfe4 100644 --- a/lib/templates/navbar.mustache +++ b/lib/templates/navbar.mustache @@ -68,11 +68,21 @@ }}{{#get_items}} {{#has_action}}