1/* horyinfo-glightbox.js 2 Napojenà GLightboxu na Horyinfo: 3 1) Fotky pÅÃmo na stránce (Älánky, cokoli s <a rel="lightbox"> i skupinové rel="lightbox[id]"). 4 2) Galerie fotek u cesty: odkazy "foto:" / "topo:" (#fotos, #fotos_topo) se mÃsto starého 5 vyskakovacÃho okna stáhnou z viewimages.php na pozadà a otevÅou rovnou v GLightboxu 6 (swipe na mobilu). Když cokoli selže, chová se to jako dÅÃv (otevÅe stránku s fotkami). 7 3) Responzivnà iframy (YouTube, Google Mapyâ¦): podle atributů width/height nastavà 8 aspect-ratio, aby se na úzké obrazovce zmenÅ¡ovaly proporÄnÄ a nekolabovaly na 150 px. 9 Vyžaduje pouze GLightbox (glightbox.min.js), žádné jQuery/prototype. 10*/ 11(function () { 12 function ready(fn) { 13 if (document.readyState !== 'loading') { fn(); } 14 else { document.addEventListener('DOMContentLoaded', fn); } 15 } 16 17 // "Popisek --- autor: Jméno" -> "Popisek â Jméno" (a když autor chybÃ, jen "Popisek") 18 function cleanTitle(t) { 19 return (t || '').replace(/\s*---\s*autor:\s*/i, ' â ').replace(/\s*â\s*$/, '').trim(); 20 } 21 22 /* FB post embed má obsah napevno (&width=NNN), takže zmenÅ¡enà iframu ho jen oÅÃzne. 23 Proto ho obalÃme a zmenÅ¡Ãme CELà pÅes transform:scale â zůstane celý vidÄt, jen menÅ¡Ã. 24 Obal držà správnou (zmenÅ¡enou) velikost, aÅ¥ sedà layout; pÅepoÄÃtá se i pÅi zmÄnÄ okna. */ 25 function fitFbIframe(f, w, h) { 26 var wrap = document.createElement('div'); 27 wrap.className = 'hi-fb-wrap'; 28 wrap.style.overflow = 'hidden'; 29 wrap.style.margin = '0 auto'; 30 f.parentNode.insertBefore(wrap, f); 31 wrap.appendChild(f); 32 // iframe musà zůstat ve své pÅirozené velikosti (pÅebÃt responzivnà pravidla), scale Åešà zmenÅ¡enà 33 f.style.transformOrigin = 'top left'; 34 f.style.setProperty('width', w + 'px', 'important'); 35 f.style.setProperty('height', h + 'px', 'important'); 36 f.style.setProperty('max-width', 'none', 'important'); 37 function fit() { 38 var host = wrap.parentNode; 39 var avail = (host && host.clientWidth) ? host.clientWidth : w; 40 var scale = avail < w ? (avail / w) : 1; 41 f.style.transform = scale < 1 ? ('scale(' + scale + ')') : 'none'; 42 wrap.style.width = Math.round(w * scale) + 'px'; 43 wrap.style.height = Math.round(h * scale) + 'px'; 44 } 45 fit(); 46 if (window.addEventListener) { window.addEventListener('resize', fit); } 47 } 48 49 ready(function () { 50 /* 0) Responzivnà iframy (YouTube, Mapyâ¦): z atributů width/height nastavÃme 51 aspect-ratio, aÅ¥ se na úzké obrazovce zmenÅ¡ujà proporÄnÄ mÃsto kolapsu na 150 px. 52 Bere jen iframy s ÄÃselnými rozmÄry v atributech (FB má rozmÄry v style â vynecháme). */ 53 document.querySelectorAll('iframe[width][height]').forEach(function (f) { 54 var wa = f.getAttribute('width'), ha = f.getAttribute('height'); 55 if (!/^\d+$/.test(wa) || !/^\d+$/.test(ha)) { return; } 56 if (/facebook\.com/.test(f.src || '')) { 57 // FB post embed: obsah má pevnou Å¡ÃÅku â zmenÅ¡it celý widget (jinak by se oÅÃzl) 58 fitFbIframe(f, parseInt(wa, 10), parseInt(ha, 10)); 59 } else { 60 // Mapy, YouTubeâ¦: obsah se pÅizpůsobà velikosti iframu â staÄà pomÄr stran 61 f.style.aspectRatio = wa + ' / ' + ha; 62 f.style.maxWidth = '100%'; 63 f.style.height = 'auto'; 64 } 65 }); 66 67 if (!window.GLightbox) { return; } 68 69 /* 1) fotky pÅÃmo na stránce (Älánky apod.) */ 70 var inline = document.querySelectorAll('a[rel^="lightbox"]'); 71 inline.forEach(function (a) { 72 var t = cleanTitle(a.getAttribute('title')); 73 if (t && !a.getAttribute('data-title')) { a.setAttribute('data-title', t); } 74 }); 75 if (inline.length) { GLightbox({ selector: 'a[rel^="lightbox"]', loop: true }); } 76 77 /* 2) galerie fotek u cesty (foto: / topo:) */ 78 document.querySelectorAll('a#fotos, a#fotos_topo').forEach(function (link) { 79 var url = link.getAttribute('href'); 80 if (!url) { return; } 81 link.removeAttribute('onclick');
81 // zruÅ¡it starý popup (openNewWindow) 82 link.onclick = null; 83 link.addEventListener('click', function (e) { 84 e.preventDefault(); 85 if (!window.fetch) { window.location = url; return; } // starý prohlÞeÄ â otevÅi postaru 86 fetch(url) 87 .then(function (r) { return r.text(); }) 88 .then(function (html) { 89 var doc = new DOMParser().parseFromString(html, 'text/html'); 90 var elements = []; 91 doc.querySelectorAll('a[rel^="lightbox"]').forEach(function (a) { 92 var href = a.getAttribute('href'); 93 if (href) { elements.push({ href: href, type: 'image', title: cleanTitle(a.getAttribute('title')) }); } 94 }); 95 if (!elements.length) { window.location = url; return; } 96 97 // VytvoÅÃme skryté <a> odkazy a otevÅeme GLightbox pÅes SELEKTOR. 98 // To je jeho nejspolehlivÄjšà režim; dynamické "elements" majà chybu, 99 // kdy prvnà snÃmek zůstane Äerný, dokud nepÅepneÅ¡ na dalÅ¡Ã. 100 var wrap = document.createElement('div'); 101 wrap.style.display = 'none'; 102 wrap.className = 'hi-cesta-galerie'; 103 elements.forEach(function (el) { 104 var a = document.createElement('a'); 105 a.href = el.href; 106 a.className = 'hi-cesta-foto-item'; 107 if (el.title) { a.setAttribute('data-title', el.title); } 108 wrap.appendChild(a); 109 }); 110 document.body.appendChild(wrap); 111 112 var gl = GLightbox({ selector: '.hi-cesta-foto-item', loop: true }); 113 gl.on('close', function () { 114 gl.destroy(); 115 if (wrap.parentNode) { wrap.parentNode.removeChild(wrap); } 116 }); 117 gl.openAt(0); 118 // pojistka: drobné pÅekreslenÃ, aÅ¥ prvnà snÃmek hned sedne 119 setTimeout(function () { 120 try { window.dispatchEvent(new Event('resize')); } catch (err) {} 121 }, 100); 122 }) 123 .catch(function () { window.location = url; }); 124 }); 125 }); 126 }); 127})();
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.