/* ===================================================================== RC Theme — Frontend JS - Smooth scroll for anchor links - Mobile menu toggle (Bootstrap collapse compatible) - Header shadow on scroll ===================================================================== */ (function () { 'use strict'; document.addEventListener('DOMContentLoaded', function () { // Smooth scroll for in-page anchors document.querySelectorAll('a[href^="#"]').forEach(function (anchor) { anchor.addEventListener('click', function (e) { var href = this.getAttribute('href'); if (href === '#' || href.length < 2) return; var target = document.querySelector(href); if (target) { e.preventDefault(); var headerOffset = 100; var targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerOffset; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); // Close mobile menu if open — use the Bootstrap collapse // API so aria-expanded and internal state stay consistent // (a plain classList.remove('show') leaves Bootstrap thinking // the menu is still open and breaks the next toggle). var menu = document.getElementById('rc_primary_menu'); if (menu && menu.classList.contains('show') && typeof bootstrap !== 'undefined' && bootstrap.Collapse) { var bsCollapse = bootstrap.Collapse.getInstance(menu) || new bootstrap.Collapse(menu, { toggle: false }); bsCollapse.hide(); } } }); }); // Header shadow / compact on scroll var header = document.getElementById('rcHeader'); if (header) { window.addEventListener('scroll', function () { var y = window.scrollY || window.pageYOffset; if (y > 20) { header.classList.add('rc-header-scrolled'); } else { header.classList.remove('rc-header-scrolled'); } }, { passive: true }); } // NOTE: we intentionally do NOT add a JS fallback that does // classList.add('show') on toggle click. Bootstrap's data-bs-toggle // already handles open/close. A fallback creates a race condition // that causes the menu to stop closing on subsequent taps. }); })();