-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathKnob.php
51 lines (45 loc) · 1.45 KB
/
Knob.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
<?php
namespace softcommerce\knob;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
class Knob extends Widget
{
public $options = [];
public $knobOptions = [];
public $name = '';
public $min = 0;
public $max = 100;
public $value = 0;
public $icon = null;
public function init()
{
parent::init();
Html::addCssClass($this->options, 'jqKnob');
}
public function run()
{
if (!array_key_exists('id', $this->options)) {
$this->options['id'] = $this->getId();
}
echo Html::textInput($this->name, $this->value, $this->options);
$view = $this->getView();
KnobAsset::register($view);
$pluginsJs = "";
if (!is_null($this->icon)) {
KnobIconAsset::register($view);
$pluginsJs .= "addKnobIcon('#{$this->options['id']}', '".addslashes($this->icon)."');\n";
}
if( $this->knobOptions['format'] )
{
$format = $this->knobOptions['format'];
unset( $this->knobOptions['format'] );
} else {
$format = false;
}
$knobOptions = empty($this->knobOptions) ? '' : Json::encode($this->knobOptions);
$js = !$format ? "jQuery('#{$this->options['id']}').knob({$knobOptions});\n" : "jQuery('#{$this->options['id']}').knob( jQuery.extend({$knobOptions},{format: {$format}}));\n";
$js .= $pluginsJs;
$view->registerJs($js);
}
}