This repository has been archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Checkbox.php
106 lines (87 loc) · 2.55 KB
/
Checkbox.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace leandrogehlen\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>
*/
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;
/**
* @var boolean whether controls is addon checkbox.
*/
public $addon = false;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->addon) {
$this->inline = true;
}
if ($this->label == null && !$this->addon && $this->hasModel()) {
$this->label = $this->model->getAttributeLabel($this->attribute);
}
}
/**
* Renders the widget.
*/
public function run()
{
$pluginOptions = [
'id' => ArrayHelper::remove($this->options, 'id'),
'data-initialize' => 'checkbox'
];
if (!$this->inline) {
Html::addCssClass($pluginOptions, 'checkbox');
}
if ($this->addon) {
Html::addCssClass($pluginOptions, 'input-group-addon');
}
if ($this->highlight === true) {
Html::addCssClass($pluginOptions, 'highlight');
}
Html::addCssClass($this->options, 'sr-only');
$this->renderCheckbox($pluginOptions);
FueluxAsset::register($this->getView());
}
/**
* Renders the checkbox input
* @param array $pluginOptions
*/
public function renderCheckbox($pluginOptions)
{
if ($this->inline){
Html::addCssClass($pluginOptions, 'checkbox-custom checkbox-inline');
echo Html::beginTag('label', $pluginOptions) . "\n";
} else {
echo Html::beginTag('div', $pluginOptions) . "\n";
echo Html::beginTag('label', ['class' => 'checkbox-custom']) . "\n";
}
if ($this->hasModel()) {
echo Html::activeInput('checkbox', $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";
if (!$this->inline) {
echo Html::endTag('div');
}
}
}