Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PhonosButton | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |||
getJavaScriptClassName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Phonos; |
4 | |
5 | use OOUI\ButtonWidget; |
6 | |
7 | class PhonosButton extends ButtonWidget { |
8 | |
9 | /** |
10 | * @inheritDoc |
11 | */ |
12 | public function __construct( array $config = [] ) { |
13 | $config['infusable'] = true; |
14 | $config['icon'] = 'volumeUp'; |
15 | $config['framed'] = false; |
16 | $config['classes'] = [ |
17 | 'ext-phonos-PhonosButton', |
18 | // `.noexcerpt` is defined by TextExtracts |
19 | 'noexcerpt' |
20 | ]; |
21 | |
22 | // Change display for errors. |
23 | if ( isset( $config['data']['error'] ) ) { |
24 | $config['classes'][] = 'ext-phonos-error'; |
25 | $config['icon'] = 'volumeOff'; |
26 | } |
27 | |
28 | if ( !$config['label'] ) { |
29 | // Add class with which to change margins when there's no visible label. |
30 | $config['classes'][] = 'ext-phonos-PhonosButton-emptylabel'; |
31 | } |
32 | parent::__construct( $config ); |
33 | |
34 | // T315404: Wrap output element in data-nosnippet |
35 | $this->setAttributes( [ 'data-nosnippet' => '' ] ); |
36 | |
37 | // Set aria-label if it's provided. This is also used as the tooltip. |
38 | if ( isset( $config['aria-label'] ) && trim( $config['aria-label'] ) !== '' ) { |
39 | $this->button->setAttributes( [ |
40 | 'aria-label' => $config['aria-label'], |
41 | 'title' => $config['aria-label'], |
42 | ] ); |
43 | } |
44 | } |
45 | |
46 | /** |
47 | * The class name of the JavaScript version of this widget. |
48 | * |
49 | * @return string |
50 | */ |
51 | protected function getJavaScriptClassName(): string { |
52 | return 'mw.Phonos.PhonosButton'; |
53 | } |
54 | } |