1/** 2 * moved into hwlib to use it in modules that load dynamic content (map popups, ...) 3 * @param phonenumberLinks 4 */ 5export function convertToTelLink(phonenumberLinks) { 6 if (!(phonenumberLinks && phonenumberLinks.length > 0)) { 7 return; 8 } 9 10 phonenumberLinks.forEach(phoneNumberSpan => { 11 const phoneNumber = phoneNumberSpan.innerText ? phoneNumberSpan.innerText : phoneNumberSpan.textContent; 12 13 // Remove everything except numbers and + 14 let cleanedNumber = phoneNumber.replace(/[^0-9+]/g, ''); 15 16 // Replace starting 0 with +49 17 if (cleanedNumber.startsWith('0')) { 18 cleanedNumber = `+49${cleanedNumber.substring(1)}`; 19 } 20 21 if (phoneNumberSpan) { 22 23 // Get the parent element of the span 24 const parentElement = phoneNumberSpan.parentNode; 25 26 // Create a new anchor element 27 const anchorElement = document.createElement('a'); 28 29 // Copy attributes and content from the span to the anchor 30 // This can be expanded to include specific attributes if necessary 31 anchorElement.innerHTML = parentElement.innerHTML; 32 anchorElement.className = parentElement.className; 33 anchorElement.classList.add('hw_link'); 34 anchorElement.querySelector('.hw_icon_text')?.classList.add('hw_link__text'); 35 36 // Find the first occurrence of a number or + in the span's text 37 const firstNumberMatch = phoneNumberSpan.textContent.match(/[+\d]/); 38 const phoneNumber = firstNumberMatch ? phoneNumberSpan.textContent.substring(firstNumberMatch.index) : ''; 39 40 // Set href or other attributes for the anchor here 41 anchorElement.href = `tel:${cleanedNumber}`; 42 anchorElement.title = `Die Telefonnummer ${phoneNumber} anrufen`; 43 44 // Replace the span with the anchor in the DOM 45 parentElement.parentNode.replaceChild(anchorElement, parentElement); 46 } 47 }); 48} 49 50/** 51 * Decoding helper function 52 * @param {number} charCode 53 * @param {number} start 54 * @param {number} end 55 * @param {number} offset 56 * @return {string} 57 */ 58function decryptCharcode(charCode, start, end, offset) { 59 60 charCode = charCode + offset; 61 62 if (offset > 0 && charCode > end) { 63 charCode = start + (charCode - end - 1); 64 } else if (offset < 0 && charCode < start) { 65 charCode = end - (start - charCode - 1); 66 } 67 68 return String.fromCharCode(charCode); 69} 70 71/** 72 * Decodes string 73 * @param {string} value 74 * @param {number} offset 75 * @return {string} 76 */ 77export function decryptString(value, offset) { 78 79 let result = ''; 80 81 for (let i = 0; i < value.length; i++) { 82 83 let charCode = value.charCodeAt(i); 84 85 if (charCode >= 0x2B && charCode <= 0x3A) { 86 result += decryptCharcode(charCode, 0x2B, 0x3A, offset); /* 0-9 . , - + / : */ 87 } else if (charCode >
87= 0x40 && charCode <= 0x5A) { 88 result += decryptCharcode(charCode, 0x40, 0x5A, offset); /* A-Z @ */ 89 } else if (charCode >= 0x61 && charCode <= 0x7A) { 90 result += decryptCharcode(charCode, 0x61, 0x7A, offset); /* a-z */ 91 } else { 92 result += value.charAt(i); 93 } 94 } 95 96 return result; 97} 98 99/** 100 * Debounce a function 101 * @param func 102 * @param wait 103 * @returns {(function(...[*]): void)|*} 104 */ 105export function debounce(func, wait = 300) { 106 let timeout; 107 108 return function (...args) { 109 const later = () => { 110 clearTimeout(timeout); 111 func(...args); 112 }; 113 114 clearTimeout(timeout); 115 timeout = setTimeout(later, wait); 116 }; 117}
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.