Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SpinnerWidget | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__toString | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Widget; |
4 | |
5 | use Exception; |
6 | use MediaWiki\Html\Html; |
7 | |
8 | /** |
9 | * PHP version of jquery.spinner. |
10 | * |
11 | * If used with jquery.spinner.styles, can be used to show a |
12 | * spinner before JavaScript has loaded. |
13 | * |
14 | * @copyright 2011-2020 MediaWiki Widgets Team and others; see AUTHORS.txt |
15 | * @license MIT |
16 | */ |
17 | class SpinnerWidget { |
18 | |
19 | private $attributes; |
20 | private $content; |
21 | |
22 | /** |
23 | * @param array $config Configuration options |
24 | */ |
25 | public function __construct( array $config = [] ) { |
26 | $size = $config['size'] ?? 'small'; |
27 | $type = $config['type'] ?? 'inline'; |
28 | |
29 | $this->attributes = []; |
30 | |
31 | if ( isset( $config['id'] ) ) { |
32 | $this->attributes['id'] = $config['id']; |
33 | } |
34 | |
35 | // Initialization |
36 | $this->attributes['class'] = [ |
37 | 'mw-spinner', |
38 | $size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large', |
39 | $type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block', |
40 | ]; |
41 | |
42 | $this->content = |
43 | '<div class="mw-spinner-container">' . |
44 | str_repeat( '<div></div>', 12 ) . |
45 | '</div>'; |
46 | } |
47 | |
48 | /** |
49 | * Render element into HTML. |
50 | * @return string HTML serialization |
51 | */ |
52 | public function toString() { |
53 | return Html::rawElement( 'div', $this->attributes, $this->content ); |
54 | } |
55 | |
56 | /** |
57 | * Magic method implementation. |
58 | * |
59 | * Copied from OOUI\Tag |
60 | * |
61 | * @return string |
62 | */ |
63 | public function __toString() { |
64 | try { |
65 | return $this->toString(); |
66 | } catch ( Exception $ex ) { |
67 | trigger_error( (string)$ex, E_USER_ERROR ); |
68 | } |
69 | } |
70 | } |