-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPreloader.php
89 lines (82 loc) · 2.31 KB
/
Preloader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php namespace webmaxx\materialize;
use yii\helpers\Html;
/**
* Button renders a materialize button.
*
* For example,
*
* ```php
* echo Preloader::widget([
* 'color' => 'red' // 'red', 'blue', 'yellow', 'green'
* ]);
* ```
* or
*
* ```php
* echo Preloader::widget([
* 'color' => ['red', 'blue', 'yellow', 'green']
* ]);
* ```
* @see http://materializecss.com/preloader.html
* @author webmaxx <[email protected]>
* @since 2.0
*/
class Preloader extends Widget
{
/**
* @var string the tag to use to render the button
*/
public $color = 'blue';
/**
* @var string default css class for button
*/
public $defaultClass = 'preloader-wrapper active';
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
parent::init();
$this->clientOptions = false;
if ($this->defaultClass)
Html::addCssClass($this->options, $this->defaultClass);
}
/**
* Renders the widget.
*/
public function run()
{
MaterializeAsset::register($this->getView());
return Html::tag('div', $this->renderItems(), $this->options);
}
/**
* Generates the preloader items that compound the group as specified on [[preloader]].
* @return string the rendering result.
*/
protected function renderItems()
{
$items = [];
if (is_array($this->color)) {
$items = [];
foreach ($this->color as $color) {
$items[] = $this->renderItem($color);
}
} else {
$items[] = $this->renderItem($this->color . '-only');
}
return implode("\n", $items);
}
/**
* Generates the preloader item.
* @return string the rendering result.
*/
protected function renderItem($color)
{
return Html::tag('div', (
Html::tag('div', Html::tag('div', '', ['class' => 'circle']), ['class' => 'circle-clipper left'])
. Html::tag('div', Html::tag('div', '', ['class' => 'circle']), ['class' => 'gap-patch'])
. Html::tag('div', Html::tag('div', '', ['class' => 'circle']), ['class' => 'circle-clipper right'])
), ['class' => 'spinner-layer spinner-' . $color]);
}
}