/* The OC Guy — page behaviour. Everything degrades: without JS the page is a plain, readable document with working links and a mail form. */ (function () { 'use strict'; var doc = document.documentElement; doc.classList.add('js'); var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches; /* ---------- entrance for the blocks of each section ---------- */ var targets = document.querySelectorAll( '.lead-caption, .box, .side-list, .section-head, .card, .feature, .news li, .ask-inner' ); if (!reduce && 'IntersectionObserver' in window) { var io = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; entry.target.classList.add('rv-in'); io.unobserve(entry.target); }); }, { rootMargin: '0px 0px -8% 0px', threshold: 0.08 }); Array.prototype.forEach.call(targets, function (el) { el.setAttribute('data-rv', '1'); io.observe(el); }); } else { Array.prototype.forEach.call(targets, function (el) { el.classList.add('rv-in'); }); } /* ---------- the ask form: one question, by mail ---------- */ var form = document.querySelector('.ask-form'); var mail = document.getElementById('ask-mail'); if (form && mail) { form.addEventListener('submit', function (event) { event.preventDefault(); var addr = (mail.value || '').trim(); if (!addr || addr.indexOf('@') === -1) { mail.setAttribute('aria-invalid', 'true'); mail.focus(); return; } mail.removeAttribute('aria-invalid'); var body = 'My question about Odoo Community:\n\n\n— reply to: ' + addr + '\n'; window.location.href = 'mailto:o.arnold@projektbox.de' + '?subject=' + encodeURIComponent('Odoo Community question') + '&body=' + encodeURIComponent(body); }); } /* ---------- which section the reader is in ---------- */ var links = Array.prototype.slice.call(document.querySelectorAll('.nav a[href^="#"]')); var sections = links .map(function (a) { return document.querySelector(a.getAttribute('href')); }) .filter(Boolean); if (sections.length && 'IntersectionObserver' in window) { var seen = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (!entry.isIntersecting) return; links.forEach(function (a) { if (a.getAttribute('href') === '#' + entry.target.id) { a.setAttribute('aria-current', 'true'); } else { a.removeAttribute('aria-current'); } }); }); }, { rootMargin: '-45% 0px -50% 0px' }); sections.forEach(function (s) { seen.observe(s); }); } })();