/**
* File fronend-pro.js
*
* Handles toggling the navigation menu for Addon widget
*
* @package astra-addon
*/
astraToggleSetupPro = function( mobileHeaderType, body, menu_click_listeners ) {
var flag = false;
var menuToggleAllLength;
if ( 'off-canvas' === mobileHeaderType || 'full-width' === mobileHeaderType ) {
// comma separated selector added, if menu is outside of Off-Canvas then submenu is not clickable, it work only for Off-Canvas area with dropdown style.
var __main_header_all = document.querySelectorAll( '#ast-mobile-popup, #ast-mobile-header' );
if ( body.classList.contains('ast-header-break-point') ) {
var menu_toggle_all = document.querySelectorAll( '#ast-mobile-header .main-header-menu-toggle' );
} else {
menu_toggle_all = document.querySelectorAll( '#ast-desktop-header .main-header-menu-toggle' );
}
menuToggleAllLength = menu_toggle_all.length;
} else {
if ( body.classList.contains('ast-header-break-point') ) {
var __main_header_all = document.querySelectorAll( '#ast-mobile-header' ),
menu_toggle_all = document.querySelectorAll( '#ast-mobile-header .main-header-menu-toggle' );
menuToggleAllLength = menu_toggle_all.length;
flag = menuToggleAllLength > 0 ? false : true;
menuToggleAllLength = flag ? 1 : menuToggleAllLength;
} else {
var __main_header_all = document.querySelectorAll( '#ast-desktop-header' ),
menu_toggle_all = document.querySelectorAll('#ast-desktop-header .main-header-menu-toggle');
menuToggleAllLength = menu_toggle_all.length;
}
}
if ( menuToggleAllLength > 0 || flag ) {
for (var i = 0; i < menuToggleAllLength; i++) {
if ( !flag ) {
menu_toggle_all[i].setAttribute('data-index', i);
if (!menu_click_listeners[i]) {
menu_click_listeners[i] = menu_toggle_all[i];
menu_toggle_all[i].removeEventListener('click', astraNavMenuToggle);
menu_toggle_all[i].addEventListener('click', astraNavMenuToggle, false);
}
}
if ('undefined' !== typeof __main_header_all[i]) {
// To handle the comma seprated selector added above we need this loop.
for( var mainHeaderCount =0; mainHeaderCount < __main_header_all.length; mainHeaderCount++ ){
if (document.querySelector('header.site-header').classList.contains('ast-builder-menu-toggle-link')) {
var astra_menu_toggle = __main_header_all[mainHeaderCount].querySelectorAll('ul.main-header-menu .menu-item-has-children > .menu-link, ul.main-header-menu .ast-menu-toggle');
} else {
var astra_menu_toggle = __main_header_all[mainHeaderCount].querySelectorAll('ul.main-header-menu .ast-menu-toggle');
}
// Add Eventlisteners for Submenu.
if (astra_menu_toggle.length > 0) {
for (var j = 0; j < astra_menu_toggle.length; j++) {
astra_menu_toggle[j].removeEventListener('click', AstraToggleSubMenu);
astra_menu_toggle[j].addEventListener('click', AstraToggleSubMenu, false);
}
}
}
}
}
}
}
astraNavMenuTogglePro = function ( event, body, mobileHeaderType, thisObj ) {
event.preventDefault();
var desktop_header = event.target.closest('#ast-desktop-header');
var desktop_header_content = document.querySelector('#masthead > #ast-desktop-header .ast-desktop-header-content');
if ( null !== desktop_header && undefined !== desktop_header && '' !== desktop_header ) {
var desktop_toggle = desktop_header.querySelector( '.main-header-menu-toggle' );
} else {
var desktop_toggle = document.querySelector('#masthead > #ast-desktop-header .main-header-menu-toggle');
}
var desktop_menu = document.querySelector('#masthead > #ast-desktop-header .ast-desktop-header-content .main-header-bar-navigation');
if ( 'desktop' === event.currentTarget.trigger_type ) {
if ( null !== desktop_menu && '' !== desktop_menu && undefined !== desktop_menu ) {
astraToggleClass(desktop_menu, 'toggle-on');
if (desktop_menu.classList.contains('toggle-on')) {
desktop_menu.style.display = 'block';
} else {
desktop_menu.style.display = '';
}
}
astraToggleClass(desktop_toggle, 'toggled');
if ( desktop_toggle.classList.contains( 'toggled' ) ) {
body.classList.add("ast-main-header-nav-open");
if ( 'dropdown' === mobileHeaderType ) {
desktop_header_content.style.display = 'block';
}
} else {
body.classList.remove("ast-main-header-nav-open");
desktop_header_content.style.display = 'none';
}
return;
}
var __main_header_all = document.querySelectorAll('#masthead > #ast-mobile-header .main-header-bar-navigation');
menu_toggle_all = document.querySelectorAll( '#masthead > #ast-mobile-header .main-header-menu-toggle' )
var event_index = '0';
var sticky_header = false;
if ( null !== thisObj.closest( '#ast-fixed-header' ) ) {
__main_header_all = document.querySelectorAll('#ast-fixed-header > #ast-mobile-header .main-header-bar-navigation');
menu_toggle_all = document.querySelectorAll( '#ast-fixed-header .main-header-menu-toggle' )
event_index = '0';
sticky_header = true;
}
if ('undefined' === typeof __main_header_all[event_index]) {
return false;
}
var menuHasChildren = __main_header_all[event_index].querySelectorAll('.menu-item-has-children');
for (var i = 0; i < menuHasChildren.length; i++) {
menuHasChildren[i].classList.remove('ast-submenu-expanded');
var menuHasChildrenSubMenu = menuHasChildren[i].querySelectorAll('.sub-menu');
for (var j = 0; j < menuHasChildrenSubMenu.length; j++) {
menuHasChildrenSubMenu[j].style.display = 'none';
}
}
var menu_class = thisObj.getAttribute('class') || '';
if ( menu_class.indexOf('main-header-menu-toggle') !== -1 ) {
astraToggleClass(__main_header_all[event_index], 'toggle-on');
astraToggleClass(menu_toggle_all[event_index], 'toggled');
if ( sticky_header && 1 < menu_toggle_all.length ) {
astraToggleClass(menu_toggle_all['1'], 'toggled');
}
if (__main_header_all[event_index].classList.contains('toggle-on')) {
__main_header_all[event_index].style.display = 'block';
body.classList.add("ast-main-header-nav-open");
} else {
__main_header_all[event_index].style.display = '';
body.classList.remove("ast-main-header-nav-open");
}
}
}
const accountMenuToggle = function () {
const checkAccountActionTypeCondition = astraAddon.hf_account_action_type && 'menu' === astraAddon.hf_account_action_type;
const accountMenuClickCondition = checkAccountActionTypeCondition && astraAddon.hf_account_show_menu_on && 'click' === astraAddon.hf_account_show_menu_on;
const headerAccountContainer = document.querySelectorAll('.ast-header-account-wrap');
if( headerAccountContainer ) {
headerAccountContainer.forEach(element => {
const accountMenu = element.querySelector('.ast-account-nav-menu');
const handlePointerUp = function( e ) {
const condition = ( accountMenuClickCondition ) || ( checkAccountActionTypeCondition && document.querySelector('body').classList.contains('ast-header-break-point'));
if( condition ) {
// if the target of the click isn't the container nor a descendant of the container
if ( accountMenu && !element.contains( e.target ) ) {
accountMenu.style.right = '';
accountMenu.style.left = '';
}
}
};
// Attach pointerup event listener only once.
if ( ! element._accountPointerUpHandler ) {
element._accountPointerUpHandler = handlePointerUp;
document.addEventListener('pointerup', handlePointerUp);
}
const headerAccountTrigger = element.querySelector( '.ast-header-account-link' );
if( headerAccountTrigger ) {
const handleAccountClick = function( e ) {
const condition = ( accountMenuClickCondition ) || ( checkAccountActionTypeCondition && document.querySelector('body').classList.contains('ast-header-break-point'));
if( condition ) {
headerSelectionPosition = e.target.closest('.site-header-section');
if( headerSelectionPosition ) {
if( headerSelectionPosition.classList.contains('site-header-section-left') ) {
accountMenu.style.left = accountMenu.style.left === '' ? '-100%' : '';
accountMenu.style.right = accountMenu.style.right === '' ? 'auto' : '';
} else {
accountMenu.style.right = accountMenu.style.right === '' ? '-100%' : '';
accountMenu.style.left = accountMenu.style.left === '' ? 'auto' : '';
}
}
}
};
// Attach click event listener only once.
if ( ! headerAccountTrigger._accountClickHandler ) {
headerAccountTrigger._accountClickHandler = handleAccountClick;
headerAccountTrigger.addEventListener( 'click', handleAccountClick);
}
}
});
}
}
/**
* Color Switcher.
*
* @since 4.10.0
*/
const astraColorSwitcher = {
...astraAddon?.colorSwitcher, // Spreading Color Switcher options.
/**
* Initializes the Color Switcher Widget.
*/
init: function () {
if ( ! this?.isInit ) {
return;
}
this.switcherButtons = document.querySelectorAll( '.ast-builder-color-switcher .ast-switcher-button' );
if ( ! this.switcherButtons?.length ) {
return;
}
this.switcherButtons?.forEach( ( switcherButton ) => {
switcherButton?.addEventListener( 'click', this.toggle ); // ✅ `this` refers to astraColorSwitcher
} );
if ( this.isDarkPalette && this.defaultMode === 'system' ) {
// Detect system preference and apply mode accordingly.
this.detectSystemColorScheme();
}
// Set initial logo state if switched
if ( this.isSwitched ) {
this.switchLogo();
}
},
/**
* Detects the system's color scheme preference and sets the theme accordingly.
*/
detectSystemColorScheme: function () {
const storedPreference = this.getCookie( 'astraColorSwitcherState' );
// Bail early, if user has previously chosen a theme.
if ( storedPreference !== null ) {
return;
}
// Detect system preference.
const prefersDark = window.matchMedia( '(prefers-color-scheme: dark)' ).matches;
if ( prefersDark && ! this.isSwitched ) {
// Apply the detected or stored theme.
this.toggle();
}
},
/**
* Toggle the palette.
*
* @param {Event} e Button click event object.
*/
toggle: function ( e ) {
e?.preventDefault();
const switcher = astraColorSwitcher;
// Toggle the state
switcher.isSwitched = ! switcher.isSwitched;
// Store state in cookie (expires in 90 days).
switcher.setCookie( 'astraColorSwitcherState', switcher.isSwitched, 90 );
if ( switcher?.forceReload ) {
window.location.reload();
return;
}
switcher.switchPaletteColors();
switcher.switchIcon();
switcher.switchLogo();
if ( switcher.isDarkPalette ) {
switcher.handleDarkModeCompatibility();
}
},
/**
* Switch Palette Colors.
*/
switchPaletteColors: function () {
// Choose the correct palette based on `isSwitched` state.
const currentPalette = this.isSwitched ? this?.palettes?.switched : this?.palettes?.default;
// Apply the colors to CSS variables.
currentPalette?.forEach( ( color, index ) => {
document.documentElement.style.setProperty( `--ast-global-color-${ index }`, color );
} );
},
/**
* Switch Icon.
*/
switchIcon: function () {
this.switcherButtons?.forEach( ( switcherButton ) => {
const [ defaultIcon, switchedIcon ] = switcherButton?.querySelectorAll( '.ast-switcher-icon' );
// Avoid icon switching if there is none or only one.
if ( defaultIcon && switchedIcon ) {
const [ first, second ] = this.isSwitched ? [ switchedIcon, defaultIcon ] : [ defaultIcon, switchedIcon ];
// Animate icon.
switcherButton?.classList.add( 'ast-animate' );
setTimeout( () => {
first?.classList.add( 'ast-current' );
second?.classList.remove( 'ast-current' );
}, 100 );
setTimeout( () => switcherButton?.classList.remove( 'ast-animate' ), 200 );
}
/// Switch aria attribute.
const ariaLabelTextKey = this.isSwitched ? 'defaultText' : 'switchedText';
switcherButton?.setAttribute(
'aria-label',
switcherButton?.dataset?.[ ariaLabelTextKey ] || 'Switch color palette.'
);
} );
},
/**
* Switch Logo.
*/
switchLogo: function () {
// Handle color switcher logo switching
if ( this.isDarkPalette && this?.logos?.switched && this?.logos?.default ) {
this.switchColorSwitcherLogo();
}
},
/**
* Switch Color Switcher Logo.
* Handles logo switching for dark/light palette modes.
*/
switchColorSwitcherLogo: function () {
// Target only main logo, exclude sticky header and transparent header logos
const logoSelectors = [
'.custom-logo-link:not(.sticky-custom-logo):not(.transparent-custom-logo) .custom-logo', // Main logo only
'.site-branding .site-logo-img img:not(.ast-sticky-header-logo)', // Main site logo, not sticky
'.ast-site-identity .site-logo-img img:not(.ast-sticky-header-logo)', // Alternative main logo structure
];
let logoImages = [];
// Try each selector to find main logo images only
for ( const selector of logoSelectors ) {
const foundImages = document.querySelectorAll( selector );
if ( foundImages.length > 0 ) {
// Filter out sticky and transparent header logos if they somehow get selected
logoImages = Array.from( foundImages).filter( ( img ) => {
// Exclude if parent contains sticky header or transparent header classes
return ! img.closest( '.ast-sticky-header-logo' ) &&
! img.closest( '.sticky-custom-logo' ) &&
! img.closest( '.transparent-custom-logo' ) &&
! img.classList.contains( 'ast-sticky-header-logo' );
} );
if ( logoImages.length > 0 ) {
break;
}
}
}
if ( ! logoImages.length ) {
return;
}
// Determine which logo to show based on current state
const targetSrc = this.isSwitched ? this.logos.switched : this.logos.default;
if ( ! targetSrc ) {
return;
}
// Update each logo image
this.updateLogoImages( logoImages, targetSrc );
},
/**
* Update Logo Images.
*/
updateLogoImages: function ( logoImages, targetSrc ) {
logoImages.forEach( ( logoImg ) => {
if ( logoImg && logoImg.src !== targetSrc ) {
// Preload image for smoother switching
const newImg = new Image();
newImg.onload = function() {
logoImg.src = targetSrc;
if ( logoImg.hasAttribute ( 'srcset' ) ) {
logoImg.removeAttribute( 'srcset' );
}
if ( logoImg.hasAttribute( 'data-src' ) ) {
logoImg.setAttribute( 'data-src', targetSrc );
}
};
newImg.onerror = function() {
logoImg.src = targetSrc; // Try anyway
};
newImg.src = targetSrc;
}
} );
},
/**
* Handle Dark Mode Compatibility.
*/
handleDarkModeCompatibility: function () {
// Add the dark mode class.
document.body.classList.toggle( 'astra-dark-mode-enable' );
// Todo: Handle dark compatibility CSS.
},
/**
* Helper function to set a cookie.
*/
setCookie: ( name, value, days ) => {
const expires = new Date();
expires.setTime( expires.getTime() + days * 24 * 60 * 60 * 1000 );
document.cookie = `${ name }=${ value }; expires=${ expires.toUTCString() }; path=/`;
},
/**
* Helper function to get a cookie.
*/
getCookie: ( name ) => {
const cookies = document.cookie.split( '; ' );
for ( let cookie of cookies ) {
const [ key, val ] = cookie.split( '=' );
if ( key === name ) return val;
}
return null;
},
};
/**
* Account Login Popup Trigger
*
* Moved from theme's JS to addon to ensure the login popup JS always loads with the account component.
* Fixes cases where the JS was missing when the widget was added due to theme script loading order.
*
* @since 4.11.5 Moved from theme to addon
*/
var accountPopupTrigger = function () {
if ( typeof astraAddon === 'undefined' || 'login' !== astraAddon.hf_account_logout_action ) {
return;
}
// Account login form popup.
var header_account_trigger = document.querySelectorAll( '.ast-account-action-login' );
if (!header_account_trigger.length) {
return;
}
const formWrapper = document.querySelector('#ast-hb-account-login-wrap');
if (!formWrapper) {
return;
}
const formCloseBtn = document.querySelector('#ast-hb-login-close');
header_account_trigger.forEach(function(_trigger) {
_trigger.addEventListener('click', function(e) {
e.preventDefault();
formWrapper.classList.add('show');
});
});
if (formCloseBtn) {
formCloseBtn.addEventListener('click', function(e) {
e.preventDefault();
formWrapper.classList.remove('show');
});
}
};
document.addEventListener( 'astPartialContentRendered', function() {
accountMenuToggle();
accountPopupTrigger();
});
window.addEventListener( 'load', function() {
accountMenuToggle();
accountPopupTrigger();
astraColorSwitcher.init();
} );
document.addEventListener( 'astLayoutWidthChanged', function() {
accountMenuToggle();
accountPopupTrigger();
} );
// Fix: Sync toggle button state when anchor links close the menu.
document.addEventListener('click', function(e) {
let target = e.target.closest('a');
let href = target && target.getAttribute('href');
if ( href && href.indexOf('#') !== -1 &&
(target.closest('.main-header-bar-navigation') || target.closest('.ast-mobile-header-content') || target.closest('.ast-desktop-header-content')) ) {
setTimeout(function() {
let allToggleButtons = document.querySelectorAll('.menu-toggle');
let menuContent = document.querySelector('.main-header-bar-navigation');
if ( menuContent && !menuContent.classList.contains('toggle-on') ) {
allToggleButtons.forEach(function(button) {
button.classList.remove('toggled');
button.setAttribute('aria-expanded', 'false');
});
}
}, 10);
}
});
/**
* Stick elements
*
* => How to use?
*
* jQuery( {SELECTOR} ).astHookExtSticky( {
* dependent: [{selectors}], // Not required. Default: []. Stick element dependent selectors.
* stick_upto_scroll: {value}, // Not required. Default: 0. Stick element after scroll upto the {value} in px.
* gutter: {value}, // Not required. Default: 0. Stick element from top of the window in px\.
* });
*
* @package Astra Addon
* @since 1.0.0
*/
;(function ( $, window, undefined ) {
var pluginName = 'astHookExtSticky',
document = window.document,
windowWidth = jQuery( window ).outerWidth(),
viewPortWidth = jQuery( window ).width(),
defaults = {
dependent : [],
max_width : '',
site_layout : '',
break_point : 920,
admin_bar_height_lg : 32,
admin_bar_height_sm : 46,
admin_bar_height_xs : 0,
stick_upto_scroll : 0,
gutter : 0,
wrap : '
wrapper with height element for smooth scroll
*
* Added 'data-stick-support' to all sticky elements
* To know the {dependent} element has support of 'stick'
*/
if ( 'none' == self.options.header_style ) {
selector.wrap( self.options.wrap )
.parent().css( 'min-height', selector.outerHeight() )
.attr( 'data-stick-support', 'on' )
.attr( 'data-stick-maxwidth', parseInt( self.options.max_width ) );
}
self.update_attrs();
// Stick me!.
jQuery( window ).on('resize', function() {
self.stickRelease( self );
self.update_attrs();
self.stick_me( self );
} );
jQuery( window ).on('scroll', function() {
// update the stick_upto_scroll if normal main header navigation is opend.
self.stick_me( self, 'scroll' );
} );
jQuery( document ).ready(function($) {
self.stick_me( self );
} );
}
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if ( ! $.data( this, 'plugin_' + pluginName )) {
$.data( this, 'plugin_' + pluginName, new astHookExtSticky( this, options ) );
}
});
}
var $body = jQuery( 'body' ),
layout_width = $body.width(),
site_layout = astraAddon.site_layout || '',
hook_sticky_header = astraAddon.hook_sticky_header || '',
hook_shrink_header = astraAddon.hook_shrink_header || '';
sticky_header_on_devices = astraAddon.hook_sticky_header_on_devices || 'desktop',
site_layout_box_width = astraAddon.site_layout_box_width || 1200,
hook_sticky_footer = astraAddon.hook_sticky_footer || '',
sticky_footer_on_devices = astraAddon.hook_sticky_footer_on_devices || 'desktop';
switch ( site_layout ) {
case 'ast-box-layout':
layout_width = parseInt( site_layout_box_width );
break;
}
jQuery( document ).ready(function($) {
// Any stick header is enabled?
if ( 'enabled' == hook_sticky_header ) {
jQuery( '.ast-custom-header' ).astHookExtSticky({
sticky_on_device: sticky_header_on_devices,
header_style: 'none',
site_layout: site_layout,
max_width: layout_width,
active_shrink: hook_shrink_header,
});
}
// Any stick footer is enabled?
if ( 'enabled' == hook_sticky_footer ) {
jQuery( '.ast-custom-footer' ).astHookExtSticky({
sticky_on_device: sticky_footer_on_devices,
max_width: layout_width,
site_layout: site_layout,
header_style: 'none',
});
}
});
}(jQuery, window));
/**
* Stick elements
*
* => How to use?
*
* jQuery( {SELECTOR} ).astExtSticky( {
* dependent: [{selectors}], // Not required. Default: []. Stick element dependent selectors.
* stick_upto_scroll: {value}, // Not required. Default: 0. Stick element after scroll upto the {value} in px.
* gutter: {value}, // Not required. Default: 0. Stick element from top of the window in px\.
* });
*
* @package Astra Addon
* @since 1.0.0
*/
;(function ( $, window, undefined ) {
var pluginName = 'astExtSticky',
document = window.document,
windowWidth = jQuery( window ).outerWidth(),
viewPortWidth = jQuery( window ).width(),
header_builder_active = astraAddon.header_builder_active,
defaults = {
dependent : [],
max_width : '',
site_layout : '',
break_point : 920,
admin_bar_height_lg : 32,
admin_bar_height_sm : 46,
admin_bar_height_xs : 0,
stick_upto_scroll : 0,
gutter : 0,
wrap : '
',
// Padding support of tag.
body_padding_support : true,
// Padding support of tag.
html_padding_support : true,
// Added shrink option.
shrink : {
padding_top : '',
padding_bottom : '',
},
// Enable sticky on mobile
sticky_on_device : 'desktop',
header_style : 'none',
hide_on_scroll : 'no',
},
/* Manage hide on scroll down */
lastScrollTop = 0,
delta = 5,
navbarHeight = 0,
loginPopup = document.querySelector('#ast-hb-account-login-wrap') !== null,
should_stick = true,
hideScrollInterval;
/**
* Init
*
* @since 1.0.0
*/
function astExtSticky( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
/* Manage hide on scroll down */
if ( '1' == this.options.hide_on_scroll ) {
this.navbarHeight = $(element).outerHeight();
}
this.lastScrollTop = 0;
this.delta = 5;
this.should_stick = true;
this.hideScrollInterval = '';
this.init();
}
/**
* Stick element
*
* @since 1.0.0
*/
astExtSticky.prototype.stick_me = function( self, type ) {
var selector = jQuery( self.element ),
windowWidth = jQuery( window ).outerWidth();
stick_upto_scroll = parseInt( self.options.stick_upto_scroll ),
max_width = parseInt( selector.parent().attr( 'data-stick-maxwidth' ) ), // parseInt( self.options.max_width ),
gutter = parseInt( selector.parent().attr( 'data-stick-gutter' ) ), // parseInt( self.options.gutter ).
aboveHeaderSelectorValue = gutter;
if ( header_builder_active && astraAddon.header_main_shrink ) {
// Decrese the top of primary / below as we decrease the min-height of all sticked headers by 20.
if ( ( selector.hasClass( 'ast-stick-primary-below-wrapper' ) || ( selector.hasClass( 'ast-primary-header' ) ) ) && 1 == astraAddon.header_above_stick && gutter > 0 ) {
gutter = gutter - 10;
}
const aboveHeaderBar = document.querySelector( '.ast-above-header-bar' );
if ( astraAddon.header_above_stick === '1' && aboveHeaderBar !== null ) {
const aboveHeaderBarHeight = aboveHeaderBar.getBoundingClientRect().height + parseInt( aboveHeaderBar.parentNode.getAttribute( 'data-stick-gutter' ) );
if ( ( selector.hasClass( 'ast-stick-primary-below-wrapper' ) || ( selector.hasClass( 'ast-primary-header' ) ) ) && gutter > 0 ) {
gutter = aboveHeaderBarHeight;
}
}
}
/**
* Check window width
*/
if (
(self.options.sticky_on_device === 'desktop' && jQuery('body').hasClass('ast-header-break-point')) ||
(self.options.sticky_on_device === 'mobile' && !jQuery('body').hasClass('ast-header-break-point'))
) {
self.stickRelease(self);
}
else {
// stick_upto_scroll with negative value enables a sticky by default so rounding up to zero.
if ( stick_upto_scroll < 0 ) {
stick_upto_scroll = 0;
}
// Check if the Elementor Motion Effect class present
var stcikyHeaderElementor = document.getElementsByClassName('elementor-motion-effects-parent');
var stickyHeaderFlag = stcikyHeaderElementor.length > 0 ? true : false;
if ( jQuery( window ).scrollTop() > stick_upto_scroll ) {
var fixed_header = selector;
if ( header_builder_active ) {
var mobile_parent = selector.closest( '.ast-mobile-header-wrap' );
var desktop_parent = selector.closest( '#ast-desktop-header' );
mobile_parent = ( 0 === mobile_parent.length ) ? selector.find( '.ast-mobile-header-wrap' ) : mobile_parent;
desktop_parent = ( 0 === desktop_parent.length ) ? selector.find( '#ast-desktop-header' ) : desktop_parent;
mobile_parent.find( '.ast-mobile-header-content' ).css( 'top', selector.outerHeight() + gutter );
if ( 'ast-box-layout' == self.options.site_layout ) {
var max_width_mobile = jQuery( 'body' ).width();
mobile_parent.find( '.ast-mobile-header-content' ).css( 'width', max_width_mobile );
} else {
mobile_parent.find( '.ast-mobile-header-content' ).css( 'width', max_width );
}
desktop_parent.find( '.ast-desktop-header-content' ).css( 'top', selector.outerHeight() + gutter );
desktop_parent.find( '.ast-desktop-header-content' ).css( 'width', max_width );
}
if ( '1' === self.options.hide_on_scroll ) {
self.hasScrolled( self, 'stick' );
}else if ( 'none' == self.options.header_style ) {
if ( ! stickyHeaderFlag ) {
selector.parent().css( 'min-height', selector.outerHeight() );
}
if ( ! document.querySelector('body').classList.contains( 'fl-builder-edit' ) ) {
selector.addClass('ast-sticky-active').stop().css({
'top': gutter,
});
}
selector.addClass( 'ast-sticky-active' ).stop().css({
'max-width' : max_width,
'padding-top' : self.options.shrink.padding_top,
'padding-bottom' : self.options.shrink.padding_bottom,
});
if ( ( selector.hasClass( 'ast-stick-primary-below-wrapper' ) || selector.hasClass( 'ast-primary-header' ) ) && 1 == astraAddon.header_above_stick && 70 > selector.closest('#ast-desktop-header').find('.ast-above-header-bar').outerHeight() ) {
selector.parent().css("min-height", selector.outerHeight());
}
selector.addClass( 'ast-sticky-shrunk' ).stop();
$( document ).trigger( "addStickyClass" );
fixed_header.addClass('ast-header-sticked');
}else if ( 'slide' == self.options.header_style ) {
fixed_header.css({
'top' : gutter,
});
fixed_header.addClass('ast-header-slide');
fixed_header.css( 'visibility', 'visible' );
fixed_header.addClass( 'ast-sticky-active' ).stop().css({
'transform': loginPopup ? 'none' : 'translateY(0)',
});
$('html').addClass('ast-header-stick-slide-active');
$( document ).trigger( "addStickyClass" );
fixed_header.addClass('ast-header-sticked');
}else if( 'fade' == self.options.header_style ) {
fixed_header.css({
'top' : gutter,
});
fixed_header.addClass('ast-header-fade');
fixed_header.css( 'visibility', 'visible' );
fixed_header.addClass( 'ast-sticky-active' ).stop().css({
'opacity' : '1',
});
$('html').addClass('ast-header-stick-fade-active');
$( document ).trigger( "addStickyClass" );
fixed_header.addClass('ast-header-sticked');
}
} else {
self.stickRelease( self );
if ( header_builder_active ) {
var mobile_parent = selector.closest( '.ast-mobile-header-wrap' );
mobile_parent = ( 0 === mobile_parent.length ) ? selector.find( '.ast-mobile-header-wrap' ) : mobile_parent;
if ( !jQuery( 'body' ).hasClass( 'ast-primary-sticky-header-active' ) || !jQuery( 'body' ).hasClass( 'ast-above-sticky-header-active' ) || !jQuery( 'body' ).hasClass( 'ast-below-sticky-header-active' ) ) {
mobile_parent.find( '.ast-mobile-header-content' ).removeAttr( 'style' );
}
}
}
}
}
astExtSticky.prototype.update_attrs = function () {
var self = this,
selector = jQuery( self.element ),
gutter = parseInt( self.options.gutter ),
max_width = self.options.max_width;
if ( 'none' == self.options.header_style && ! jQuery( 'body' ).hasClass( 'ast-sticky-toggled-off' ) ) {
var stick_upto_scroll = selector.offset().top || 0;
}else{
if ( $('#masthead').length ) {
var masthead = $('#masthead');
var masthead_bottom = 'none' == self.options.header_style
? masthead.offset().top
: masthead.offset().top + masthead.outerHeight() + 100;
var stick_upto_scroll = masthead_bottom || 0;
}
}
/**
* Update Max-Width
*/
if ( 'ast-box-layout' != self.options.site_layout ) {
max_width = jQuery( 'body' ).width();
}
/**
* Check dependent element
* - Is exist?
* - Has attr 'data-stick-support' with status 'on'
*/
if ( self.options.dependent ) {
jQuery.each( self.options.dependent, function(index, val) {
if (
( jQuery( val ).length ) &&
( jQuery( val ).parent().attr( 'data-stick-support' ) == 'on' )
) {
dependent_height = jQuery( val ).outerHeight();
gutter += parseInt( dependent_height );
stick_upto_scroll -= parseInt( dependent_height );
}
});
}
/**
* Add support for Admin bar height
*/
if ( self.options.admin_bar_height_lg && jQuery( '#wpadminbar' ).length && viewPortWidth > 782 ) {
gutter += parseInt( self.options.admin_bar_height_lg );
stick_upto_scroll -= parseInt( self.options.admin_bar_height_lg );
}
if ( self.options.admin_bar_height_sm && jQuery( '#wpadminbar' ).length && ( viewPortWidth >= 600 && viewPortWidth <= 782 ) ) {
gutter += parseInt( self.options.admin_bar_height_sm );
stick_upto_scroll -= parseInt( self.options.admin_bar_height_sm );
}
if( self.options.admin_bar_height_xs && jQuery( '#wpadminbar' ).length ){
gutter += parseInt( self.options.admin_bar_height_xs );
stick_upto_scroll -= parseInt( self.options.admin_bar_height_xs );
}
/**
* Add support for tag
*/
if ( self.options.body_padding_support ) {
gutter += parseInt( jQuery( 'body' ).css( 'padding-top' ), 10 );
stick_upto_scroll -= parseInt( jQuery( 'body' ).css( 'padding-top' ), 10 );
}
/**
* Add support for tag
*/
if ( self.options.html_padding_support ) {
gutter += parseInt( jQuery( 'html' ).css( 'padding-top' ), 10 );
stick_upto_scroll -= parseInt( jQuery( 'html' ).css( 'padding-top' ), 10 );
}
/**
* Reduce the stick_upto_scrll by one if filter `astra_addon_sticky_header_stick_origin_position` is set true.
* This will make the sticky header appear sticky on initial load.
*/
if ( stick_origin_position ) {
stick_upto_scroll--;
}
/**
* Updated vars
*/
self.options.stick_upto_scroll = stick_upto_scroll;
/**
* Update Attributes
*/
if ( 'none' == self.options.header_style ) {
selector.parent()
.css( 'min-height', selector.outerHeight() )
.attr( 'data-stick-gutter', parseInt( gutter ) )
.attr( 'data-stick-maxwidth', parseInt( max_width ) );
}else{
selector.parent()
.attr( 'data-stick-gutter', parseInt( gutter ) )
.attr( 'data-stick-maxwidth', parseInt( max_width ) );
if ( 'ast-padded-layout' === self.options.site_layout ) {
selector.css( 'max-width', parseInt( max_width ) );
}
}
}
astExtSticky.prototype.hasScrolled = function( self, method ) {
var st = $( window ).scrollTop();
// Make sure they scroll more than delta
if(Math.abs(lastScrollTop - st) <= delta)
return;
// If they scrolled down and are past the navbar, add class .nav-up.
// This is necessary so you never see what is "behind" the navbar.
var fixed_header = jQuery(self.element);
if (st > lastScrollTop && st > navbarHeight){
// Scroll Down
jQuery(self.element).removeClass('ast-nav-down').addClass('ast-nav-up');
} else {
// Scroll Up
if(st + $(window).height() < $(document).height()) {
jQuery(self.element).removeClass('ast-nav-up').addClass('ast-nav-down');
}
}
lastScrollTop = st;
if ( !$(self.element).hasClass('ast-nav-up') && 'stick' == method ) {
fixed_header.css({
'top' : gutter,
});
fixed_header.addClass('ast-header-sticked');
fixed_header.addClass('ast-header-slide');
fixed_header.css( 'visibility', 'visible' );
fixed_header.addClass( 'ast-sticky-active' ).stop().css({
'transform':'translateY(0)',
});
$( document ).trigger( "addStickyClass" );
$('html').addClass('ast-header-stick-scroll-active');
}else{
fixed_header.css({
'transform':'translateY(-100%)',
}).stop();
setTimeout(function() {
fixed_header.removeClass( 'ast-sticky-active' );
}, 300);
fixed_header.css({
'visibility' : 'hidden',
'top' : '',
});
$( document ).trigger( "removeStickyClass" );
$('html').removeClass('ast-header-stick-scroll-active');
fixed_header.removeClass('ast-header-sticked');
}
}
astExtSticky.prototype.stickRelease = function( self ) {
var selector = jQuery( self.element );
var fixed_header = selector;
if ( '1' === self.options.hide_on_scroll ) {
self.hasScrolled( self, 'release' );
}else{
if ( 'none' == self.options.header_style ) {
selector.removeClass( 'ast-sticky-active' ).stop().css({
'max-width' : '',
'top' : '',
'padding' : '',
});
selector.parent().css( 'min-height', '' );
$( document ).trigger( "removeStickyClass" );
fixed_header.removeClass('ast-header-sticked');
selector.removeClass( 'ast-sticky-shrunk' ).stop();
}else if ( 'slide' == self.options.header_style ) {
fixed_header.removeClass( 'ast-sticky-active' ).stop().css({
'transform': loginPopup ? 'translateY(-100vh)' : 'translateY(-100%)',
});
fixed_header.css({
'visibility' : 'hidden',
'top' : '',
});
$('html').removeClass('ast-header-stick-slide-active');
$( document ).trigger( "removeStickyClass" );
fixed_header.removeClass('ast-header-sticked');
}else if( 'fade' == self.options.header_style ) {
fixed_header.removeClass( 'ast-sticky-active' ).stop().css({
'opacity' : '0',
});
fixed_header.css({
'visibility' : 'hidden',
});
fixed_header.removeClass('ast-header-sticked');
$( document ).trigger( "removeStickyClass" );
$('html').removeClass('ast-header-stick-fade-active');
}
}
}
/**
* Init Prototype
*
* @since 1.0.0
*/
astExtSticky.prototype.init = function () {
/**
* If custom stick options are set
*/
if ( jQuery( this.element ) ) {
var self = this,
selector = jQuery( self.element );
/**
* Add parent
wrapper with height element for smooth scroll
*
* Added 'data-stick-support' to all sticky elements
* To know the {dependent} element has support of 'stick'
*/
if ( 'none' == self.options.header_style ) {
selector.wrap( self.options.wrap )
.parent().css( 'min-height', selector.outerHeight() )
.attr( 'data-stick-support', 'on' )
.attr( 'data-stick-maxwidth', parseInt( self.options.max_width ) );
}else{
selector.wrap( self.options.wrap )
.attr( 'data-stick-support', 'on' )
.attr( 'data-stick-maxwidth', parseInt( self.options.max_width ) );
}
self.update_attrs();
// Stick me!.
jQuery( window ).on('resize', function() {
self.stickRelease( self );
self.update_attrs();
self.stick_me( self );
} );
jQuery( window ).on('scroll', function() {
// update the stick_upto_scroll if normal main header navigation is opend.
self.stick_me( self, 'scroll' );
if( jQuery( 'body' ).hasClass( 'ast-sticky-toggled-off' ) ){
self.update_attrs();
self.stick_me( self, 'scroll' );
}
} );
jQuery( document ).ready(function($) {
self.stick_me( self );
setTimeout( () => self.stick_me( self ), 0 );
} );
}
};
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if ( ! $.data( this, 'plugin_' + pluginName )) {
$.data( this, 'plugin_' + pluginName, new astExtSticky( this, options ) );
}
});
}
var $body = jQuery( 'body' ),
layout_width = $body.width(),
stick_header_meta = astraAddon.stick_header_meta || 'default',
stick_main = astraAddon.header_main_stick || '',
main_shrink = astraAddon.header_main_shrink || '',
stick_above = astraAddon.header_above_stick || '',
stick_below = astraAddon.header_below_stick || '',
header_main_stick_meta = astraAddon.header_main_stick_meta || '',
header_above_stick_meta = astraAddon.header_above_stick_meta || '',
header_below_stick_meta = astraAddon.header_below_stick_meta || '',
site_layout = astraAddon.site_layout || '',
site_layout_box_width = astraAddon.site_layout_box_width || 1200,
sticky_header_on_devices = astraAddon.sticky_header_on_devices || 'desktop',
sticky_header_style = astraAddon.sticky_header_style || 'none',
sticky_hide_on_scroll = astraAddon.sticky_hide_on_scroll || '',
header_logo_width = astraAddon.header_logo_width || '',
responsive_header_logo_width = astraAddon.responsive_header_logo_width || '',
stick_origin_position = astraAddon.stick_origin_position || '',
tablet_break_point = astraAddon.tablet_break_point || 768,
mobile_break_point = astraAddon.mobile_break_point || 544;
/**
* Check meta options
*/
if ( 'disabled' == stick_header_meta ) {
return;
}
if ( 'enabled' === stick_header_meta ) {
stick_main = header_main_stick_meta;
stick_above = header_above_stick_meta;
stick_below = header_below_stick_meta;
}
if ( $('header .site-logo-img img').length > 0 ) {
var id_img = $('header .site-logo-img img');
var id_height = id_img.attr('height');
if ( typeof id_height === 'undefined' ) {
id_height = id_img.height();
}
if ( id_height == 0 ) {
id_height = '';
}
if ( -1 === id_height.toString().indexOf('%') ) {
id_height += 'px';
}
if ( '' != responsive_header_logo_width.desktop || '' != responsive_header_logo_width.tablet || '' != responsive_header_logo_width.mobile ) {
var output = "";
}else if( '' != header_logo_width ){
var output = "";
}
$("head").append( output );
}
// Any stick header is enabled?
if ( stick_main || stick_above || stick_below ) {
// Add Respective class to the body dependent on which sticky header is activated.
$( document ).on( "addStickyClass", function() {
var bodyClass = '';
if ( '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main ) {
bodyClass += " ast-primary-sticky-header-active";
}
if ( '1' == stick_above || 'on' == stick_above || 'disabled' == stick_above ) {
bodyClass += " ast-above-sticky-header-active";
}
if ( '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below ) {
bodyClass += " ast-below-sticky-header-active";
}
$('body').addClass(bodyClass);
});
// Remove Respective class from the body dependent on which sticky header is not activated.
$( document ).on( "removeStickyClass", function() {
var bodyClass = '';
if ( '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main ) {
bodyClass += " ast-primary-sticky-header-active";
}
if ( '1' == stick_above || 'on' == stick_above || 'disabled' == stick_above ) {
bodyClass += " ast-above-sticky-header-active";
}
if ( '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below ) {
bodyClass += " ast-below-sticky-header-active";
}
$('body').removeClass(bodyClass);
});
switch ( site_layout ) {
case 'ast-box-layout':
layout_width = parseInt( site_layout_box_width );
break;
}
jQuery( document ).on('ready astLayoutWidthChanged', function( e ) {
if( 'astLayoutWidthChanged' === e.type ) {
// return if sticky not enabled.
if (!(parseInt( stick_main ) || parseInt( stick_below ) || parseInt( stick_above ))) {
return;
}
// Unwrapping sticky to reapply again.
jQuery('div.ast-stick-primary-below-wrapper').children().unwrap();
jQuery('div[data-stick-support="on"]').children().unwrap();
}
if ( '1' == sticky_hide_on_scroll ) {
if ( '1' == main_shrink ) {
jQuery( '#ast-fixed-header' ).addClass( 'ast-sticky-shrunk' ).stop();
}
if( !( '1' == stick_above || 'on' == stick_above || 'disabled' == stick_above ) ) {
jQuery( '#ast-fixed-header .ast-above-header' ).hide();
}
if( !( '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main ) ) {
jQuery( '#ast-fixed-header .main-header-bar' ).hide();
}
if( !( '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below ) ) {
jQuery( '#ast-fixed-header .ast-below-header' ).hide();
}
jQuery( '#ast-fixed-header' ).astExtSticky({
//dependent: ['#masthead .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
sticky_on_device: sticky_header_on_devices,
header_style: 'slide',
hide_on_scroll: sticky_hide_on_scroll,
});
}else{
if ('none' == sticky_header_style) {
if (header_builder_active) {
var headers = 'both' === sticky_header_on_devices ? ['desktop', 'mobile'] : [sticky_header_on_devices];
headers.forEach(function (header) {
/**
* Stick Above Header
*/
if ('1' == stick_above || 'on' == stick_above || 'disabled' == stick_above) {
jQuery('#masthead #ast-' + header + '-header .ast-above-header').astExtSticky({
max_width: layout_width,
site_layout: site_layout,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
// Add wrapper class to primary header & below header if stick primary header , stick below header and shrink primary header is enabled.
// stick wrapper class of primary header and below header
if (('1' == stick_main || 'on' == stick_main || 'disabled' == stick_main) &&
('1' == stick_below || 'on' == stick_below || 'disabled' == stick_below)
) {
var selector = jQuery('#masthead #ast-' + header + '-header .main-header-bar-wrap').length ?
jQuery('#masthead #ast-' + header + '-header .main-header-bar-wrap') :
jQuery('#masthead #ast-' + header + '-header .ast-below-header-wrap');
selector.wrap('
')
jQuery('#masthead #ast-' + header + '-header .ast-below-header-wrap').prependTo('#masthead #ast-' + header + '-header .ast-stick-primary-below-wrapper');
jQuery('#masthead #ast-' + header + '-header .main-header-bar-wrap').prependTo('#masthead #ast-' + header + '-header .ast-stick-primary-below-wrapper');
jQuery('#masthead #ast-' + header + '-header .ast-stick-primary-below-wrapper').astExtSticky({
dependent: ['#masthead #ast-' + header + '-header .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
} else {
/**
* Stick Main Header
*/
if ('1' == stick_main || 'on' == stick_main || 'disabled' == stick_main) {
// If shrink is enabled
// then add shrink top and bottom paddings.
var shrink_options = '';
if (main_shrink) {
shrink_options = {
padding_top: '',
padding_bottom: '',
}
}
jQuery('#masthead #ast-' + header + '-header .main-header-bar').astExtSticky({
dependent: ['#masthead #ast-' + header + '-header .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
jQuery('#masthead #ast-' + header + '-header .ast-custom-header').astExtSticky({
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
/**
* Stick Below Header
*/
if (('1' == stick_below || 'on' == stick_below || 'disabled' == stick_below)) {
jQuery('#masthead #ast-' + header + '-header .ast-below-header').astExtSticky({
dependent: ['#masthead #ast-' + header + '-header .main-header-bar', '#masthead #ast-' + header + '-header .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
}
});
} else {
/**
* Stick Above Header
*/
if ('1' == stick_above || 'on' == stick_above || 'disabled' == stick_above) {
jQuery('#masthead .ast-above-header').astExtSticky({
max_width: layout_width,
site_layout: site_layout,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
// Add wrapper class to primary header & below header if stick primary header , stick below header and shrink primary header is enabled.
// stick wrapper class of primary header and below header
if (('1' == stick_main || 'on' == stick_main || 'disabled' == stick_main) &&
('1' == stick_below || 'on' == stick_below || 'disabled' == stick_below)
) {
jQuery('#masthead .main-header-bar-wrap').wrap('
')
jQuery('#masthead .ast-below-header-wrap').prependTo('.ast-stick-primary-below-wrapper');
jQuery('#masthead .main-header-bar-wrap').prependTo('.ast-stick-primary-below-wrapper');
jQuery('#masthead .ast-stick-primary-below-wrapper').astExtSticky({
dependent: ['#masthead .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
} else {
/**
* Stick Main Header
*/
if ('1' == stick_main || 'on' == stick_main || 'disabled' == stick_main) {
// If shrink is enabled
// then add shrink top and bottom paddings.
var shrink_options = '';
if (main_shrink) {
shrink_options = {
padding_top: '',
padding_bottom: '',
}
}
jQuery('#masthead .main-header-bar').astExtSticky({
dependent: ['#masthead .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
jQuery('#masthead .ast-custom-header').astExtSticky({
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
/**
* Stick Below Header
*/
if (('1' == stick_below || 'on' == stick_below || 'disabled' == stick_below)) {
jQuery('#masthead .ast-below-header').astExtSticky({
dependent: ['#masthead .main-header-bar', '#masthead .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
}
}
}
else{
jQuery( '#ast-fixed-header' ).addClass( 'ast-sticky-shrunk' ).stop();
if( !( '1' == stick_above || 'on' == stick_above || 'disabled' == stick_above ) ) {
jQuery( '#ast-fixed-header .ast-above-header' ).hide();
}
if( !( '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main ) ) {
jQuery( '#ast-fixed-header .main-header-bar' ).hide();
}
if( !( '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below) ) {
jQuery( '#ast-fixed-header .ast-below-header' ).hide();
}
/**
* Stick Main Header
*/
if ( '1' == stick_above || 'on' == stick_above || 'disabled' == stick_above
|| '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main
|| '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below
) {
// If shrink is enabled
// then add shrink top and bottom paddings.
var shrink_options = '';
if( main_shrink ) {
shrink_options = {
padding_top: '',
padding_bottom: '',
}
}
jQuery( '#ast-fixed-header' ).astExtSticky({
//dependent: ['#masthead .ast-above-header'],
max_width: layout_width,
site_layout: site_layout,
shrink: shrink_options,
sticky_on_device: sticky_header_on_devices,
header_style: sticky_header_style,
hide_on_scroll: sticky_hide_on_scroll,
});
}
}
}
// If Sticky Header for both mobile , desktops.
if ( 'mobile' == sticky_header_on_devices || 'both' == sticky_header_on_devices ) {
// Normal Header Mobile Menu Toggled
jQuery( '#masthead .main-header-menu-toggle' ).click(function(event) {
/* If menu navigation is opened and has sticky active */
if( jQuery( '#masthead .main-header-menu-toggle' ).hasClass( 'toggled' ) ){
// Add body class to update the stick_upto_scroll.
$body.addClass('ast-sticky-toggled-off');
if (
'none' == defaults['header_style'] &&
( jQuery( '#masthead .main-header-bar' ).hasClass('ast-sticky-active') ||
jQuery( '#masthead .ast-stick-primary-below-wrapper' ).hasClass('ast-sticky-active') )
){
// Only If none style is selected
var windowHeight = jQuery( window ).height(),
headerSectionHeight = 0;
if ( jQuery( '#masthead .ast-above-header' ) && jQuery( '#masthead .ast-above-header' ).length ) {
headerSectionHeight = jQuery( '#masthead .ast-above-header' ).height();
}
// overflow hide for html.
if ( '1' == sticky_hide_on_scroll ) {
jQuery( 'html' ).css({
'overflow' : 'hidden',
});
}
// add min height to wrapper class of primary header and below header
if ( '1' == main_shrink &&
( '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main ) &&
( '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below )
) {
jQuery( '#masthead .ast-stick-primary-below-wrapper' ).css({
'max-height' : ( windowHeight - headerSectionHeight ) +'px',
'overflow-y' : 'auto',
});
} else {
// ass max height to sticky header.
jQuery( '#masthead .main-header-bar.ast-sticky-active' ).css({
'max-height' : ( windowHeight - headerSectionHeight ) +'px',
'overflow-y' : 'auto',
});
}
}
}
else{
$body.addClass('ast-sticky-toggled-off');
jQuery( 'html' ).css({
'overflow' : '',
});
if ( '1' == main_shrink &&
( '1' == stick_main || 'on' == stick_main || 'disabled' == stick_main ) &&
( '1' == stick_below || 'on' == stick_below || 'disabled' == stick_below )
) {
jQuery( '#masthead .ast-stick-primary-below-wrapper' ).css({
'max-height' : '',
'overflow-y' : '',
});
} else {
// ass max height to sticky header.
jQuery( '#masthead .main-header-bar.ast-sticky-active' ).css({
'max-height' : '',
'overflow-y' : '',
});
}
}
});
// Fixed Header Mobile Menu Toggled
jQuery( '#ast-fixed-header .main-header-menu-toggle' ).click(function(event) {
/* If menu navigation is opened and has sticky active */
if( jQuery( '#ast-fixed-header .main-header-menu-toggle' ).hasClass( 'toggled' ) ){
var windowHeight = jQuery( window ).height();
// overflow hide for html.
if ( '1' == sticky_hide_on_scroll ) {
jQuery( 'html' ).css({
'overflow' : 'auto',
});
}
// ass max height to sticky header.
jQuery( '#ast-fixed-header' ).css({
'max-height' : ( windowHeight ) +'px',
'overflow-y' : 'auto',
});
}
// remove css if menu toggle is closed.
else{
jQuery( 'html' ).css({
'overflow' : '',
});
jQuery( '#ast-fixed-header' ).css({
'max-height' : '',
'overflow-y' : '',
});
}
});
}
});
}
/**
* Handle mobile menu close behavior for fade/slide header animations
* This code ensures that when a user clicks on an anchor link (#) in the mobile menu:
* 1. The mobile menu is properly closed
* 2. The toggle button state is reset
* 3. The body class for open navigation is removed
*/
if ( astraAddon.header_animation_effect == 'fade' || astraAddon.header_animation_effect == 'slide' ){
document.querySelectorAll('#ast-hf-mobile-menu a[href^="#"]').forEach(link => {
link.addEventListener('click', function (e) {
const mobileMenu = document.querySelector('.ast-main-header-bar-navigation.toggle-on');
const toggleButtons = document.querySelectorAll('.ast-mobile-menu-trigger-minimal');
setTimeout(() => {
if (mobileMenu) {
mobileMenu.style.display = "none";
mobileMenu.classList.remove("toggle-on");
}
toggleButtons.forEach((btn) => {
btn.classList.remove("toggled");
btn.setAttribute("aria-expanded", "false");
});
document.body.classList.remove("ast-main-header-nav-open");
}, 50);
});
});
}
}(jQuery, window));
const accordionContainer = document.querySelector(".ast-woocommerce-accordion");
if( accordionContainer ) {
const accordionHeadings = accordionContainer.querySelectorAll(".ast-accordion-header");
const accordionContents = accordionContainer.querySelectorAll(".ast-accordion-content");
const activeClass = 'active';
let singleAccordionContent;
accordionHeadings.forEach( function ( heading, headingIndex ) {
//get content related to heading
singleAccordionContent = heading.nextElementSibling;
//get original height of each content when in opened state
let accordionContentHeight = singleAccordionContent.clientHeight;
// Close all content except first by default
if ( headingIndex == 0 ) {
singleAccordionContent.style.height = accordionContentHeight + "px";
} else {
singleAccordionContent.style.height = 0;
}
// Close and open accordion when clicked.
heading.addEventListener( "click", function ( event ) {
// Removes class active for all accordion content.
accordionContents.forEach(function ( dropdown, dropdownIndex ) {
if ( headingIndex !== dropdownIndex ) {
dropdown.style.height = 0;
dropdown.classList.remove( activeClass );
}
} );
// Removes class active for all accordion headings.
accordionHeadings.forEach(function ( single, singleIndex ) {
if ( headingIndex !== singleIndex ) {
single.classList.remove( activeClass );
}
} );
// current accordion content.
const currentAccordionContent = event.target.nextElementSibling;
// Sets new height when accordion opened.
accordionContentHeight = currentAccordionContent.querySelector( '.ast-accordion-wrap' ).clientHeight;
if (currentAccordionContent.classList.contains( activeClass ) ) {
currentAccordionContent.classList.remove( activeClass );
event.target.classList.remove( activeClass );
currentAccordionContent.style.height = 0;
} else {
currentAccordionContent.classList.add( activeClass );
event.target.classList.add( activeClass );
currentAccordionContent.style.height = accordionContentHeight + "px";
}
} );
} );
}
/**
* Handle "Leave a Comment" link to open reviews tab and scroll to comment form
*/
function handleCommentLinkClick() {
if ( window.location.hash === '#respond' || window.location.hash.includes( '#comment' ) ) {
const reviewsTabLink = document.querySelector( '.woocommerce-tabs ul.tabs li.reviews_tab a' ) || document.querySelector( 'a[href="#tab-reviews"]' );
if ( reviewsTabLink ) {
reviewsTabLink.click();
}
setTimeout( function() {
const commentForm = document.querySelector( '#respond' ) || document.querySelector( '#review_form' );
if ( commentForm ) {
commentForm.scrollIntoView( { behavior: 'smooth', block: 'center' } );
}
}, 300 );
}
}
/**
* Handle review link click to open accordion accordion when accordion layout is enabled
*/
function handleReviewLinkClick() {
const reviewLinks = document.querySelectorAll( 'a.woocommerce-review-link' );
reviewLinks.forEach( function( link ) {
link.addEventListener( 'click', function( event ) {
if ( accordionContainer && accordionContainer.classList.contains( 'ast-woocommerce-accordion' ) ) {
event.preventDefault();
const reviewsTabHeaders = accordionContainer.querySelectorAll( '.ast-single-tab .ast-accordion-header' );
let reviewsHeader = null;
reviewsTabHeaders.forEach( function( header ) {
const content = header.nextElementSibling;
if ( content && content.id === 'tab-reviews' ) {
reviewsHeader = header;
}
} );
if ( reviewsHeader ) {
reviewsHeader.click();
setTimeout( function() {
const reviewsSection = accordionContainer.querySelector( '#tab-reviews' );
if ( reviewsSection ) {
reviewsSection.scrollIntoView( { behavior: 'smooth', block: 'center' } );
}
}, 300 );
}
}
} );
} );
}
document.addEventListener( 'DOMContentLoaded', handleCommentLinkClick );
window.addEventListener( 'hashchange', handleCommentLinkClick );
document.addEventListener( 'DOMContentLoaded', handleReviewLinkClick );
var tns=function(){var t=window,bi=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.msRequestAnimationFrame||function(t){return setTimeout(t,16)},e=window,wi=e.cancelAnimationFrame||e.mozCancelAnimationFrame||function(t){clearTimeout(t)};function Ci(t){for(var e,n,i,o=t||{},a=1,r=arguments.length;a
";return t.innerHTML=o,i.appendChild(t),e.appendChild(i),t=Math.abs(i.getBoundingClientRect().left-t.children[67].getBoundingClientRect().left)<2,e.fake?Ni(e,n):i.remove(),t}(),t),E=e.tMQ?Mi(e.tMQ):Ti(e,"tMQ",function(){if(window.matchMedia||window.msMatchMedia)return!0;var t=document,e=Ei(),n=Ai(e),i=t.createElement("div"),o=t.createElement("style"),a="@media all and (min-width:1px){.tns-mq-test{position:absolute}}";return o.type="text/css",i.className="tns-mq-test",e.appendChild(o),e.appendChild(i),o.styleSheet?o.styleSheet.cssText=a:o.appendChild(t.createTextNode(a)),a=(window.getComputedStyle?window.getComputedStyle(i):i.currentStyle).position,e.fake?Ni(e,n):i.remove(),"absolute"===a}(),t),a=e.tTf?Mi(e.tTf):Ti(e,"tTf",ji("transform"),t),r=e.t3D?Mi(e.t3D):Ti(e,"t3D",function(t){if(!t)return!1;if(!window.getComputedStyle)return!1;var e=document,n=Ei(),i=Ai(n),o=e.createElement("p"),e=9
=-ae)return t}:function(){return Dt&&H&&!qt?F-1:qt||H?Math.max(0,ie-Math.ceil(kt)):ie-1},de=Je(nn("startIndex")),fe=de,pe=(Ke(),0),ve=Lt?null:ce(),he=M.preventActionWhenRunning,me=M.swipeAngle,ye=!me||"?",ge=!1,xe=M.onInit,be=new Xi,we=" tns-slider tns-"+M.mode,Ce=P.id||(Y=window.tnsId,window.tnsId=Y?Y+1:1,"tns"+window.tnsId),Me=nn("disable"),Te=!1,Ee=M.freezable,Ae=!(!Ee||Lt)&&gn(),Ne=!1,Le={click:ti,keydown:function(t){t=li(t);var e=[i.LEFT,i.RIGHT].indexOf(t.keyCode);0<=e&&(0===e?Z.disabled||ti(t,-1):$.disabled||ti(t,1))}},Be={click:function(t){if(ge){if(he)return;Zn()}for(var e,n,i=si(t=li(t));i!==it&&!ki(i,"data-nav");)i=i.parentNode;ki(i,"data-nav")&&(e=ut=Number(Ri(i,"data-nav")),n=Bt||Lt?e*F/at:e*kt,$n(Pe?e:Math.min(Math.ceil(n),F-1),t),lt===e&&(vt&&ai(),ut=-1))},keydown:function(t){t=li(t);var e,n=T.activeElement;ki(n,"data-nav")&&(e=[i.LEFT,i.RIGHT,i.ENTER,i.SPACE].indexOf(t.keyCode),n=Number(Ri(n,"data-nav")),0<=e&&(0===e?0"," animation"]),(t||We)&&(Tt={},At=!(Et={}),Nt=k?function(t,e){return t.x-e.x}:function(t,e){return t.y-e.y}),Lt||Ye(Me||Ae),a&&(ue=a,le="translate",se=r?(le+=k?"3d(":"3d(0px, ",k?", 0px, 0px)":", 0px)"):(le+=k?"X(":"Y(",")")),H&&(P.className=P.className.replace("tns-vpfix","")),function(){if(en("gutter"),R.className="tns-outer",I.className="tns-inner",R.id=Ce+"-ow",I.id=Ce+"-iw",""===P.id&&(P.id=Ce),we+=g||Lt?" tns-subpixel":" tns-no-subpixel",we+=y?" tns-calc":" tns-no-calc",Lt&&(we+=" tns-autowidth"),we+=" tns-"+M.axis,P.className+=we,H?((O=T.createElement("div")).id=Ce+"-mw",O.className="tns-ovh",R.appendChild(O),O.appendChild(I)):R.appendChild(I),Ft&&((O||I).className+=" tns-ah"),z.insertBefore(R,P),I.appendChild(P),Si(q,function(t,e){Oi(t,"tns-item"),t.id||(t.id=Ce+"-item"+e),!H&&L&&Oi(t,L),Ii(t,{"aria-hidden":"true",tabindex:"-1"})}),ne){for(var t=T.createDocumentFragment(),e=T.createDocumentFragment(),n=ne;n--;){var i=n%F,o=q[i].cloneNode(!0);Oi(o,Fe),Pi(o,"id"),e.insertBefore(o,e.firstChild),H&&(i=q[F-1-i].cloneNode(!0),Oi(i,Fe),Pi(i,"id"),t.appendChild(i))}P.insertBefore(t,P.firstChild),P.appendChild(e),q=P.children}}(),function(){if(!H)for(var t=de,e=de+Math.min(F,kt);t .tns-item","font-size:"+m.getComputedStyle(q[0]).fontSize+";",Bi(Zt)),Li(Zt,"#"+Ce,"font-size:0;",Bi(Zt))):H&&Si(q,function(t,e){t.style.marginLeft=y?y+"("+100*e+"% / "+ie+")":100*e/ie+"%"})),E?(x&&(a=O&&M.autoHeight?sn(M.speed):"",Li(Zt,"#"+Ce+"-mw",a,Bi(Zt))),a=on(M.edgePadding,M.gutter,M.fixedWidth,M.speed,M.autoHeight),Li(Zt,"#"+Ce+"-iw",a,Bi(Zt)),H&&(a=k&&!Lt?"width:"+an(M.fixedWidth,M.gutter,M.items)+";":"",x&&(a+=sn(zt)),Li(Zt,"#"+Ce,a,Bi(Zt))),a=k&&!Lt?rn(M.fixedWidth,M.gutter,M.items):"",M.gutter&&(a+=un(M.gutter)),H||(x&&(a+=sn(zt)),b&&(a+=cn(zt)))):(H&&Ft&&(O.style[x]=zt/1e3+"s"),I.style.cssText=on(St,Ht,Bt,Ft),H&&k&&!Lt&&(P.style.width=an(Bt,Ht,kt)),a=k&&!Lt?rn(Bt,Ht,kt):"",Ht&&(a+=un(Ht))),a&&Li(Zt,"#"+Ce+" > .tns-item",a,Bi(Zt)),B&&E)for(var i in B){var i=parseInt(i),o=B[i],a="",r="",u="",l="",s="",c=Lt?null:nn("items",i),d=nn("fixedWidth",i),f=nn("speed",i),p=nn("edgePadding",i),v=nn("autoHeight",i),h=nn("gutter",i);x&&O&&nn("autoHeight",i)&&"speed"in o&&(r="#"+Ce+"-mw{"+sn(f)+"}"),("edgePadding"in o||"gutter"in o)&&(u="#"+Ce+"-iw{"+on(p,h,d,f,v)+"}"),H&&k&&!Lt&&("fixedWidth"in o||"items"in o||Bt&&"gutter"in o)&&(l="width:"+an(d,h,c)+";"),x&&"speed"in o&&(l+=sn(f)),l=l&&"#"+Ce+"{"+l+"}",("fixedWidth"in o||Bt&&"gutter"in o||!H&&"items"in o)&&(s+=rn(d,h,c)),"gutter"in o&&(s+=un(h)),!H&&"speed"in o&&(x&&(s+=sn(f)),b&&(s+=cn(f))),(a=r+u+l+(s=s&&"#"+Ce+" > .tns-item{"+s+"}"))&&Zt.insertRule("@media (min-width: "+i/16+"em) {"+a+"}",Zt.cssRules.length)}}(),dn();var Qe=qt?H?function(){var t=pe,e=ve;t+=Rt,e-=Rt,St?(t+=1,--e):Bt&&(Ot+Ht)%(Bt+Ht)&&--e,ne&&(e=parseInt(i)&&t in B[i]&&(n=B[i][t]);return"slideBy"===t&&"page"===n&&(n=nn("items")),n=!(H||"slideBy"!==t&&"items"!==t)?Math.floor(n):n}function on(t,e,n,i,o){var a,r="";return void 0!==t?(a=t,e&&(a-=e),r=k?"margin: 0 "+a+"px 0 "+t+"px;":"margin: "+t+"px 0 "+a+"px 0;"):e&&!n&&(e="-"+e+"px",r="margin: 0 "+(k?e+" 0 0":"0 "+e+" 0")+";"),!H&&o&&x&&i&&(r+=sn(i)),r}function an(t,e,n){return t?(t+e)*ie+"px":y?y+"("+100*ie+"% / "+n+")":100*ie/n+"%"}function rn(t,e,n){var i;return i="width:"+(i=t?t+e+"px":(H||(n=Math.floor(n)),i=H?ie:n,y?y+"(100% / "+i+")":100/i+"%")),"inner"!==S?i+";":i+" !important;"}function un(t){return!1!==t?(k?"padding-":"margin-")+(k?"right":"bottom")+": "+t+"px;":""}function ln(t,e){e=t.substring(0,t.length-e).toLowerCase();return e=e&&"-"+e+"-"}function sn(t){return ln(x,18)+"transition-duration:"+t/1e3+"s;"}function cn(t){return ln(b,17)+"animation-duration:"+t/1e3+"s;"}function dn(){var t;en("autoHeight")||Lt||!k?(Si(t=P.querySelectorAll("img"),function(t){var e=t.src;$t||(e&&e.indexOf("data:image")<0?(t.src="",Gi(t,Ve),Oi(t,"loading"),t.src=e):Ln(t))}),bi(function(){On(zi(t),function(){Q=!0})}),en("autoHeight")&&(t=Sn(de,Math.min(de+kt-1,ie-1))),$t?fn():bi(function(){On(zi(t),fn)})):(H&&Yn(),vn(),hn())}function fn(){var i;Lt&&1slide '+En()+" of "+F+" "),X=R.querySelector(".tns-liveregion .current"),ze&&(e=Yt?"stop":"start",xt?Ii(xt,{"data-action":e}):M.autoplayButtonOutput&&(R.insertAdjacentHTML($e(M.autoplayPosition),'