| 28 | |
| 29 | // Size the title to fit the available space. |
| 30 | function updateTitleFontSize() { |
| 31 | let fontSize = parseInt(window.getComputedStyle(title).fontSize, 10); |
| 32 | |
| 33 | // Constrain font size to 58px, or 10% of the window width, whichever is smaller. |
| 34 | let maxFontSize = Math.min(58, Math.round(window.innerWidth * 0.1)); |
| 35 | if (fontSize > maxFontSize) { |
| 36 | fontSize = maxFontSize; |
| 37 | title.style.fontSize = maxFontSize + 'px'; |
| 38 | } |
| 39 | |
| 40 | // If the font size is less than the maximum font size, |
| 41 | // increase the font size until it overflows. |
| 42 | while (fontSize < maxFontSize && title.scrollWidth <= title.clientWidth) { |
| 43 | fontSize++; |
| 44 | title.style.fontSize = fontSize + 'px'; |
| 45 | } |
| 46 | |
| 47 | // Reduce the font size until it doesn't overflow. |
| 48 | while (fontSize > 10 && title.scrollWidth > title.clientWidth + 1) { |
| 49 | fontSize--; |
| 50 | title.style.fontSize = fontSize + 'px'; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | updateTitleFontSize(); |
| 55 | |