-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preload template and options via layout
- Loading branch information
Rob Aimes
committed
Nov 20, 2020
1 parent
6869281
commit 57a8b1e
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Fisheye Media Ltd. All rights reserved. | ||
* See LICENCE.txt for licence details. | ||
*/ | ||
|
||
namespace Fisheye\Lazyload\Block; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Magento\Framework\Serialize\SerializerInterface; | ||
|
||
class Preload extends Template | ||
{ | ||
/** | ||
* @var SerializerInterface | ||
*/ | ||
protected $serializer; | ||
|
||
/** | ||
* @param Template\Context $context | ||
* @param SerializerInterface $serializer | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
SerializerInterface $serializer, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->serializer = $serializer; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getJsConfig(): string | ||
{ | ||
return $this->serializer->serialize([ | ||
'preload_selectors' => $this->getData('preload_elements'), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Fisheye Media Ltd. All rights reserved. | ||
* See LICENCE.txt for licence details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="before.body.end"> | ||
<block name="lazyload.preload.config" | ||
class="Fisheye\Lazyload\Block\Preload" | ||
template="Fisheye_Lazyload::preload.phtml" | ||
ifconfig="catalog/product_image_lazyload/preload"> | ||
<arguments> | ||
<!-- | ||
* Item "name" attribute should be descriptive to the area | ||
* Item value should be a CSS selector vage enough to select groups of elements for efficiency | ||
--> | ||
<argument name="preload_elements" xsi:type="array"> | ||
<item name="header_images" xsi:type="string">header .lazyload</item> | ||
</argument> | ||
</arguments> | ||
</block> | ||
</referenceContainer> | ||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Copyright © Fisheye Media Ltd. All rights reserved. | ||
* See LICENCE.txt for licence details. | ||
*/ | ||
/** @var Fisheye\Lazyload\Block\Preload $block */ | ||
?> | ||
<script type="text/x-magento-init"> | ||
{ | ||
"*": { | ||
"Fisheye_Lazyload/js/preload": <?= /* @noEscape */ $block->getJsConfig() ?> | ||
} | ||
} | ||
</script> |