1class ShareLinks { 2 constructor() { 3 this.pageUrl = encodeURIComponent(document.URL); 4 this.pageTitle = encodeURIComponent(document.title); 5 this.initEventListeners(); 6 this.initCopyLink(); 7 this.hideWhatsAppIfNotMobile(); 8 } 9 10 initEventListeners() { 11 document.addEventListener('click', event => { 12 let url = null; 13 let target = event.target; 14 15 // If the target is <i>, get the parent (anchor) element 16 if (target.tagName.toLowerCase() === 'i') { 17 target = target.parentElement; 18 } 19 20 if (target.classList.contains('share_facebook')) { 21 url = "https://www.facebook.com/sharer.php?u=" + this.pageUrl; 22 this.openSocialWindow(url, 570, 570); 23 } 24 25 if (target.classList.contains('share_twitter-x')) { 26 url = "https://twitter.com/intent/tweet?url=" + this.pageUrl + "&text=" + this.pageTitle; 27 this.openSocialWindow(url, 570, 300); 28 } 29 30 if (target.classList.contains('share_linkedin')) { 31 url = "https://www.linkedin.com/shareArticle?mini=true&url=" + this.pageUrl; 32 this.openSocialWindow(url, 570, 570); 33 } 34 35 if (target.classList.contains('share_whatsapp')) { 36 url = "whatsapp://send?text=" + this.pageTitle + "%20" + this.pageUrl; 37 this.openSocialWindow(url, 570, 450); 38 } 39 }, false); 40 } 41 42 initCopyLink() { 43 const copyLinkElement = document.getElementById('copy-page-link'); 44 if (copyLinkElement) { 45 copyLinkElement.addEventListener('click', () => { 46 const inputId = copyLinkElement.dataset.inputid; 47 const inputElement = document.getElementById(inputId); 48 console.log(inputId); 49 if (inputElement) { 50 inputElement.select(); 51 document.execCommand('copy'); 52 inputElement.value = 'Copied'; 53 inputElement.parentElement.classList.add('copied'); 54 copyLinkElement.classList.add('copied'); 55 copyLinkElement.classList.add('disabled'); 56 } 57 }); 58 } 59 } 60 61 hideWhatsAppIfNotMobile() { 62 const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); 63 const whatsappLinks = document.querySelectorAll('.share_whatsapp'); 64 if (!isMobile) { 65 whatsappLinks.forEach(link => { 66 link.style.display = 'none'; 67 }); 68 } 69 } 70 71 openSocialWindow(url, width, height) { 72 const left = (screen.width - width) / 2; 73 const top = (screen.height - height) / 2; 74 const params = "menubar=no,toolbar=no,status=no,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left; 75 window.open(url, "", params); 76 } 77}
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.