Uncategorized Archives - Page 2 of 2 - Smartmove
Showing 17–25 of 25 results
QUICK QUOTE
tag)
document.addEventListener('DOMContentLoaded', function() {
// Get current page URL path
let currentPath = window.location.pathname;
// Normalize the path - remove trailing slash for comparison
currentPath = currentPath.replace(/\/$/, '') || '/';
// Get all nav links
const navLinks = document.querySelectorAll('.navbar-nav .nav-link');
navLinks.forEach(link => {
let href = link.getAttribute('href');
if (!href) return;
// Normalize href - remove trailing slash
let normalizedHref = href.replace(/\/$/, '') || '/';
// Special case: if we're on root (/) and link is /home, mark as active
if (currentPath === '/' && normalizedHref === '/home') {
link.classList.add('active');
const navItem = link.closest('.nav-item');
if (navItem) {
navItem.classList.add('active');
}
return;
}
// Check if current path matches the link href exactly
if (currentPath === normalizedHref) {
link.classList.add('active');
const navItem = link.closest('.nav-item');
if (navItem) {
navItem.classList.add('active');
}
return;
}
// For dropdown parent items, check if current path starts with the href
if (normalizedHref !== '/' && normalizedHref !== '/home' && currentPath.startsWith(normalizedHref)) {
link.classList.add('active');
const navItem = link.closest('.nav-item');
if (navItem) {
navItem.classList.add('active');
}
}
});
// Also check dropdown items
const dropdownLinks = document.querySelectorAll('.dropdown-item');
dropdownLinks.forEach(link => {
let href = link.getAttribute('href');
if (!href) return;
// Normalize href
let normalizedHref = href.replace(/\/$/, '') || '/';
if (currentPath === normalizedHref) {
link.classList.add('active');
// Add active to parent dropdown nav-item
const parentDropdown = link.closest('.nav-item.dropdown');
if (parentDropdown) {
parentDropdown.classList.add('active');
const parentLink = parentDropdown.querySelector('.nav-link.dropdown-toggle');
if (parentLink) {
parentLink.classList.add('active');
}
}
}
});
// Also check mega menu links
const megaLinks = document.querySelectorAll('.mega-tile');
megaLinks.forEach(link => {
let href = link.getAttribute('href');
if (!href) return;
let normalizedHref = href.replace(/\/$/, '') || '/';
if (currentPath === normalizedHref || currentPath.startsWith(normalizedHref + '/')) {
link.classList.add('active');
// Add active to parent mega menu nav-item
const parentMega = link.closest('.nav-item.mega-parent');
if (parentMega) {
parentMega.classList.add('active');
const parentLink = parentMega.querySelector('.nav-link.dropdown-toggle');
if (parentLink) {
parentLink.classList.add('active');
}
}
}
});
});// JavaScript to make parent links clickable and use hover on desktop
document.addEventListener("DOMContentLoaded", function () {// Desktop hover open
if (window.innerWidth >= 992) {
document.querySelectorAll('.nav-item.dropdown, .nav-item.mega-parent')
.forEach(function (dropdown) {dropdown.addEventListener('mouseenter', function () {
const menu = this.querySelector('.dropdown-menu');
if (menu) menu.classList.add('show');
});dropdown.addEventListener('mouseleave', function () {
const menu = this.querySelector('.dropdown-menu');
if (menu) menu.classList.remove('show');
});
});// Prevent dropdown-toggle from blocking navigation
document.querySelectorAll('.nav-link.dropdown-toggle')
.forEach(function (toggle) {
toggle.addEventListener('click', function (e) {
// Allow navigation on desktop
const href = this.getAttribute('href');
if (href && href !== '#' && href !== '') {
window.location = href;
}
});
});
}
});