|
5 | 5 | <script src="{{ '/javascripts/prism.js' | cache_buster }}" type="text/javascript" defer></script>
|
6 | 6 | <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@docsearch/js@3/dist/umd/index.min.js"></script>
|
7 | 7 | <script type="text/javascript">
|
8 |
| -docsearch({ |
9 |
| - container: '#docsearch', |
10 |
| - appId: 'FBHBYS3J0U', |
11 |
| - indexName: 'home-assistant', |
12 |
| - apiKey: "{{ site.algolia.api_key }}", |
13 |
| -}); |
14 |
| -document.querySelector('.site-title').addEventListener('contextmenu', function(ev) { |
15 |
| - ev.preventDefault(); |
16 |
| - document.location.assign("https://design.home-assistant.io/#brand/logo") |
17 |
| -}); |
| 8 | + docsearch({ |
| 9 | + container: '#docsearch', |
| 10 | + appId: 'FBHBYS3J0U', |
| 11 | + indexName: 'home-assistant', |
| 12 | + apiKey: "{{ site.algolia.api_key }}", |
| 13 | + }); |
| 14 | + document.querySelector('.site-title').addEventListener('contextmenu', function (ev) { |
| 15 | + ev.preventDefault(); |
| 16 | + document.location.assign("https://design.home-assistant.io/#brand/logo") |
| 17 | + }); |
18 | 18 | </script>
|
19 | 19 |
|
20 | 20 |
|
21 | 21 | {% if page.hero_unit %}
|
22 | 22 | <script type="text/javascript">
|
23 |
| - const changeNavColor = () => { |
24 |
| - const scrollPosition = document.documentElement.scrollTop; |
25 |
| - const nav = document.querySelector("header"); |
26 |
| - if (scrollPosition <= 1) { |
27 |
| - nav.classList.add("dark"); |
28 |
| - } else { |
29 |
| - nav.classList.remove("dark"); |
| 23 | + { |
| 24 | + const changeNavColor = () => { |
| 25 | + const scrollPosition = document.documentElement.scrollTop; |
| 26 | + const nav = document.querySelector("header"); |
| 27 | + if (scrollPosition <= 1) { |
| 28 | + nav.classList.add("dark"); |
| 29 | + } else { |
| 30 | + nav.classList.remove("dark"); |
| 31 | + } |
30 | 32 | }
|
31 |
| - } |
32 | 33 |
|
33 |
| - window.addEventListener("load", () => changeNavColor()); |
34 |
| - window.addEventListener("scroll", () => changeNavColor()); |
| 34 | + window.addEventListener("load", () => changeNavColor()); |
| 35 | + window.addEventListener("scroll", () => changeNavColor(), { passive: true }); |
| 36 | + } |
35 | 37 | </script>
|
36 | 38 | {% endif %}
|
| 39 | + |
| 40 | +<script type="text/javascript"> |
| 41 | + { |
| 42 | + const article = document.querySelector("article.post"); |
| 43 | + if (article) { |
| 44 | + const iframes = article.querySelectorAll("iframe[data-src]"); |
| 45 | + let loaded = false; |
| 46 | + if (iframes) { |
| 47 | + document.addEventListener('mousemove', loadLazyFrames, { passive: true, once: true }); |
| 48 | + document.addEventListener('touchmove', loadLazyFrames, { passive: true, once: true }); |
| 49 | + document.addEventListener('scroll', loadLazyFrames, { passive: true, once: true }); |
| 50 | + |
| 51 | + function loadLazyFrames() { |
| 52 | + if (loaded) return; |
| 53 | + loaded = true; |
| 54 | + |
| 55 | + iframes.forEach((iframe) => { |
| 56 | + const src = iframe.getAttribute("data-src"); |
| 57 | + if (src) { |
| 58 | + iframe.setAttribute("src", src); |
| 59 | + iframe.removeAttribute("data-src"); |
| 60 | + } |
| 61 | + }); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +</script> |
0 commit comments