Skip to content

Commit 6397276

Browse files
authored
11123-Adapted-To-Security-Policy-M2.4.7
1 parent a9373a2 commit 6397276

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

view/frontend/templates/lazy.phtml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<?php
1010
/**
1111
* @var $block \Magefan\LazyLoad\Block\Lazy
12+
* @var $mfSecureRenderer \Magefan\Community\Api\SecureHtmlRendererInterface
1213
*/
1314
?>
1415
<?php if ($block->isNoScriptEnabled()) { ?>
@@ -20,15 +21,16 @@
2021
</style>
2122
<?php } ?>
2223
<?php if ($block->getIsJavascriptLazyLoadMethod()) { ?>
23-
<script data-rocketjavascript="false">
24+
<?php
25+
$script = "
2426
window.mfLazyUtilLoad = setInterval(function() {
25-
if (window.scrollY > 100 || isMfLazyPixelImageInAViewPort(document.querySelector('main img[src$="pixel.jpg"], main .mflazy-background-image, div[data-original]'))) {
27+
if (window.scrollY > 100 || isMfLazyPixelImageInAViewPort(document.querySelector('main img[src$=\"pixel.jpg\"], main .mflazy-background-image, div[data-original]'))) {
2628
loadLazyLoad();
2729
}
2830
}, 10);
2931
30-
document.addEventListener("DOMContentLoaded", function () {
31-
if (isMfLazyPixelImageInAViewPort(document.querySelector('main img[src$="pixel.jpg"], main .mflazy-background-image, div[data-original]'))) {
32+
document.addEventListener('DOMContentLoaded', function () {
33+
if (isMfLazyPixelImageInAViewPort(document.querySelector('main img[src$=\"pixel.jpg\"], main .mflazy-background-image, div[data-original]'))) {
3234
loadLazyLoad();
3335
} else {
3436
document.addEventListener('scroll', loadLazyLoad, { once: true });
@@ -43,39 +45,43 @@
4345
4446
function loadLazyLoad() {
4547
clearInterval(window.mfLazyUtilLoad);
46-
<?php if ($block->isNoScriptEnabled()) { ?>
48+
" . ($block->isNoScriptEnabled() ? "
4749
document.body.className = document.body.className.replace('mflazyzoad-no-js', '');
48-
<?php } ?>
49-
var jsSrc = '<?php echo $block->getViewFileUrl('Magefan_LazyLoad::js/lazyload.min.js'); ?>';
50-
function loadScript(e,t){var a,n,r;n=!1,(a=document.createElement("script")).type="text/javascript",a.src=e,a.onload=a.onreadystatechange=function(){n||this.readyState&&"complete"!=this.readyState||(n=!0,t())},(r=document.getElementsByTagName("script")[0]).parentNode.insertBefore(a,r)}
50+
" : "") . "
51+
var jsSrc = '{$block->getViewFileUrl('Magefan_LazyLoad::js/lazyload.min.js')}';
52+
function loadScript(e,t){var a,n,r;n=!1,(a=document.createElement('script')).type='text/javascript',a.src=e,a.onload=a.onreadystatechange=function(){n||this.readyState&&\"complete\"!=this.readyState||(n=!0,t())},(r=document.getElementsByTagName('script')[0]).parentNode.insertBefore(a,r)}
5153
loadScript(jsSrc, function(){
52-
var lazyLoadConfig = <?= $block->getLazyLoadConfig() ?>;
54+
var lazyLoadConfig = {$block->getLazyLoadConfig()};
5355
var myLazyLoad = false;
5456
if (document.readyState !== 'loading') {
5557
myLazyLoad = new LazyLoad(lazyLoadConfig);
5658
setTimeout(function(){
5759
new LazyLoad(lazyLoadConfig);
5860
}, 2000);
5961
} else {
60-
document.addEventListener("DOMContentLoaded", function() {
62+
document.addEventListener('DOMContentLoaded', function() {
6163
myLazyLoad = new LazyLoad(lazyLoadConfig);
6264
setTimeout(function(){
6365
new LazyLoad(lazyLoadConfig);
6466
}, 2000);
6567
});
6668
}
6769
68-
document.body.addEventListener("contentUpdated", function(){
70+
document.body.addEventListener('contentUpdated', function(){
6971
if (myLazyLoad) {
7072
myLazyLoad.update();
7173
}
7274
});
7375
return true;
7476
});
7577
}
76-
</script>
77-
<script>
78-
document.addEventListener("DOMContentLoaded", function() {
78+
";
79+
?>
80+
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', ['data-rocketjavascript' => 'false'], $script, false) ?>
81+
<?php
82+
83+
$script = "
84+
document.addEventListener('DOMContentLoaded', function() {
7985
function replacePixelImage(img) {
8086
if (!img.classList.contains('loaded')) {
8187
var src = img.getAttribute('data-original');
@@ -96,19 +102,19 @@
96102
var productInfoDetailedImg = document.querySelector('.product.info.detailed .data.item.title a');
97103
if(productInfoDetailedImg){
98104
productInfoDetailedImg.addEventListener('click', function () {
99-
document.querySelectorAll('.product.info.detailed img[data-original^="h"],.product.info.detailed source[data-originalset^="h"]').forEach(function(el){
105+
document.querySelectorAll('.product.info.detailed img[data-original^=\"h\"],.product.info.detailed source[data-originalset^=\"h\"]').forEach(function(el){
100106
replacePixelImage(el);
101107
});
102108
});
103109
}
104110
105111
document.querySelectorAll('.nav-sections, .navigation-bar').forEach(function(el){
106-
el.addEventListener("click", handlerMouseEvent, false);
107-
el.addEventListener("mouseenter", handlerMouseEvent, false);
112+
el.addEventListener('click', handlerMouseEvent, false);
113+
el.addEventListener('mouseenter', handlerMouseEvent, false);
108114
});
109115
110116
function handlerMouseEvent(e) {
111-
e.target.querySelectorAll('img[data-original^="h"],source[data-originalset^="h"]').forEach(function (el) {
117+
e.target.querySelectorAll('img[data-original^=\"h\"],source[data-originalset^=\"h\"]').forEach(function (el) {
112118
replacePixelImage(el);
113119
});
114120
}
@@ -156,7 +162,9 @@
156162
});
157163
}, 2000);
158164
});
159-
</script>
165+
";
166+
?>
167+
<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?>
160168
<?php } ?>
161169

162170
<style>

0 commit comments

Comments
 (0)