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