https://www.sesamprojektet.se/download/18.4baa7f8118723120631afb1/…/fix-links-with-call-to-action.js
1/* 2 * Source: misc-js/fix-links-with-call-to-action.js 3 */ 4 5function filterElements(elements) { 6 return elements.filter(element => { 7 const href = element.getAttribute('href'); 8 return href && !href.includes('mailto:') && !href.includes('tel:'); 9 }); 10} 11 12function addCallToActionToParentsOf(elements) { 13 elements.forEach(element => { 14 const parentElementsIsButton = element.parentElement.classList.contains('button'); 15 const textContentLengthIsSame = element.textContent === element.parentElement.textContent; 16 17 if (!parentElementsIsButton && textContentLengthIsSame) { 18 element.parentElement.classList.add('call-to-action'); 19 } 20 }); 21} 22 23/* 24* Links that are stand alone in a text module 25* should get the call-to-action class added to its element. 26* To make this work in edit mode (since sitevision reloads when adding new element) 27* we have to make sure that an interval is running so the class gets re-added 28* to the elements that should have the call-to-action class. 29*/ 30window.addEventListener('DOMContentLoaded', () => { 31 const run = () => { 32 const selectorStatement = 'p.uu-text a:only-child'; 33 const elements = document.querySelectorAll(selectorStatement); 34 35 // Links in link groups or contact boxes should not have call-to-action class 36 let filteredElements = Array.from(elements).filter(element => { 37 return !element.closest('.uu-link-group') && 38 !element.closest('.contact-box'); 39 }); 40 41 addCallToActionToParentsOf(filterElements(filteredElements)); 42 }; 43 run(); // Run immediately after DOMContentLoaded 44 setInterval(run, 3000); // Then every 3 seconds 45});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.