|
1 |
| -<meta name="google-site-verification" content="Lffz_ab-_S5cmA07ZXVbucHVklaRsnk8gEt8frHKjMk" /> |
| 1 | +<meta name="google-site-verification" content="Lffz_ab-_S5cmA07ZXVbucHVklaRsnk8gEt8frHKjMk"/> |
2 | 2 | <!-- Google Analytics -->
|
3 | 3 | <script>
|
4 | 4 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
11 | 11 | </script>
|
12 | 12 | <!-- End Google Analytics -->
|
13 | 13 | <script>
|
14 |
| - window.onload = function () { |
| 14 | + window.onload = function() { |
15 | 15 | function updateIframeThemes(theme) {
|
16 | 16 | const iframes = document.getElementsByTagName('iframe');
|
17 | 17 |
|
|
46 | 46 | }
|
47 | 47 |
|
48 | 48 | function doObserveIFrame(el) {
|
49 |
| - resize_iframe_out(el) |
50 |
| - let observer = new MutationObserver(function (mutations) { |
51 |
| - var resize = false |
| 49 | + resize_iframe_out(el); |
| 50 | + const mutationObserver = new MutationObserver((mutations) => { |
| 51 | + let resize = false; |
52 | 52 | for (let mutation of mutations) {
|
53 | 53 | // skip attribute changes except open to avoid loop
|
54 | 54 | // (callback sees change in iframe, triggers resize, sees change...)
|
55 | 55 | if (mutation.type === 'attributes') {
|
56 | 56 | if (mutation.attributeName === 'open') {
|
57 |
| - resize_iframe_out(el) |
58 |
| - resized = true |
| 57 | + resize = true; |
59 | 58 | }
|
60 | 59 | } else {
|
61 |
| - |
62 |
| - resize = true |
| 60 | + resize = true; |
63 | 61 | }
|
64 | 62 | }
|
65 | 63 | if (resize) {
|
66 |
| - resize_iframe_out(el) |
| 64 | + resize_iframe_out(el); |
67 | 65 | }
|
68 | 66 | });
|
69 |
| - |
70 |
| - observer.observe(el.contentDocument.documentElement, {childList: true, subtree: true, characterData: true, attributes: true}); |
71 |
| - |
| 67 | + mutationObserver.observe( |
| 68 | + el.contentDocument.documentElement, |
| 69 | + { childList: true, subtree: true, characterData: true, attributes: true }, |
| 70 | + ); |
| 71 | + |
| 72 | + const visibilityObserver = new IntersectionObserver( |
| 73 | + () => resize_iframe_out(el), |
| 74 | + { root: document.documentElement }, |
| 75 | + ); |
| 76 | + visibilityObserver.observe(el); |
72 | 77 | }
|
73 | 78 |
|
74 | 79 | function observeIFrame(el) {
|
75 |
| - if (el.contentWindow && el.contentWindow.performance && el.contentWindow.performance.timing.loadEventEnd === 0) { |
76 |
| - el.addEventListener('load', () => doObserveIFrame(el), true) |
| 80 | + if (el.contentWindow && |
| 81 | + el.contentWindow.performance && |
| 82 | + el.contentWindow.performance.timing.loadEventEnd === 0 |
| 83 | + ) { |
| 84 | + el.addEventListener('load', () => doObserveIFrame(el), true); |
77 | 85 | } else {
|
78 |
| - doObserveIFrame(el) |
| 86 | + doObserveIFrame(el); |
79 | 87 | }
|
80 | 88 | }
|
81 | 89 |
|
82 | 90 | let iframes = document.querySelectorAll('iframe');
|
83 |
| - |
84 | 91 | for (let i = 0; i < iframes.length; i++) {
|
85 |
| - observeIFrame(iframes[i]) |
| 92 | + observeIFrame(iframes[i]); |
86 | 93 | }
|
87 | 94 |
|
88 |
| - let bodyObserver = new MutationObserver(function (mutations) { |
89 |
| - mutations.forEach(function (mutation) { |
| 95 | + let bodyObserver = new MutationObserver((mutations) => { |
| 96 | + mutations.forEach(function(mutation) { |
90 | 97 | for (let i = 0; i < mutation.addedNodes.length; i++) {
|
91 | 98 | let addedNode = mutation.addedNodes[i];
|
92 | 99 | if (addedNode.tagName === 'IFRAME') {
|
93 | 100 | observeIFrame(addedNode);
|
94 | 101 | } else if (addedNode.tagName === 'SECTION') {
|
95 |
| - let iframes = []; |
96 |
| - |
97 | 102 | function traverse(node) {
|
98 | 103 | if (node.tagName === 'IFRAME') {
|
99 | 104 | observeIFrame(node);
|
100 | 105 | }
|
101 |
| - |
102 | 106 | for (let i = 0; i < node.children.length; i++) {
|
103 | 107 | traverse(node.children[i]);
|
104 | 108 | }
|
|
110 | 114 | });
|
111 | 115 | });
|
112 | 116 |
|
113 |
| - bodyObserver.observe(document.documentElement || document.body, {childList: true, subtree: true, attributes: true}); |
114 |
| - observeHtmlClassChanges() |
| 117 | + bodyObserver.observe( |
| 118 | + document.documentElement || document.body, |
| 119 | + { childList: true, subtree: true, attributes: true }, |
| 120 | + ); |
| 121 | + observeHtmlClassChanges(); |
| 122 | + |
115 | 123 | // initialize theme
|
116 | 124 | const htmlElement = document.documentElement;
|
117 | 125 | const theme = htmlElement.classList.contains('theme-light') ? 'light' : 'dark';
|
118 | 126 | updateIframeThemes(theme);
|
119 |
| - } |
| 127 | + }; |
120 | 128 | </script>
|
0 commit comments