From 1c4b301aa4f2c73433abab53f5f73163489865dd Mon Sep 17 00:00:00 2001 From: Semenov Date: Thu, 5 Nov 2020 13:48:37 +0300 Subject: [PATCH] Add option noIncludeCssFilesOnPjax --- CHANGELOG.md | 5 ++++ README.md | 3 +- src/AssetsAutoCompressComponent.php | 44 +++++++++++++++++------------ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d882b14..cb9aa3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 25bbcb0..e6b8c86 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/AssetsAutoCompressComponent.php b/src/AssetsAutoCompressComponent.php index ae070a3..835166e 100644 --- a/src/AssetsAutoCompressComponent.php +++ b/src/AssetsAutoCompressComponent.php @@ -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; @@ -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 */ @@ -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; + } } }); @@ -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); - }*/ } }); } @@ -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 "
" . print_r($result, true); die;
+        echo "
".print_r($result, true);
+        die;
 
     }
 
@@ -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;
@@ -550,7 +559,7 @@ protected function _processingJs($parts)
 
         return $result;
     }
-    
+
     /**
      * @param array $files
      */
@@ -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