/** * PRISRA PATCH 1.1 — CUSTOM JS * Tilda: Site Settings → More → Custom JS (before
) * ------------------------------------------------------- * Targets: A1 lang, A2 alt attributes, A4 form labels, * F3 lazy/preload, F4 CLS reveal fix, U3 scroll fix */ (function () { 'use strict'; /* ================================================ A1: lang attribute — set from URL path Runs immediately (in
via head.html too, this is the body-level fallback) ================================================ */ function setLang() { var p = window.location.pathname; var lang = 'ru'; if (p.startsWith('/ua')) lang = 'uk'; else if (p.startsWith('/en') || p.startsWith('/english')) lang = 'en'; if (document.documentElement.lang !== lang) { document.documentElement.lang = lang; } } setLang(); /* ================================================ A2: Alt attributes — audit + auto-fix missing Decorative images get alt="", semantic get a generated fallback (then review manually) ================================================ */ function fixAltAttributes() { var images = document.querySelectorAll('img:not([alt])'); images.forEach(function (img) { // Social icons — empty alt (decorative) if (img.closest('a[href*="facebook"]') || img.closest('a[href*="instagram"]') || img.closest('a[href*="linkedin"]') || img.closest('a[href*="youtube"]') || img.closest('a[href*="telegram"]') || img.closest('a[href*="whatsapp"]')) { img.setAttribute('alt', ''); return; } // Logo if (img.closest('.t-logo') || img.className.includes('logo')) { img.setAttribute('alt', 'PRISRA'); return; } // Service cards — try to read from sibling title var card = img.closest('.t-card, .t-tile__item, [class*="card"]'); if (card) { var title = card.querySelector('.t-card__title, .t-tile__title, h3, h4'); if (title && title.textContent.trim()) { img.setAttribute('alt', title.textContent.trim() + ' — PRISRA'); return; } } // Team photos — try from sibling var teamItem = img.closest('[class*="team"], [class*="person"]'); if (teamItem) { var name = teamItem.querySelector('[class*="name"], h3, h4, strong'); if (name) { img.setAttribute('alt', name.textContent.trim() + ', PRISRA team'); return; } } // Fallback — set empty (decorative) to avoid violation img.setAttribute('alt', ''); }); // aria-label on social icon links without text var socialLinks = document.querySelectorAll( 'a[href*="facebook.com"], a[href*="instagram.com"], a[href*="linkedin.com"], a[href*="youtube.com"], a[href*="t.me"], a[href*="telegram"]' ); var labelMap = { 'facebook.com': 'Facebook', 'instagram.com': 'Instagram', 'linkedin.com': 'LinkedIn', 'youtube.com': 'YouTube', 't.me': 'Telegram', 'telegram': 'Telegram', 'whatsapp': 'WhatsApp', 'wa.me': 'WhatsApp' }; socialLinks.forEach(function (a) { if (!a.getAttribute('aria-label') && !a.textContent.trim()) { for (var key in labelMap) { if (a.href.includes(key)) { a.setAttribute('aria-label', labelMap[key]); break; } } } }); } /* ================================================ A4: Form labels — inject sr-only labels for any input/textarea without accessible name ================================================ */ function fixFormLabels() { var labelMap = { 'name': 'Имя', 'имя': 'Имя', 'phone': 'Телефон', 'телефон': 'Телефон', 'tel': 'Телефон', 'email': 'Email', 'site': 'Сайт', 'url': 'Сайт', 'task': 'Что нужно', 'comment': 'Комментарий', 'комментарий': 'Комментарий' }; var inputs = document.querySelectorAll( 'input:not([type="hidden"]):not([type="submit"]):not([type="button"]), textarea, select' ); inputs.forEach(function (input) { // Already has accessible name if (input.getAttribute('aria-label') || input.getAttribute('aria-labelledby') || input.id && document.querySelector('label[for="' + input.id + '"]')) { return; } var placeholder = (input.getAttribute('placeholder') || '').toLowerCase(); var name = (input.getAttribute('name') || '').toLowerCase(); var labelText = null; for (var key in labelMap) { if (placeholder.includes(key) || name.includes(key)) { labelText = labelMap[key]; break; } } if (!labelText) { labelText = input.getAttribute('placeholder') || 'Поле формы'; } // Add aria-label (non-intrusive) input.setAttribute('aria-label', labelText); }); } /* ================================================ F3: Lazy loading — add to below-fold images (Hero image keeps eager/fetchpriority=high) ================================================ */ function fixLazyLoading() { var heroSection = document.querySelector('.t-cover, [data-record-type="cover"]'); var heroImgs = heroSection ? heroSection.querySelectorAll('img') : []; var heroImgSet = new Set(heroImgs); var allImgs = document.querySelectorAll('img:not([loading])'); allImgs.forEach(function (img) { if (heroImgSet.has(img)) { // Hero image: eager + fetchpriority img.setAttribute('loading', 'eager'); img.setAttribute('fetchpriority', 'high'); } else { img.setAttribute('loading', 'lazy'); // Add explicit dimensions if missing to prevent CLS if (!img.getAttribute('width') && img.naturalWidth) { img.setAttribute('width', img.naturalWidth); img.setAttribute('height', img.naturalHeight); } } }); // Video poster var videos = document.querySelectorAll('video:not([poster])'); videos.forEach(function (v) { // Can't set poster without knowing the image URL — log for manual fix console.warn('[PRISRA A11y] Video missing poster attribute:', v.src || v.currentSrc); }); } /* ================================================ F4 + U3: Scroll reveal — fix blank sections Override Tilda's slow reveal threshold ================================================ */ function fixRevealAnimations() { if (!window.IntersectionObserver) return; var obs = new IntersectionObserver(function (entries) { entries.forEach(function (e) { if (e.isIntersecting) { var el = e.target; el.style.opacity = '1'; el.style.transform = 'none'; el.style.visibility = 'visible'; obs.unobserve(el); } }); }, { threshold: 0, rootMargin: '0px 0px 800px 0px' }); // Make hero/above-fold visible immediately var aboveFold = document.querySelectorAll( '.t-cover *, .t-cover, [data-record-type="cover"] *' ); aboveFold.forEach(function (el) { el.style.opacity = '1'; el.style.transform = 'none'; el.style.animation = 'none'; }); // Observe below-fold animated elements var animated = document.querySelectorAll( '[data-animate-once="1"], [data-animate], .t-animate, .t-entry-animate' ); animated.forEach(function (el) { // Skip hero if (el.closest('.t-cover')) return; obs.observe(el); }); } /* ================================================ SEO2: Tap targets — fix too-small touchables ================================================ */ function fixTapTargets() { var minSize = 48; // Social links in header var socialLinks = document.querySelectorAll( '.t-header .t-sociallinks a, .t-header a[href*="social"]' ); socialLinks.forEach(function (a) { var rect = a.getBoundingClientRect(); if (rect.width < minSize || rect.height < minSize) { a.style.minWidth = minSize + 'px'; a.style.minHeight = minSize + 'px'; a.style.display = 'inline-flex'; a.style.alignItems = 'center'; a.style.justifyContent = 'center'; } }); // Dropdown arrows var dropdownBtns = document.querySelectorAll( '.t-menu__list-item > button, [class*="dropdown-toggle"]' ); dropdownBtns.forEach(function (btn) { var rect = btn.getBoundingClientRect(); if (rect.height < minSize) { btn.style.minHeight = minSize + 'px'; btn.style.padding = '12px'; } }); } /* ================================================ RUN: DOMContentLoaded ================================================ */ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } function init() { fixAltAttributes(); fixFormLabels(); fixLazyLoading(); fixRevealAnimations(); fixTapTargets(); } // Re-run after Tilda's own DOMReady (Tilda fires custom events) document.addEventListener('tildaready', function () { fixAltAttributes(); fixFormLabels(); fixLazyLoading(); fixRevealAnimations(); }); })();
Кейсы
Результаты таргетированной рекламы и performance-кампаний из рекламных кабинетов.
SEO-кейсы