From 4053f476bbb235da688678c975cc325faa6810f3 Mon Sep 17 00:00:00 2001 From: Morne Alberts Date: Fri, 17 Nov 2023 15:30:12 +0200 Subject: [PATCH] Add showActive parameter --- docs/components.md | 11 +++++++++-- docs/release-notes.md | 3 ++- layouts/clean.xml | 4 ++-- layouts/fixedhead.xml | 4 ++-- layouts/layout.rng | 11 +++++++++-- layouts/navhead.xml | 4 ++-- layouts/standard.xml | 4 ++-- layouts/stickyhead.xml | 4 ++-- src/Components/NavMenu.php | 12 ++++++++++-- 9 files changed, 40 insertions(+), 17 deletions(-) diff --git a/docs/components.md b/docs/components.md index ed93770a..0242179c 100644 --- a/docs/components.md +++ b/docs/components.md @@ -94,7 +94,7 @@ recommended. Use `fixedwidth` for a responsive fixed width layout. Use `fluid` for a full width layout, spanning the entire width of the viewport. - + Use a breakpoint name for a responsive container (since Chameleon 4.1.0). * `id`: @@ -265,7 +265,7 @@ assign a CSS id or class for styling purposes. ------------------------------------------------------------------------------- ### Component `ContentBody` -Allows to display the content body independently of the [MainContent](#component-maincontent). +Allows to display the content body independently of the [MainContent](#component-maincontent). Since Chameleon 4.2.0 @@ -783,6 +783,13 @@ Using the message _MediaWiki:Secondary-menu_: both attributes in the same `NavMenu` instance, but it can make sense to use them separately in complementary instances. +* `showActive`: + * Allowed values: Boolean (`yes`|`no`) + * Default: `no` + * Optional. + + If set a menu link will be highlighted if it is the current page. + #### Allowed Parent Elements: * [Structure](#structure) * [Cell](#cell) diff --git a/docs/release-notes.md b/docs/release-notes.md index 6753b01e..f75d309a 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,10 +1,11 @@ ## Release Notes -### Chameleon 4.2.2 +### Chameleon 4.3.0 Under development. * Fixed deprecated Hooks usage for MediaWiki 1.40 (thanks @malberts) +* Added `showActive` parameter for highlighting the current page in the `NavMenu` component (thanks @malberts) ### Chameleon 4.2.1 diff --git a/layouts/clean.xml b/layouts/clean.xml index 28fca972..dc9250f1 100644 --- a/layouts/clean.xml +++ b/layouts/clean.xml @@ -1,6 +1,6 @@ - + diff --git a/layouts/fixedhead.xml b/layouts/fixedhead.xml index 5bdef18c..3ac21816 100644 --- a/layouts/fixedhead.xml +++ b/layouts/fixedhead.xml @@ -1,6 +1,6 @@ - + diff --git a/layouts/layout.rng b/layouts/layout.rng index 24ddb274..03335479 100644 --- a/layouts/layout.rng +++ b/layouts/layout.rng @@ -25,13 +25,13 @@ with this program. If not, see . Schema for Chameleon layout files - Version 3.5 + Version 3.6 Copyright 2013 - 2021, Stephan Gambke GNU General Public License, version 3 (or any later version) @@ -325,6 +325,13 @@ with this program. If not, see . + + + + + + + diff --git a/layouts/navhead.xml b/layouts/navhead.xml index 3c125eb5..1e7ba6ac 100644 --- a/layouts/navhead.xml +++ b/layouts/navhead.xml @@ -1,6 +1,6 @@ - + diff --git a/layouts/standard.xml b/layouts/standard.xml index df9f6170..0b50c156 100644 --- a/layouts/standard.xml +++ b/layouts/standard.xml @@ -1,6 +1,6 @@ - + diff --git a/layouts/stickyhead.xml b/layouts/stickyhead.xml index f91eef92..17007099 100644 --- a/layouts/stickyhead.xml +++ b/layouts/stickyhead.xml @@ -1,6 +1,6 @@ - + diff --git a/src/Components/NavMenu.php b/src/Components/NavMenu.php index 9472b831..f6b8bd93 100644 --- a/src/Components/NavMenu.php +++ b/src/Components/NavMenu.php @@ -143,8 +143,11 @@ protected function buildMenuItemsForDropdownMenu( $menuDescription, $indent = 0 foreach ( $menuDescription['content'] as $key => $item ) { $id = $item['id'] ?? ''; - $menuitems .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $item, - [ 'tag' => 'div', 'class' => 'nav-item', 'link-class' => 'nav-link '. $id ] ); + $menuitems .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $item, [ + 'tag' => 'div', + 'class' => 'nav-item', + 'link-class' => 'nav-link '. $id . ( $this->isHrefActive( $item['href'] ) ? ' active' : '' ) + ] ); } $this->indent( - $indent ); @@ -255,4 +258,9 @@ public function getMenusToBeFlattened() { return $flatten; } + private function isHrefActive( string $href ): bool { + return filter_var( $this->getDomElement()->getAttribute( 'showActive' ), FILTER_VALIDATE_BOOLEAN ) + && $href === $this->getSkin()->getTitle()->getLocalURL(); + } + }