|
2 | 2 | {% set header_classes = ["bd-header-announcement", "container-fluid", "init"] %}
|
3 | 3 | {% set is_remote=theme_announcement.startswith("http") %}
|
4 | 4 | {# If we are remote, add a script to make an HTTP request for the value on page load #}
|
5 |
| -{%- if is_remote %} |
6 | 5 | <script>
|
7 |
| -document.write(`<aside class="bd-header-announcement d-print-none" aria-label="{{ banner_label }}"></aside>`); |
8 |
| -fetch("{{ theme_announcement }}") |
9 |
| - .then(res => {return res.text();}) |
10 |
| - .then(data => { |
11 |
| - if (data.length === 0) { |
12 |
| - console.log("[PST]: Empty announcement at: {{ theme_announcement }}"); |
13 |
| - return; |
14 |
| - } |
15 |
| - div = document.querySelector(".bd-header-announcement"); |
16 |
| - div.classList.add(...{{ header_classes | tojson }}); |
17 |
| - div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`; |
| 6 | +function setAnnouncementHeight() { |
| 7 | + const div = document.querySelector(".bd-header-announcement"); |
18 | 8 | // At least 3rem height
|
19 | 9 | const autoHeight = Math.min(
|
20 | 10 | div.offsetHeight,
|
|
36 | 26 | div.style.setProperty("min-height", "3rem");
|
37 | 27 | }, 320);
|
38 | 28 | }, 10);
|
39 |
| - }) |
40 |
| - .catch(error => { |
41 |
| - console.log("[PST]: Failed to load announcement at: {{ theme_announcement }}"); |
42 |
| - }); |
| 29 | + } |
| 30 | +is_remote = {{ is_remote | tojson }}; |
| 31 | +if (is_remote) { |
| 32 | + document.write(`<aside class="bd-header-announcement d-print-none" aria-label="{{ banner_label }}"></aside>`); |
| 33 | + fetch("{{ theme_announcement }}") |
| 34 | + .then(res => {return res.text();}) |
| 35 | + .then(data => { |
| 36 | + if (data.length === 0) { |
| 37 | + console.log("[PST]: Empty announcement at: {{ theme_announcement }}"); |
| 38 | + return; |
| 39 | + } |
| 40 | + div = document.querySelector(".bd-header-announcement"); |
| 41 | + div.classList.add(...{{ header_classes | tojson }}); |
| 42 | + div.innerHTML = `<div class="bd-header-announcement__content">${data}</div>`; |
| 43 | + setAnnouncementHeight(); |
| 44 | + }) |
| 45 | + .catch(error => { |
| 46 | + console.log("[PST]: Failed to load announcement at: {{ theme_announcement }}"); |
| 47 | + }); |
| 48 | +} else { |
| 49 | + document.write(`<aside class="{{ header_classes | join(' ') }} bd-header-announcement" aria-label="{{ banner_label }}"> |
| 50 | + <div class="bd-header-announcement__content">{{ theme_announcement }}</div> |
| 51 | + </aside>`) |
| 52 | + console.log("[PST]: Using local announcement.") |
| 53 | + setAnnouncementHeight(); |
| 54 | +} |
43 | 55 | </script>
|
44 |
| -{#- if announcement text is not remote, populate announcement w/ local content -#} |
45 |
| -{%- else %} |
46 |
| - <aside class="{{ header_classes | join(' ') }} bd-header-announcement" |
47 |
| - aria-label="{{ banner_label }}"> |
48 |
| - <div class="bd-header-announcement__content">{{ theme_announcement }}</div> |
49 |
| - </aside> |
50 |
| -{% endif %} |
|
0 commit comments