Skip to content

Commit b8fd6a4

Browse files
committed
Add showActive parameter
1 parent 5a30a22 commit b8fd6a4

File tree

10 files changed

+41
-23
lines changed

10 files changed

+41
-23
lines changed

docs/components.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ recommended.
9494

9595
Use `fixedwidth` for a responsive fixed width layout. Use `fluid` for a full
9696
width layout, spanning the entire width of the viewport.
97-
97+
9898
Use a breakpoint name for a responsive container (since Chameleon 4.1.0).
9999

100100
* `id`:
@@ -265,7 +265,7 @@ assign a CSS id or class for styling purposes.
265265
-------------------------------------------------------------------------------
266266
### Component `ContentBody`
267267

268-
Allows to display the content body independently of the [MainContent](#component-maincontent).
268+
Allows to display the content body independently of the [MainContent](#component-maincontent).
269269

270270
Since Chameleon 4.2.0
271271

@@ -783,6 +783,13 @@ Using the message _MediaWiki:Secondary-menu_:
783783
both attributes in the same `NavMenu` instance, but it can make sense to use
784784
them separately in complementary instances.
785785

786+
* `showActive`:
787+
* Allowed values: Boolean (`yes`|`no`)
788+
* Default: `no`
789+
* Optional.
790+
791+
If set the menu link for the current page will be highlighted.
792+
786793
#### Allowed Parent Elements:
787794
* [Structure](#structure)
788795
* [Cell](#cell)

docs/release-notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## Release Notes
22

3-
### Chameleon 4.2.2
3+
### Chameleon 4.3.0
44

55
Under development.
66

77
* Fixed deprecated Hooks usage for MediaWiki 1.40 (thanks @malberts)
8+
* Added `showActive` parameter for highlighting the current page in the `NavMenu` component (thanks @malberts)
89

910
### Chameleon 4.2.1
1011

layouts/clean.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
3+
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
44
This file is part of the MediaWiki skin Chameleon.
55
66
@copyright 2013 - 2021, Stephan Gambke
@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
2323
@since 1.1
2424
@ingroup Skins
2525
-->
26-
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
26+
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
2727

2828
<component type="NavbarHorizontal" >
2929
<modification type="ShowOnlyFor" permission="edit"/>

layouts/fixedhead.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
3+
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
44
This file is part of the MediaWiki skin Chameleon.
55
66
@copyright 2013 - 2021, Stephan Gambke
@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
2323
@since 1.0
2424
@ingroup Skins
2525
-->
26-
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
26+
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
2727

2828
<component type="NavbarHorizontal">
2929
<modification type="Sticky"/>

layouts/layout.rng

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
2525
<grammar
2626
xmlns="http://relaxng.org/ns/structure/1.0"
2727
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
28-
ns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng"
28+
ns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng"
2929
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
3030
>
3131

3232
<a:documentation>
3333
Schema for Chameleon layout files
34-
Version 3.5
34+
Version 3.6
3535
Copyright 2013 - 2021, Stephan Gambke
3636
GNU General Public License, version 3 (or any later version)
3737
</a:documentation>
@@ -325,6 +325,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
325325
<data type="string"/>
326326
</attribute>
327327
</optional>
328+
329+
<optional>
330+
<attribute name="showActive" a:defaultValue="no">
331+
<ref name="BoolValues"/>
332+
</attribute>
333+
</optional>
334+
328335
</define>
329336

330337
<define name="Component" combine="choice">
@@ -567,11 +574,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
567574
<value>Toc</value>
568575
</attribute>
569576

570-
<optional>
571-
<!-- <attribute name="follow" a:defaultValue="yes">-->
572-
<!-- <ref name="BoolValues"/>-->
573-
<!-- </attribute>-->
574-
</optional>
575577
</define>
576578

577579
<!-- Toolbox -->

layouts/navhead.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
3+
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
44
This file is part of the MediaWiki skin Chameleon.
55
66
@copyright 2013 - 2021, Stephan Gambke
@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
2323
@since 1.0
2424
@ingroup Skins
2525
-->
26-
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
26+
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
2727
<component type="NavbarHorizontal">
2828
<component type="Logo" position="head"/>
2929
<component type="NavMenu" flatten="navigation" />

layouts/standard.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
3+
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
44
This file is part of the MediaWiki skin Chameleon.
55
66
@copyright 2013 - 2021, Stephan Gambke
@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
2323
@since 1.0
2424
@ingroup Skins
2525
-->
26-
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
26+
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
2727
<grid class="flex-fill">
2828
<row>
2929
<cell class="flex-grow-0">

layouts/stickyhead.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.4/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
3+
<?xml-model href="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
44
This file is part of the MediaWiki skin Chameleon.
55
66
@copyright 2013 - 2021, Stephan Gambke
@@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
2323
@since 1.0
2424
@ingroup Skins
2525
-->
26-
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng">
26+
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
2727

2828
<component type="NavbarHorizontal" class="small bg-darker">
2929
<component type="Menu" message="secondary-menu"/>

maintenance/validateLayout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function validateFile( $filename ) {
7979
$xml = new DOMDocument();
8080
$xml->load( $filename );
8181

82-
if ( !$xml->relaxNGValidate( 'https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng' ) ) {
82+
if ( !$xml->relaxNGValidate( 'https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng' ) ) {
8383
libxml_display_errors();
8484
} else {
8585
print "Ok!\n";

src/Components/NavMenu.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ protected function buildMenuItemsForDropdownMenu( $menuDescription, $indent = 0
143143

144144
foreach ( $menuDescription['content'] as $key => $item ) {
145145
$id = $item['id'] ?? '';
146-
$menuitems .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $item,
147-
[ 'tag' => 'div', 'class' => 'nav-item', 'link-class' => 'nav-link '. $id ] );
146+
$menuitems .= $this->indent() . $this->getSkinTemplate()->makeListItem( $key, $item, [
147+
'tag' => 'div',
148+
'class' => 'nav-item',
149+
'link-class' => 'nav-link '. $id . ( $this->isHrefActive( $item['href'] ) ? ' active' : '' )
150+
] );
148151
}
149152

150153
$this->indent( - $indent );
@@ -255,4 +258,9 @@ public function getMenusToBeFlattened() {
255258
return $flatten;
256259
}
257260

261+
private function isHrefActive( string $href ): bool {
262+
return filter_var( $this->getDomElement()->getAttribute( 'showActive' ), FILTER_VALIDATE_BOOLEAN )
263+
&& $href === $this->getSkin()->getTitle()->getLocalURL();
264+
}
265+
258266
}

0 commit comments

Comments
 (0)