mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-02 03:07:13 +00:00
d150131561
This patch involves cached HTML changes - Replace '-content-container' id with '-unpinned-container' - Replace '-content' id with '-pinnable-element' - Rename pinnableHeader.js to pinnableElement.js - Replace PinnableDropdownContents.mustache with PinnableElement/Open.mustache and Close - Add PinnedContainer/Open & Close and UnpinnedContainer/Open & Close - Rename .vector-dropdown-content to .vector-pinnable-element - Add new PinnableElement.less stylesheet Bug: T318013 Change-Id: I85aec387f87126a17e760fd9fd10e10572ff3152
72 lines
1.9 KiB
PHP
72 lines
1.9 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 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
|
|
* @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,
|
|
?bool $moveElement = true,
|
|
?string $labelTagName = 'div'
|
|
) {
|
|
$this->localizer = $localizer;
|
|
$this->pinned = $pinned;
|
|
$this->name = $name;
|
|
$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
|
|
];
|
|
if ( $this->moveElement ) {
|
|
// Assumes consistent naming standard for pinnable elements and their containers
|
|
$data = array_merge( $data, [
|
|
'data-pinnable-element-id' => $this->name . '-pinnable-element',
|
|
'data-unpinned-container-id' => $this->name . '-unpinned-container',
|
|
'data-pinned-container-id' => $this->name . '-pinned-container',
|
|
] );
|
|
}
|
|
return $data;
|
|
}
|
|
}
|