PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.6.21
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.6.21
2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 2.6.4 2.6.3 2.5.23 All 138 releases
metasync / admin / js / metasync-iframe.js

metasync-iframe.js in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.6.21, at admin/js/metasync-iframe.js

85 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * MetaSync iframe height auto-resize.
3 *
4 * Extracted from admin/class-metasync-admin.php (Phase 5, #887).
5 */
6 function adjustIframeHeight(iframe) {
7 var attempts = 0;
8 var maxAttempts = 20; // Try for up to 10 seconds
9
10 function tryAdjustHeight() {
11 try {
12 attempts++;
13
14 // Try to access iframe content height
15 var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
16 if (iframeDocument) {
17 // Wait for content to load by checking if body has meaningful content
18 var body = iframeDocument.body;
19 var hasContent = body && (body.children.length > 1 || body.innerText.trim().length > 100);
20
21 if (!hasContent && attempts < maxAttempts) {
22 // Content still loading, try again
23 setTimeout(tryAdjustHeight, 500);
24 return;
25 }
26
27 var height = Math.max(
28 body ? body.scrollHeight : 0,
29 body ? body.offsetHeight : 0,
30 iframeDocument.documentElement.clientHeight,
31 iframeDocument.documentElement.scrollHeight,
32 iframeDocument.documentElement.offsetHeight
33 );
34
35 // Only apply if we got a reasonable height
36 if (height > 600) {
37 iframe.style.height = height + 'px';
38 } else if (attempts < maxAttempts) {
39 // Height too small, content probably still loading
40 setTimeout(tryAdjustHeight, 500);
41 return;
42 }
43 } else {
44 // Can't access content, try again or fallback
45 if (attempts < maxAttempts) {
46 setTimeout(tryAdjustHeight, 500);
47 return;
48 }
49 }
50 } catch (e) {
51 // Cross-origin restrictions - use viewport height
52 iframe.style.height = '100vh';
53 }
54 }
55
56 // Start the height adjustment process
57 tryAdjustHeight();
58 }
59
60 // Bind to the dashboard iframe via addEventListener
61 (function() {
62 var iframe = document.getElementById('metasync-dashboard-iframe');
63 if (iframe) {
64 iframe.addEventListener('load', function() {
65 adjustIframeHeight(iframe);
66 });
67 }
68
69 // Also listen for window resize
70 window.addEventListener('resize', function() {
71 var iframe = document.getElementById('metasync-dashboard-iframe');
72 if (iframe) {
73 adjustIframeHeight(iframe);
74 }
75 });
76
77 // Additional attempt after 3 seconds (for very slow loading apps)
78 setTimeout(function() {
79 var iframe = document.getElementById('metasync-dashboard-iframe');
80 if (iframe) {
81 adjustIframeHeight(iframe);
82 }
83 }, 3000);
84 })();
85