(function () { var root = document.querySelector('[data-blp-legal]'); if (!root) return; var article = root.querySelector('.blp-lg-article'); var heads = Array.prototype.filter.call(article.querySelectorAll('h2'), function (h) { return !h.hasAttribute('data-blp-lg-skip'); }); var toc = root.querySelector('[data-blp-lg-toc]'), tocM = root.querySelector('[data-blp-lg-toc-mobile]'); var used = {}; heads.forEach(function (h, i) { var label = h.textContent.trim(); if (!h.id) h.id = label.toLowerCase().replace(/&/g, 'and').replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '') || 'section-' + (i + 1); if (used[h.id]) h.id += '-' + (i + 1); used[h.id] = 1; if (!h.closest('.blp-lg-contact')) { var n = document.createElement('span'); n.className = 'blp-lg-num'; n.setAttribute('aria-hidden', 'true'); n.textContent = i + 1; h.prepend(n); } [toc, tocM].forEach(function (list) { if (!list) return; var li = document.createElement('li'), a = document.createElement('a'); a.href = '#' + h.id; a.textContent = (h.closest('.blp-lg-contact') ? '' : (i + 1) + '. ') + label; li.appendChild(a); list.appendChild(li); }); }); /* contents links: jump below whatever sticky header the site shows (it can pin itself mid-jump, so correct once) */ function headerOffset() { var bottom = 0; [0.25, 0.5, 0.75].forEach(function (fx) { (document.elementsFromPoint ? document.elementsFromPoint(innerWidth * fx, 2) : []).forEach(function (n) { for (; n && n !== document.body && n !== document.documentElement; n = n.parentElement) { if (root.contains(n)) break; var pos = getComputedStyle(n).position; if (pos === 'fixed' || pos === 'sticky') { var b = n.getBoundingClientRect().bottom; if (b > bottom && b < innerHeight / 2) bottom = b; } } }); }); return bottom; } function jump(el) { function y() { return Math.max(0, el.getBoundingClientRect().top + window.pageYOffset - headerOffset() - 16); } window.scrollTo(0, y()); setTimeout(function () { window.scrollTo(0, y()); }, 80); } [toc, tocM].forEach(function (list) { if (!list) return; list.addEventListener('click', function (e) { var a = e.target.closest('a'); if (!a) return; var el = document.getElementById(a.getAttribute('href').slice(1)); if (!el) return; e.preventDefault(); e.stopPropagation(); if (list === tocM) tocM.closest('details').open = false; jump(el); if (history.replaceState) history.replaceState(null, '', a.getAttribute('href')); }); }); if (location.hash) { var start = document.getElementById(decodeURIComponent(location.hash.slice(1))); if (start && root.contains(start)) setTimeout(function () { jump(start); }, 60); } /* highlight the section you're reading: the last heading that has scrolled past the top */ var links = toc ? toc.querySelectorAll('a') : [], ticking = false; function mark() { ticking = false; var current = null; heads.forEach(function (h) { if (h.getBoundingClientRect().top <= 130) current = h.id; }); if (!current && heads.length) current = heads[0].id; links.forEach(function (a) { a.classList.toggle('is-active', a.getAttribute('href') === '#' + current); }); } if (links.length) { window.addEventListener('scroll', function () { if (!ticking) { ticking = true; requestAnimationFrame(mark); } }, { passive: true }); mark(); } var pr = root.querySelector('[data-blp-lg-print]'); if (pr) pr.addEventListener('click', function () { window.print(); }); })();