1/* wpc_lazy_chrome.js â hydrate decorative chrome imagery that ships as 2 data-src / data-srcset instead of src / srcset. 3 4 WHY the markup is written that way: chrome art (tool promo covers, modal 5 artwork, card-brand icons) is not content. A real `src` makes it a crawlable 6 image URL on high-authority surfaces â the homepage and the five type 7 archives â competing for the image-SEO signal those pages should spend on 8 wallpapers. Google Images keeps one landing page per image URL, so every 9 extra claimant is a dilution. Chrome should be visible, never claimed. 10 11 IntersectionObserver, not a blanket sweep on load, for two reasons: 12 1. it keeps the fetch off the critical path â these are below-fold strips; 13 2. hidden chrome never intersects, so nav mega-menu panels and the 14 checkout / upsell / funnel modals are left alone. Those have their own 15 open-time hydrators (wp-nav.js, checkout_modal.js, upsell.js) and must 16 NOT be forced to load while closed. 17 18 No-JS behaviour is deliberate: the strips render as text-only cards. They 19 are promos, not content, so a missing cover costs nothing that matters. */ 20(function () { 21 var SEL = 'img[data-src], source[data-srcset]'; 22 23 function hydrate(el) { 24 var v = el.getAttribute('data-src') || el.getAttribute('data-srcset'); 25 if (!v) return; 26 // A <source> inside <picture> wins over the <img>, so both halves must be
27 // hydrated or the browser paints nothing. 28 if (el.tagName === 'SOURCE') { el.srcset = v; el.removeAttribute('data-srcset'); } 29 else { el.src = v; el.removeAttribute('data-src'); } 30 } 31 32 function boot() { 33 var nodes = document.querySelectorAll(SEL); 34 if (!nodes.length) return; 35 if (!('IntersectionObserver' in window)) { 36 // Old browser: just hydrate everything. Correctness beats the fetch 37 // ordering nicety on a browser this old. 38 Array.prototype.forEach.call(nodes, hydrate); 39 return; 40 } 41 var io = new IntersectionObserver(function (entries) { 42 entries.forEach(function (entry) { 43 if (!entry.isIntersecting) return; 44 var el = entry.target; 45 io.unobserve(el); 46 // Hydrate the whole <picture>, not just the element that tripped the 47 // observer â the <img> is what intersects, but its <source> siblings 48 // are what the browser actually picks from. 49 var pic = el.closest ? el.closest('picture') : null; 50 if (pic) pic.querySelectorAll(SEL).forEach(hydrate); 51 else hydrate(el); 52 }); 53 }, { rootMargin: '300px 0px' }); 54 Array.prototype.forEach.call(nodes, function (el) { 55 // Observe the <img>: a <source> has no box and never intersects. 56 if (el.tagName === 'IMG') io.observe(el); 57 }); 58 } 59 60 if (document.readyState === 'loading') { 61 document.addEventListener('DOMContentLoaded', boot); 62 } else { 63 boot(); 64 } 65})();
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.