{"version":3,"sources":["webpack:///./cartridges/app_aob_core/cartridge/js/pages/product/productQuantity.js"],"names":["quantitySelector","eventHandlersAttached","initCache","$quantityInput","$","quantityInput","quantityIncrease","quantityDecrease","minValue","maxValue","length","data","Math","min","parseInt","increaseQuantity","element","val","trigger","decreaseQuantity","checkInputValue","$cache","this","$quantityDecrease","parent","find","$quantityIncrease","match","addClass","removeClass","initEvents","_that","document","on","InputMask","placeholder","mask","get","init"],"mappings":"8GAAA,gCAMIA,EAAmB,CACnBC,uBAAuB,EAMvBC,UAAW,WACP,IAAMC,EAAiBC,EAAE,2CAYzB,MAVa,CACTC,cAAeF,EACfG,iBAAkBF,EAAE,yBACpBG,iBAAkBH,EAAE,yBACpBI,SAAU,EACVC,SAAWN,EAAeO,QAAUP,EAAeQ,KAAK,aAClDC,KAAKC,IAAI,IAAKC,SAASX,EAAeQ,KAAK,aAAc,KACzD,IAUdI,iBAAkB,SAASC,GACvBA,EAAQC,IAAIH,SAASE,EAAQC,MAAO,IAAM,GAC1Cb,EAAEY,GAASE,QAAQ,6BAOvBC,iBAAkB,SAASH,GACvBA,EAAQC,IAAIH,SAASE,EAAQC,MAAO,IAAM,GAC1Cb,EAAEY,GAASE,QAAQ,6BAOvBE,gBAAiB,SAASJ,EAASR,EAAUC,GACzC,IAAIY,EAAoBC,KAAKpB,YACzBqB,EAAoBP,EAAQQ,SAASC,KAAK,yBAC1CC,EAAoBV,EAAQQ,SAASC,KAAK,yBAE1CX,SAASE,EAAQC,MAAO,KAAOI,EAAOb,WAAaQ,EAAQC,QAAUD,EAAQC,MAAMU,MAAM,UACzFX,EAAQC,IAAII,EAAOb,UACnBe,EAAkBK,SAAS,kCAE3BL,EAAkBM,YAAY,iCAG9Bf,SAASE,EAAQC,MAAO,KAAOI,EAAOZ,UACtCO,EAAQC,IAAII,EAAOZ,UACnBiB,EAAkBE,SAAS,kCAE3BF,EAAkBG,YAAY,kCAStCC,WAAY,WACR,IAAIT,EAASC,KAAKpB,YACd6B,EAAQT,KAEZA,KAAKF,gBAAgBC,EAAOhB,cAAegB,EAAOb,SAAUa,EAAOZ,UAE9Da,KAAKrB,wBACNG,EAAE4B,UAAUC,GAAG,QAAS,yBAAyB,WAC7C,IAAI9B,EAAiBC,EAAEkB,MAAME,SAASC,KAAK,sBAE3CM,EAAMhB,iBAAiBZ,GACvB4B,EAAMX,gBAAgBjB,EAAgBkB,EAAOb,SAAUa,EAAOZ,aAGlEL,EAAE4B,UAAUC,GAAG,QAAS,yBAAyB,WAC7C,IAAI9B,EAAiBC,EAAEkB,MAAME,SAASC,KAAK,sBAE3CM,EAAMZ,iBAAiBhB,GACvB4B,EAAMX,gBAAgBjB,EAAgBkB,EAAOb,SAAUa,EAAOZ,aAGlEL,EAAE4B,UAAUC,GAAG,SAAU,sBAAsB,WAC3C,IAAI9B,EAAiBC,EAAEkB,MAAME,SAASC,KAAK,sBAE3CM,EAAMX,gBAAgBjB,EAAgBkB,EAAOb,SAAUa,EAAOZ,aAGlEa,KAAKrB,uBAAwB,GAG7BoB,EAAOhB,cAAcK,QACrBwB,IAAU,MAAO,CAAEC,YAAa,KAAMC,KAAKf,EAAOhB,cAAcgC,IAAI,KAI5EC,KAAM,WACFhB,KAAKQ,eAIE9B","file":"js/product-quantity-chunk.js","sourcesContent":["'use strict';\r\nimport InputMask from 'inputmask';\r\n\r\n/**\r\n* @description Handles quantity selector on PDP pages\r\n*/\r\nvar quantitySelector = {\r\n eventHandlersAttached: false,\r\n\r\n /**\r\n * @function\r\n * @description - caches dom elements used as vars and returns an object\r\n */\r\n initCache: function() {\r\n const $quantityInput = $('.product-add-to-cart .js_quantity_input');\r\n\r\n var $cache = {\r\n quantityInput: $quantityInput,\r\n quantityIncrease: $('.js_quantity_increase'),\r\n quantityDecrease: $('.js_quantity_decrease'),\r\n minValue: 1,\r\n maxValue: ($quantityInput.length && $quantityInput.data('available'))\r\n ? Math.min(999, parseInt($quantityInput.data('available'), 10))\r\n : 5\r\n };\r\n\r\n return $cache;\r\n },\r\n\r\n /**\r\n * @function\r\n * @description - Increases quantity with 1\r\n */\r\n increaseQuantity: function(element) {\r\n element.val(parseInt(element.val(), 10) + 1);\r\n $(element).trigger('productQuantityIncreased');\r\n },\r\n\r\n /**\r\n * @function\r\n * @description - Decreases quantity with 1\r\n */\r\n decreaseQuantity: function(element) {\r\n element.val(parseInt(element.val(), 10) - 1);\r\n $(element).trigger('productQuantityDecreased');\r\n },\r\n\r\n /**\r\n * @function\r\n * @description - Checks input value in order to handle the max and min values allowed and to handle - and + controls state (enable/disable)\r\n */\r\n checkInputValue: function(element, minValue, maxValue) {\r\n var $cache = this.initCache();\r\n var $quantityDecrease = element.parent().find('.js_quantity_decrease');\r\n var $quantityIncrease = element.parent().find('.js_quantity_increase');\r\n\r\n if (parseInt(element.val(), 10) <= $cache.minValue || !element.val() || !element.val().match(/^\\d+$/)) {\r\n element.val($cache.minValue);\r\n $quantityDecrease.addClass('c-product__quantity--disabled');\r\n } else {\r\n $quantityDecrease.removeClass('c-product__quantity--disabled');\r\n }\r\n\r\n if (parseInt(element.val(), 10) >= $cache.maxValue) {\r\n element.val($cache.maxValue);\r\n $quantityIncrease.addClass('c-product__quantity--disabled');\r\n } else {\r\n $quantityIncrease.removeClass('c-product__quantity--disabled');\r\n }\r\n },\r\n\r\n /**\r\n * @function\r\n * @description - Handles events for the quantity selector\r\n */\r\n\r\n initEvents: function() {\r\n var $cache = this.initCache(),\r\n _that = this;\r\n\r\n this.checkInputValue($cache.quantityInput, $cache.minValue, $cache.maxValue);\r\n\r\n if (!this.eventHandlersAttached) {\r\n $(document).on('click', '.js_quantity_increase', function() {\r\n var $quantityInput = $(this).parent().find('.js_quantity_input');\r\n\r\n _that.increaseQuantity($quantityInput);\r\n _that.checkInputValue($quantityInput, $cache.minValue, $cache.maxValue);\r\n });\r\n\r\n $(document).on('click', '.js_quantity_decrease', function() {\r\n var $quantityInput = $(this).parent().find('.js_quantity_input');\r\n\r\n _that.decreaseQuantity($quantityInput);\r\n _that.checkInputValue($quantityInput, $cache.minValue, $cache.maxValue);\r\n });\r\n\r\n $(document).on('change', '.js_quantity_input', function() {\r\n var $quantityInput = $(this).parent().find('.js_quantity_input');\r\n\r\n _that.checkInputValue($quantityInput, $cache.minValue, $cache.maxValue);\r\n });\r\n\r\n this.eventHandlersAttached = true;\r\n }\r\n\r\n if ($cache.quantityInput.length) {\r\n InputMask('999', { placeholder: '' }).mask($cache.quantityInput.get(0));\r\n }\r\n },\r\n\r\n init: function() {\r\n this.initEvents();\r\n }\r\n};\r\n\r\nexport default quantitySelector;\r\n"],"sourceRoot":""}