From 711483b00e1625e30a2ba48af91e438ddc7415e7 Mon Sep 17 00:00:00 2001 From: Matheus Evangelista Morais Date: Mon, 18 Mar 2019 21:20:06 -0300 Subject: [PATCH] Configuration in config/params.php, att README.md, att PaceAsset.php and links composer.json --- Pace.php | 18 +++++++++++++---- PaceAsset.php | 9 ++++++++- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/Pace.php b/Pace.php index 02fdb41..4109a9a 100644 --- a/Pace.php +++ b/Pace.php @@ -17,8 +17,8 @@ */ class Pace extends Widget { - public $color = 'blue'; - public $theme = 'minimal'; + public $color; + public $theme; public $options; /** @@ -35,8 +35,18 @@ public function init() */ public function run() { - if(!empty($this->options)){ - $this->getView()->registerJs('window.paceOptions='.json_encode($this->options),\yii\web\View::POS_BEGIN); + if(isset(Yii::$app->params['paceOptions']['color']) && !empty(Yii::$app->params['paceOptions']['color']) && $this->color === null) { + $this->color = Yii::$app->params['paceOptions']['color']; + }elseif ($this->color === null){ + $this->color = 'blue'; + } + if(isset(Yii::$app->params['paceOptions']['theme']) && !empty(Yii::$app->params['paceOptions']['theme']) && $this->theme === null) { + $this->theme = Yii::$app->params['paceOptions']['theme']; + }elseif ($this->color === null){ + $this->theme = 'minimal'; + } + if(isset(Yii::$app->params['paceOptions']['options']) && !empty(Yii::$app->params['paceOptions']['options']) && $this->options === null) { + $this->getView()->registerJs('window.paceOptions=' . json_encode(Yii::$app->params['paceOptions']['options']), \yii\web\View::POS_BEGIN); } PaceAsset::register($this->getView()); diff --git a/PaceAsset.php b/PaceAsset.php index 48b46c7..af67c0c 100644 --- a/PaceAsset.php +++ b/PaceAsset.php @@ -14,9 +14,16 @@ class PaceAsset extends AssetBundle { public $sourcePath = "@npm"; + private $path = "pace-js/"; + public function registerAssetFiles($view) { - $this->js = YII_DEBUG?'pace-js/pace.js':'pace-js/pace.min.js'; + if(YII_DEBUG){ + $this->js = [$this->path.'pace.js']; + }else{ + $this->js = [$this->path.'pace.min.js']; + } + parent::registerAssetFiles($view); // TODO: Change the autogenerated stub } } \ No newline at end of file diff --git a/README.md b/README.md index eeccf6f..5ed4975 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The preferred way to install this extension is through [composer](http://getcomp Either run ``` -composer require --prefer-dist thtmorais/yii2-pace "*" +composer require thtmorais/yii2-pace "*" ``` or add @@ -28,4 +28,56 @@ Usage Once the extension is installed, simply use it in your code by : ```php -``` \ No newline at end of file + +``` + +or + +```php + +``` + +We recommend using in the `layouts/main.php` file. Or if you prefer in each view file with their respective settings. + +Configuration +------------- + +By default the PACE comes configured with blue color and animation minimal. + +You can add general rule for all views in the `config/params.php` file as follows: + +```php + [ + 'color' => 'blue', + 'theme' => 'minimal', + 'options' => [] + ] + ]; +?> +``` + +or individually in each view: + +```php +'red', + 'theme'=>'corner-indicator', + 'options'=>[] +]); + +?> +``` + +You can preview **themes** and **colors** [here](http://github.hubspot.com/pace/docs/welcome/). \ No newline at end of file