Skip to content

Commit

Permalink
Configuration in config/params.php, att README.md, att PaceAsset.php …
Browse files Browse the repository at this point in the history
…and links composer.json
  • Loading branch information
thtmorais committed Mar 19, 2019
1 parent 17a6851 commit 711483b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
18 changes: 14 additions & 4 deletions Pace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
class Pace extends Widget
{
public $color = 'blue';
public $theme = 'minimal';
public $color;
public $theme;
public $options;

/**
Expand All @@ -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());
Expand Down
9 changes: 8 additions & 1 deletion PaceAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,4 +28,56 @@ Usage
Once the extension is installed, simply use it in your code by :

```php
<?= \thtmorais\pace\AutoloadExample::widget(); ?>```
<?php

use thtmorais\pace\Pace;

echo Pace::widget();

?>
```

or

```php
<?= \thtmorais\pace\Pace::widget() ?>
```

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
<?php
return [
'paceOptions' => [
'color' => 'blue',
'theme' => 'minimal',
'options' => []
]
];
?>
```

or individually in each view:

```php
<?php

use thtmorais\pace\Pace;

echo Pace::widget([
'color'=>'red',
'theme'=>'corner-indicator',
'options'=>[]
]);

?>
```

You can preview **themes** and **colors** [here](http://github.hubspot.com/pace/docs/welcome/).

0 comments on commit 711483b

Please sign in to comment.