1/** 2 * lazy-tags.js â viewport-based orchestrator for lazy ad tags. 3 * 4 * Server-side (Model_Util_Tags::_wrapLazyScripts) renders inert <template data-lazy-ad> 5 * inside containers marked [data-lazy-ad-container] when tag_lazy=1. 6 * This script materializes each container's scripts when it enters a 200px 7 * pre-viewport margin (IntersectionObserver). 8 * 9 * Falls back to immediate materialization on browsers without IntersectionObserver. 10 * No jQuery dependency. 11 */ 12(function () { 13 'use strict'; 14 15 function reanimateScript(original) { 16 var copy = document.createElement('script'); 17 for (var i = 0; i < original.attributes.length; i++) { 18 var attr = original.attributes[i]; 19 copy.setAttribute(attr.name, attr.value); 20 } 21 // Browsers ignore a script's inline body when src is set â mimic that contract. 22 if (!original.src) { 23 copy.textContent = original.textContent; 24 } 25 return copy; 26 } 27 28 function materialize(container) { 29 if (container.dataset.lazyAdDone === '1') return; 30 container.dataset.lazyAdDone = '1'; 31 32 var templates = container.querySelectorAll('template[data-lazy-ad]'); 33 for (var i = 0; i < templates.length; i++) { 34 var tpl = templates[i]; 35 var scripts = tpl.content.querySelectorAll('script'); 36 for (var j = 0; j < scripts.length; j++) { 37 container.appendChild(reanimateScript(scripts[j])); 38 } 39 tpl.parentNode.removeChild(tpl); 40 } 41 } 42
43 function materializeAll(containers) { 44 for (var i = 0; i < containers.length; i++) { 45 materialize(containers[i]); 46 } 47 } 48 49 function initObserver(containers) { 50 var io = new IntersectionObserver(function (entries) { 51 for (var i = 0; i < entries.length; i++) { 52 var entry = entries[i]; 53 if (!entry.isIntersecting) continue; 54 io.unobserve(entry.target); 55 materialize(entry.target); 56 } 57 }, { rootMargin: '200px 0px 200px 0px' }); 58 59 for (var i = 0; i < containers.length; i++) { 60 io.observe(containers[i]); 61 } 62 } 63 64 function init() { 65 var containers = document.querySelectorAll('[data-lazy-ad-container]'); 66 if (!containers.length) return; 67 if (!('IntersectionObserver' in window)) { 68 materializeAll(containers); 69 return; 70 } 71 initObserver(containers); 72 } 73 74 if (document.readyState === 'loading') { 75 document.addEventListener('DOMContentLoaded', init); 76 } else { 77 init(); 78 } 79})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.