{"version":3,"file":"../cart-shipping-220.min.js","sources":["cart-shipping-220.js"],"sourcesContent":["/**\n * Manage cart shipping ajax actions.\n *\n * DEPENDS ON:\n * - jQuery // Interact with WooCommerce events\n */\n (function (root, factory) {\n\tif ( typeof define === 'function' && define.amd ) {\n\t\tdefine([], factory(root));\n\t} else if ( typeof exports === 'object' ) {\n\t\tmodule.exports = factory(root);\n\t} else {\n\t\troot.CartShipping = factory(root);\n\t}\n})(typeof global !== 'undefined' ? global : this.window || this.global, function (root) {\n\n\t'use strict';\n\n\tvar $ = jQuery;\n\tvar _hasJQuery = ( $ != null );\n\n\tvar _hasInitialized = false;\n\tvar _publicMethods = {};\n\tvar _settings = {\n\t\tbodyClass: 'has-fc-cart-shipping',\n\n\t\tmessagesWrapperSelector: '.woocommerce-notices-wrapper',\n\n\t\tformSubmitFieldsSelector: 'input:not( [type=\"button\"] ):not( [type=\"submit\"] ):not( [type=\"reset\"] ):not( [type=\"file\"] ):not( [type=\"image\"] )',\n\n\t\tshippingMethodsSectionSelector: '.fc-shipping-method__packages',\n\t\tshippingMethodsSelector: 'select.shipping_method, input[name^=\"shipping_method\"]',\n\t\tshippingMethodsChosenSelector: 'select.shipping_method, input[name^=\"shipping_method\"][type=\"radio\"]:checked, input[name^=\"shipping_method\"][type=\"hidden\"]',\n\t\tshippingMethodIndexAttribute: 'data-index',\n\n\t\tshippingCalcFormSelector: '.shipping-calculator-form',\n\t\tshippingCalcUpdateButtonSelector: '[name=\"calc_shipping\"]',\n\t\tshippingCalcDataFieldsSelector: 'input, select, textarea',\n\n\t\tcollapsibleBlockElementSelector: '[data-collapsible]',\n\n\t\tupdateShippingMethodsNonce: '', // Value updated during runtime\n\t\tupdateShippingAddressNonce: '', // Value updated during runtime\n\t};\n\n\n\n\t/**\n\t * METHODS\n\t */\n\n\n\n\t/**\n\t * Add notices at the top of the page, then scroll to display it on the screen.\n\t *\n\t * @param HTML content HTML content to be displayed.\n\t */\n\tvar showNotices = function( content ) {\n\t\tvar messagesWrapper = document.querySelector( _settings.messagesWrapperSelector );\n\t\tmessagesWrapper.innerHTML = content;\n\t\t\n\t\t// Maybe scroll notices into view\n\t\tif ( window.CartUpdate ) {\n\t\t\tCartUpdate.scrollToNotices();\n\t\t}\n\t}\n\n\n\n\t/**\n\t * Add notices in the coupon code section.\n\t *\n\t * @param HTML content HTML content to be displayed.\n\t */\n\tvar showShippingNotices = function( content ) {\n\t\tif ( window.CartUpdate ) {\n\t\t\tCartUpdate.showShippingNotices( content );\n\t\t}\n\t}\n\n\t/**\n\t * Remove all notices from the coupon code section.\n\t *\n\t * @param HTML content HTML content to be displayed.\n\t */\n\tvar clearShippingNotices = function() {\n\t\tif ( window.CartUpdate ) {\n\t\t\tCartUpdate.clearShippingNotices();\n\t\t}\n\t}\n\n\n\n\t/**\n\t * Block the element UI from user interaction.\n\t *\n\t * @param HTMLElement element Element to block the UI and show the loading indicator.\n\t *\n\t * @see CartUpdate.blockUI\n\t */\n\tvar blockUI = function( element ) {\n\t\t// Maybe block element UI\n\t\tif ( window.CartUpdate ) {\n\t\t\tCartUpdate.blockUI( element );\n\t\t}\n\t}\n\n\t/**\n\t * Unblock UI element to be used again.\n\t *\n\t * @param HTMLElement element Element to get the UI unblocked.\n\t *\n\t * @see CartUpdate.unblockUI\n\t */\n\tvar unblockUI = function( element ) {\n\t\t// Maybe unblock element UI\n\t\tif ( window.CartUpdate ) {\n\t\t\tCartUpdate.unblockUI( element );\n\t\t}\n\t}\n\n\n\n\t/**\n\t * Maybe reinitialize the collapsible blocks elements.\n\t */\n\tvar maybeReinitializeCollapsibleBlocks = function() {\n\t\tif ( window.CollapsibleBlock ) {\n\t\t\tvar collapsibleBlocks = document.querySelectorAll( _settings.collapsibleBlockElementSelector );\n\t\t\tfor ( var i = 0; i < collapsibleBlocks.length; i++ ) {\n\t\t\t\tvar collapsibleBlock = collapsibleBlocks[ i ];\n\t\t\t\t\n\t\t\t\t// Maybe initialize the collapsible block\n\t\t\t\tif ( ! CollapsibleBlock.getInstance( collapsibleBlock ) ) {\n\t\t\t\t\tCollapsibleBlock.initializeElement( collapsibleBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\n\n\t/**\n\t * Process update shipping calculator address and shipping costs.\n\t */\n\tvar processShippingCalculatorUpdate = function() {\n\t\tvar shippingForm = document.querySelector( _settings.shippingCalcFormSelector );\n\n\t\t// Bail if shipping form not found\n\t\tif ( ! shippingForm ) { return; }\n\t\t\n\t\t// Get cart item data\n\t\tvar data = {};\n\t\tvar fields = shippingForm.querySelectorAll( _settings.shippingCalcDataFieldsSelector );\n\t\tfor ( var i = 0; i < fields.length; i++ ) {\n\t\t\tvar field = fields[ i ];\n\t\t\tvar fieldName = field.name;\n\t\t\tvar fieldValue = field.value;\n\t\t\t\n\t\t\t// Skip field if it does not have a name attribute\n\t\t\tif ( ! fieldName ) { continue; }\n\n\t\t\t// Skip radio buttons not checked\n\t\t\tif ( 'radio' === field.type && ! field.checked ) { continue; }\n\n\t\t\t// Maybe set checkbox field value as empty\n\t\t\tif ( 'checkbox' === field.type && ! field.checked ) {\n\t\t\t\tfieldValue = '';\n\t\t\t}\n\n\t\t\tdata[ fieldName ] = fieldValue;\n\t\t}\n\n\t\t_publicMethods.updateShippingAddress( data );\n\t}\n\n\n\n\t/**\n\t * Handle document clicks and route to the appropriate function.\n\t */\n\tvar handleClick = function( e ) {\n\t\t// SHIPPING CALCULATOR SUBMIT\n\t\tif ( e.target.closest( _settings.shippingCalcUpdateButtonSelector ) ) {\n\t\t\te.preventDefault();\n\t\t\tprocessShippingCalculatorUpdate( e.target.closest( _settings.shippingCalcUpdateButtonSelector ) );\n\t\t}\n\t};\n\n\t/**\n\t * Handle form field change event and route to the appropriate function.\n\t */\n\tvar handleChange = function( e ) {\n\t\t\n\t\t// SHIPPING METHOD\n\t\tif ( e.target.matches( _settings.shippingMethodsSelector ) ) {\n\t\t\t_publicMethods.setShippingMethodChosen();\n\t\t}\n\n\t};\n\n\t/**\n\t * Handle keypress event.\n\t */\n\tvar handleKeyDown = function( e ) {\n\t\t// Should do nothing if the default action has been cancelled\n\t\tif ( e.defaultPrevented ) { return; }\n\n\t\t// ENTER on input fields\n\t\tif ( FCUtils.keyboardKeys.ENTER === e.key && e.target.closest( _settings.cartItemSelector ) && e.target.matches( _settings.formSubmitFieldsSelector ) ) {\n\t\t\t// Prevents submitting form\n\t\t\te.preventDefault();\n\t\t}\n\t};\n\n\n\n\t/**\n\t * Update the shipping address information and trigger fragments refresh.\n\t *\n\t * @param object data The shipping address data to be updated.\n\t */\n\t_publicMethods.updateShippingAddress = function( data ) {\n\t\t// Block the shipping section element from further changes\n\t\tvar shippingMethods = document.querySelector( _settings.shippingMethodsSectionSelector );\n\t\tblockUI( shippingMethods );\n\n\t\t// Clear shipping notices\n\t\tclearShippingNotices();\n\n\t\t// Add security\n\t\tdata = FCUtils.extendObject( data, {\n\t\t\tsecurity: _settings.updateShippingAddressNonce,\n\t\t} );\n\n\t\t$.ajax({\n\t\t\ttype:\t\t'POST',\n\t\t\turl:\t\tfcSettings.wcAjaxUrl.toString().replace( '%%endpoint%%', 'fc_pro_update_shipping_address' ),\n\t\t\tdata:\t\tdata,\n\t\t\tdataType: 'json',\n\t\t\tsuccess:\tfunction( response ) {\n\n\t\t\t\tif ( response.result && 'success' === response.result ) {\n\t\t\t\t\t$( document.body ).trigger( 'wc_fragment_refresh' );\n\t\t\t\t}\n\t\t\t\telse if ( response.result && 'error' === response.result ) {\n\t\t\t\t\t// Unblock shipping section element\n\t\t\t\t\tvar shippingMethods = document.querySelector( _settings.shippingMethodsSectionSelector );\n\t\t\t\t\tunblockUI( shippingMethods );\n\n\t\t\t\t\t// Maybe show shipping notices\n\t\t\t\t\tif ( response.message ) {\n\t\t\t\t\t\tshowShippingNotices( response.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t});\n\t};\n\n\n\n\t/**\n\t * Set the chosen shipping method to the cart.\n\t */\n\t_publicMethods.setShippingMethodChosen = function() {\n\t\t// Block the element from further changes\n\t\tvar shippingMethodsSection = document.querySelector( _settings.shippingMethodsSectionSelector );\n\t\tblockUI( shippingMethodsSection );\n\n\t\t// Get chosen shipping methods\n\t\tvar chosenShippingMethods = document.querySelectorAll( _settings.shippingMethodsChosenSelector );\n\t\tvar shippingMethods = {};\n\t\tfor ( var i = 0; i < chosenShippingMethods.length; i++ ) {\n\t\t\tvar shippingMethod = chosenShippingMethods[ i ];\n\t\t\tvar index = shippingMethod.getAttribute( _settings.shippingMethodIndexAttribute );\n\t\t\tshippingMethods[ index ] = shippingMethod.value;\n\t\t}\n\n\t\tvar data = {\n\t\t\tsecurity: _settings.updateShippingMethodsNonce,\n\t\t\tshipping_methods: shippingMethods,\n\t\t};\n\n\t\t$.ajax({\n\t\t\ttype:\t\t'POST',\n\t\t\turl:\t\tfcSettings.wcAjaxUrl.toString().replace( '%%endpoint%%', 'fc_pro_update_shipping_methods' ),\n\t\t\tdata:\t\tdata,\n\t\t\tdataType: 'json',\n\t\t\tsuccess:\tfunction( response ) {\n\n\t\t\t\tif ( response.result && 'success' === response.result ) {\n\t\t\t\t\t$( document.body ).trigger( 'updated_shipping_method' );\n\t\t\t\t\t$( document.body ).trigger( 'wc_fragment_refresh' );\n\t\t\t\t}\n\t\t\t\telse if ( response.result && 'error' === response.result ) {\n\t\t\t\t\t// Unblock the element\n\t\t\t\t\tvar shippingMethodsSection = document.querySelector( _settings.shippingMethodsSectionSelector );\n\t\t\t\t\tunblockUI( shippingMethodsSection );\n\n\t\t\t\t\tshowNotices( response.message );\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t});\n\t};\n\n\n\n\t/**\n\t * Initialize component and set related handlers.\n\t */\n\t_publicMethods.init = function( options ) {\n\t\tif ( _hasInitialized ) return;\n\n\t\t// Merge settings\n\t\t_settings = FCUtils.extendObject( _settings, options );\n\n\t\t// Add event listeners\n\t\tdocument.addEventListener( 'click', handleClick, true );\n\t\tdocument.addEventListener( 'keydown', handleKeyDown, true );\n\t\tdocument.addEventListener( 'change', handleChange, true );\n\n\t\tif ( _hasJQuery ) {\n\t\t\t// After cart fragments has been updated\n\t\t\t$( document.body ).on( 'wc_fragments_refreshed', maybeReinitializeCollapsibleBlocks );\n\t\t}\n\n\t\t// Add init class\n\t\tdocument.body.classList.add( _settings.bodyClass );\n\n\t\t_hasInitialized = true;\n\t};\n\n\n\n\t//\n\t// Public APIs\n\t//\n\treturn _publicMethods;\n\n});\n"],"names":["root","factory","define","amd","exports","module","CartShipping","global","this","window","blockUI","element","CartUpdate","unblockUI","maybeReinitializeCollapsibleBlocks","CollapsibleBlock","collapsibleBlocks","document","querySelectorAll","_settings","collapsibleBlockElementSelector","i","length","collapsibleBlock","getInstance","initializeElement","handleClick","e","target","closest","shippingCalcUpdateButtonSelector","preventDefault","shippingForm","querySelector","shippingCalcFormSelector","data","fields","shippingCalcDataFieldsSelector","field","fieldName","name","fieldValue","value","type","checked","_publicMethods","updateShippingAddress","handleChange","matches","shippingMethodsSelector","setShippingMethodChosen","handleKeyDown","defaultPrevented","FCUtils","keyboardKeys","ENTER","key","cartItemSelector","formSubmitFieldsSelector","$","jQuery","_hasJQuery","_hasInitialized","bodyClass","messagesWrapperSelector","shippingMethodsSectionSelector","shippingMethodsChosenSelector","shippingMethodIndexAttribute","updateShippingMethodsNonce","updateShippingAddressNonce","shippingMethods","clearShippingNotices","extendObject","security","ajax","url","fcSettings","wcAjaxUrl","toString","replace","dataType","success","response","content","result","body","trigger","message","showShippingNotices","shippingMethodsSection","chosenShippingMethods","shippingMethod","getAttribute","shipping_methods","innerHTML","scrollToNotices","init","options","addEventListener","on","classList","add"],"mappings":"AAMC,CAAA,SAAWA,EAAMC,GACM,YAAlB,OAAOC,QAAyBA,OAAOC,IAC3CD,OAAO,GAAID,EAAY,CAAC,EACM,UAAnB,OAAOG,QAClBC,OAAOD,QAAUH,EAAY,EAE7BD,EAAKM,aAAeL,EAAY,CAEjC,EAAoB,aAAlB,OAAOM,OAAyBA,OAASC,KA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