Skip to content

Commit 26355f3

Browse files
committed
Refactor last pr
1 parent 004de49 commit 26355f3

File tree

8 files changed

+12
-164
lines changed

8 files changed

+12
-164
lines changed

Block/Adminhtml/System/Config/Form/Js.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

Model/Config/Source/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Method implements \Magento\Framework\Option\ArrayInterface
3333
public function toOptionArray(): array
3434
{
3535
return [
36-
['value' => self::JAVASCRIPT, 'label' => __('Non-jQuery JavaScript Library (Require Advanced Configuration)')],
36+
['value' => self::JAVASCRIPT, 'label' => __('Non-jQuery JavaScript Library (Requires Advanced Configuration)')],
3737
['value' => self::NATIVE, 'label' => __('Native Browser Lazy Loading')],
3838
];
3939
}

Plugin/BlockPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected function isEnabled($block, string $html): bool
245245
* @param $block
246246
* @return bool
247247
*/
248-
private function isBlockSkiped($block): bool
248+
private function isBlockSkipped($block): bool
249249
{
250250
return in_array(get_class($block), $this->skipBlocks);
251251
}

Setup/Patch/Data/SaveDefaultLazyLoadMethod.php

Lines changed: 0 additions & 95 deletions
This file was deleted.

etc/adminhtml/system.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
<field id="method" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="27" translate="label comment" type="select" canRestore="1">
3232
<label>Method</label>
3333
<source_model>Magefan\LazyLoad\Model\Config\Source\Method</source_model>
34-
<frontend_model>Magefan\LazyLoad\Block\Adminhtml\System\Config\Form\Js</frontend_model>
3534
</field>
3635

3736
<field id="blocks_to_lazy_load" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="28" translate="label comment" type="select" canRestore="1">
@@ -40,10 +39,10 @@
4039

4140
<comment><![CDATA[
4241
<strong>If the "All" option is chosen:</strong><br/>
43-
Lazy Load will be added to all blocks. In the "Lazy Load Blocks" section you can skip n images for some blocks to make them visible immediately.
42+
Lazy Load will be added to all blocks. In the "Lazy Load Blocks" section you can skip a few images for some blocks to make them visible immediately.
4443
<br/>
4544
<strong>If the "Selected" option is chosen:</strong><br/>
46-
You need to specify the blocks in which images should be lazy-loaded. Here you can also skip the first n images.
45+
You need to specify the blocks in which images should be lazy-loaded. Here you can also skip the first few images.
4746
]]></comment>
4847
</field>
4948

@@ -65,7 +64,7 @@
6564
<depends>
6665
<field id="method">0</field>
6766
</depends>
68-
<tooltip>The noscript HTML element defines a section of HTML that is inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser. This option enables the display of images even when JavaScript is disabled in the browser and lazy load js script cannot be loaded. Note that when enabled it adds extra HTML tags to the page.</tooltip>
67+
<comment>The noscript HTML element defines a section of HTML that is inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser. This option enables the display of images even when JavaScript is disabled in the browser and lazy load js script cannot be loaded. Note that when enabled it adds extra HTML tags to the page.</comment>
6968
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
7069
</field>
7170
</group>

etc/config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<general>
1414
<mfmodule>LazyLoad</mfmodule>
1515
<mftype>1</mftype>
16-
<method>1</method>
17-
<blocks_to_lazy_load>0</blocks_to_lazy_load>
16+
<method>0</method>
17+
<blocks_to_lazy_load>1</blocks_to_lazy_load>
1818
<lazy_blocks>
1919
{
2020
"_1686830676971_971":{"block_identifier":"footer","first_images_to_skip":"0"},

view/adminhtml/templates/js.phtml

Lines changed: 0 additions & 30 deletions
This file was deleted.

view/frontend/templates/lazy.phtml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@
2121
<?php } ?>
2222
<?php if ($block->getIsJavascriptLazyLoadMethod()) { ?>
2323
<script data-rocketjavascript="false">
24-
var utilLoad = setInterval(function() {
25-
if (window.scrollY > 100 || isPixelImageInAViewPort(document.querySelector('main img[src$="pixel.jpg"]'))) {
24+
window.mfLazyUtilLoad = setInterval(function() {
25+
if (window.scrollY > 100 || isMfLazyPixelImageInAViewPort(document.querySelector('main img[src$="pixel.jpg"]'))) {
2626
loadLazyLoad();
2727
}
2828
}, 10);
2929

3030
document.addEventListener("DOMContentLoaded", function () {
31-
if (isPixelImageInAViewPort(document.querySelector('main img[src$="pixel.jpg"]'))) {
31+
if (isMfLazyPixelImageInAViewPort(document.querySelector('main img[src$="pixel.jpg"]'))) {
3232
loadLazyLoad();
3333
} else {
3434
document.addEventListener('scroll', loadLazyLoad, { once: true });
3535
document.addEventListener('click', loadLazyLoad, { once: true });
3636
}
3737
});
3838

39-
function isPixelImageInAViewPort(element, offset = 100)
39+
function isMfLazyPixelImageInAViewPort(element, offset = 100)
4040
{
4141
return element && ((element.getBoundingClientRect().top - offset) < window.innerHeight);
4242
}
4343

4444
function loadLazyLoad() {
45-
clearInterval(utilLoad);
45+
clearInterval(window.mfLazyUtilLoad);
4646
<?php if ($block->isNoScriptEnabled()) { ?>
4747
document.body.className = document.body.className.replace('mflazyzoad-no-js', '');
4848
<?php } ?>

0 commit comments

Comments
 (0)