|
9 | 9 | <?php |
10 | 10 | /** |
11 | 11 | * @var $block \Magefan\LazyLoad\Block\Lazy |
| 12 | + * @var $mfSecureRenderer \Magefan\Community\Api\SecureHtmlRendererInterface |
12 | 13 | */ |
13 | 14 | ?> |
14 | 15 | <?php if ($block->isNoScriptEnabled()) { ?> |
|
20 | 21 | </style> |
21 | 22 | <?php } ?> |
22 | 23 | <?php if ($block->getIsJavascriptLazyLoadMethod()) { ?> |
23 | | -<script data-rocketjavascript="false"> |
| 24 | +<?php |
| 25 | +$script = " |
24 | 26 | 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]'))) { |
26 | 28 | loadLazyLoad(); |
27 | 29 | } |
28 | 30 | }, 10); |
29 | 31 |
|
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]'))) { |
32 | 34 | loadLazyLoad(); |
33 | 35 | } else { |
34 | 36 | document.addEventListener('scroll', loadLazyLoad, { once: true }); |
|
43 | 45 |
|
44 | 46 | function loadLazyLoad() { |
45 | 47 | clearInterval(window.mfLazyUtilLoad); |
46 | | - <?php if ($block->isNoScriptEnabled()) { ?> |
| 48 | + " . ($block->isNoScriptEnabled() ? " |
47 | 49 | 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)} |
51 | 53 | loadScript(jsSrc, function(){ |
52 | | - var lazyLoadConfig = <?= $block->getLazyLoadConfig() ?>; |
| 54 | + var lazyLoadConfig = {$block->getLazyLoadConfig()}; |
53 | 55 | var myLazyLoad = false; |
54 | 56 | if (document.readyState !== 'loading') { |
55 | 57 | myLazyLoad = new LazyLoad(lazyLoadConfig); |
56 | 58 | setTimeout(function(){ |
57 | 59 | new LazyLoad(lazyLoadConfig); |
58 | 60 | }, 2000); |
59 | 61 | } else { |
60 | | - document.addEventListener("DOMContentLoaded", function() { |
| 62 | + document.addEventListener('DOMContentLoaded', function() { |
61 | 63 | myLazyLoad = new LazyLoad(lazyLoadConfig); |
62 | 64 | setTimeout(function(){ |
63 | 65 | new LazyLoad(lazyLoadConfig); |
64 | 66 | }, 2000); |
65 | 67 | }); |
66 | 68 | } |
67 | 69 |
|
68 | | - document.body.addEventListener("contentUpdated", function(){ |
| 70 | + document.body.addEventListener('contentUpdated', function(){ |
69 | 71 | if (myLazyLoad) { |
70 | 72 | myLazyLoad.update(); |
71 | 73 | } |
72 | 74 | }); |
73 | 75 | return true; |
74 | 76 | }); |
75 | 77 | } |
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() { |
79 | 85 | function replacePixelImage(img) { |
80 | 86 | if (!img.classList.contains('loaded')) { |
81 | 87 | var src = img.getAttribute('data-original'); |
|
96 | 102 | var productInfoDetailedImg = document.querySelector('.product.info.detailed .data.item.title a'); |
97 | 103 | if(productInfoDetailedImg){ |
98 | 104 | 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){ |
100 | 106 | replacePixelImage(el); |
101 | 107 | }); |
102 | 108 | }); |
103 | 109 | } |
104 | 110 |
|
105 | 111 | 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); |
108 | 114 | }); |
109 | 115 |
|
110 | 116 | 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) { |
112 | 118 | replacePixelImage(el); |
113 | 119 | }); |
114 | 120 | } |
|
156 | 162 | }); |
157 | 163 | }, 2000); |
158 | 164 | }); |
159 | | -</script> |
| 165 | +"; |
| 166 | +?> |
| 167 | +<?= /* @noEscape */ $mfSecureRenderer->renderTag('script', [], $script, false) ?> |
160 | 168 | <?php } ?> |
161 | 169 |
|
162 | 170 | <style> |
|
0 commit comments