PluginProbe
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor / 2.0.13
Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor v2.0.13
2.0.13 2.0.12 2.0.11 2.0.10 2.0.9 trunk 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8
blockenberg / blocks / embed / frontend.js

frontend.js in Blockenberg — 600+ Advanced Gutenberg Blocks & AI Agent for WordPress Block Editor 2.0.13, at blocks/embed/frontend.js

43 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 // Embed Block — lazy-load iframes on scroll for performance
5 function initEmbeds() {
6 var iframes = document.querySelectorAll('.bkbg-embed-iframe[loading="lazy"]');
7 if (!iframes.length) return;
8
9 // Modern browsers handle loading="lazy" natively on iframes
10 // This is a fallback for older browsers
11 if ('loading' in HTMLIFrameElement.prototype) return;
12
13 if (!('IntersectionObserver' in window)) return;
14
15 var obs = new IntersectionObserver(function (entries) {
16 entries.forEach(function (entry) {
17 if (!entry.isIntersecting) return;
18 var iframe = entry.target;
19 var dataSrc = iframe.getAttribute('data-src');
20 if (dataSrc) {
21 iframe.src = dataSrc;
22 iframe.removeAttribute('data-src');
23 }
24 obs.unobserve(iframe);
25 });
26 }, { rootMargin: '200px 0px' });
27
28 iframes.forEach(function (iframe) {
29 if (iframe.src && !iframe.getAttribute('data-src')) {
30 iframe.setAttribute('data-src', iframe.src);
31 iframe.removeAttribute('src');
32 }
33 obs.observe(iframe);
34 });
35 }
36
37 if (document.readyState === 'loading') {
38 document.addEventListener('DOMContentLoaded', initEmbeds);
39 } else {
40 initEmbeds();
41 }
42 }());
43