"use strict"; // Set document ready promise HTMLDocument.prototype.ready = function () { return new Promise(function (resolve, reject) { if (document.readyState === 'complete') { resolve(document); } else { document.addEventListener('DOMContentLoaded', function () { resolve(document); }); } }); }; var pyccaStore = {}; pyccaStore.generalModel = { cartInfo: null, userDevice: '', breadCrumb: [], productPreview: {} } pyccaStore.generalController = (function () { return { init: init /* currencyFormat: currencyFormat, calculateTax: calculateTax, setDecimals: setDecimals, removeNumberParenthesis: removeNumberParenthesis, getCartInfo: getCartInfo */ } function init() { // _identifyDevice(); //_identifyDeviceResize(); //_changeNewsletterWords(); // getCartInfo(); // pyccaStore.productAddedView.init(); // pyccaStore.searchView.init(); // pyccaStore.desktopMenutView.init(); pyccaStore.mobileMenuView.init(); pyccaStore.headerView.init(); // pyccaStore.footerView.init(); // pyccaStore.setMobileMiniCart.init(); // window.addEventListener('resize', _identifyDevice); } }()); pyccaStore.mobileMenuView = (function () { return { init: init, visible: false, selector: document.querySelector('.pyccaMenuMobile'), backSelector: document.querySelector('.backMenuMobile'), showHide: showHide } function init() { _setHeight(); _setCloseButton(); _setAcordeonMenu(); } function _setHeight() { var menuMobileBox = pyccaStore.mobileMenuView.selector, background = pyccaStore.mobileMenuView.backSelector; _heightMenu(); window.addEventListener("resize", _heightMenu); function _heightMenu() { menuMobileBox.style.height = window.innerHeight + 'px'; background.style.height = window.innerHeight + 'px'; } } function _setCloseButton(e) { var close = document.querySelector('.pyccaMenuMobile__close'), back = pyccaStore.mobileMenuView.backSelector; close.addEventListener('click', showHide); back.addEventListener('click', showHide); } function _setAcordeonMenu() { var elementsFirstLevel = Array.prototype.slice.call(document.querySelectorAll('.pyccaMenuMobile__menuList__item span')); elementsFirstLevel.forEach(function (element, index) { return (function (node) { var sibling = node.nextSibling, visible = false; node.addEventListener('click', function () { if (visible === false) { $(sibling).slideDown(); visible = true; } else { $(sibling).slideUp(); visible = false; } }); }(element)); }); } function showHide() { var self = pyccaStore.mobileMenuView, box = self.selector, back = self.backSelector; if (pyccaStore.mobileMenuView.visible === false) { box.setAttribute('class', 'pyccaMenuMobile pyccaMenuMobile--open'); $(back).fadeIn(); pyccaStore.mobileMenuView.visible = true; } else { box.setAttribute('class', 'pyccaMenuMobile'); $(back).fadeOut(); pyccaStore.mobileMenuView.visible = false; } } }()); pyccaStore.headerView = (function () { return { init: init } function init() { _setMobileMenuBottom(); } function _setMobileMenuBottom() { var menuBoton = document.querySelector('.headerSite__btnMenuMobile'); menuBoton.addEventListener('click', pyccaStore.mobileMenuView.showHide); } }()); document.ready().then(function () { pyccaStore.generalController.init(); });