-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheckbox.php
More file actions
100 lines (84 loc) · 2.37 KB
/
Copy pathCheckbox.php
File metadata and controls
100 lines (84 loc) · 2.37 KB
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
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace xemware\fuelux;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\InputWidget;
/**
* @see http://exacttarget.github.io/fuelux/javascript.html#checkboxes
* @author Leandrogehlen <leandroghelen@gmail.com>
* @since 2.0
*/
class Checkbox extends InputWidget
{
/**
* @var string the checkbox label
*/
public $label;
/**
* @var boolean whether controls appear on the same line.
*/
public $inline = false;
/**
* @var boolean whether add a background highlight upon check
*/
public $highlight = false;
private $_internalOptions;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->initInternalOptions();
}
/**
* Renders the widget.
*/
public function run()
{
Html::addCssClass($this->options, 'sr-only');
if (!$this->inline){
echo Html::beginTag('div', $this->_internalOptions) . "\n";
$this->renderCheckbox();
echo Html::endTag('div');
} else {
$this->renderCheckbox();
}
}
/**
* Renders the checkbox input
*/
public function renderCheckbox()
{
if ($this->inline == true){
Html::addCssClass($this->_internalOptions, 'checkbox-custom checkbox-inline');
echo Html::beginTag('label', $this->_internalOptions) . "\n";
} else {
echo Html::beginTag('label', ['class' => 'checkbox-custom']) . "\n";
}
if ($this->hasModel()) {
echo Html::activeCheckbox($this->model, $this->attribute, $this->options) . "\n";
} else {
echo Html::checkbox($this->name, $this->value, $this->options) . "\n";
}
echo $this->label . "\n";
echo Html::endTag('label') . "\n";
}
/**
* Initializes the internal options.
* This method sets the default values for various options.
*/
protected function initInternalOptions()
{
$this->_internalOptions = [
'id' => ArrayHelper::remove($this->options, 'id'),
'data-initialize' => 'checkbox'
];
if (!$this->inline) {
Html::addCssClass($this->_internalOptions, 'checkbox');
}
if ($this->highlight === true) {
Html::addCssClass($this->_internalOptions, 'highlight');
}
}
}