forked from yii2mod/yii2-ion-slider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IonSlider.php
74 lines (62 loc) · 1.52 KB
/
IonSlider.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
<?php
namespace yii2mod\slider;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;
/**
* Class IonSlider
*
* @package yii2mod\slider
*/
class IonSlider extends InputWidget
{
/**
* Single type of the slider
*/
const TYPE_SINGLE = 'single';
/**
* Double type of the slider
*/
const TYPE_DOUBLE = 'double';
/**
* @var string the type of the slider. Defaults to `TYPE_SINGLE`
*/
public $type = self::TYPE_SINGLE;
/**
* @var array plugin options
*/
public $pluginOptions = [];
/**
* Render range slider
*
* @return string
*/
public function run()
{
$this->registerAssets();
if ($this->hasModel()) {
return Html::activeTextInput($this->model, $this->attribute, $this->options);
}
return Html::textInput($this->name, $this->value, $this->options);
}
/**
* Register client assets
*/
protected function registerAssets()
{
$view = $this->getView();
IonSliderAsset::register($view);
$view->registerJs('$("#' . $this->options['id'] . '").ionRangeSlider(' . $this->getPluginOptions() . ');');
}
/**
* Return plugin options in json format
*
* @return string
*/
protected function getPluginOptions()
{
$this->pluginOptions['type'] = ArrayHelper::getValue($this->pluginOptions, 'type', $this->type);
return Json::encode($this->pluginOptions);
}
}