|
1 | 1 | /* global document */ |
2 | 2 | (function() { |
3 | 3 | var targets = document.querySelectorAll('pre'); |
| 4 | + var main = document.querySelector('#main'); |
| 5 | + |
| 6 | + var footer = document.querySelector('#footer'); |
| 7 | + var pageTitle = document.querySelector('#page-title'); |
| 8 | + var pageTitleHeight = 0; |
| 9 | + |
| 10 | + var footerHeight = footer.getBoundingClientRect().height; |
| 11 | + |
| 12 | + if (pageTitle) { |
| 13 | + pageTitleHeight = pageTitle.getBoundingClientRect().height; |
| 14 | + |
| 15 | + // Adding margin (Outer height) |
| 16 | + pageTitleHeight += 45; |
| 17 | + } |
| 18 | + |
| 19 | + // subtracted 20 for extra padding. |
| 20 | + // eslint-disable-next-line no-undef |
| 21 | + var divMaxHeight = window.innerHeight - pageTitleHeight - footerHeight - 80; |
4 | 22 |
|
5 | 23 | setTimeout(function() { |
6 | 24 | targets.forEach(function(item) { |
7 | 25 | var innerHTML = item.innerHTML; |
8 | 26 | var divElement = document.createElement('div'); |
9 | 27 |
|
| 28 | + divElement.style.maxHeight = divMaxHeight + 'px'; |
| 29 | + divElement.style.marginTop = '2rem'; |
10 | 30 | divElement.innerHTML = innerHTML; |
11 | 31 | // item.removeChild(); |
12 | 32 | item.innerHTML = ''; |
13 | 33 | item.appendChild(divElement); |
14 | 34 | }); |
| 35 | + |
| 36 | + // eslint-disable-next-line no-undef |
| 37 | + main.style.minHeight = window.innerHeight - footerHeight - 15 + 'px'; |
| 38 | + |
| 39 | + // See if we have to move something into view |
| 40 | + // eslint-disable-next-line no-undef |
| 41 | + var location = window.location.href.split('#')[1]; |
| 42 | + |
| 43 | + if (location && location.length > 0) { |
| 44 | + var element = document.querySelector('#'.concat(location)); |
| 45 | + |
| 46 | + element.scrollIntoView(); |
| 47 | + } |
15 | 48 | }, 300); |
16 | 49 | })(); |
0 commit comments