Skip to content

Commit b7e3bf0

Browse files
committed
Code improvements
1 parent 92d0632 commit b7e3bf0

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

Block/Lazy.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ protected function _toHtml()
3232
return '';
3333
}
3434

35+
/**
36+
* @return bool
37+
*/
38+
public function isNoScriptEnabled()
39+
{
40+
return (bool)$this->_scopeConfig->getValue(
41+
\Magefan\LazyLoad\Model\Config::XML_PATH_LAZY_NOSCRIPT,
42+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
43+
);
44+
}
45+
3546
/**
3647
* Retrieve lazy load config json string
3748
*

Observer/LayoutLoadBeforeObserver.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ public function __construct(
4040
*/
4141
public function execute(\Magento\Framework\Event\Observer $observer)
4242
{
43-
if ($this->config->getEnabled()) {
43+
if ($this->config->getEnabled() && $this->config->isNoScriptEnabled()) {
4444
$layout = $observer->getLayout();
45-
if ($this->config->isNoScriptEnabled()) {
46-
$layout->getUpdate()->addHandle('mflazyzoad_no_js');
47-
}
45+
$layout->getUpdate()->addHandle('mflazyzoad_no_js');
4846
}
4947
}
5048
}

etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</field>
4141
<field id="noscript" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="40" translate="label comment" type="select">
4242
<label>Include Noscript HTML Tag</label>
43-
<comment>The noscript HTML element defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser. This option enables to 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>
43+
<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>
4444
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
4545
</field>
4646
</group>

view/frontend/templates/lazy.phtml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
* Glory to Ukraine! Glory to the heroes!
77
*/
88
?>
9-
<?php
10-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
11-
$config = $objectManager->get(\Magefan\LazyLoad\Model\Config::class);
12-
?>
13-
<?php if ($config->isNoScriptEnabled()) { ?>
9+
<?php if ($block->isNoScriptEnabled()) { ?>
1410
<style>
1511
.mflazyzoad-no-js [data-original],
1612
.mflazyzoad-no-js [data-originalset] {
@@ -20,7 +16,7 @@ $config = $objectManager->get(\Magefan\LazyLoad\Model\Config::class);
2016
<?php } ?>
2117
<script data-rocketjavascript="false">
2218
(function(){
23-
<?php if ($config->isNoScriptEnabled()) { ?>
19+
<?php if ($block->isNoScriptEnabled()) { ?>
2420
document.body.className = document.body.className.replace('mflazyzoad-no-js', '');
2521
<?php } ?>
2622
var jsSrc = '<?php echo $this->getViewFileUrl('Magefan_LazyLoad::js/lazyload.min.js'); ?>';

0 commit comments

Comments
 (0)