|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Contains the component class for rendering a collapsible. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright (C) 2018, Tobias Oetterer, Paderborn University |
|
6
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3 (or later) |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of the MediaWiki extension BootstrapComponents. |
|
9
|
|
|
* The BootstrapComponents extension is free software: you can redistribute it |
|
10
|
|
|
* and/or modify it under the terms of the GNU General Public License as published |
|
11
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
12
|
|
|
* (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* The BootstrapComponents extension is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
* @file |
|
23
|
|
|
* @ingroup BootstrapComponents |
|
24
|
|
|
* @author Tobias Oetterer |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace BootstrapComponents\Components; |
|
28
|
|
|
|
|
29
|
|
|
use BootstrapComponents\ApplicationFactory; |
|
30
|
|
|
use BootstrapComponents\AbstractComponent; |
|
31
|
|
|
use BootstrapComponents\ParserRequest; |
|
32
|
|
|
use \Html; |
|
33
|
|
|
use \MWException; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class Collapse |
|
37
|
|
|
* |
|
38
|
|
|
* Class for component 'collapse' |
|
39
|
|
|
* |
|
40
|
|
|
* @see https://github.com/oetterer/BootstrapComponents/blob/master/docs/components.md#Collapse |
|
41
|
|
|
* @since 1.0 |
|
42
|
|
|
*/ |
|
43
|
|
|
class Collapse extends AbstractComponent { |
|
44
|
|
|
/** |
|
45
|
|
|
* @inheritdoc |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $input |
|
48
|
|
|
*/ |
|
49
|
7 |
|
public function placeMe( $input ) { |
|
50
|
7 |
|
$buttonPrintOut = $this->generateButton( |
|
51
|
7 |
|
clone $this->getParserRequest() |
|
52
|
7 |
|
); |
|
53
|
|
|
|
|
54
|
7 |
|
list ( $class, $style ) = $this->processCss( 'collapse', [] ); |
|
55
|
7 |
|
return $buttonPrintOut . Html::rawElement( |
|
56
|
7 |
|
'div', |
|
57
|
|
|
[ |
|
58
|
7 |
|
'class' => $this->arrayToString( $class, ' ' ), |
|
59
|
7 |
|
'style' => $this->arrayToString( $style, ';' ), |
|
60
|
7 |
|
'id' => $this->getId(), |
|
61
|
7 |
|
], |
|
62
|
|
|
$input |
|
63
|
7 |
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Spawns the button for our collapse component. |
|
69
|
|
|
* |
|
70
|
|
|
* @param ParserRequest $parserRequest |
|
71
|
|
|
* |
|
72
|
|
|
* @throws MWException cascading {@see \BootstrapComponents\Component::parseComponent} |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
7 |
|
private function generateButton( ParserRequest $parserRequest ) { |
|
76
|
7 |
|
$button = new Button( $this->getComponentLibrary(), $this->getParserOutputHelper(), $this->getNestingController() ); |
|
77
|
7 |
|
$button->injectRawAttributes( [ 'data-toggle' => 'collapse' ] ); |
|
78
|
|
|
|
|
79
|
7 |
|
$buttonAttributes = $parserRequest->getAttributes(); |
|
80
|
7 |
|
unset( $buttonAttributes['id'] ); |
|
81
|
|
|
|
|
82
|
|
|
// note that button indeed is a parser function. however, the argument isParserFunction to getNewParserRequest |
|
83
|
|
|
// only determines how the first parameter is processed. pretending to be a tag extension is easier to produce. |
|
84
|
7 |
|
$buttonParserRequest = ApplicationFactory::getInstance()->getNewParserRequest( |
|
85
|
7 |
|
[ '#' . $this->getId(), $buttonAttributes, $parserRequest->getParser(), $parserRequest->getFrame() ], |
|
86
|
7 |
|
false, |
|
87
|
|
|
'button' |
|
88
|
7 |
|
); |
|
89
|
|
|
|
|
90
|
7 |
|
$buttonPrintOut = $button->parseComponent( $buttonParserRequest ); |
|
91
|
7 |
|
if ( is_array( $buttonPrintOut ) ) { |
|
92
|
7 |
|
$buttonPrintOut = $buttonPrintOut[0]; |
|
93
|
7 |
|
} |
|
94
|
7 |
|
return $buttonPrintOut; |
|
95
|
|
|
} |
|
96
|
|
|
} |