"use strict"; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var botiga = botiga || {}; /** * Is the DOM ready? * * This implementation is coming from https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/ * * @param {Function} fn Callback function to run. */ botiga.helpers = { botigaDomReady: function botigaDomReady(fn) { if (typeof fn !== 'function') { return; } if (document.readyState === 'interactive' || document.readyState === 'complete') { return fn(); } document.addEventListener('DOMContentLoaded', fn, false); }, isInVerticalViewport: function isInVerticalViewport(el) { var rect = el.getBoundingClientRect(); return rect.top >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight); }, isInHorizontalViewport: function isInHorizontalViewport(el) { var rect = el.getBoundingClientRect(); return rect.left >= 0 && rect.right <= document.documentElement.clientWidth; }, ajax: function ajax(action, nonce, extraParams, successCallback) { var ajax = new XMLHttpRequest(); ajax.open('POST', botiga.ajaxurl, true); ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajax.onload = function () { if (this.status >= 200 && this.status < 400) { successCallback.apply(this); } }; var extraParamsStr = ''; extraParams = Object.entries(extraParams); for (var i = 0; i < extraParams.length; i++) { extraParamsStr += '&' + extraParams[i].join('='); } ajax.send('action=' + action + '&nonce=' + nonce + extraParamsStr); }, setCookie: function setCookie(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; }, getCookie: function getCookie(cname) { var name = cname + "=", ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } }; /** * Handles toggling the navigation menu for small screens and enables TAB key * navigation support for dropdown menus. */ botiga.navigation = { init: function init() { var self = this, siteNavigation = document.getElementById('site-navigation') == null ? document.getElementById('site-navigation-mobile') : document.getElementById('site-navigation'), offCanvas = document.getElementsByClassName('botiga-offcanvas-menu')[0], button = document.getElementsByClassName('menu-toggle')[0]; if (siteNavigation === null) { return; } // Return early if the navigation don't exist. if (!siteNavigation && typeof button === 'undefined') { return; } if (typeof offCanvas === 'undefined') { return; } var closeButton = document.getElementsByClassName('mobile-menu-close')[0]; // Return early if the button don't exist. if ('undefined' === typeof button) { return; } var menu = siteNavigation.getElementsByTagName('ul')[0]; var mobileMenuClose = siteNavigation.getElementsByClassName('mobile-menu-close')[0]; // Hide menu toggle button if menu is empty and return early. if ('undefined' === typeof menu) { button.style.display = 'none'; return; } if (!menu.classList.contains('nav-menu')) { menu.classList.add('nav-menu'); } var focusableEls = offCanvas.querySelectorAll('a[href]:not([disabled]):not(.mobile-menu-close)'); var firstFocusableEl = focusableEls[0]; button.addEventListener('click', function (e) { e.preventDefault(); button.classList.add('open'); offCanvas.classList.add('toggled'); document.body.classList.add('mobile-menu-visible'); // Toggle submenus var submenuToggles = offCanvas.querySelectorAll('.dropdown-symbol, .menu-item-has-children > a[href="#"]'); var _iterator = _createForOfIteratorHelper(submenuToggles), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var submenuToggle = _step.value; submenuToggle.addEventListener('touchstart', submenuToggleHandler); submenuToggle.addEventListener('click', submenuToggleHandler); submenuToggle.addEventListener('keydown', function (e) { var isTabPressed = e.key === 'Enter' || e.keyCode === 13; if (!isTabPressed) { return; } e.preventDefault(); var parent = submenuToggle.parentNode.parentNode; parent.getElementsByClassName('sub-menu')[0].classList.toggle('toggled'); }); } //Trap focus inside modal } catch (err) { _iterator.e(err); } finally { _iterator.f(); } firstFocusableEl.focus(); }); function submenuToggleHandler(e) { if (e.cancelable) { e.preventDefault(); } var parent = e.target.closest('li'); if (parent.querySelector('.sub-menu').classList.contains('toggling')) { return false; } parent.querySelector('.sub-menu').classList.toggle('toggling'); parent.querySelector('.sub-menu').classList.toggle('toggled'); setTimeout(function () { parent.querySelector('.sub-menu').classList.remove('toggling'); }, 300); } // Close the offcanvas when a anchor that contains a hash is clicked var anchors = offCanvas.querySelectorAll('a[href*="#"]'); if (anchors.length) { var _iterator2 = _createForOfIteratorHelper(anchors), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var anchor = _step2.value; anchor.addEventListener('click', function (e) { if (e.target.hash && document.querySelector(e.target.hash) !== null && !e.target.classList.contains('botiga-tabs-nav-link')) { button.classList.remove('open'); offCanvas.classList.remove('toggled'); document.body.classList.remove('mobile-menu-visible'); } }); } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } } var focusableEls = offCanvas.querySelectorAll('a[href]:not([disabled])'); var firstFocusableEl = focusableEls[0]; var lastFocusableEl = focusableEls[focusableEls.length - 1]; var KEYCODE_TAB = 9; lastFocusableEl.addEventListener('keydown', function (e) { var isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB; if (!isTabPressed) { return; } if (e.shiftKey) /* shift + tab */{} else /* tab */{ firstFocusableEl.focus(); } }); closeButton.addEventListener('click', function (e) { e.preventDefault(); var buttonRect = button.getBoundingClientRect(); if (buttonRect.top + buttonRect.height > 0) { button.focus(); } button.classList.remove('open'); offCanvas.classList.remove('toggled'); document.body.classList.remove('mobile-menu-visible'); }); document.addEventListener('click', function (e) { if (e.target.closest('.botiga-offcanvas-menu') === null && !e.target.classList.contains('menu-toggle') && e.target.closest('.menu-toggle') === null) { button.classList.remove('open'); offCanvas.classList.remove('toggled'); document.body.classList.remove('mobile-menu-visible'); } }); // Get all the link elements within the menu. var links = menu.getElementsByTagName('a'); // Get all the link elements with children within the menu. var linksWithChildren = menu.querySelectorAll('.menu-item-has-children > a, .page_item_has_children > a'); // Toggle focus each time a menu link is focused or blurred. var _iterator3 = _createForOfIteratorHelper(links), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var link = _step3.value; link.addEventListener('focus', toggleFocus, true); link.addEventListener('blur', toggleFocus, true); } // Toggle focus each time a menu link with children receive a touch event. } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } var _iterator4 = _createForOfIteratorHelper(linksWithChildren), _step4; try { for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { var _link = _step4.value; _link.addEventListener('touchstart', toggleFocus, false); } /** * Sets or removes .focus class on an element. */ } catch (err) { _iterator4.e(err); } finally { _iterator4.f(); } function toggleFocus() { if (event.type === 'focus' || event.type === 'blur') { var _self2 = this; // Move up through the ancestors of the current link until we hit .nav-menu. while (!_self2.classList.contains('nav-menu')) { // On li elements toggle the class .focus. if ('li' === _self2.tagName.toLowerCase()) { _self2.classList.toggle('focus'); } _self2 = _self2.parentNode; } } if (event.type === 'touchstart') { var menuItem = this.parentNode; event.preventDefault(); var _iterator5 = _createForOfIteratorHelper(menuItem.parentNode.children), _step5; try { for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) { var link = _step5.value; if (menuItem !== link) { link.classList.remove('focus'); } } } catch (err) { _iterator5.e(err); } finally { _iterator5.f(); } menuItem.classList.toggle('focus'); } } // Mobile accordion style navigation this.mobileAccordionNavigation(); // Hover with delay effect this.initHoverClass(); // Menu reverse this.checkMenuReverse(); }, /** * Initialize hover class for dropdown items. */ initHoverClass: function initHoverClass() { var self = this; if (typeof botiga.settings !== 'undefined' && 'no' === botiga.settings.misc.dropdowns_hover_delay) { return false; } // Add hover class to dropdown items. // Run it only once and after the first user interaction on the page. var initialized = false; var events = [{ name: 'scroll', selector: window }, { name: 'mouseenter', selector: document }, { name: 'mouseover', selector: document }, { name: 'touchstart', selector: document }]; for (var _i = 0, _events = events; _i < _events.length; _i++) { var _event = _events[_i]; _event.selector.addEventListener(_event.name, function () { if (initialized) { return false; } initialized = true; self.addHoverClassToDropdownItems(); }); } }, /** * Add hover class to dropdown items. */ addHoverClassToDropdownItems: function addHoverClassToDropdownItems() { var dropdownLis = document.querySelectorAll('.botiga-dropdown-li'); var _iterator6 = _createForOfIteratorHelper(dropdownLis), _step6; try { var _loop = function _loop() { var li = _step6.value; var mouseOutTimeout, mouseOverTimeout, delayTime = 300; var parent = li; li.addEventListener('mouseover', function (e) { var self = this; clearTimeout(mouseOutTimeout); mouseOverTimeout = setTimeout(function () { self.classList.add('hovered'); }, delayTime); }); var subDropdownLis = li.querySelectorAll('.botiga-dropdown-ul > .botiga-dropdown-li'); var _iterator7 = _createForOfIteratorHelper(subDropdownLis), _step7; try { for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) { var subLi = _step7.value; subLi.addEventListener('mouseover', function (e) { clearTimeout(mouseOutTimeout); setTimeout(function () { parent.classList.add('hovered'); }, delayTime); }); } } catch (err) { _iterator7.e(err); } finally { _iterator7.f(); } li.addEventListener('mouseout', function (e) { var self = this; clearTimeout(mouseOverTimeout); if (parent.contains(e.relatedTarget)) { return false; } mouseOutTimeout = setTimeout(function () { self.classList.remove('hovered'); }, delayTime); }); }; for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { _loop(); } } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } }, /* * Mobile navigation (accordion style navigation) */ mobileAccordionNavigation: function mobileAccordionNavigation() { var navs = document.querySelectorAll('.botiga-dropdown-mobile-accordion'); if (!navs.length) { return false; } var _iterator8 = _createForOfIteratorHelper(navs), _step8; try { for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) { var nav = _step8.value; var nav_item = nav.querySelectorAll('.menu-item-has-children'); if (!nav_item.length) { return false; } var _iterator9 = _createForOfIteratorHelper(nav_item), _step9; try { for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) { var item = _step9.value; var dropdownToggler = item.querySelectorAll('.dropdown-symbol'); dropdownToggler[0].addEventListener('click', function (e) { e.stopPropagation(); var parent = this.parentNode; if (parent.classList.contains('expand')) { parent.classList.remove('expand'); } else { parent.classList.add('expand'); } }); } } catch (err) { _iterator9.e(err); } finally { _iterator9.f(); } } } catch (err) { _iterator8.e(err); } finally { _iterator8.f(); } }, /* * Check if sub-menu items are visible. If not, reverse the item position */ checkMenuReverse: function checkMenuReverse() { var items = document.querySelectorAll('.header-login-register, .top-bar-login-register, .botiga-dropdown .menu li'); var _iterator0 = _createForOfIteratorHelper(items), _step0; try { for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) { var element = _step0.value; element.removeEventListener('mouseover', this.menuReverseEventHandler); element.addEventListener('mouseover', this.menuReverseEventHandler, { passive: true }); element.removeEventListener('touchstart', this.menuReverseEventHandler); element.addEventListener('touchstart', this.menuReverseEventHandler, { passive: true }); } } catch (err) { _iterator0.e(err); } finally { _iterator0.f(); } }, menuReverseEventHandler: function menuReverseEventHandler() { var is_rtl = 'rtl' === document.querySelector('html').getAttribute('dir'); event.stopPropagation(); var submenu = event.currentTarget.querySelector('.header-login-register>nav, .top-bar-login-register>nav, .sub-menu'); if (submenu === null) { return false; } // Reverse horizontally submenu.classList.remove('sub-menu-reverse'); if (is_rtl) { submenu.classList.add('sub-menu-reverse'); } else { if (botiga.helpers.isInHorizontalViewport(submenu) == false && !submenu.closest('.menu-item').classList.contains('botiga-mega-menu')) { submenu.classList.add('sub-menu-reverse'); } else { submenu.classList.remove('sub-menu-reverse'); } } // Reverse vertically // Do not reverse vertically if the menu is in the header if (submenu.closest('.site-header') || submenu.closest('.bottom-header-row') || submenu.closest('.bhfb-header')) { return false; } submenu.classList.remove('sub-menu-reverse-vertically'); if (botiga.helpers.isInVerticalViewport(submenu) == false && !submenu.closest('.menu-item').classList.contains('botiga-mega-menu')) { submenu.classList.add('sub-menu-reverse-vertically'); } else { submenu.classList.remove('sub-menu-reverse-vertically'); } } }; // Auto select single available variation botiga.autoSelectVariations = { init: function init() { var _botiga$settings; if (!((_botiga$settings = botiga.settings) !== null && _botiga$settings !== void 0 && (_botiga$settings = _botiga$settings.misc) !== null && _botiga$settings !== void 0 && _botiga$settings.auto_select_variations)) { return; } // Use event delegation on document to catch dynamically loaded forms document.addEventListener('wc_variation_form', function (e) { var form = e.target; if (!form || !form.matches('.variations_form')) return; // Get variation data from the form's dataset var variationData = form.dataset.product_variations ? JSON.parse(form.dataset.product_variations) : []; // Filter for in-stock and purchasable variations var availableVariations = variationData.filter(function (variation) { return variation.is_in_stock && variation.is_purchasable; }); // Proceed only if exactly one variation is available if (availableVariations.length !== 1) return; var singleVariation = availableVariations[0]; var attributes = singleVariation.attributes; // Loop through each attribute and set the corresponding