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AAYN,GAG1BA,EAAKQ,QAtBL,CAuBD,EACD,EA5EA,CAAsDC,GCMtD,aAqBC,WAAmB/F,G,MAPT,KAAAkG,QAA+B,CAAC,EAQzCjG,KAAKD,SAAWA,EAOhB,IAAMiB,EAAuD,QAA/B,EAAAP,OAAOyF,gCAAwB,QAAI,CAChEC,SAAU,GACVC,cAAe,GACfC,cAAe,GACfC,gBAAiB,GAIlBrG,EAAuBK,KAAK,CAG3BU,sBAAuBA,IAGxB,IAAMuF,EAAqC,CAC1CzE,uBAAwB7B,EAAuBG,YAGhDJ,KAAKiG,QAAQ,qBAAuB,IAAIO,EAAkCD,GAC1EvG,KAAKiG,QAAQ,oBAAsB,IAAIQ,EAAiCF,EACzE,CA2BD,OApBe,EAAAnG,SAAd,WAGC,IAAIsG,EAAyBxG,UAC5B,MAAM,IAAIG,MAAM,6KAEjB,OAAOqG,EAAyBxG,SACjC,EAQc,EAAAI,KAAd,SAAmBP,GAGlB,OAAO,IAAI2G,EAAyB3G,EACrC,EACD,EA5EA,GLHgBF,EAWb6G,EAAyBpG,KAXFR,EAWQ6G,kCAVN,WAAvBhF,SAASiF,WAGZ/G,EAASC,GAKT6B,SAASkF,iBAAiB,oBAAoB,WAAM,OAAAhH,EAASC,EAAT,G","sources":["webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/classes/cart-fragments/class.cart-fragments-handler.ts","webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/index.ts","webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/classes/widgets/base/class.widget.ts","webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/classes/widgets/base/class.advanced-dropdown-widget.ts","webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/classes/widgets/class.dropdown-currency-selector-widget.ts","webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/classes/widgets/class.dropdown-country-selector-widget.ts","webpack://aelia_currency_switcher_frontend_scripts_bundle/./src/classes/scripts-manager/class.frontend-scripts-manager.ts"],"sourcesContent":["import { ICart_Fragments_Handler_Settings } from './interface.cart-fragments-handler-settings';\n\n/**\n * Implements the scripts to handle WooCommerce's cart fragments.\n *\n * @since 4.12.1.210629\n */\nexport class Cart_Fragments_Handler { // NOSONAR\n\t/**\n\t * The argument that can be used to set a currency via the URL.\n\t *\n\t * @var string\n\t */\n\tprotected static ARG_CURRENCY: string = 'aelia_cs_currency';\n\n\t/**\n\t * The singleton instance of this class.\n\t *\n\t * @var Cart_Fragments_Handler\n\t */\n\tprotected static _instance: Cart_Fragments_Handler;\n\n\t /**\n\t\t* The settings passed to the class.\n\t\t*\n\t\t* @var ICart_Fragments_Handler_Settings\n\t\t*/\n\tprotected settings: ICart_Fragments_Handler_Settings;\n\n\t/**\n\t * Constructor.\n\t *\n\t * @param settings ICart_Fragments_Handler_Settings\n\t */\n\tpublic constructor(settings: ICart_Fragments_Handler_Settings) {\n\t\tthis.settings = settings;\n\t\tCart_Fragments_Handler._instance = this;\n\n\t\tthis.maybe_invalidate_minicart_cache();\n\t}\n\n\t/**\n\t * Returns the instance of this class.\n\t *\n\t * @returns Edit_Product\n\t */\n\tpublic static instance(): Cart_Fragments_Handler {\n\t\t// If the class has not been instantiated, throw an exception. The handler must be\n\t\t// initialised first, as it needs a couple of settings to get ready.\n\t\tif(!Cart_Fragments_Handler._instance) {\n\t\t\tthrow new Error('Class \"Cart_Fragments_Handler\" has not been instantiated. Please call `Cart_Fragments_Handler.init()` before calling `Cart_Fragments_Handler.instance()`.');\n\t\t}\n\t\treturn Cart_Fragments_Handler._instance;\n\t}\n\n\t/**\n\t * Initialises the class and its event handlers.\n\t *\n\t * @param settings ICart_Fragments_Handler_Settings\n\t * @return Cart_Fragments_Handler\n\t */\n\tpublic static init(settings: ICart_Fragments_Handler_Settings): Cart_Fragments_Handler {\n\t\t// Initialise the Edit_Product handler. We can't call Edit_Product.instance here,\n\t\t// as the handler must be initialised with the settings first\n\t\treturn new Cart_Fragments_Handler(settings);\n\t}\n\n\t/**\n\t * Removes an item from the browsers' session storage.\n\t *\n\t * @param item_key\n\t */\n\tpublic remove_session_storage_item(item_key: string): void {\n\t\ttry {\n\t\t\t// Invalidate cache of WooCommerce minicart when the currency is selected via\n\t\t\t// the URL. This will ensure that the minicart is updated correctly\n\t\t\tconst supports_html5_storage = ((window['sessionStorage'] ?? null) !== null);\n\t\t\tif(supports_html5_storage) {\n\t\t\t\t// The fragment name might be generated dynamically by WooCommerce, so\n\t\t\t\t// we have to retrieve it from the WC parameters\n\t\t\t\t// @since WC 3.1\n\t\t\t\tsessionStorage.removeItem(item_key);\n\t\t\t}\n\t\t}\n\t\tcatch(error) {\n\t\t\tconst error_msg = 'Aelia - Exception occurred while accessing window.sessionStorage. ' +\n\t\t\t\t\t\t\t\t\t\t\t\t'This could be caused by the browser disabling cookies. ' +\n\t\t\t\t\t\t\t\t\t\t\t\t'COOKIES MUST BE ENABLED for the site to work correctly. ' +\n\t\t\t\t\t\t\t\t\t\t\t\t'Exception details below.';\n\t\t\tconsole.error(error_msg);\n\t\t\tconsole.error(error);\n\t\t}\n\t}\n\n\t/**\n\t * Purges the cart fragments from the browser's storage session.\n\t */\n\tpublic purge_cart_fragments(): void {\n\t\tconst cart_fragments_name: string = (this.settings.cart_fragments_params['fragment_name'] ?? '').trim();\n\t\tif(cart_fragments_name) {\n\t\t\tthis.remove_session_storage_item(cart_fragments_name);\n\t\t}\n\t}\n\n\t/**\n\t * Invalidates the minicart cache when the currency has been selected via the URL.\n\t */\n\tprotected maybe_invalidate_minicart_cache(): void {\n\t\tconst current_url: URL = new URL(window.location.href);\n\t\tconst is_currency_set_by_url: boolean = ((current_url.searchParams.get(Cart_Fragments_Handler.ARG_CURRENCY) ?? '').length > 0);\n\n\t\t// If the currency is set via the URL, and there are cart fragments stored in the session,\n\t\t// remove them so that they can be fetched using the active currency\n\t\tif(is_currency_set_by_url) {\n\t\t\tthis.purge_cart_fragments();\n\t\t}\n\t}\n}","import { IWC_Cart_Fragments_Params } from \"./classes/cart-fragments/interface.cart-fragments-handler-settings\";\nimport { Frontend_Scripts_Manager } from \"./classes/scripts-manager/class.frontend-scripts-manager\";\nimport { IAelia_CS_Frontend_Params } from \"./classes/scripts-manager/interface.aelia-currency-switcher-params\";\n\n// Add a reference to the global parameters\ndeclare global {\n\tvar wc_aelia_currency_switcher_params: IAelia_CS_Frontend_Params;\n\tvar wc_cart_fragments_params: IWC_Cart_Fragments_Params;\n}\n\n(function ready(callback, args) {\n if(document.readyState != 'loading'){\n\t\t// If this function is called after the document has finished loading,\n\t\t// invoke the callback immediately\n\t\tcallback(args);\n\t}\n\telse {\n\t\t// If the document is still loading, trigger the callback on the\n\t\t// \"DOM loaded\" event\n\t\tdocument.addEventListener('DOMContentLoaded', () => callback(args));\n }\n})(Frontend_Scripts_Manager.init, wc_aelia_currency_switcher_params);\n","import { IWidget_Settings } from \"../interface.widget-settings\";\n\n/**\n * A base class for the widgets provided by the Aelia Currency Switcher.\n *\n * @since 4.12.1.210629\n */\nexport abstract class Widget { // NOSONAR\n\t/**\n\t\t* The settings passed to the class.\n\t\t*\n\t\t* @var IWidget_Settings\n\t\t*/\n\tprotected settings: IWidget_Settings;\n\n\t/**\n\t * Constructor.\n\t *\n\t * @param settings IWidget_Settings\n\t */\n\tpublic constructor(settings: IWidget_Settings) {\n\t\tthis.settings = settings;\n\n\t\t// Initialise the event handlers used by the widget\n\t\tthis.init_event_handlers();\n\t}\n\n\t/**\n\t * Initialise the event handlers used by the widget.\n\t */\n\tprotected init_event_handlers(): void {\n\t\t// Purge the cart fragments when the country or the currency selection form is submitted\n\t\t// @since 4.12.4.210805\n\t\tjQuery(document).on('submit', '.currency_switch_form, .country_switch_form', (event: Event): void => {\n\t\t\tthis.purge_cart_fragments();\n\t\t});\n\n\t\t// Purge the cart fragments when the country or the currency change event is fired\n\t\t// @since 4.12.4.210805\n\t\tjQuery(document).on('aelia_currency_selected aelia_country_selected', (event: Event): void => {\n\t\t\tthis.purge_cart_fragments();\n\t\t});\n\t}\n\n\t/**\n\t * Purges the cart fragments. Convenience method.\n\t */\n\tprotected purge_cart_fragments(): void {\n\t\tthis.settings.cart_fragments_handler.purge_cart_fragments();\n\t}\n}","import { Widget } from \"./class.widget\";\n\n/**\n * Implements the features for the advanced dropdown currency selector widget, which\n * is rendered with HTML elements instead of a basic field.\n *\n * @since 4.12.1.210629\n */\nexport class Dropdown_Currency_Selector_Widget extends Advanced_Dropdown_Widget { // NOSONAR\n\t/**\n\t * The argument passed with POST requests to select a currency.\n\t */\n\tprotected ARG_CURRENCY = 'aelia_cs_currency';\n\n\t/**\n\t * Returns a jQuery element matching all the selector widgets handled by this class.\n\t *\n\t * @returns JQuery\n\t */\n\tprotected get_all_dropdowns(): JQuery {\n\t\treturn jQuery('.wc_aelia_cs_currency_selector.active').find('.dropdown');\n\t}\n\n\t/**\n\t * Initialise the event handlers used by the widget.\n\t */\n\tprotected init_event_handlers(): void {\n\t\tsuper.init_event_handlers();\n\n\t\t// Advanced dropdown selector widget (custom HTML, flags)\n\t\t// Activate the currency selector dropdown when the selector is clicked\n\t\tjQuery(document).on('click', '.wc_aelia_cs_currency_selector .selected_currency', (event: Event): void => { // NOSONAR\n\t\t\tthis.toggle_dropdown(event, jQuery(event.currentTarget).parents('.wc_aelia_cs_currency_selector').first());\n\t\t});\n\n\t\t// Intercepts the currency selection and reloads the page with the new currency\n\t\tjQuery(document).on('click', '.wc_aelia_cs_currency_selector .currency', (event: Event): void => { // NOSONAR\n\t\t\tthis.submit_selection(jQuery(event.currentTarget).data('value'));\n\t\t});\n\n\t\t// Basic dropdown selector widget\n\t\t// Monitor the \"on change\" at the document level, to intercept the currency selection\n\t\t// in widgets created on the fly (e.g. by page builders)\n\t\t// @since 4.7.11.190924\n\t\tjQuery(document).on('change', '.widget_wc_aelia_currencyswitcher_widget .aelia_cs_currencies', (event: Event): void => { // NOSONAR\n\t\t\tevent.stopPropagation();\n\t\t\tthis.submit_selection(jQuery(event.currentTarget).val().toString());\n\t\t});\n\t}\n\n\t/**\n\t * Intercepts the currency selection and performs a POST request to update the page.\n\t *\n\t * @param selected_value\n\t * @returns void\n\t */\n\tprotected submit_selection(selected_value: string): void {\n\t\tif(!selected_value) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger an event to indicate that a currency has been selected. This will purge the\n\t\t// cart fragments before submitting the selection, and ensure that the cart fragments\n\t\t// are fetched \"fresh\", using the new currency\n\t\tjQuery(document).trigger('aelia_currency_selected');\n\n\t\t// Create an element to contain the currency\n\t\tconst currency_field: HTMLInputElement = document.createElement('input');\n\t\tcurrency_field.type = 'hidden';\n\t\tcurrency_field.name = this.ARG_CURRENCY;\n\t\tcurrency_field.value = selected_value;\n\n\t\t// Create a hidden
element that will be used to send the POST request\n\t\tconst form: HTMLFormElement = document.createElement('form');\n\t\tform.classList.add('currency_switch_form');\n\t\tform.method = 'post';\n\t\tform.style.display = 'none !important';\n\t\tform.appendChild(currency_field);\n\t\tdocument.body.appendChild(form);\n\n\t\t// Submit the form\n\t\tform.submit();\n\t}\n}","import { Advanced_Dropdown_Widget } from \"./base/class.advanced-dropdown-widget\";\n\n/**\n * Implements the features for the basic dropdown country selector widget.\n *\n * @since 4.12.1.210629\n */\nexport class Dropdown_Country_Selector_Widget extends Advanced_Dropdown_Widget { // NOSONAR\n\t/**\n\t * The argument passed with POST requests to select a country.\n\t */\n\tprotected ARG_CUSTOMER_COUNTRY: string = 'aelia_customer_country';\n\n\t/**\n\t * Returns a jQuery element matching all the selector widgets handled by this class.\n\t *\n\t * @returns JQuery\n\t */\n\tprotected get_all_dropdowns(): JQuery {\n\t\treturn jQuery('.wc_aelia_cs_country_selector.active').find('.dropdown');\n\t}\n\n\t/**\n\t * Initialise the event handlers used by the widget.\n\t */\n\tprotected init_event_handlers(): void {\n\t\tsuper.init_event_handlers();\n\n\t\t// @since 4.12.2.210706\n\t\t// Advanced dropdown selector widget (custom HTML, flags)\n\t\t// Activate the country selector dropdown when the selector is clicked\n\t\tjQuery(document).on('click', '.wc_aelia_cs_country_selector .selected_country', (event: Event): void => { // NOSONAR\n\t\t\tthis.toggle_dropdown(event, jQuery(event.currentTarget).parents('.wc_aelia_cs_country_selector').first());\n\t\t});\n\n\t\t// Intercepts the country selection and reloads the page with the new country\n\t\tjQuery(document).on('click', '.wc_aelia_cs_country_selector .country', (event: Event): void => { // NOSONAR\n\t\t\tthis.submit_selection(jQuery(event.currentTarget).data('value'));\n\t\t});\n\n\t\t// Basic dropdown selector widget\n\t\t// Monitor the \"on change\" at the document level, to intercept the country selection\n\t\t// in widgets created on the fly (e.g. by page builders)\n\t\t// @since 4.7.11.190924\n\t\tjQuery(document).on('change', '.currency_switcher.widget_wc_aelia_country_selector_widget .countries', (event: Event): void => { // NOSONAR\n\t\t\tevent.stopPropagation();\n\t\t\tthis.submit_selection(jQuery(event.currentTarget).val().toString());\n\t\t});\n\t}\n\n\t/**\n\t * Intercepts the country selection and performs a POST request to update the page.\n\t *\n\t * @param selected_value\n\t * @returns void\n\t */\n\tprotected submit_selection(selected_value: string): void {\n\t\tif(!selected_value) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Trigger an event to indicate that a country has been selected. This will purge the\n\t\t// cart fragments before submitting the selection, and ensure that the cart fragments\n\t\t// are fetched \"fresh\", using the new country\n\t\tjQuery(document).trigger('aelia_currency_selected');\n\n\t\t// Create an element to contain the country\n\t\tconst country_field: HTMLInputElement = document.createElement('input');\n\t\tcountry_field.type = 'hidden';\n\t\tcountry_field.name = this.ARG_CUSTOMER_COUNTRY;\n\t\tcountry_field.value = selected_value;\n\n\t\t// Create a hidden element that will be used to send the POST request\n\t\tconst form: HTMLFormElement = document.createElement('form');\n\t\tform.classList.add('country_switch_form');\n\t\tform.method = 'post';\n\t\tform.style.display = 'none !important';\n\t\tform.appendChild(country_field);\n\t\tdocument.body.appendChild(form);\n\n\t\t// Submit the form\n\t\tform.submit();\n\t}\n}","import { Cart_Fragments_Handler } from '../cart-fragments/class.cart-fragments-handler';\nimport { Widget } from '../widgets/base/class.widget';\nimport { IDictionary } from '../../../../../common/interface.dictionary';\nimport { IAelia_CS_Frontend_Params } from './interface.aelia-currency-switcher-params';\nimport { Dropdown_Currency_Selector_Widget } from '../widgets/class.dropdown-currency-selector-widget';\nimport { IWidget_Settings } from '../widgets/interface.widget-settings';\nimport { Dropdown_Country_Selector_Widget } from '../widgets/class.dropdown-country-selector-widget';\n\n/**\n * Implements the scripts to handle WooCommerce's cart fragments.\n *\n * @since 4.12.1.210629\n */\nexport class Frontend_Scripts_Manager { // NOSONAR\n\t/**\n\t * The singleton instance of this class.\n\t */\n\tprotected static _instance: Frontend_Scripts_Manager;\n\n\t /**\n\t\t* The settings passed to the class.\n\t\t*/\n\tprotected settings: IAelia_CS_Frontend_Params;\n\n\t/**\n\t * A list of the widgets loaded on the frontend.\n\t */\n\tprotected widgets: IDictionary = {};\n\n\t/**\n\t * Constructor.\n\t *\n\t * @param settings IAelia_CS_Frontend_Params\n\t */\n\tpublic constructor(settings: IAelia_CS_Frontend_Params) {\n\t\tthis.settings = settings;\n\n\t\t// If the cart fragments variable is missing, use a default object,\n\t\t// with empty values. This condition can occur if some optimisation\n\t\t// plugin strips the cart fragment scripts from the frontend.\n\t\t// The scripts should NOT be removed, but some tools do it anyway\n\t\t// @since 4.12.4.210805\n\t\tconst cart_fragments_params = window.wc_cart_fragments_params ?? {\n\t\t\tajax_url: '',\n\t\t\tcart_hash_key: '',\n\t\t\tfragment_name: '',\n\t\t\trequest_timeout: 0,\n\t\t}\n\n\t\t// Initialise the Cart Fragments Handler\n\t\tCart_Fragments_Handler.init({\n\t\t\t// Variable wc_cart_fragments_params is global, generated by WooCommerce\n\t\t\t// @see IWC_Cart_Fragments_Params\n\t\t\tcart_fragments_params: cart_fragments_params,\n\t\t});\n\n\t\tconst widgets_settings: IWidget_Settings = {\n\t\t\tcart_fragments_handler: Cart_Fragments_Handler.instance(),\n\t\t}\n\n\t\tthis.widgets['currency-selector'] = new Dropdown_Currency_Selector_Widget(widgets_settings);\n\t\tthis.widgets['country-selector'] = new Dropdown_Country_Selector_Widget(widgets_settings);\n\t}\n\n\t/**\n\t * Returns the instance of this class.\n\t *\n\t * @returns Edit_Product\n\t */\n\tpublic static instance(): Frontend_Scripts_Manager {\n\t\t// If the class has not been instantiated, throw an exception. The handler must be\n\t\t// initialised first, as it needs a couple of settings to get ready.\n\t\tif(!Frontend_Scripts_Manager._instance) {\n\t\t\tthrow new Error('Class \"Frontend_Scripts_Manager\" has not been instantiated. Please call `Frontend_Scripts_Manager.init()` before calling `Frontend_Scripts_Manager.instance()`.');\n\t\t}\n\t\treturn Frontend_Scripts_Manager._instance;\n\t}\n\n\t/**\n\t * Initialises the class and its event handlers.\n\t *\n\t * @param settings IAelia_CS_Frontend_Params\n\t * @return Frontend_Scripts_Manager\n\t */\n\tpublic static init(settings: IAelia_CS_Frontend_Params): Frontend_Scripts_Manager {\n\t\t// Initialise the Edit_Product handler. We can't call Edit_Product.instance here,\n\t\t// as the handler must be initialised with the settings first\n\t\treturn new Frontend_Scripts_Manager(settings);\n\t}\n}"],"names":["callback","args","settings","this","Cart_Fragments_Handler","_instance","maybe_invalidate_minicart_cache","instance","Error","init","remove_session_storage_item","item_key","window","sessionStorage","removeItem","error","console","purge_cart_fragments","cart_fragments_name","cart_fragments_params","trim","URL","location","href","searchParams","get","ARG_CURRENCY","length","init_event_handlers","jQuery","document","on","event","cart_fragments_handler","target","closest","close_all_dropdowns","which","$selected_option","currentTarget","parents","first","find","submit_selection","data","$dropdown","search_value","val","toString","filter_options_by_search_value","toggle_dropdown","$widget","is","removeClass","slideUp","set_dropdown_position","slideDown","trigger","addClass","$dropdowns","get_all_dropdowns","each","index","element","reset_filtered_options","css","dropdown_data","getBoundingClientRect","innerHeight","y","height","_search_value","toLowerCase","$current_element","$search_data","log","search_match","idx","includes","toggleClass","Widget","stopPropagation","selected_value","currency_field","createElement","type","name","value","form","classList","add","method","style","display","appendChild","body","submit","Advanced_Dropdown_Widget","ARG_CUSTOMER_COUNTRY","country_field","widgets","wc_cart_fragments_params","ajax_url","cart_hash_key","fragment_name","request_timeout","widgets_settings","Dropdown_Currency_Selector_Widget","Dropdown_Country_Selector_Widget","Frontend_Scripts_Manager","wc_aelia_currency_switcher_params","readyState","addEventListener"],"sourceRoot":""}