1(function(){ 2 'use strict'; 3 4 var overlay = null; 5 var lastFocused = null; 6 var desktopMedia = window.matchMedia ? window.matchMedia('(min-width: 768px)') : null; 7 8 function isDesktop(){ 9 return desktopMedia ? desktopMedia.matches : window.innerWidth >= 768; 10 } 11 12 function closeLightbox(){ 13 if(!overlay){ 14 return; 15 } 16 17 document.body.classList.remove('caip-infografia-lightbox-open'); 18 overlay.parentNode.removeChild(overlay); 19 overlay = null; 20 21 if(lastFocused && typeof lastFocused.focus === 'function'){ 22 lastFocused.focus(); 23 } 24 } 25 26 function openLightbox(link){ 27 var image = link.querySelector('img'); 28 var fullImage = document.createElement('img'); 29 var closeButton = document.createElement('button'); 30 var inner = document.createElement('div'); 31 32 closeLightbox(); 33 lastFocused = document.activeElement; 34 35 overlay = document.createElement('div'); 36 overlay.className = 'caip-infografia-lightbox'; 37 overlay.setAttribute('role', 'dialog'); 38 overlay.setAttribute('aria-modal', 'true'); 39 40 inner.className = 'caip-infografia-lightbox__inner'; 41 42 fullImage.className = 'caip-infografia-lightbox__image'; 43 fullImage.src = link.href; 44 fullImage.alt = image ? image.alt : ''; 45 46 closeButton.className = 'caip-infografia-lightbox__close'; 47 closeButton.type = 'button'; 48 closeButton.setAttribute('aria-label', 'Cerrar'); 49 closeButton.innerHTML = '<span aria-hidden="true">×</span>'; 50 closeButton.addEventListener('click', closeLightbox); 51 52 inner.appendChild(fullImage); 53 inner.appendChild(closeButton); 54 overlay.appendChild(inner); 55 document.body.appendChild(overlay); 56 document.body.classList.add('caip-infografia-lightbox-open'); 57 closeButton.focus(); 58 59 overlay.addEventListener('click', function(event){ 60 if(event.target === overlay){ 61 closeLightbox(); 62 } 63 }); 64 } 65 66 document.addEventListener('click', function(event){ 67 var link = event.target.closest ? event.target.closest('a.caip-infografia-zoom') : null; 68 69 if(!link || !isDesktop()){ 70 return; 71 } 72 73 if(event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey){ 74 return; 75 } 76 77 event.preventDefault(); 78 openLightbox(link); 79 }); 80 81 document.addEventListener('keydown', function(event){ 82 if(event.key === 'Escape'){ 83 closeLightbox(); 84 } 85 }); 86}());
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.