Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add showActive parameter #401

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the menu link for the current page will be highlighted.

#### 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
16 changes: 9 additions & 7 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 Expand Up @@ -567,11 +574,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<value>Toc</value>
</attribute>

<optional>
<!-- <attribute name="follow" a:defaultValue="yes">-->
<!-- <ref name="BoolValues"/>-->
<!-- </attribute>-->
</optional>
</define>

<!-- Toolbox -->
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
2 changes: 1 addition & 1 deletion maintenance/validateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function validateFile( $filename ) {
$xml = new DOMDocument();
$xml->load( $filename );

if ( !$xml->relaxNGValidate( 'https://ProfessionalWiki.github.io/chameleon/schema/3.5/layout.rng' ) ) {
if ( !$xml->relaxNGValidate( 'https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng' ) ) {
libxml_display_errors();
} else {
print "Ok!\n";
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();
}

}