-const yellowBoxStyle = "border:1px solid black; background-color:#FFF2CC; padding:10px;"; function updateFocusToHashAnchor() { if (location.hash != "") { let desiredLocationHash = location.hash; location.hash = ""; location.hash = desiredLocationHash; } } function drawYellowBoxAroundNotices() { const noticeSectionRegex = RegExp('^Notice:'); document.querySelectorAll('.legal\_doc .otnotice p').forEach( (node) => { if (noticeSectionRegex.test(node.outerText)) { node.style = yellowBoxStyle; } } ); } function addTogglableContent() { const READ\_MORE = " Read More"; const READ\_LESS = " Read Less"; const TOGGLE\_START\_MARKER = "READ\_MORE\_START" const TOGGLE\_END\_MARKER = "READ\_MORE\_END" function addListener(element, eventName, handler) { if (element.addEventListener) { element.addEventListener(eventName, handler, false); } else if (element.attachEvent) { element.attachEvent('on' + eventName, handler); } else { element\['on' + eventName\] = handler; } } function toggleVisibility(element) { if (element.style.display === "none") { element.style.display = "block"; } else { element.style.display = "none"; } } function toggleLinkText(element) { if (element.innerHTML === READ\_MORE) { element.innerHTML = READ\_LESS; } else { element.innerHTML = READ\_MORE; } } document.querySelector('.otnotice').querySelectorAll('p').forEach((pNode, i) => { // Identify all the <p> tags that contain the start marker if (pNode.innerHTML.indexOf(TOGGLE\_START\_MARKER) != -1) { // Find the previous non-text HTML element, and the previous HTML text element let prevSibling = pNode.previousSibling; if (prevSibling == null) { return } while (prevSibling.lastChild !== null && prevSibling.lastChild.nodeType == prevSibling.ELEMENT\_NODE){ prevSibling = prevSibling.lastChild; } prevText = prevSibling; while (prevText.lastChild !== null){ prevText = prevText.lastChild; } // Create <div> to hold togglable content let togglableContent = document.createElement('div'); // Add <a> link to toggle visibility of togglable content var temp\_link = document.createElement("a"); temp\_link.innerHTML = READ\_MORE; addListener(temp\_link, "click", function() { toggleVisibility(togglableContent); toggleLinkText(temp\_link); } ); prevText.parentNode.appendChild(temp\_link); // Append the togglable content, after appending the link prevSibling.appendChild(togglableContent); // Fill the togglable <div> with all the HTML until the end marker is found let iterNode = pNode.nextSibling; let nodesToAppend = \[\] while (iterNode != null) { if (iterNode.innerHTML.indexOf(TOGGLE\_END\_MARKER) == -1) { nodesToAppend.push(iterNode); iterNode = iterNode.nextSibling; } else { iterNode.parentNode.removeChild(iterNode); iterNode = null; } } nodesToAppend.forEach(n => {togglableContent.appendChild(n);}); pNode.parentNode.removeChild(pNode); togglableContent.style = yellowBoxStyle; // Initially hide all the togglable content togglableContent.style.display = "none"; } }); } function renameOneTrustHeaderTags() { const ONETRUST\_CLASS\_SELECTOR = '.otnotice' const punctuationRegex = /\[ '"\`.,\\/\\\\><#!$%?@\\^&\\\*+;:{}=\\~()-\]/g; const allHeaderTagsQuerySelector = 'h1, h2, h3, h4, h5, h6'; const regexForNumericPrefix = /^\[0-9\]+\[.\]\[0-9\]\* /; const regexForDuplicateUnderscores = /\[\_\]{2,}/g; const regexForLeadingUnderscores = /^\_+/g; const regexForTrailingUnderscores = /\_+$/g; document.querySelector(ONETRUST\_CLASS\_SELECTOR).querySelectorAll(allHeaderTagsQuerySelector).forEach( (node) => { let newNameForTag = node.textContent .replace(regexForNumericPrefix, "") .replace(punctuationRegex, "\_") .replace(regexForDuplicateUnderscores, "\_") .replace(regexForLeadingUnderscores, "") .replace(regexForTrailingUnderscores, "") .toLowerCase(); node.setAttribute( "id", newNameForTag ); } ); } (function fetchPolicyDocumentFromOneTrust() { OneTrust.NoticeApi.Initialized.then(function() { page\_info = document.getElementById('vimeo\_onetrust\_page\_src'); url = page\_info.dataset.url; production = page\_info.dataset.prod; OneTrust.NoticeApi.LoadNotices(\[url\], production) .then(renameOneTrustHeaderTags) .then(drawYellowBoxAroundNotices) .then(addTogglableContent) .then(updateFocusToHashAnchor); }); })();
0 commit comments