Blog
- // Ahmad Raza — SEO Portfolio — shared behaviour (function(){ “use strict”; var WA_NUMBER = “923037407693”; window.waLink = function(msg){ var text = msg || “Hi Ahmad, I visited your SEO portfolio website and would like to discuss SEO services.”; return “https://wa.me/” + WA_NUMBER + “?text=” + encodeURIComponent(text); }; document.addEventListener(“DOMContentLoaded”, function(){ // scroll progress bar var bar = document.createElement(“div”); bar.className = “scroll-progress”; document.body.appendChild(bar); window.addEventListener(“scroll”, function(){ var h = document.documentElement; var scrolled = (h.scrollTop) / (h.scrollHeight – h.clientHeight) * 100; bar.style.width = (scrolled || 0) + “%”; }, {passive:true}); // stagger index for grid reveal children (nice cascading entrance) document.querySelectorAll(“.grid”).forEach(function(grid){ Array.prototype.forEach.call(grid.children, function(child, i){ child.style.setProperty(“–stagger”, i % 6); }); }); // wire up every [data-wa] element with the default (or custom) message document.querySelectorAll(“[data-wa]”).forEach(function(el){ var custom = el.getAttribute(“data-wa-msg”); el.setAttribute(“href”, window.waLink(custom)); el.setAttribute(“target”, “_blank”); el.setAttribute(“rel”, “noopener”); }); // mobile nav var burger = document.querySelector(“.burger”); if (burger){ burger.addEventListener(“click”, function(){ document.body.classList.toggle(“nav-open”); var open = document.body.classList.contains(“nav-open”); burger.setAttribute(“aria-expanded”, open ? “true” : “false”); }); document.querySelectorAll(“.mobile-nav a”).forEach(function(a){ a.addEventListener(“click”, function(){ document.body.classList.remove(“nav-open”); }); }); } // faq accordion document.querySelectorAll(“.faq-q”).forEach(function(q){ q.addEventListener(“click”, function(){ var item = q.closest(“.faq-item”); var wasOpen = item.classList.contains(“open”); item.parentElement.querySelectorAll(“.faq-item”).forEach(function(i){ i.classList.remove(“open”); }); if (!wasOpen) item.classList.add(“open”); }); }); // portfolio filters var filterBtns = document.querySelectorAll(“.filter-btn”); if (filterBtns.length){ filterBtns.forEach(function(btn){ btn.addEventListener(“click”, function(){ filterBtns.forEach(function(b){ b.classList.remove(“active”); }); btn.classList.add(“active”); var f = btn.getAttribute(“data-filter”); document.querySelectorAll(“[data-cat]”).forEach(function(card){ var show = (f === “all”) || (card.getAttribute(“data-cat”).indexOf(f) > -1); card.style.display = show ? “” : “none”; }); }); }); } // scroll reveal var reveals = document.querySelectorAll(“.reveal”); if (“IntersectionObserver” in window && reveals.length){ var io = new IntersectionObserver(function(entries){ entries.forEach(function(entry){ if (entry.isIntersecting){ entry.target.classList.add(“in”); io.unobserve(entry.target); } }); }, {threshold:.14}); reveals.forEach(function(el){ io.observe(el); }); } else { reveals.forEach(function(el){ el.classList.add(“in”); }); } // active nav link var path = location.pathname.split(“/”).pop() || “index.html”; document.querySelectorAll(“.nav-links a, .mobile-nav a”).forEach(function(a){ var href = a.getAttribute(“href”); if (href === path || (path === “” && href === “index.html”)){ a.classList.add(“active”); } }); // contact form (client-side only demo -> routes to WhatsApp with prefilled summary) var form = document.getElementById(“contact-form”); if (form){ form.addEventListener(“submit”, function(e){ e.preventDefault(); var name = form.name.value.trim(); var email = form.email.value.trim(); var service = form.service.value; var msg = form.message.value.trim(); var errBox = document.getElementById(“form-status”); if (!name || !email || !msg){ errBox.textContent = “Please fill in your name, email and message before sending.”; errBox.style.color = “#B23B3B”; return; } var summary = “Hi Ahmad, my name is ” + name + “. I’m interested in: ” + (service || “SEO services”) + “. ” + msg; errBox.textContent = “Thanks, ” + name.split(” “)[0] + ” — opening WhatsApp so you can send this directly to Ahmad.”; errBox.style.color = “#147A5F”; setTimeout(function(){ window.open(window.waLink(summary), “_blank”); }, 500); form.reset(); }); } }); })();