{"version":3,"file":"default/js/storeLocator.js","mappings":";;;;;;;;;;AAAa;;AAEb;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,UAAU,QAAQ;AAClB,YAAY,OAAO;AACnB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,UAAU,OAAO;AACjB,UAAU,QAAQ;AAClB,UAAU,QAAQ;AAClB;AACA;AACA;AACA,+CAA+C,KAAK,IAAI,uCAAuC,GAAG,KAAK;;AAEvG;AACA;AACA;;AAEA;AACA;AACA;AACA,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB,cAAc,OAAO;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA,cAAc,QAAQ;AACtB,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;;;;;;;;;;ACxEa;;AAEb;AACA,wBAAwB,mBAAO,CAAC,+GAA0B;;AAE1D;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB,aAAa,QAAQ;AACrB;AACA;AACA;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA,UAAU,QAAQ;AAClB,UAAU,QAAQ;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA,aAAa;AACb;AACA,SAAS;;AAET;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,MAAM;AACN;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,aAAa;AACxB,aAAa,SAAS;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA,mDAAmD,oCAAoC;AACvF;;AAEA;AACA;AACA;AACA,mDAAmD,oCAAoC;AACvF;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,qCAAqC;;AAErC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,kEAAkE,oCAAoC;AACtG;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA,gBAAgB;AAChB;AACA;AACA;;AAEA;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,4DAA4D,oCAAoC;AAChG,SAAS;AACT,KAAK;;AAEL;AACA;AACA,cAAc,SAAS;AACvB;AACA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;;;;;AChOa;;AAEb;AACA;AACA,UAAU,QAAQ;AAClB,UAAU,QAAQ;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA,SAAS;;AAET;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;;;;;ACrDa;;AAEb;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;UCZA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;;;;ACtBa;;AAEb,qBAAqB,mBAAO,CAAC,uFAAW;;AAExC;AACA,mBAAmB,mBAAO,CAAC,4HAAgC;AAC3D,mBAAmB,mBAAO,CAAC,sHAA6B;AACxD,CAAC","sources":["webpack://sfra-startup-kit/./cartridges/app_ahumada/cartridge/client/default/js/storeLocator/statesAndCities.js","webpack://sfra-startup-kit/./cartridges/app_ahumada/cartridge/client/default/js/storeLocator/storeLocator.js","webpack://sfra-startup-kit/./cartridges/app_ahumada/cartridge/client/default/js/utils/googleMapsUtils.js","webpack://sfra-startup-kit/./cartridges/app_storefront_base/cartridge/client/default/js/util.js","webpack://sfra-startup-kit/webpack/bootstrap","webpack://sfra-startup-kit/./cartridges/app_ahumada/cartridge/client/default/js/storeLocator.js"],"sourcesContent":["\"use strict\";\n\n/* Constants */\nconst storeLocatorData = $(\".js-states-and-cities-json\");\nconst stateAndCityList = storeLocatorData.data(\"state-and-city-list\");\nconst defaultState = storeLocatorData.data(\"default-state\") || \"\";\nconst defaultCity = storeLocatorData.data(\"default-city\") || \"\";\n\n/**\n* Returns the list of cities for a given state\n* @param {Object} $stateDropdown - jQuery object of the state dropdown\n* @returns {Array} - an array of cities for the given state\n*/\nfunction getCityList($stateDropdown) {\n var $selectedState = $stateDropdown.find(\"option:selected\");\n\n return stateAndCityList[$selectedState.val().toString()];\n}\n\n/**\n* Populates the city dropdown with the list of cities\n* @param {Array} cityList - List of cities\n* @param {Object} $cityDropdown - jQuery object of the city dropdown\n* @param {String} defaultCity - Default city to be selected\n*/\nfunction populateCityDropdown(cityList, $cityDropdown, defaultCity) {\n for (var city of cityList) {\n var cityOptionHtml = ``;\n\n $cityDropdown.append(cityOptionHtml);\n }\n}\n\nmodule.exports = {\n /**\n * Event handler for when the state dropdown is changed\n * @param {Object} $container - jQuery object of the store locator container\n * @param {Object} $stateDropdown - jQuery object of the state dropdown\n * @param {Object} $citiesDropdown - jQuery object of the cities dropdown\n * @param {Object} $citiesDropdownOptions - jQuery object of the cities dropdown options\n * @param {Array} cityList - array of cities\n */\n updateCitiesDropdownOnStateSelection : function () {\n $(document).on(\"change\", \".js-current-state\", function (e, defaultCity) {\n var $container = $(\".store-locator-container\");\n var $stateDropdown = $(this, $container);\n var $citiesDropdown = $(\".js-dropdown-cities\", $container);\n var $citiesDropdownOptions = $citiesDropdown.find(\"option\");\n var cityList = getCityList($stateDropdown);\n\n $citiesDropdownOptions.not(\":first\").remove();\n\n if (cityList) {\n populateCityDropdown(cityList, $citiesDropdown, defaultCity);\n }\n\n $citiesDropdown.trigger(\"change\");\n });\n },\n\n /**\n * Sets the default state and city for the store locator\n * @param {string} defaultState - the default state\n * @param {string} defaultCity - the default city\n */\n initDefaultStateAndCity : function () {\n if (defaultState && defaultCity) {\n $(\".js-current-state\")\n .val(defaultState)\n .trigger(\"change\", [defaultCity]);\n }\n },\n};\n","\"use strict\";\n\n/* Constants */\nconst googleMapsUtils = require(\"../utils/googleMapsUtils\");\n\n// Chile Coordinates\nconst initialLocation = {\n latitude : -33.478043,\n longitude: -70.599010\n};\n\n/**\n * appends params to a url\n * @param {string} url - Original url\n * @param {Object} params - Parameters to append\n * @returns {string} result url with appended parameters\n */\nfunction appendToUrl(url, params) {\n let newUrl = url;\n\n newUrl += (newUrl.indexOf(\"?\") !== -1 ? \"&\" : \"?\") + Object.keys(params).map(function (key) {\n return key + \"=\" + encodeURIComponent(params[key]);\n }).join(\"&\");\n\n return newUrl;\n}\n\n/**\n* Initializes the Google Maps with the store locations\n* @param {Object} initialLocation - the initial location of the map\n* @param {Object} storeLocations - the parsed JSON object with the store locations\n*/\nfunction initGoogleMaps() {\n const infowindow = new google.maps.InfoWindow();\n const latlng = new google.maps.LatLng(initialLocation.latitude, initialLocation.longitude);\n const mapOptions = {\n scrollwheel : false,\n zoom : 6,\n center : latlng\n };\n window.googleMap = new google.maps.Map($(\".map-canvas\")[0], mapOptions);\n let storeLocations = $(\".map-canvas\").attr(\"data-locations\");\n\n window.googleMapLocations = storeLocations = JSON.parse(storeLocations);\n\n const bounds = new google.maps.LatLngBounds();\n\n Object.keys(storeLocations).forEach(function (key) {\n var item = storeLocations[key];\n var storeLocation = new google.maps.LatLng(item.latitude, item.longitude);\n var marker = new google.maps.Marker({\n animation: google.maps.Animation.DROP,\n position : storeLocation,\n map : window.googleMap,\n });\n\n marker.addListener(\"click\", function () {\n infowindow.setOptions({\n content : item.infoWindowHtml\n });\n infowindow.open(window.googleMap, marker);\n });\n\n // Create a minimum bound based on a set of storeLocations\n bounds.extend(marker.position);\n });\n\n // Fit the all the store marks in the center of a minimum bounds when any store has been found.\n if (storeLocations && storeLocations.length !== 0) {\n if (storeLocations.length === 1) {\n window.googleMap.setCenter(bounds.getCenter());\n window.googleMap.setZoom(15);\n } else {\n window.googleMap.fitBounds(bounds);\n }\n }\n}\n\n/**\n * Renders the results of the search and updates the map\n * @param {Object} data - Response from the server\n */\nfunction updateStoresResults(data) {\n const $resultsDiv = $(\".results\");\n const $storeLocations = $(\".map-canvas\");\n const hasResults = data.stores.length > 0;\n\n $resultsDiv.empty()\n .data(\"has-results\", hasResults)\n .data(\"radius\", data.radius)\n .data(\"search-key\", data.searchKey);\n\n $storeLocations.attr(\"data-locations\", data.locations);\n\n if ($storeLocations.data(\"has-google-api\")) {\n initGoogleMaps();\n } else {\n $(\".store-locator-no-apiKey\").show();\n }\n\n if (data.storesResultsHtml) {\n $resultsDiv.append(data.storesResultsHtml);\n }\n}\n\n/**\n * Search for stores with new zip code\n * @param {HTMLElement} element - the target html element\n * @returns {boolean} false to prevent default event\n */\nfunction search(showAllStores) {\n const $regionErrorSelect = $(\".js-current-state\");\n const $communeErrorSelect = $(\".js-dropdown-cities\");\n const $storeLocatorContainer = $(\".store-locator-container\");\n const $form = $(\"form.store-locator\");\n let url = $form.attr(\"action\");\n let urlParams = {};\n let regionId = $(\".js-current-state option:selected\");\n let communeId = $(\".js-dropdown-cities option:selected\");\n\n if (showAllStores) {\n urlParams = {\n showAllStores : true\n };\n } else {\n if (!regionId || regionId.data(\"not-selectable\")) {\n regionId = null;\n $regionErrorSelect.addClass(\"is-invalid\");\n $regionErrorSelect[0].scrollIntoView({ behavior: \"smooth\", block: \"start\" });\n }\n\n if (!communeId || communeId.data(\"not-selectable\")) {\n communeId = null;\n $communeErrorSelect.addClass(\"is-invalid\");\n $regionErrorSelect[0].scrollIntoView({ behavior: \"smooth\", block: \"start\" });\n }\n\n if (!regionId || !communeId) {\n return;\n }\n\n $regionErrorSelect.removeClass(\"is-invalid\");\n $communeErrorSelect.removeClass(\"is-invalid\");\n\n urlParams = {\n regionId : regionId.val(),\n communeId : communeId.val()\n };\n }\n\n let payload = showAllStores ? {} : $form.serialize();\n\n $storeLocatorContainer.spinner().start();\n\n $.ajax({\n url : appendToUrl(url, urlParams),\n type : $form.attr(\"method\"),\n data : payload,\n dataType : \"json\",\n success : function (data) {\n updateStoresResults(data);\n\n if ($(window).width() < 768) {\n $(\".store-locator-container\")[0].scrollIntoView({ behavior: \"smooth\", block: \"start\" });\n }\n $storeLocatorContainer.spinner().stop();\n },\n error : function () {\n $storeLocatorContainer.spinner().stop();\n }\n });\n\n return false;\n}\n\nmodule.exports = {\n /**\n * Initializes the Google Maps API and sets up event listeners for the store locator page\n * @returns {void}\n */\n init : function () {\n const $body = $(\"body\");\n\n if ($(\".map-canvas\").data(\"has-google-api\")) {\n initGoogleMaps();\n } else {\n $(\".store-locator-no-apiKey\").show();\n }\n\n const $resultsDiv = $(\".results\");\n const storeResultsHtml = $resultsDiv.data(\"stores-results-html\");\n\n if (storeResultsHtml) {\n $resultsDiv.append(storeResultsHtml);\n }\n\n $body.on(\"click\", \".js-see-store-in-map\", function (e) {\n e.preventDefault();\n const $this = $(this);\n\n googleMapsUtils.setCenter(\n $this.data(\"latitude\"),\n $this.data(\"longitude\")\n );\n\n $(\".maps-canvas-container\")[0].scrollIntoView({ behavior: \"smooth\", block: \"start\" });\n });\n },\n\n /**\n * Handles the store locator form submission and show all button click\n * @param {boolean} showAll - whether to show all stores or not\n */\n search : function () {\n $(document).on(\"submit\", \".store-locator-container form.store-locator\", function (e) {\n e.preventDefault();\n search(false);\n });\n\n $(document).on(\"click\", \".store-locator-container button.btn-show-all\", function (e) {\n e.preventDefault();\n search(true);\n });\n }\n};\n","\"use strict\";\n\n/**\n* Sets the center of the given Google Map coordinates\n @param {number} lat - the latitude of the center\n* @param {number} lng - the longitude of the center\n*/\nfunction setCenter(lat, lng) {\n const latlng = new google.maps.LatLng(lat, lng);\n const mapOptions = {\n scrollwheel : false,\n zoom : 14,\n center : latlng,\n mapTypeId : google.maps.MapTypeId.ROADMAP\n };\n\n window.googleMap = new google.maps.Map($(\".map-canvas\")[0], mapOptions);\n const bounds = new google.maps.LatLngBounds();\n const selectedStore = window.googleMapLocations.find((store) => {\n var currentStore = new google.maps.LatLng(store.latitude, store.longitude);\n\n return currentStore.equals(latlng);\n });\n\n const storeLocation = new google.maps.LatLng(selectedStore.latitude, selectedStore.longitude);\n const marker = new google.maps.Marker({\n animation: google.maps.Animation.DROP,\n position : storeLocation,\n map : window.googleMap,\n });\n\n if (selectedStore.infoWindowHtml) {\n const infowindow = new google.maps.InfoWindow({\n content: selectedStore.infoWindowHtml\n });\n\n marker.addListener(\"click\", function () {\n infowindow.open(window.googleMap, marker);\n });\n\n infowindow.open(window.googleMap, marker);\n }\n\n // Create a minimum bound based on a set of storeLocations\n bounds.extend(marker.position);\n\n // Fit the all the store marks in the center of a minimum bounds when any store has been found.\n window.googleMap.setCenter(bounds.getCenter());\n window.googleMap.setZoom(14);\n}\n\nmodule.exports = {\n setCenter : setCenter\n};\n","'use strict';\n\nmodule.exports = function (include) {\n if (typeof include === 'function') {\n include();\n } else if (typeof include === 'object') {\n Object.keys(include).forEach(function (key) {\n if (typeof include[key] === 'function') {\n include[key]();\n }\n });\n }\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","\"use strict\";\n\nvar processInclude = require(\"base/util\");\n\n$(() => {\n processInclude(require(\"./storeLocator/statesAndCities\"));\n processInclude(require(\"./storeLocator/storeLocator\"));\n});\n"],"names":[],"sourceRoot":""}