2019-03-27 11:41:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Widget;
|
|
|
|
|
|
2024-01-02 18:31:56 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2024-06-12 23:59:33 +00:00
|
|
|
use Stringable;
|
2024-01-02 18:31:56 +00:00
|
|
|
|
2019-03-27 11:41:55 +00:00
|
|
|
/**
|
|
|
|
|
* PHP version of jquery.spinner.
|
|
|
|
|
*
|
|
|
|
|
* If used with jquery.spinner.styles, can be used to show a
|
|
|
|
|
* spinner before JavaScript has loaded.
|
|
|
|
|
*
|
|
|
|
|
* @copyright 2011-2020 MediaWiki Widgets Team and others; see AUTHORS.txt
|
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
2024-06-12 23:59:33 +00:00
|
|
|
class SpinnerWidget implements Stringable {
|
2019-03-27 11:41:55 +00:00
|
|
|
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var array */
|
2019-03-27 11:41:55 +00:00
|
|
|
private $attributes;
|
2024-09-13 20:19:49 +00:00
|
|
|
/** @var string */
|
2019-03-27 11:41:55 +00:00
|
|
|
private $content;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $config Configuration options
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( array $config = [] ) {
|
|
|
|
|
$size = $config['size'] ?? 'small';
|
|
|
|
|
$type = $config['type'] ?? 'inline';
|
|
|
|
|
|
|
|
|
|
$this->attributes = [];
|
|
|
|
|
|
|
|
|
|
if ( isset( $config['id'] ) ) {
|
|
|
|
|
$this->attributes['id'] = $config['id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
|
$this->attributes['class'] = [
|
|
|
|
|
'mw-spinner',
|
|
|
|
|
$size === 'small' ? 'mw-spinner-small' : 'mw-spinner-large',
|
|
|
|
|
$type === 'inline' ? 'mw-spinner-inline' : 'mw-spinner-block',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->content =
|
|
|
|
|
'<div class="mw-spinner-container">' .
|
|
|
|
|
str_repeat( '<div></div>', 12 ) .
|
|
|
|
|
'</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Render element into HTML.
|
|
|
|
|
* @return string HTML serialization
|
|
|
|
|
*/
|
|
|
|
|
public function toString() {
|
2024-01-02 18:31:56 +00:00
|
|
|
return Html::rawElement( 'div', $this->attributes, $this->content );
|
2019-03-27 11:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Magic method implementation.
|
|
|
|
|
*
|
|
|
|
|
* Copied from OOUI\Tag
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function __toString() {
|
2025-06-12 03:58:36 +00:00
|
|
|
return $this->toString();
|
2019-03-27 11:41:55 +00:00
|
|
|
}
|
|
|
|
|
}
|