-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlickWidget.php
49 lines (40 loc) · 1.29 KB
/
SlickWidget.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
<?php
namespace dev7ch\slick;
use dev7ch\slick\assets\PicturefillAsset;
use dev7ch\slick\assets\ResourcesAsset;
use dev7ch\slick\assets\SlickAsset;
\Yii::setAlias('@slick', '@bower/slick-carousel');
\Yii::setAlias('@resources', dirname(__DIR__).'/src/resources');
class SlickWidget extends \luya\base\Widget
{
public $baseUrl;
public $images;
public $slickConfig = [];
public $slickConfigWidget;
public function init()
{
PicturefillAsset::register($this->getView());
SlickAsset::register($this->getView());
ResourcesAsset::register($this->getView());
$this->slickConfig = $this->slickConfigWidget;
$this->view->registerJs(
"var slickSlider = $('.slick-slider').slick({"
.implode(', ',
array_map(
function ($config, $option) {
return sprintf('%s:%s', $option, $config);
},
$this->slickConfig, array_keys($this->slickConfig)
)
).
'});',
\luya\web\View::POS_READY,
'slickSlider'
);
parent::init();
}
public function run()
{
return $this->render('SlickSlider', ['widget' => $this]);
}
}