. ============================================================ */ (function () { function init() { /* ---------- 1. Tools grid: icon fallback + category filter ---------- */ (function(){ var g=document.querySelector('.obtt-grid'); if(!g)return; function fallback(i){ if(i.dataset.r){i.style.display='none';i.nextElementSibling.style.display='block';} else{i.dataset.r='1';i.src='https://www.google.com/s2/favicons?domain='+i.dataset.d+'&sz=128';} } g.addEventListener('error',function(e){ if(e.target.tagName==='IMG')fallback(e.target); },true); g.querySelectorAll('img').forEach(function(i){ if(i.complete&&i.naturalWidth===0)fallback(i); }); var radios=document.querySelectorAll('.obtt-radio'); function sync(){ radios.forEach(function(r){ if(r.checked)g.setAttribute('data-cat',r.id.replace('tt-','')); }); } radios.forEach(function(r){r.addEventListener('change',sync);}); sync(); })(); /* ---------- 2. Services tabs ---------- */ (function () { const tabs = document.querySelectorAll('.tab-btn'); const panels = document.querySelectorAll('.panel'); function activate(tabId) { tabs.forEach(function (tab) { const isActive = tab.dataset.tab === tabId; tab.classList.toggle('active', isActive); tab.setAttribute('aria-selected', isActive ? 'true' : 'false'); }); panels.forEach(function (panel) { panel.classList.toggle('active', panel.id === tabId); }); } tabs.forEach(function (tab) { tab.addEventListener('mouseenter', function () { activate(tab.dataset.tab); }); // hover tab.addEventListener('click', function () { activate(tab.dataset.tab); }); // tap / click tab.addEventListener('focus', function () { activate(tab.dataset.tab); }); // keyboard }); })(); /* ---------- 3. Testimonials slider + YouTube facade ---------- */ (function () { var outer = document.getElementById('tsOuter'); var track = document.getElementById('tsTrack'); var prev = document.getElementById('tsPrev'); var next = document.getElementById('tsNext'); var dotsWrap = document.getElementById('tsDots'); if (!outer || !track) return; var cards = track.children; var index = 0; function perView() { var w = window.innerWidth; return w <= 500 ? 1 : w <= 860 ? 2 : 4; } function maxIndex() { return Math.max(0, cards.length - perView()); } function update() { var m = maxIndex(); if (index > m) index = m; var card = cards[0]; if (!card) return; var gap = 18; var step = card.offsetWidth + gap; track.style.transform = 'translateX(' + (-index * step) + 'px)'; if (prev) prev.disabled = index === 0; if (next) next.disabled = index === m; if (dotsWrap) { var dots = dotsWrap.children; for (var i = 0; i < dots.length; i++) { dots[i].className = 'ts-dot' + (i === index ? ' active' : ''); } } } function buildDots() { if (!dotsWrap) return; dotsWrap.innerHTML = ''; var m = maxIndex(); for (var i = 0; i <= m; i++) { var d = document.createElement('button'); d.className = 'ts-dot'; d.setAttribute('aria-label', 'Go to slide ' + (i + 1)); d.dataset.i = i; dotsWrap.appendChild(d); } } function go(i) { index = Math.min(Math.max(0, i), maxIndex()); update(); } if (prev) prev.addEventListener('click', function () { go(index - 1); }); if (next) next.addEventListener('click', function () { go(index + 1); }); if (dotsWrap) dotsWrap.addEventListener('click', function (e) { if (e.target.dataset.i !== undefined) go(+e.target.dataset.i); }); /* Touch swipe */ var startX = null; outer.addEventListener('touchstart', function (e) { startX = e.touches[0].clientX; }, { passive: true }); outer.addEventListener('touchend', function (e) { if (startX === null) return; var dx = e.changedTouches[0].clientX - startX; if (Math.abs(dx) > 40) go(index + (dx < 0 ? 1 : -1)); startX = null; }, { passive: true }); /* Thumbnail fallback: hqdefault -> mqdefault (derived from video id, no data attribute needed) */ track.addEventListener('error', function (e) { var img = e.target; if (img.tagName !== 'IMG' || img.dataset.r) return; img.dataset.r = '1'; var yt = img.closest('.ts-thumb'); if (yt && yt.dataset.yt) { img.src = 'https://img.youtube.com/vi/' + yt.dataset.yt + 'https://obeliskinfotechcomf5e50.zapwp.com/q:i/r:0/wp:0/w:1/u:https://obeliskinfotech.com/mqdefault.jpg'; } }, true); /* YouTube facade: only load the heavy iframe when a thumbnail is clicked */ function play(thumb) { if (thumb.classList.contains('playing')) return; thumb.classList.add('playing'); var f = document.createElement('iframe'); f.src = 'https://www.youtube-nocookie.com/embed/' + thumb.dataset.yt + '?autoplay=1&rel=0'; f.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture'; f.allowFullscreen = true; f.title = thumb.getAttribute('aria-label') || 'Testimonial video'; thumb.appendChild(f); } track.addEventListener('click', function (e) { var t = e.target.closest('.ts-thumb'); if (t) play(t); }); track.addEventListener('keydown', function (e) { if (e.key !== 'Enter' && e.key !== ' ') return; var t = e.target.closest('.ts-thumb'); if (t) { e.preventDefault(); play(t); } }); /* Rebuild on resize (debounced) */ var rt; window.addEventListener('resize', function () { clearTimeout(rt); rt = setTimeout(function () { buildDots(); update(); }, 150); }); buildDots(); update(); })(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();