/*
* FRS Roofing - Custom Divi JavaScript/jQuery
* Version: 1.0.0
* Description: Enhances Divi theme with sticky header and custom mobile menu functionality.
*
* IMPORTANT: Paste this code into Divi > Theme Options > Integration > Add code to the < body > (bottom).
* Ensure jQuery is loaded before this script.
*/
(function($) {
$(document).ready(function() {
// Sticky Header Functionality
var $mainHeader = $('#main-header.frs-main-header'); // Desktop header
var $mobileHeader = $('.et-l--header.frs-mobile-header'); // Mobile header (Theme Builder)
var scrollThresholdDesktop = 100; // Pixels to scroll before sticky on desktop
var scrollThresholdMobile = 50; // Pixels to scroll before sticky on mobile
function handleStickyHeader() {
if ($(window).width() > 980) { // Desktop view
if ($(window).scrollTop() > scrollThresholdDesktop) {
$mainHeader.addClass('frs-fixed-header');
} else {
$mainHeader.removeClass('frs-fixed-header');
}
} else { // Mobile view
if ($(window).scrollTop() > scrollThresholdMobile) {
$mobileHeader.addClass('frs-fixed-header');
} else {
$mobileHeader.removeClass('frs-fixed-header');
}
}
}
// Attach event listeners
$(window).on('scroll', handleStickyHeader);
$(window).on('resize', handleStickyHeader); // Re-evaluate on resize
handleStickyHeader(); // Initial check on page load
// Mobile Menu Toggle Functionality
// Assuming the mobile menu toggle button has the ID 'frs-mobile-menu-toggle'
// and the mobile menu overlay has the class 'frs-mobile-menu-overlay'
$('#frs-mobile-menu-toggle').on('click', function() {
$('.et_pb_section.frs-mobile-menu-overlay').addClass('frs-mobile-menu-open');
});
// Assuming the close button inside the overlay has the class 'frs-mobile-menu-close-button'
$('.et_pb_section.frs-mobile-menu-overlay .frs-mobile-menu-close-button').on('click', function() {
$('.et_pb_section.frs-mobile-menu-overlay').removeClass('frs-mobile-menu-open');
});
// Close mobile menu when a link inside it is clicked
$('.et_pb_section.frs-mobile-menu-overlay .frs-mobile-menu-nav a').on('click', function() {
$('.et_pb_section.frs-mobile-menu-overlay').removeClass('frs-mobile-menu-open');
});
});
})(jQuery);

