{"version":3,"file":"default/js/storeLocator.js","mappings":";;;;;;;;;;AAAA;AACA;AACa;;AAEb;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qCAAqC;AACrC;AACA;AACA;AACA;AACA,qFAAqF;AACrF;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA;AACA,SAAS;AACT,KAAK;;AAEL;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB,cAAc;AACd;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA,SAAS;;AAET;AACA;;AAEA,KAAK;AACL;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,MAAM;AACN;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;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;;AAEL;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,SAAS;AACT,KAAK;AACL;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;;;;;AC1Ta;;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;AACa;;AAEb,qBAAqB,mBAAO,CAAC,gFAAQ;;AAErC;AACA,mBAAmB,mBAAO,CAAC,0HAA6B;AACxD,CAAC","sources":["webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/storeLocator/storeLocator.js","webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/util.js","webpack://sfra-startup-kit/webpack/bootstrap","webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/storeLocator.js"],"sourcesContent":["/* eslint-disable no-undef */\n/* globals google */\n\"use strict\";\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 var newUrl = url;\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 * Uses google maps api to render a map\n */\nfunction maps() {\n var map;\n var infowindow = new google.maps.InfoWindow();\n // Init U.S. Map in the center of the viewport\n var latlng = new google.maps.LatLng(37.09024, -95.712891);\n var mapOptions = {\n scrollwheel: false,\n zoom: 4,\n center: latlng\n };\n map = new google.maps.Map($(\".map-canvas\")[0], mapOptions);\n var service = new google.maps.places.PlacesService(map);\n // Create a request object with the place ID of the store\n $(\"body\").find(\".store-details\").each(function () {\n var placeId = $(this).data(\"placeid\");\n var request = {\n placeId: placeId\n };\n var $storeDetails = $(this); // Store the reference to the current store-details element\n service.getDetails(request, function (place, status) {\n if (status === google.maps.places.PlacesServiceStatus.OK) {\n const storeHours = place.opening_hours;\n if (storeHours && storeHours.weekday_text) {\n const storeMapHoursDiv = $storeDetails.find(\".store-map-hours\"); // Use the stored reference to find the store-map-hours element\n if (storeMapHoursDiv.length > 0) {\n const weekdayText = storeHours.weekday_text;\n weekdayText.forEach(function (text) {\n storeMapHoursDiv.append(text + \"
\");\n });\n }\n }\n }\n });\n });\n\n var mapdiv = $(\".map-canvas\").attr(\"data-locations\");\n\n mapdiv = JSON.parse(mapdiv);\n\n var bounds = new google.maps.LatLngBounds();\n\n // Customized google map marker icon with svg format\n var markerImg = {\n path: \"M13.5,30.1460153 L16.8554555,25.5 L20.0024287,25.5 C23.039087,25.5 25.5,\" +\n \"23.0388955 25.5,20.0024287 L25.5,5.99757128 C25.5,2.96091298 23.0388955,0.5 \" +\n \"20.0024287,0.5 L5.99757128,0.5 C2.96091298,0.5 0.5,2.96110446 0.5,5.99757128 \" +\n \"L0.5,20.0024287 C0.5,23.039087 2.96110446,25.5 5.99757128,25.5 L10.1445445,\" +\n \"25.5 L13.5,30.1460153 Z\",\n fillColor: \"#0070d2\",\n fillOpacity: 1,\n scale: 1.1,\n strokeColor: \"white\",\n strokeWeight: 1,\n anchor: new google.maps.Point(13, 30),\n labelOrigin: new google.maps.Point(12, 12)\n };\n\n Object.keys(mapdiv).forEach(function (key) {\n var item = mapdiv[key];\n var lable = parseInt(key, 10) + 1;\n var storeLocation = new google.maps.LatLng(item.latitude, item.longitude);\n var marker = new google.maps.Marker({\n position: storeLocation,\n map: map,\n title: item.name,\n icon: markerImg,\n label: {\n text: lable.toString(),\n color: \"white\",\n fontSize: \"16px\"\n }\n });\n\n marker.addListener(\"click\", function () {\n var storeMapHours = $(\".store-map-hours[data-name|='\" + $.escapeSelector(marker.title) + \"']\");\n if (storeMapHours.length > 0) {\n infowindow.setOptions({\n content: item.infoWindowHtml + storeMapHours[0].innerHTML\n });\n } else {\n // Handle the case when storeMapHours element is not found\n infowindow.setOptions({\n content: item.infoWindowHtml\n });\n }\n infowindow.open(map, 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 (mapdiv && mapdiv.length !== 0) {\n map.fitBounds(bounds);\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 var $resultsDiv = $(\".results\");\n var $mapDiv = $(\".map-canvas\");\n var hasResults = data.stores.length > 0;\n\n if (!hasResults) {\n $(\".store-locator-no-results\").show();\n } else {\n $(\".store-locator-no-results\").hide();\n }\n\n $resultsDiv.empty()\n .data(\"has-results\", hasResults)\n .data(\"radius\", data.radius)\n .data(\"search-key\", data.searchKey);\n\n $mapDiv.attr(\"data-locations\", data.locations);\n\n if ($mapDiv.data(\"has-google-api\")) {\n maps();\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(element) {\n var dialog = element.closest(\".in-store-inventory-dialog\");\n var spinner = dialog.length ? dialog.spinner() : $.spinner();\n spinner.start();\n var $form = element.closest(\".store-locator\");\n var radius = $(\".results\").data(\"radius\");\n var url = $form.attr(\"action\");\n var urlParams = {\n radius: radius\n };\n\n var payload = $form.is(\"form\") ? $form.serialize() : {\n postalCode: $form.find(\"[name=\\\"postalCode\\\"]\").val()\n };\n\n url = appendToUrl(url, urlParams);\n\n $.ajax({\n url: url,\n type: $form.attr(\"method\"),\n data: payload,\n dataType: \"json\",\n success: function (data) {\n spinner.stop();\n updateStoresResults(data);\n maps();\n $(\".select-store\").prop(\"disabled\", true);\n }\n });\n return false;\n}\n\nmodule.exports = {\n init: function () {\n if ($(\".map-canvas\").data(\"has-google-api\")) {\n maps();\n } else {\n $(\".store-locator-no-apiKey\").show();\n }\n\n if (!$(\".results\").data(\"has-results\")) {\n $(\".store-locator-no-results\").show();\n }\n\n this.detectLocation();\n },\n\n detectLocation: function () {\n // clicking on detect location.\n $(\".detect-location\").on(\"click\", function () {\n $.spinner().start();\n if (!navigator.geolocation) {\n $.spinner().stop();\n return;\n }\n\n navigator.geolocation.getCurrentPosition(function (position) {\n var $detectLocationButton = $(\".detect-location\");\n var url = $detectLocationButton.data(\"action\");\n var $mapDiv = $(\".map-canvas\");\n var radius = $(\".results\").data(\"radius\");\n var urlParams = {\n radius: radius,\n lat: position.coords.latitude,\n long: position.coords.longitude\n };\n\n url = appendToUrl(url, urlParams);\n $.ajax({\n url: url,\n type: \"get\",\n dataType: \"json\",\n success: function (data) {\n $.spinner().stop();\n updateStoresResults(data);\n if ($mapDiv.data(\"has-google-api\")) {\n maps();\n }\n $(\".select-store\").prop(\"disabled\", true);\n }\n });\n });\n });\n },\n\n search: function () {\n $(\".store-locator-container form.store-locator\").submit(function (e) {\n e.preventDefault();\n search($(this));\n });\n $(\".store-locator-container .btn-storelocator-search[type=\\\"button\\\"]\").click(function (e) {\n e.preventDefault();\n search($(this));\n });\n },\n\n changeRadius: function () {\n $(\".store-locator-container .radius\").change(function () {\n var radius = $(this).val();\n var searchKeys = $(\".results\").data(\"search-key\");\n var $mapDiv = $(\".map-canvas\");\n var url = $(this).data(\"action-url\");\n var urlParams = {};\n\n if (searchKeys.postalCode) {\n urlParams = {\n radius: radius,\n postalCode: searchKeys.postalCode\n };\n } else if (searchKeys.lat && searchKeys.long) {\n urlParams = {\n radius: radius,\n lat: searchKeys.lat,\n long: searchKeys.long\n };\n }\n\n url = appendToUrl(url, urlParams);\n var dialog = $(this).closest(\".in-store-inventory-dialog\");\n var spinner = dialog.length ? dialog.spinner() : $.spinner();\n spinner.start();\n $.ajax({\n url: url,\n type: \"get\",\n dataType: \"json\",\n success: function (data) {\n spinner.stop();\n updateStoresResults(data);\n if ($mapDiv.data(\"has-google-api\")) {\n maps();\n }\n $(\".select-store\").prop(\"disabled\", true);\n }\n });\n });\n },\n selectStore: function () {\n $(\".store-locator-container\").on(\"click\", \".select-store\", (function (e) {\n e.preventDefault();\n var selectedStore = $(\":checked\", \".results-card .results\");\n var data = {\n storeID: selectedStore.val(),\n searchRadius: $(\"#radius\").val(),\n searchPostalCode: $(\".results\").data(\"search-key\").postalCode,\n storeDetailsHtml: selectedStore.siblings(\"label\").find(\".store-details\").html(),\n event: e\n };\n\n $(\"body\").trigger(\"store:selected\", data);\n }));\n },\n updateSelectStoreButton: function () {\n $(\"body\").on(\"change\", \".select-store-input\", (function () {\n $(\".select-store\").prop(\"disabled\", false);\n }));\n }\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","/* eslint-disable no-undef */\n\"use strict\";\n\nvar processInclude = require(\"./util\");\n\n$(document).ready(function () {\n processInclude(require(\"./storeLocator/storeLocator\"));\n});\n"],"names":[],"sourceRoot":""}