Skip to content

Commit 9286678

Browse files
author
Chepurnoy
committed
init
0 parents  commit 9286678

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed

IonSlider.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace yii2mod\slider;
4+
5+
use yii\base\InvalidConfigException;
6+
use yii\helpers\Html;
7+
use yii\helpers\Json;
8+
use yii\widgets\InputWidget;
9+
10+
/**
11+
* Class IonSlider
12+
* @package yii2mod\slider
13+
*/
14+
class IonSlider extends InputWidget
15+
{
16+
/**
17+
* @var array the HTML attributes for the input tag.
18+
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
19+
*/
20+
public $options = [];
21+
22+
/**
23+
* @var array plugin options
24+
*/
25+
public $pluginOptions = [];
26+
27+
/**
28+
* Slider type - single, double
29+
* @var string
30+
*/
31+
public $type = 'single';
32+
33+
/**
34+
* Initializes the object.
35+
* This method is invoked at the end of the constructor after the object is initialized with the
36+
* given configuration.
37+
*/
38+
public function init()
39+
{
40+
parent::init();
41+
}
42+
43+
/**
44+
* Render range slider
45+
* @return string|void
46+
*/
47+
public function run()
48+
{
49+
if ($this->hasModel()) {
50+
echo Html::activeTextInput($this->model, $this->attribute, $this->options);
51+
}
52+
$this->registerAssets();
53+
}
54+
55+
/**
56+
* Register client assets
57+
*/
58+
protected function registerAssets()
59+
{
60+
$view = $this->getView();
61+
IonSliderAsset::register($view);
62+
$js = '$("#' . $this->getInputId() . '").ionRangeSlider(' . $this->getPluginOptions() . ');';
63+
$view->registerJs($js, $view::POS_END);
64+
}
65+
66+
/**
67+
* Return plugin options in json format
68+
* @return string
69+
*/
70+
public function getPluginOptions()
71+
{
72+
$this->pluginOptions['type'] = $this->type;
73+
74+
return Json::encode($this->pluginOptions);
75+
}
76+
77+
/**
78+
* Return select id
79+
* @return mixed
80+
* @throws InvalidConfigException
81+
*/
82+
public function getInputId()
83+
{
84+
return $this->options['id'];
85+
}
86+
}

IonSliderAsset.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace yii2mod\slider;
4+
5+
use yii\web\AssetBundle;
6+
7+
/**
8+
* Class IonSliderAsset
9+
* @package yii2mod\slider
10+
*/
11+
class IonSliderAsset extends AssetBundle
12+
{
13+
14+
/**
15+
* @var string
16+
*/
17+
public $sourcePath = '@bower/ion.rangeSlider';
18+
19+
/**
20+
* @var array
21+
*/
22+
public $css = [
23+
'css/normalize.css',
24+
'css/ion.rangeSlider.css',
25+
'css/ion.rangeSlider.skinHTML5.css'
26+
];
27+
28+
/**
29+
* @var array
30+
*/
31+
public $js = [
32+
'js/ion.rangeSlider.js',
33+
];
34+
35+
/**
36+
* @var array
37+
*/
38+
public $depends = [
39+
'app\assets\AppAsset',
40+
];
41+
}

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Ion Range Slider Widget for Yii 2
2+
=========
3+
- Widget based on Ion.RangeSlider extension http://ionden.com/a/plugins/ion.rangeSlider/en.html
4+
5+
Installation
6+
------------
7+
8+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
9+
10+
Either run
11+
12+
```
13+
php composer.phar require --prefer-dist yii2mod/yii2-ion-slider "*"
14+
```
15+
16+
or add
17+
18+
```json
19+
"yii2mod/yii2-ion-slider": "*"
20+
```
21+
22+
to the require section of your composer.json.
23+
24+
Usage
25+
------------
26+
Once the extension is installed, simply add widget to your page as follows:
27+
28+
1) Usage with ActiveForm and model
29+
```php
30+
echo $form->field($model, "option")->widget(IonSlider::className(), [
31+
'pluginOptions' => [
32+
'min' => 0,
33+
'max' => 1,
34+
'step' => 1,
35+
'onChange' => new \yii\web\JsExpression('
36+
function(data) {
37+
console.log(data);
38+
}
39+
'),
40+
],
41+
]);
42+
```
43+
44+
Slider Options
45+
----------------
46+
You can find them on the [options page](http://ionden.com/a/plugins/ion.rangeSlider/en.html)

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "yii2mod/yii2-ion-slider",
3+
"description": "Ion Slider widget based on Ion.RangeSlider extension {@link http://ionden.com/a/plugins/ion.rangeSlider/en.html)",
4+
"type": "yii2-extension",
5+
"keywords": ["yii2", "module"],
6+
"license": "Apache-2.0",
7+
"authors": [
8+
{
9+
"name": "Igor Chepurnoy",
10+
"email": "igorzfort@gmail.com"
11+
}
12+
],
13+
"require": {
14+
"yii2mod/yii2-user": "*"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"yii2mod\\slider\\": ""
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)