Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit e2fb104

Browse files
committed
stable release
1 parent 3263fe6 commit e2fb104

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,19 @@ Usage
2828
Once the extension is installed, simply use it in your code by :
2929

3030
```php
31-
<?= \oakcms\bootstrapswitch\AutoloadExample::widget(); ?>```
31+
<?= $form->field($model, 'field')->widget(\oakcms\bootstrapswitch\Switcher::className()) ?>
32+
```
33+
34+
Or
35+
36+
```php
37+
<?= \oakcms\bootstrapswitch\Switcher::widget([
38+
'name' => 'Name',
39+
'checked' => true,
40+
'clientOptions' => [
41+
'size' => 'large',
42+
'onColor' => 'success',
43+
'offColor' => 'danger'
44+
]
45+
]); ?>
46+
```

src/STrait.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ trait STrait
2525
* Please refer to the Bootstrap Switch 3 plugin Web page for possible options.
2626
* @see http://www.bootstrap-switch.org/
2727
*/
28-
public $clientOptions = [];
28+
public $clientOptions = [
29+
'size' => 'small',
30+
'onColor' => 'success',
31+
'offColor' => 'danger'
32+
];
2933

3034
/**
3135
* @var array the event handlers for the underlying Bootstrap Switch 3 input JS plugin.
@@ -53,6 +57,6 @@ public function registerClientScript()
5357
$js[] = "jQuery('$this->selector').on('$event', $handler);";
5458
}
5559
}
56-
$view->registerJs(implode("\n", $js));
60+
$this->view->registerJs(implode("\n", $js));
5761
}
5862
}

src/Switcher.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class Switcher extends InputWidget
3535
{
36-
use SwitchTrait;
36+
use STrait;
3737

3838
/**
3939
* @var bool whether to display the label inline or not. Defaults to true.
@@ -45,13 +45,14 @@ class Switcher extends InputWidget
4545
*/
4646
public function run()
4747
{
48+
$option = array_merge(['label' => false, 'class' => 'make-switch'], $this->options);
4849
if ($this->hasModel()) {
49-
$input = Html::activeCheckbox($this->model, $this->attribute, $this->options);
50+
$input = Html::activeCheckbox($this->model, $this->attribute, $option);
5051
} else {
51-
$input = Html::checkbox($this->name, $this->checked, $this->options);
52+
$input = Html::checkbox($this->name, $this->checked, $option);
5253
}
5354
echo $this->inlineLabel ? $input : Html::tag('div', $input);
54-
$this->selector = "#{$this->options['id']}";
55+
$this->selector = "#{$option['id']}";
5556
$this->registerClientScript();
5657
}
5758

0 commit comments

Comments
 (0)