-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSmoothScroll.php
88 lines (78 loc) · 1.88 KB
/
SmoothScroll.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
<?php
namespace demogorgorn\uikit;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* SmoothScroll renders an SmoothScroll component.
*
* For example,
*
* ```php
* echo SmoothScroll::widget([
* 'showButton' => true,
* 'options' => ['href' => '#footer'],
* 'body' => 'Say hello...',
* ]);
* ```
*
* The following example will show the content enclosed between the [[begin()]]
* and [[end()]] calls within the SmoothScroll box:
*
* ```php
* SmoothScroll::begin([
* 'showButton' => true,
* ]);
*
* echo 'Say hello...';
*
* SmoothScroll::end();
* ```
* @see http://www.getuikit.com/docs/smooth-scroll.html
* @author Oleg Martemjanov <[email protected]>
* @since 2.0
*
*/
class SmoothScroll extends Widget
{
/**
* @var string the body content in the SmoothScroll component. Note that anything between
* the [[begin()]] and [[end()]] calls of the SmoothScroll widget will also be treated
* as the body content, and will be rendered before this.
*/
public $body;
/**
* @var boolean add button css class to SmoothScroll component.
*/
public $showButton = false;
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
$this->initOptions();
echo Html::beginTag('a', $this->options) . "\n";
}
/**
* Renders the widget.
*/
public function run()
{
echo "\n" . $this->body;
echo "\n" . Html::endTag('a');
$this->registerAsset();
}
/**
* Initializes the widget options.
* This method sets the default values for various options.
*/
protected function initOptions()
{
if($this->showButton)
Html::addCssClass($this->options, 'uk-button');
$this->options = array_merge([
'data-uk-smooth-scroll' => '',
], $this->options);
}
}