1/** 2 * Partilha â ações sem link: copiar ligação, imprimir e partilha nativa 3 * (Web Share API). Sem dependências. 4 */ 5(function () { 6 'use strict'; 7 8 var canShare = typeof navigator.share === 'function'; 9 10 function announce(box, message) { 11 var status = box.querySelector('.core-partilha__estado'); 12 if (!status) { 13 return; 14 } 15 status.textContent = ''; 16 // Reescrever no frame seguinte garante novo anúncio mesmo com o mesmo texto. 17 window.requestAnimationFrame(function () { 18 status.textContent = message; 19 }); 20 clearTimeout(status._partilhaTimer); 21 status._partilhaTimer = setTimeout(function () { 22 status.textContent = ''; 23 }, 4000); 24 } 25 26 function copyFallback(text) { 27 var field = document.createElement('textarea'); 28 field.value = text; 29 field.setAttribute('readonly', ''); 30 field.style.position = 'absolute'; 31 field.style.left = '-9999px'; 32 document.body.appendChild(field); 33 field.select(); 34 var ok = false; 35 try { 36 ok = document.execCommand('copy'); 37 } catch (e) { 38 ok = false; 39 } 40 document.body.removeChild(field); 41 return ok; 42 } 43 44 function copy(box, url) { 45 var done = function () { announce(box, 'Ligação copiada'); }; 46 var fail = function () { announce(box, 'Não foi possÃvel copiar a ligação'); }; 47 48 if (navigator.clipboard && window.isSecureContext) { 49 navigator.clipboard.writeText(url).then(done, function () { 50 (copyFallback(url) ? done : fail)(); 51 }); 52 return; 53 } 54 (copyFallback(url) ? done : fail)(); 55 } 56 57 function init() { 58 document.querySelectorAll('.core-partilha').forEach(function (box) { 59 if (canShare) { 60 box.querySelectorAll('.core-partilha__item--nativa').forEach(function (li) { 61 li.hidden = false; 62 }); 63 } 64 65 box.addEventListener('click', function (event) { 66 var button = event.target.closest('[data-partilha-acao]'); 67 if (!button || !box.contains(button)) { 68 return; 69 } 70 71 var url = box.getAttribute('data-url') || window.location.href; 72 var title = box.getAttribute('data-title') || document.title; 73 74 switch (button.getAttribute('data-partilha-acao')) { 75 case 'copiar': 76 copy(box, url); 77 break; 78 case 'imprimir': 79 window.print(); 80 break; 81 case 'nativa': 82 if (canShare) { 83 // AbortError (utilizador fechou a folha) não é erro a anunciar. 84 navigator.share({ title: title, url: url }).catch(function () {}); 85 } 86 break; 87 } 88 }); 89 }); 90 } 91 92 if (document.readyState === 'loading') { 93 document.addEventListener('DOMContentLoaded', init); 94 } else { 95 init(); 96 } 97})();
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.