mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-25 08:05:51 +00:00
9abdaf54c3
This allows '.vector-main-menu' to correspond to MainMenu.mustache, and 'vector-page-tools' with PageTools.mustache Bug: T317900 Change-Id: I65c0d7cffbdf1cf9e59cde0c0fc4dca788e799de
82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use MessageLocalizer;
|
|
|
|
/**
|
|
* VectorComponentPinnableHeader component
|
|
*/
|
|
class VectorComponentPinnableHeader implements VectorComponent {
|
|
/** @var MessageLocalizer */
|
|
private $localizer;
|
|
/** @var bool */
|
|
private $pinned;
|
|
/** @var string */
|
|
private $name;
|
|
/** @var string|null */
|
|
private $featureName;
|
|
/**
|
|
* @var bool
|
|
* Flag controlling if the pinnable element should be automatically moved in the DOM when pinned/unpinned
|
|
*/
|
|
private $moveElement;
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $labelTagName;
|
|
|
|
/**
|
|
* @param MessageLocalizer $localizer
|
|
* @param bool $pinned
|
|
* @param string $name By convention, this should include the `vector-`
|
|
* prefix e.g. `vector-page-tools` or `vector-toc`.
|
|
* @param string|null $featureName If set, pinned and unpinned states will
|
|
* persist for logged-in users by leveraging features.js to manage the user
|
|
* preference storage and the toggling of the body class. This name should NOT
|
|
* contain the "vector-" prefix.
|
|
* @param bool|null $moveElement
|
|
* @param string|null $labelTagName Element type of the label. Either a 'div' or a 'h2'
|
|
* in the case of the pinnable ToC.
|
|
*/
|
|
public function __construct(
|
|
MessageLocalizer $localizer,
|
|
bool $pinned,
|
|
string $name,
|
|
?string $featureName,
|
|
?bool $moveElement = true,
|
|
?string $labelTagName = 'div'
|
|
) {
|
|
$this->localizer = $localizer;
|
|
$this->pinned = $pinned;
|
|
$this->name = $name;
|
|
$this->featureName = $featureName;
|
|
$this->moveElement = $moveElement;
|
|
$this->labelTagName = $labelTagName;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
$messageLocalizer = $this->localizer;
|
|
$data = [
|
|
'is-pinned' => $this->pinned,
|
|
'label' => $messageLocalizer->msg( $this->name . '-label' ),
|
|
'label-tag-name' => $this->labelTagName,
|
|
'pin-label' => $messageLocalizer->msg( 'vector-pin-element-label' ),
|
|
'unpin-label' => $messageLocalizer->msg( 'vector-unpin-element-label' ),
|
|
'data-name' => $this->name,
|
|
'data-feature-name' => $this->featureName
|
|
];
|
|
if ( $this->moveElement ) {
|
|
// Assumes consistent naming standard for pinnable elements and their containers
|
|
$data = array_merge( $data, [
|
|
'data-pinnable-element-id' => $this->name,
|
|
'data-unpinned-container-id' => $this->name . '-unpinned-container',
|
|
'data-pinned-container-id' => $this->name . '-pinned-container',
|
|
] );
|
|
}
|
|
return $data;
|
|
}
|
|
}
|