Skip to content

Commit

Permalink
Add showActive parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
malberts committed Nov 17, 2023
1 parent 5a30a22 commit 4053f47
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 17 deletions.
11 changes: 9 additions & 2 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions layouts/clean.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
This file is part of the MediaWiki skin Chameleon.
@copyright 2013 - 2021, Stephan Gambke
Expand All @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.1
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">

<component type="NavbarHorizontal" >
<modification type="ShowOnlyFor" permission="edit"/>
Expand Down
4 changes: 2 additions & 2 deletions layouts/fixedhead.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
This file is part of the MediaWiki skin Chameleon.
@copyright 2013 - 2021, Stephan Gambke
Expand All @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">

<component type="NavbarHorizontal">
<modification type="Sticky"/>
Expand Down
11 changes: 9 additions & 2 deletions layouts/layout.rng
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<grammar
xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
ns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng"
ns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
>

<a:documentation>
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)
</a:documentation>
Expand Down Expand Up @@ -325,6 +325,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<data type="string"/>
</attribute>
</optional>

<optional>
<attribute name="showActive" a:defaultValue="no">
<ref name="BoolValues"/>
</attribute>
</optional>

</define>

<define name="Component" combine="choice">
Expand Down
4 changes: 2 additions & 2 deletions layouts/navhead.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
This file is part of the MediaWiki skin Chameleon.
@copyright 2013 - 2021, Stephan Gambke
Expand All @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<component type="NavbarHorizontal">
<component type="Logo" position="head"/>
<component type="NavMenu" flatten="navigation" />
Expand Down
4 changes: 2 additions & 2 deletions layouts/standard.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
This file is part of the MediaWiki skin Chameleon.
@copyright 2013 - 2021, Stephan Gambke
Expand All @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<grid class="flex-fill">
<row>
<cell class="flex-grow-0">
Expand Down
4 changes: 2 additions & 2 deletions layouts/stickyhead.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
This file is part of the MediaWiki skin Chameleon.
@copyright 2013 - 2021, Stephan Gambke
Expand All @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">

<component type="NavbarHorizontal" class="small bg-darker">
<component type="Menu" message="secondary-menu"/>
Expand Down
12 changes: 10 additions & 2 deletions src/Components/NavMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
}

}

0 comments on commit 4053f47

Please sign in to comment.