PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / trunk
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more vtrunk
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / assets / js / lazy-load.js
embedpress / assets / js Last commit date
chunks 1 week ago vendor 8 months ago admin.build.js 1 week ago admin.js 3 months ago analytics-tracker.js 4 weeks ago analytics.build.js 1 week ago blocks.build.js 1 week ago carousel.js 1 year ago custom-player.build.js 1 week ago documents-viewer-script.js 3 months ago ep-pdf-lightbox.js 3 months ago ep-view-count.js 1 week ago ep-yt-queue.js 4 weeks ago feature-notices.js 7 months ago front.js 4 weeks ago frontend.build.js 3 months ago gallery-justify.js 1 week ago gutneberg-script.js 1 month ago index.html 7 years ago initCarousel.js 2 years ago initplyr.js 1 month ago instafeed.js 4 weeks ago instagram-shortcode-generator.js 1 month ago lazy-load.js 6 months ago license.js 3 months ago meetup-timezone.js 3 months ago onboarding.build.js 1 week ago pdf-gallery-elementor-editor.js 3 months ago pdf-gallery.js 3 months ago preview.js 8 months ago settings.js 3 months ago sponsored.js 9 months ago
lazy-load.js
150 lines
1 /**
2 * EmbedPress Lazy Load
3 *
4 * Custom lazy loading implementation for iframe embeds using Intersection Observer API
5 * Only loads iframes when they're about to enter the viewport
6 *
7 * @package EmbedPress
8 * @since 4.0.0
9 */
10
11 (function() {
12 'use strict';
13
14 // Check if Intersection Observer is supported
15 if (!('IntersectionObserver' in window)) {
16 console.warn('EmbedPress Lazy Load: IntersectionObserver not supported, loading all iframes immediately');
17 loadAllIframes();
18 return;
19 }
20
21 /**
22 * Get dynamic root margin based on viewport height
23 * This prevents lazy loading from triggering immediately on short pages
24 * Uses 50% of viewport height or 200px, whichever is smaller
25 */
26 function getObserverConfig() {
27 const viewportHeight = window.innerHeight;
28 const margin = Math.min(200, Math.max(50, viewportHeight * 0.25));
29
30 return {
31 rootMargin: margin + 'px 0px',
32 threshold: 0.01
33 };
34 }
35
36 const observerConfig = getObserverConfig();
37
38 /**
39 * Callback function when iframe placeholder enters viewport
40 */
41 function onIntersection(entries, observer) {
42 entries.forEach(function(entry) {
43 if (entry.isIntersecting) {
44 const placeholder = entry.target;
45 loadIframe(placeholder);
46 observer.unobserve(placeholder);
47 }
48 });
49 }
50
51 /**
52 * Load the actual iframe from placeholder
53 */
54 function loadIframe(placeholder) {
55 const iframeSrc = placeholder.getAttribute('data-ep-lazy-src');
56
57 if (!iframeSrc) {
58 console.warn('EmbedPress Lazy Load: No data-ep-lazy-src found on placeholder');
59 return;
60 }
61
62 // Create iframe element
63 const iframe = document.createElement('iframe');
64 iframe.src = iframeSrc;
65
66 // Copy style
67 const iframeStyle = placeholder.getAttribute('data-ep-iframe-style');
68 if (iframeStyle) {
69 iframe.setAttribute('style', iframeStyle);
70 }
71
72 // Copy all data-ep-iframe-* attributes
73 Array.from(placeholder.attributes).forEach(function(attr) {
74 if (attr.name.startsWith('data-ep-iframe-')) {
75 const iframeAttr = attr.name.replace('data-ep-iframe-', '');
76 if (iframeAttr !== 'style') {
77 iframe.setAttribute(iframeAttr, attr.value);
78 }
79 }
80 });
81
82 // Copy class (remove placeholder class)
83 if (placeholder.hasAttribute('class')) {
84 const classes = placeholder.getAttribute('class').replace(/ep-lazy-iframe-placeholder/g, '').trim();
85 if (classes) {
86 iframe.setAttribute('class', classes);
87 }
88 }
89
90 // Copy other important attributes
91 ['data-emid', 'data-embedpress-content', 'data-embed-type', 'title'].forEach(function(attr) {
92 if (placeholder.hasAttribute(attr)) {
93 iframe.setAttribute(attr, placeholder.getAttribute(attr));
94 }
95 });
96
97 // Replace placeholder with iframe
98 if (placeholder.parentNode) {
99 placeholder.parentNode.replaceChild(iframe, placeholder);
100 }
101 }
102
103 /**
104 * Fallback: Load all iframes immediately (for unsupported browsers)
105 */
106 function loadAllIframes() {
107 const placeholders = document.querySelectorAll('.ep-lazy-iframe-placeholder');
108 placeholders.forEach(function(placeholder) {
109 // Add 2 second delay before loading iframe
110 loadIframe(placeholder);
111 });
112 }
113
114 /**
115 * Initialize lazy loading
116 */
117 function initLazyLoad() {
118 const placeholders = document.querySelectorAll('.ep-lazy-iframe-placeholder');
119
120 if (placeholders.length === 0) {
121 return;
122 }
123
124 // Create observer
125 const observer = new IntersectionObserver(onIntersection, observerConfig);
126
127 // Observe all placeholders
128 placeholders.forEach(function(placeholder) {
129 observer.observe(placeholder);
130 });
131 }
132
133 /**
134 * Run on DOM ready
135 */
136 if (document.readyState === 'loading') {
137 // Add 2 second delay before initializing lazy load
138 setTimeout(initLazyLoad, 1000);
139 } else {
140 setTimeout(initLazyLoad, 1000);
141 }
142
143 /**
144 * Re-initialize for dynamically added content (e.g., AJAX loaded content)
145 */
146 window.epReinitLazyLoad = initLazyLoad;
147
148 })();
149
150