1// Social share widget â externalized. 2// PHP data via window.pplShareData (wp_localize_script): { template, nativeHint }. 3(function () { 4 function tplText() { return (window.pplShareData && window.pplShareData.template) || ''; } 5 6 function getBaseUrl() { 7 return window.location.origin + window.location.pathname; 8 } 9 10 function getShareText() { 11 var h1 = document.querySelector('h1'); 12 var titre = h1 ? h1.innerText.trim() : document.title; 13 return tplText().replace('{titre}', titre); 14 } 15 16 function getShareUrl(source) { 17 var u = new URL(getBaseUrl()); 18 u.searchParams.set('source', source); 19 return u.toString(); 20 } 21 22 window.asSocialShare = function (platform) { 23 var txt = encodeURIComponent(getShareText()); 24 var links = { 25 fb: 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(getShareUrl('share-facebook')) + '"e=' + txt, 26 x: 'https://twitter.com/intent/tweet?text=' + txt + '&url=' + encodeURIComponent(getShareUrl('share-twitter')), 27 wa: 'https://api.whatsapp.com/send?text=' + txt + '%20' + encodeURIComponent(getShareUrl('share-whatsapp')), 28 tg: 'https://t.me/share/url?url=' + encodeURIComponent(getShareUrl('share-telegram')) + '&text=' + txt 29 }; 30 if (!links[platform]) return; 31 var w = 600, h = 500, l = (window.innerWidth - w) / 2, t = (window.innerHeight - h) / 2; 32 window.open(links[platform], '_blank', 'width=' + w + ',height=' + h + ',top=' + t + ',left=' + l); 33 }; 34 35 window.asNativeShare = function () { 36 var url = getShareUrl('share-native'); 37 if (navigator.share) { 38 navigator.share({ title: document.title, text: getShareText(), url: url }); 39 } else { 40 alert((window.pplShareData && window.pplShareData.nativeHint) || ''); 41 } 42 }; 43 44 window.asCopyLink = function (btn) { 45 var url = getShareUrl('share-copy'); 46 var show = function () { 47 var tip = btn.querySelector('.copy-tooltip'); 48 if (!tip) return; 49 tip.style.display = 'block'; 50 setTimeout(function () { tip.style.display = 'none'; }, 2500); 51 }; 52 if (navigator.clipboard) { 53 navigator.clipboard.writeText(url).then(show); 54 } else { 55 var i = document.createElement('input'); 56 i.value = url; i.style.cssText = 'position:absolute;left:-9999px'; 57 document.body.appendChild(i); i.select(); document.execCommand('copy'); i.remove(); 58 show(); 59 } 60 }; 61 62 // Show native button only if navigator.share available (mobile). Wait for DOM. 63 function showNative() { 64 if (navigator.share) { 65 var btn = document.getElementById('as-native-share-btn'); 66 if (btn) btn.style.display = 'flex'; 67 } 68 } 69 if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', showNative); 70 else showNative(); 71}());
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.