Skip to content

Commit 1f4c95d

Browse files
committed
first commit
1 parent e28eb7d commit 1f4c95d

9 files changed

+2671
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Yii2 Superfish jQuery menu widget
2+
=====================================
3+
4+
This is the Yii2 SudoSlider widget that renders a nice looking slider (http://webbies.dk/SudoSlider/index.html).
5+
6+
7+
Example of ajax mode configuration:
8+
```php
9+
echo \demogorgorn\uikit\sudoslider\Sudoslider::widget([
10+
'configuration' => [
11+
'ajax' => [
12+
\Yii::$app->request->getBaseUrl() . '/images/slider/01.jpg',
13+
\Yii::$app->request->getBaseUrl() . '/images/slider/02.jpg',
14+
\Yii::$app->request->getBaseUrl() . '/images/slider/03.jpg',
15+
],
16+
'numeric' => false,
17+
'continuous' => true,
18+
'effect' => 'fade',
19+
'auto' => true,
20+
'prevNext' => false
21+
],
22+
]);
23+
```
24+
25+
Installation
26+
------------
27+
28+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
29+
30+
Either run
31+
32+
```
33+
php composer.phar require demogorgorn/yii2-sudo-slider "*"
34+
```
35+
36+
or add
37+
38+
```
39+
"demogorgorn/yii2-sudo-slider": "*"
40+
```
41+
42+
to the require section of your `composer.json` file and run `composer update`.
43+

Sudoslider.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace demogorgorn\sudoslider;
4+
5+
use Yii;
6+
use yii\helpers\Html;
7+
use yii\base\InvalidConfigException;
8+
use demogorgorn\sudoslider\SudosliderAssets;
9+
10+
/**
11+
* Yii2 widget for jQuery SudoSlider (http://webbies.dk/SudoSlider/index.html).
12+
*
13+
* Example of ajax mode configuration:
14+
* ```php
15+
* echo \demogorgorn\uikit\sudoslider\Sudoslider::widget([
16+
* 'configuration' => [
17+
* 'ajax' => [
18+
* \Yii::$app->request->getBaseUrl() . '/images/slider/01.jpg',
19+
* \Yii::$app->request->getBaseUrl() . '/images/slider/02.jpg',
20+
* \Yii::$app->request->getBaseUrl() . '/images/slider/03.jpg',
21+
* ],
22+
* 'numeric' => false,
23+
* 'continuous' => true,
24+
* 'effect' => 'fade',
25+
* 'auto' => true,
26+
* 'prevNext' => false
27+
* ],
28+
* ]);
29+
* ```
30+
*
31+
* @author Oleg Martemjanov <[email protected]>
32+
*/
33+
34+
class Sudoslider extends \yii\base\Widget {
35+
36+
/**
37+
* @var array the HTML attributes for the widget container tag.
38+
*/
39+
public $options = [];
40+
41+
/**
42+
* @var array of the slider js options
43+
* @see http://webbies.dk/SudoSlider/help/
44+
*/
45+
public $configuration = [];
46+
47+
/**
48+
* Initializes the widget.
49+
*/
50+
public function init() {
51+
52+
parent::init();
53+
54+
if (!isset($this->options['id']))
55+
$this->options['id'] = $this->getId();
56+
57+
}
58+
59+
/**
60+
* Renders the widget.
61+
*/
62+
public function run() {
63+
64+
SudosliderAssets::register($this->view);
65+
66+
echo Html::tag('div','', $this->options);
67+
68+
$this->registerScript();
69+
}
70+
71+
public function getConfig() {
72+
73+
if (!isset($this->configuration) || !is_array($this->configuration) || empty($this->configuration))
74+
throw new InvalidConfigException("You should define 'configuration' option and add values according to the documentation!");
75+
76+
return \yii\helpers\Json::encode($this->configuration);
77+
}
78+
79+
protected function registerScript()
80+
{
81+
$this->getView()->registerJs("
82+
$('#" . $this->options['id'] . "').sudoSlider(" . $this->getConfig() . ");
83+
");
84+
}
85+
86+
}

SudosliderAssets.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Assets class file
4+
*
5+
* @author Oleg Martemjanov
6+
*/
7+
namespace demogorgorn\sudoslider;
8+
9+
use yii\web\AssetBundle;
10+
use Yii;
11+
12+
class SudosliderAssets extends AssetBundle
13+
{
14+
public $sourcePath = '@ss/assets';
15+
public $basePath = '@webroot/assets';
16+
public $js = [
17+
'js/jquery.sudoSlider.min.js',
18+
];
19+
public $depends = [
20+
'yii\web\JqueryAsset',
21+
];
22+
23+
public function init() {
24+
Yii::setAlias('@ss', __DIR__);
25+
return parent::init();
26+
}
27+
}

0 commit comments

Comments
 (0)