{"version":3,"file":"js/chunks/modules.js","sources":["webpack:///./org_colony/cartridge/js/modules.js"],"sourcesContent":["const dialog = require('./dialog');\nconst minicart = require('./minicart');\nconst searchsuggest = require('./searchsuggest');\nconst util = require('./util');\nconst ajax = require('./ajax');\n\n/**\n * @function\n * @desc Initializes the textarea character limit functionality\n */\nfunction initCharacterLimit() {\n const controlKeys = ['8', '9', '13', '46', '45', '36', '35', '38', '37', '40', '39'];\n\n $('body').on('keydown', 'textarea[data-character-limit], input[data-character-limit]', (e) => {\n const text = $.trim($(e.currentTarget).val());\n const charsLimit = $(e.currentTarget).data('character-limit');\n const charsUsed = text.length;\n\n if ((charsUsed >= charsLimit) && (controlKeys.indexOf(e.which.toString()) < 0)) {\n e.preventDefault();\n }\n }).on('change keyup mouseup', 'textarea[data-character-limit], input[data-character-limit]', (e) => {\n const text = $(e.currentTarget).val();\n const charsLimit = $(e.currentTarget).data('character-limit');\n const charsUsed = text.length;\n\n let charsRemain = charsLimit - charsUsed;\n\n if (charsRemain < 0) {\n $(e.currentTarget).val(text.slice(0, charsRemain));\n charsRemain = 0;\n }\n $(e.currentTarget).parent().find('.char-count .char-remain-count').html(charsRemain);\n });\n\n // load js specific styles\n util.limitCharacters();\n}\n\n/**\n * @function\n * @desc Initializes the search suggestion functionality in the header\n */\nfunction initSearchSuggestions() {\n /**\n * initialize search suggestions, pending the value of the site preference(enhancedSearchSuggestions)\n * this will either init the legacy(false) or the beta versions(true) of the the search suggest feature.\n * */\n const $searchContainer = $('.top-banner .header-search');\n searchsuggest.init($searchContainer, Resources.SIMPLE_SEARCH);\n}\n\n/**\n * @function\n * @desc Initializes the secondary navigation functionality\n */\nfunction initSecondaryNavigation() {\n // add show/hide navigation elements\n $('.secondary-navigation .toggle').click((e) => {\n $(e.currentTarget).toggleClass('expanded').next('ul').toggle();\n });\n}\n\n/**\n * @function\n * @desc Initializes the generic toggle functionality\n */\nfunction initToggle() {\n // add generic toggle functionality\n $('.toggle').next('.toggle-content').hide();\n\n $('.toggle').on('click', (e) => {\n if (!$(e.currentTarget).parents('.disable-toggle').length) {\n $(e.currentTarget).toggleClass('expanded').next('.toggle-content').toggle();\n }\n });\n}\n\n/**\n * @function\n * @desc Initializes the generic check box functionality\n */\nfunction initCheckBoxes() {\n // ensure checkbox values reflect checked state\n $('body').on('click', '.checkbox label', (e) => {\n util.setCheckboxValues($(e.currentTarget));\n });\n}\n\n/**\n * @function\n * @desc Initializes the email signup functionality\n */\nfunction initEmailSignup() {\n // subscribe email box\n const $subscribeEmail = $('.subscribe-email');\n\n if ($subscribeEmail.length > 0) {\n $subscribeEmail.focus((e) => {\n const val = $(e.currentTarget).val();\n if (val.length > 0 && val !== Resources.SUBSCRIBE_EMAIL_DEFAULT) {\n return; // do not animate when contains non-default value\n }\n\n $(e.currentTarget).animate({color: '#999999'}, 500, 'linear', function animateCallback() {\n $(this).val('').css('color', '#333333');\n });\n }).blur((e) => {\n const val = $.trim($(e.currentTarget).val());\n if (val.length > 0) {\n return; // do not animate when contains value\n }\n $(e.currentTarget).val(Resources.SUBSCRIBE_EMAIL_DEFAULT).css('color', '#999999').animate({color: '#333333'}, 500, 'linear');\n });\n }\n}\n\n/**\n * @function loadCustomContentFiles\n * @desc handles custom content CSS and JS\n * @returns\n */\nfunction loadCustomContentFiles() {\n if ($('.content-asset').length) {\n util.clearDynamicCss();\n util.clearDynamicJs();\n\n $('.content-asset').each((index, element) => {\n if ($(element).data('csspath')) {\n util.loadedCssFiles.push(util.loadCssFile($(element).data('csspath')));\n }\n if ($(element).data('jspath')) {\n util.loadedJsFiles.push(util.loadJsFile($(element).data('jspath')));\n }\n });\n }\n}\n\n/**\n * @function\n * @desc Initializes the general Open Modal functionality\n */\nfunction initOpenModal() {\n $('body').on('click', '.openModal, .privacy-policy, .openIframe', (e) => {\n e.preventDefault();\n /// Checking for the page/asset link\n /// If it is not on the clicked item, check for a parent\n let iFrame = false;\n let width;\n let $cParent;\n let href;\n if ($(e.target).attr('href')) {\n href = $(e.target).attr('href');\n $cParent = $(e.target);\n } else {\n $cParent = $(e.target);\n while (href === 'undefined' || !href) {\n $cParent = $cParent.parent();\n href = $cParent.attr('href');\n }\n }\n iFrame = $('.openIframe').length > 0 ? 'true' : 'false';\n\n if (iFrame === 'true') {\n width = (navigator.userAgent.includes('Android') || navigator.userAgent.includes('iPhone')) ? '316' : '975';\n } else {\n width = $cParent.data('dlg-width') ? $cParent.data('dlg-width') : '800';\n }\n dialog.open({\n url: href,\n doClose: $('.pt_product-search-result').length === 0,\n options: {\n width,\n title: $cParent.data('dlg-title') ? $cParent.data('dlg-title') : $(e.currentTarget).attr('title'),\n dialogClass: $cParent.data('dlg-class'),\n open() {\n // Check if a vertical scroll has been set and\n // Fix the dialog scroll from starting at 1/2 way down\n if ($('#dialog-container').css('overflow-y') === 'scroll' || $('#dialog-container').css('overflow-y') === 'auto') {\n $('#dialog-container').scrollTop(0);\n }\n // load custom asset content\n loadCustomContentFiles();\n },\n },\n });\n });\n}\n\nfunction initSocialDialog() {\n $('body').on('click', '.share-dialog', (e) => {\n e.preventDefault();\n const content = $(e.currentTarget).attr('href');\n\n dialog.open({\n html: content,\n options: {\n title: $(e.currentTarget).data('title'),\n },\n });\n });\n}\n\n/**\n * @function\n * @desc Initializes the mini cart functionality\n */\nfunction initMiniCart() {\n // Minicart focus\n minicart.setFocus();\n}\n\n/**\n * @function\n * @desc Initializes the misc. header functionality\n */\nfunction initHeader() {\n $(document).on('click', () => {\n $('html, #wrapper').removeClass('menu-active');\n });\n\n // main menu toggle\n $('.menu-toggle').on('click', (e) => {\n e.stopPropagation();\n $('html, #wrapper').toggleClass('menu-active');\n });\n\n $('.account-menu-toggle.registered').on('click', (e) => {\n e.stopPropagation();\n e.preventDefault();\n $('html, #wrapper').toggleClass('menu-active');\n $('.mobile-account-navigation a.registered').click();\n });\n\n $('#navigation').on('click', (e) => {\n const mobileMenuViewport = util.getViewports('mobile-menu') - 1;\n const mobileMenuMediaQuery = matchMedia(`(max-width: ${mobileMenuViewport}px)`);\n\n if (mobileMenuMediaQuery.matches) {\n e.stopPropagation();\n }\n });\n}\n\n/**\n * @function\n * @desc Initializes the misc. footer functionality\n */\nfunction initFooter() {\n const emailSignupForm = $('#email-alert-signup');\n const emailInput = $('#email-alert-address');\n\n emailInput.on('focus', () => {\n emailSignupForm.next('.email-signup-msg').remove();\n });\n\n // Handles the submission of the email sign up in the footer\n emailSignupForm.submit((e) => {\n e.preventDefault();\n if (!emailSignupForm.valid()) {\n return false;\n }\n ajax.getJson({\n url: Urls.emailSignUpFooter,\n data: {\n email: emailInput.val(),\n },\n callback(data) {\n let msg; let\n msgClass;\n if (data && data.success) {\n emailInput.trigger('blur').val('');\n msg = Resources.EMAIL_SIGNUP_SUCCESS;\n msgClass = 'email-signup-msg';\n } else {\n msg = Resources.EMAIL_SIGNUP_ERROR;\n msgClass = 'email-signup-msg error';\n }\n // append/show result messaging\n let msgContainer = $('.email-signup-msg');\n if (msgContainer.length > 0) {\n msgContainer.prop('class', '').addClass(msgClass).html(msg);\n } else {\n msgContainer = $('').addClass(msgClass).html(msg);\n emailSignupForm.after(msgContainer);\n }\n },\n });\n return true;\n });\n}\n\nfunction initNavPosition(target) {\n const desktopQuery = util.mediaBreakpointUp('mobile-menu');\n\n // restrict mouse events to desktop; affects iOS navigation\n if (desktopQuery) {\n if (!$(target).children('.level-2').isOnScreen(1, 0.5)) {\n $(target).children('.level-2').addClass('edge');\n }\n }\n}\n\n/**\n * @function\n * @desc Initializes the navigation functionality\n */\nfunction initNavigation() {\n /**\n * @listener\n * @description Listens for the click event on the menu links to toggle the different levels on mobile\n */\n $('.menu-category a').on('click', (e) => {\n const mobileMenuViewport = util.getViewports('mobile-menu') - 1;\n const mobileMenuMediaQuery = matchMedia(`(max-width: ${mobileMenuViewport}px)`);\n let level;\n let nextLevel;\n let prevLevel;\n\n // Only trigger the menus if we are in the mobile menu viewport\n if (mobileMenuMediaQuery.matches) {\n // Trigger the sub menu if the chosen link has a sub menu\n if ($(e.currentTarget).hasClass('has-sub-menu')) {\n e.preventDefault();\n level = $(e.currentTarget).attr('data-level');\n nextLevel = Number(level) + 1;\n\n $('.menu-category a, .custom-navigation-item a, .sub-nav-content-asset, .mobile-menu-level-label').removeClass('show-menu-item');\n\n $(e.currentTarget).next().find(`[data-level=\"${nextLevel}\"]`).addClass('show-menu-item');\n $(e.currentTarget).next().find('.sub-nav-content-asset').addClass('show-menu-item');\n\n // customer service menu is only visible in level-1\n $('.mobile-menu-utility-user').hide();\n $('.level-1 > li:last-child > a::after').show();\n\n // scroll to top\n window.scrollTo(0, 0);\n\n // Open the previous menu if the back link is clicked\n } else if ($(e.currentTarget).hasClass('back-link')) {\n e.preventDefault();\n level = $(e.currentTarget).attr('data-level');\n prevLevel = Number(level) - 1;\n\n $('.menu-category a, .custom-navigation-item a, .sub-nav-content-asset, .mobile-menu-level-label').removeClass('show-menu-item');\n\n if (prevLevel > 1) {\n $(e.currentTarget).parents(`[data-container-level=\"${prevLevel}\"]`).find(`[data-level=\"${prevLevel}\"]`).addClass('show-menu-item');\n } else {\n $(`[data-container-level=\"${prevLevel}\"]`).find(`[data-level=\"${prevLevel}\"]`).addClass('show-menu-item');\n $('#navigation > .mobile-menu-level-label').addClass('show-menu-item');\n }\n\n if (prevLevel === 1) {\n $('.mobile-menu-utility-user').show();\n $('.level-1 > li:last-child > a::after').hide();\n }\n }\n }\n });\n\n // Mobile Account Menu for Registered Credit holders\n $('.mobile-account-navigation a.registered, .mobile-account-menu .back').on('click', (e) => {\n const mobileMenuViewport = util.getViewports('mobile-menu') - 1;\n const mobileMenuMediaQuery = matchMedia(`(max-width: ${mobileMenuViewport}px)`);\n\n // Only trigger the menus if we are in the mobile menu viewport\n if (mobileMenuMediaQuery.matches) {\n // Trigger the sub menu\n e.preventDefault();\n $('.mobile-account-navigation a').removeClass('show-menu-item');\n\n // hide category navigation\n $('.mobile-cap + .mobile-menu-level-label').removeClass('show-menu-item');\n $('.menu-category').hide();\n // hide customer service links\n $('.mobile-menu-utility-user').hide();\n\n // show account menu\n $('.mobile-account-menu.level-2').show();\n\n // Open the previous menu if the back link is clicked\n if ($(e.currentTarget).hasClass('back')) {\n e.preventDefault();\n\n // put back category navigation\n $('.mobile-cap + .mobile-menu-level-label').addClass('show-menu-item');\n $('.menu-category').show();\n // show other customer service links\n $('.mobile-menu-utility-user').show();\n\n // hide account menu\n $('.mobile-account-menu.level-2').hide();\n }\n\n // scroll to top\n window.scrollTo(0, 0);\n }\n });\n\n $('.account-nav-desktop-bottom .account-nav-toggle').on('click', (e) => {\n e.stopPropagation();\n $('.account-menu-toggle').click();\n });\n\n const navTimeout = window.SitePreferences.NAV_TIMEOUT;\n const navInterval = window.SitePreferences.NAV_INTERVAL;\n\n function navHover() {\n $(this).addClass('navActive');\n initNavPosition(this);\n }\n\n function navLeave() {\n $(this).removeClass('navActive');\n }\n\n $('#navigation').hoverIntent({\n over: navHover,\n out: navLeave,\n timeout: navTimeout,\n interval: navInterval,\n selector: '.level-1 li',\n });\n\n $('.menu-utility-user').hoverIntent({\n over: navHover,\n out: navLeave,\n timeout: navTimeout,\n interval: navInterval,\n selector: 'li',\n });\n\n util.smartResize(() => {\n $('.level-2').removeClass('edge');\n });\n}\n\n/**\n * @function\n * @desc Initializes the quantity module events and DOM changes\n */\nfunction initQuantity() {\n /**\n * @listener\n * @desc Listens for the click and keyup events on the quantity decrease button\n */\n $('body').on('click keyup', '.quantity-decrease', (e) => {\n if (e.type === 'click' || (e.type === 'keyup' && e.which === 13)) {\n const $this = $(e.currentTarget);\n const qtyInput = $this.parents('.quantity-module').find('input');\n const qtyInputValue = Number(qtyInput.val());\n\n if ((qtyInputValue > 1)\n || ($this.parents('.product-set-list').length && qtyInputValue >= 0)\n || ($this.parents('.pnc').length && qtyInputValue > 0)) {\n qtyInput.val(qtyInputValue - 1);\n qtyInput.trigger('change');\n }\n }\n });\n\n /**\n * @listener\n * @desc Listens for the click and keyup events on the quantity increase button\n */\n $('body').on('click keyup', '.quantity-increase', (e) => {\n if (e.type === 'click' || (e.type === 'keyup' && e.which === 13)) {\n const qtyInput = $(e.currentTarget).parents('.quantity-module').find('input');\n const qtyInputValue = Number(qtyInput.val());\n const maxQtyValue = Number(qtyInput.attr('max'));\n const pnc = $('.pnc');\n\n // Do nothing if the quantity input is in the disabled state\n if (qtyInput.hasClass('disabled')) {\n e.preventDefault();\n return;\n }\n\n // Only increase the value if the current value is less than the max value\n if (qtyInputValue < maxQtyValue) {\n qtyInput.val(qtyInputValue + 1);\n qtyInput.trigger('change');\n } else if (pnc.length > 0 && qtyInput.hasClass('pnc-qty')) {\n const selectedQty = parseInt($('.pnc-remain-count').text(), 10);\n const totalQty = parseInt($('.pnc ').data('packcount'), 10);\n // Show errors when Pick 'n Choose max quantity limit reached\n if (selectedQty === totalQty) {\n const url = util.appendParamsToUrl(Urls.pageShow, {cid: 'picknchoose-max-error', format: 'ajax'});\n if (window.pageContext.ns === 'product') {\n dialog.create({\n target: $('#PickNChooseDialog'),\n options: {\n width: '700',\n },\n });\n dialog.open({\n url,\n options: {\n title: Resources.PRODUCT_ALERT,\n buttons: [{\n text: Resources.OK,\n class: 'button primary',\n click() {\n $(this).dialog('close');\n },\n }],\n },\n });\n } else if (pnc.find('.pnc-error').length === 0) {\n $('