Skip to content

Commit 50ad369

Browse files
LBeckXserver1601com
authored andcommitted
Implement style loading IE fix and checkbox option;
1 parent 1290366 commit 50ad369

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/EventListener/Loader2/Loader2Style.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Agentur1601com\FileLazyLoader\EventListener\Loader2;
44

5+
use Agentur1601com\FileLazyLoader\Service\Helper;
56
use Contao\Combiner;
67
use Contao\DataContainer;
78
use Contao\FilesModel;
@@ -13,7 +14,7 @@
1314

1415
class Loader2Style extends AbstractLoader2
1516
{
16-
private $_combiner = null;
17+
private $_combiner;
1718

1819
public function __construct()
1920
{
@@ -38,6 +39,10 @@ public function generateTemplateFiles(PageModel $page, LayoutModel $layout, Page
3839

3940
$link = $this->_combine($file['style_files_path']);
4041

42+
if (intval($layout->fileLazyLoaderStyleIEFix) === 1 && Helper::isIE()) {
43+
$file["style_param"] = 'head';
44+
}
45+
4146
switch ($file["style_param"]) {
4247
case 'preload':
4348
$GLOBALS['TL_HEAD'][] = "<link rel='preload' href='" . $link . "' as='style'>";

src/Resources/contao/dca/tl_layout.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
->addLegend('fileLazyLoader_files_style_legend', 'fileLazyLoader_files_js_legend', PaletteManipulator::POSITION_AFTER)
1515
->addField('fileLazyLoaderStylePath', 'fileLazyLoader_files_style_legend', PaletteManipulator::POSITION_APPEND)
1616
->addField('fileLazyLoaderStyleFilesLoad', 'fileLazyLoader_files_style_legend', PaletteManipulator::POSITION_APPEND)
17+
->addField('fileLazyLoaderStyleIEFix', 'fileLazyLoader_files_style_legend', PaletteManipulator::POSITION_APPEND)
1718
->applyToPalette('default', 'tl_layout');
1819

1920
$GLOBALS['TL_DCA']['tl_layout']['fields']['fileLazyLoaderJsPath'] = [
@@ -197,3 +198,13 @@
197198
],
198199
'sql' => "blob NULL"
199200
];
201+
202+
$GLOBALS['TL_DCA']['tl_layout']['fields']['fileLazyLoaderStyleIEFix'] = [
203+
'label' => &$GLOBALS['TL_LANG']['tl_layout']['fileLazyLoaderStyleIEFix'],
204+
'exclude' => true,
205+
'inputType' => 'checkbox',
206+
'default' => 1,
207+
'eval' => ['tl_class'=>'w50'],
208+
'sql' => "char(1) NOT NULL default ''"
209+
];
210+

src/Resources/contao/languages/de/tl_layout.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
$GLOBALS['TL_LANG'][TABLE_NAME]['fileLazyLoaderStylePath'] = ['CSS, SCSS, LESS', ''];
2323
$GLOBALS['TL_LANG'][TABLE_NAME]['fileLazyLoaderStyleFilesLoad'] = ['Style-Dateien', ''];
24+
$GLOBALS['TL_LANG'][TABLE_NAME]['fileLazyLoaderStyleIEFix'] = ['IE Fix', 'Loading all styles over head'];
2425

2526
$GLOBALS['TL_LANG'][TABLE_NAME]['style_select'] = ["Aktiv"];
2627
$GLOBALS['TL_LANG'][TABLE_NAME]['style_files_path'] = ["Pfad"];

src/Service/Helper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Helper
1515
* @return array
1616
* @throws \Exception
1717
*/
18-
public function getPathsByUUIDs($fileTree):array
18+
public function getPathsByUUIDs($fileTree): array
1919
{
2020
if(!$fileTree)
2121
{
@@ -125,16 +125,16 @@ public function createDir($dir)
125125
{
126126
return true;
127127
}
128+
128129
return mkdir($dir);
129130
}
130131

131132
/**
132-
* @param string $path
133-
* @return mixed
133+
* @return bool
134134
*/
135-
public function generateMinFileName(string $path)
135+
public static function isIE(): bool
136136
{
137-
$dataFile = pathinfo($path);
138-
return trim("seosee_" . md5($dataFile["dirname"]) . "_" . $dataFile["filename"] . ".min." . $dataFile["extension"]);
137+
return strpos(\Environment::get('httpUserAgent'), 'MSIE') !== FALSE ||
138+
strpos(\Environment::get('httpUserAgent'), 'Trident') !== FALSE;
139139
}
140140
}

0 commit comments

Comments
 (0)