-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace mhunesi\scrollbar; | ||
|
||
use yii\helpers\ArrayHelper; | ||
use yii\helpers\Html; | ||
use yii\helpers\Json; | ||
|
||
/** | ||
* This is just an example. | ||
*/ | ||
class PerfectScrollbar extends \yii\base\Widget | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
public $height = 250; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
public $width = 250; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $unit = 'px'; | ||
|
||
/** | ||
* @var array the HTML attributes for the widget container tag. The following special options are recognized: | ||
* | ||
* - `tag`: string, the tag name for the container. Defaults to `div` | ||
* This option is available since version 2.0.7. | ||
* See also [[\yii\helpers\Html::tag()]]. | ||
* | ||
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. | ||
*/ | ||
public $options = []; | ||
|
||
/** | ||
* @var array the options for the underlying Select2 JS plugin. | ||
* Please refer to the plugin Web page for possible options. | ||
* | ||
* @see https://github.com/mdbootstrap/perfect-scrollbar#options | ||
*/ | ||
public $clientOptions = []; | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
ob_start(); | ||
|
||
$style = array_merge([ | ||
'position' => 'relative', | ||
'overflow' => 'auto', | ||
'width' => $this->width . $this->unit, | ||
'height' => $this->height . $this->unit, | ||
],ArrayHelper::getValue($this->options,'style',[])); | ||
|
||
$this->options = array_merge($this->options,[ | ||
'id' => $this->id, | ||
'style' => $style | ||
]); | ||
|
||
$tag = ArrayHelper::remove($this->options, 'tag', 'div'); | ||
echo Html::beginTag($tag, $this->options); | ||
|
||
} | ||
|
||
public function run() | ||
{ | ||
echo Html::endTag(ArrayHelper::remove($this->options, 'tag', 'div')); | ||
|
||
$content = ob_get_clean(); | ||
|
||
$this->registerClientScript(); | ||
|
||
return $content; | ||
} | ||
|
||
public function registerClientScript() | ||
{ | ||
PerfectScrollbarAsset::register($this->view); | ||
|
||
$id = $this->options['id']; | ||
|
||
$jsonConfig = Json::encode($this->clientOptions); | ||
|
||
$js = "var ps_{$id} = new PerfectScrollbar('#{$id}', $jsonConfig);"; | ||
|
||
$this->view->registerJs($js); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
namespace mhunesi\scrollbar; | ||
|
||
class PerfectScrollbarAsset extends \yii\web\AssetBundle | ||
{ | ||
public $sourcePath = '@npm/perfect-scrollbar'; | ||
|
||
public $css = [ | ||
'css/perfect-scrollbar.css', | ||
]; | ||
|
||
public $js = [ | ||
'dist/perfect-scrollbar.min.js', | ||
]; | ||
|
||
public $jsOptions = array( | ||
'position' => \yii\web\View::POS_HEAD | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "mhunesi/yii2-perfect-scrollbar", | ||
"description": "Yii2 Perfect Scrollbar Extension", | ||
"type": "yii2-extension", | ||
"keywords": ["yii2","extension","perfect-scrollbar","scrollbar"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Mustafa Hayri ÜNEŞİ", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"yiisoft/yii2": "~2.0.0", | ||
"npm-asset/perfect-scrollbar": "^1.5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"mhunesi\\scrollbar\\": "" | ||
} | ||
} | ||
} |