Skip to content

Commit

Permalink
Add option noIncludeCssFilesOnPjax
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Nov 5, 2020
1 parent 531cdf7 commit 1c4b301
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
==============

1.4.3.2
-----------------
* Fixed option noIncludeJsFilesOnPjax = true
* Add option noIncludeCssFilesOnPjax = true — Do not connect the css files when all pjax requests when enabled cssFileCompile

1.4.3.1
-----------------
* Fixed: https://github.com/skeeks-semenov/yii2-assets-auto-compress/pull/60
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ How to use
'jsFileCompress' => true, //Enable compression and processing js before saving a file
'jsFileCompressFlaggedComments' => true, //Cut comments during processing js

'noIncludeJsFilesOnPjax' => true, //Do not connect the js files when all pjax requests
'noIncludeJsFilesOnPjax' => true, //Do not connect the js files when all pjax requests when all pjax requests when enabled jsFileCompile
'noIncludeCssFilesOnPjax' => true, //Do not connect the css files when all pjax requests when all pjax requests when enabled cssFileCompile

'htmlFormatter' => [
//Enable compression html
Expand Down
44 changes: 26 additions & 18 deletions src/AssetsAutoCompressComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AssetsAutoCompressComponent extends Component implements BootstrapInterfac

/**
* Enables the compilation of files in groups rather than in a single file. Works only when the $cssFileCompile option is enabled
* @var bool
* @var bool
*/
public $cssFileCompileByGroups = false;

Expand Down Expand Up @@ -139,10 +139,16 @@ class AssetsAutoCompressComponent extends Component implements BootstrapInterfac
public $jsFileCompressFlaggedComments = true;

/**
* Do not connect the js files when all pjax requests.
* Do not connect the js files when all pjax requests when enabled jsFileCompile
* @var bool
*/
public $noIncludeJsFilesOnPjax = true;

/**
* Do not connect the css files when all pjax requests when enabled cssFileCompile
* @var bool
*/
public $noIncludeCssFilesOnPjax = true;
/**
* @var bool|array|string|IFormatter
*/
Expand Down Expand Up @@ -220,8 +226,15 @@ public function bootstrap($app)
}

//TODO:: Think about it
if ($this->enabled && $app->request->isPjax && $this->noIncludeJsFilesOnPjax) {
\Yii::$app->view->jsFiles = null;
if ($this->enabled && $app->request->isPjax) {

if ($this->noIncludeJsFilesOnPjax && $this->jsFileCompile) {
\Yii::$app->view->jsFiles = null;
}

if ($this->noIncludeCssFilesOnPjax && $this->cssFileCompile) {
\Yii::$app->view->cssFiles = null;
}
}
});

Expand All @@ -233,10 +246,6 @@ public function bootstrap($app)
if (!empty($response->data)) {
$response->data = $this->_processingHtml($response->data);
}

/*if (!empty($response->content)) {
$response->content = $this->_processingHtml($response->content);
}*/
}
});
}
Expand Down Expand Up @@ -345,14 +354,14 @@ protected function _processAndGroupJsFiles($files = [])

$result = [];
$groupedFiles = $this->_getGroupedFiles($files);
foreach ($groupedFiles as $files)
{
foreach ($groupedFiles as $files) {
$resultGroup = $this->_processingJsFiles($files);
$result = ArrayHelper::merge($result, $resultGroup);
}

return $result;
echo "<pre><code>" . print_r($result, true); die;
echo "<pre><code>".print_r($result, true);
die;

}

Expand All @@ -366,7 +375,7 @@ public function _getGroupedFiles($files)
foreach ($files as $fileCode => $fileTag) {
list($one, $two, $key) = explode("/", $fileCode);

$counter ++;
$counter++;

if ($key != $lastKey && $counter > 1) {
$result[] = $tmpData;
Expand Down Expand Up @@ -550,7 +559,7 @@ protected function _processingJs($parts)

return $result;
}

/**
* @param array $files
*/
Expand All @@ -562,16 +571,15 @@ protected function _processAndGroupCssFiles($files = [])

$result = [];
$groupedFiles = $this->_getGroupedFiles($files);
foreach ($groupedFiles as $files)
{
foreach ($groupedFiles as $files) {
$resultGroup = $this->_processingCssFiles($files);
$result = ArrayHelper::merge($result, $resultGroup);
}

return $result;

}

/**
* @param array $files
* @return array
Expand Down

0 comments on commit 1c4b301

Please sign in to comment.