/*! 1.3.0 | © Algolia | github.com/algolia/places */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["placesAutocompleteDataset"] = factory();
else
root["placesAutocompleteDataset"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
'use strict';
var _createAutocompleteDataset = __webpack_require__(50);
var _createAutocompleteDataset2 = _interopRequireDefault(_createAutocompleteDataset);
var _places = __webpack_require__(65);
var _places2 = _interopRequireDefault(_places);
var _insertCss = __webpack_require__(66);
var _insertCss2 = _interopRequireDefault(_insertCss);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
(0, _insertCss2.default)(_places2.default, { prepend: true });
// must use module.exports to be commonJS compatible
module.exports = _createAutocompleteDataset2.default;
/***/ },
/***/ 50:
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = createAutocompleteDataset;
var _createAutocompleteSource = __webpack_require__(51);
var _createAutocompleteSource2 = _interopRequireDefault(_createAutocompleteSource);
var _defaultTemplates = __webpack_require__(56);
var _defaultTemplates2 = _interopRequireDefault(_defaultTemplates);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createAutocompleteDataset(options) {
var templates = _extends({}, _defaultTemplates2.default, options.templates);
var source = (0, _createAutocompleteSource2.default)(_extends({}, options, {
formatInputValue: templates.value,
templates: undefined
}));
return {
source: source,
templates: templates,
displayKey: 'value',
name: 'places'
};
}
/***/ },
/***/ 51:
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = createAutocompleteSource;
var _formatHit = __webpack_require__(52);
var _formatHit2 = _interopRequireDefault(_formatHit);
var _version = __webpack_require__(55);
var _version2 = _interopRequireDefault(_version);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function createAutocompleteSource(_ref) {
var algoliasearch = _ref.algoliasearch;
var clientOptions = _ref.clientOptions;
var apiKey = _ref.apiKey;
var appId = _ref.appId;
var aroundLatLng = _ref.aroundLatLng;
var aroundRadius = _ref.aroundRadius;
var aroundLatLngViaIP = _ref.aroundLatLngViaIP;
var countries = _ref.countries;
var formatInputValue = _ref.formatInputValue;
var _ref$computeQueryPara = _ref.computeQueryParams;
var computeQueryParams = _ref$computeQueryPara === undefined ? function (params) {
return params;
} : _ref$computeQueryPara;
var _ref$useDeviceLocatio = _ref.useDeviceLocation;
var useDeviceLocation = _ref$useDeviceLocatio === undefined ? false : _ref$useDeviceLocatio;
var _ref$language = _ref.language;
var language = _ref$language === undefined ? navigator.language.split('-')[0] : _ref$language;
var _ref$onHits = _ref.onHits;
var onHits = _ref$onHits === undefined ? function () {} : _ref$onHits;
var _ref$onError = _ref.onError;
var onError = _ref$onError === undefined ? function (e) {
throw e;
} : _ref$onError;
var onRateLimitReached = _ref.onRateLimitReached;
var type = _ref.type;
var placesClient = algoliasearch.initPlaces(appId, apiKey, clientOptions);
placesClient.as.addAlgoliaAgent('Algolia Places ' + _version2.default);
var defaultQueryParams = {
countries: countries,
hitsPerPage: 5,
language: language,
type: type
};
if (aroundLatLng) {
defaultQueryParams.aroundLatLng = aroundLatLng;
} else if (aroundLatLngViaIP !== undefined) {
defaultQueryParams.aroundLatLngViaIP = aroundLatLngViaIP;
}
if (aroundRadius) {
defaultQueryParams.aroundRadius = aroundRadius;
}
var userCoords = void 0;
if (useDeviceLocation) {
navigator.geolocation.watchPosition(function (_ref2) {
var coords = _ref2.coords;
return userCoords = coords.latitude + ',' + coords.longitude;
});
}
return function (query, cb) {
var _extends2;
return placesClient.search(computeQueryParams(_extends({}, defaultQueryParams, (_extends2 = {}, _defineProperty(_extends2, userCoords ? 'aroundLatLng' : undefined, userCoords), _defineProperty(_extends2, 'query', query), _extends2)))).then(function (content) {
var hits = content.hits.map(function (hit, hitIndex) {
return (0, _formatHit2.default)({
formatInputValue: formatInputValue,
hit: hit,
hitIndex: hitIndex,
query: query,
rawAnswer: content
});
});
onHits({
hits: hits,
query: query,
rawAnswer: content
});
return hits;
}).then(cb).catch(function (e) {
if (e.message === 'Too many requests') {
onRateLimitReached();
return;
}
onError(e);
});
};
}
/***/ },
/***/ 52:
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.default = formatHit;
var _findCountryCode = __webpack_require__(53);
var _findCountryCode2 = _interopRequireDefault(_findCountryCode);
var _findType = __webpack_require__(54);
var _findType2 = _interopRequireDefault(_findType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function formatHit(_ref) {
var formatInputValue = _ref.formatInputValue;
var hit = _ref.hit;
var hitIndex = _ref.hitIndex;
var query = _ref.query;
var rawAnswer = _ref.rawAnswer;
try {
var name = hit.locale_names[0];
var country = hit.country;
var administrative = hit.administrative && hit.administrative[0] !== name ? hit.administrative[0] : undefined;
var city = hit.city && hit.city[0] !== name ? hit.city[0] : undefined;
var highlight = {
name: hit._highlightResult.locale_names[0].value,
city: city ? hit._highlightResult.city[0].value : undefined,
administrative: administrative ? hit._highlightResult.administrative[0].value : undefined,
country: country ? hit._highlightResult.country.value : undefined
};
var suggestion = {
name: name,
administrative: administrative,
city: city,
country: country,
countryCode: (0, _findCountryCode2.default)(hit._tags),
type: (0, _findType2.default)(hit._tags),
latlng: {
lat: hit._geoloc.lat,
lng: hit._geoloc.lng
},
postcode: hit.postcode && hit.postcode[0]
};
// this is the value to put inside the \n Built by \n using \n ',
value: _formatInputValue2.default,
suggestion: _formatDropdownValue2.default
};
/***/ },
/***/ 57:
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = formatInputValue;
function formatInputValue(_ref) {
var administrative = _ref.administrative;
var city = _ref.city;
var country = _ref.country;
var name = _ref.name;
var type = _ref.type;
var out = ('' + name + (type !== 'country' && country !== undefined ? ',' : '') + '\n ' + (city ? city + ',' : '') + '\n ' + (administrative ? administrative + ',' : '') + '\n ' + (country ? country : '')).replace(/\s*\n\s*/g, ' ').trim();
return out;
}
/***/ },
/***/ 58:
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = formatDropdownValue;
var _address = __webpack_require__(59);
var _address2 = _interopRequireDefault(_address);
var _city = __webpack_require__(60);
var _city2 = _interopRequireDefault(_city);
var _country = __webpack_require__(61);
var _country2 = _interopRequireDefault(_country);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var icons = {
address: _address2.default,
city: _city2.default,
country: _country2.default
};
function formatDropdownValue(_ref) {
var type = _ref.type;
var highlight = _ref.highlight;
var name = highlight.name;
var administrative = highlight.administrative;
var city = highlight.city;
var country = highlight.country;
var out = ('' + icons[type].trim() + '\n' + name + '\n\n ' + [city, administrative, country].filter(function (token) {
return token !== undefined;
}).join(', ') + '').replace(/\s*\n\s*/g, ' ');
return out;
}
/***/ },
/***/ 59:
/***/ function(module, exports) {
module.exports = "\n"
/***/ },
/***/ 60:
/***/ function(module, exports) {
module.exports = "\n"
/***/ },
/***/ 61:
/***/ function(module, exports) {
module.exports = "\n"
/***/ },
/***/ 62:
/***/ function(module, exports) {
module.exports = "\n"
/***/ },
/***/ 63:
/***/ function(module, exports) {
module.exports = "\n"
/***/ },
/***/ 65:
/***/ function(module, exports) {
module.exports = ".algolia-places {\n width: 100%; }\n\n.ap-input, .ap-hint {\n width: 100%;\n padding-right: 35px;\n padding-left: 16px;\n line-height: 40px;\n height: 40px;\n border: 1px solid #CCC;\n border-radius: 3px;\n outline: none;\n font: inherit; }\n\n.ap-input:hover ~ .ap-input-icon svg,\n.ap-input:focus ~ .ap-input-icon svg,\n.ap-input-icon:hover svg {\n fill: #aaaaaa; }\n\n.ap-dropdown-menu {\n width: 100%;\n background: #ffffff;\n box-shadow: 0 1px 10px rgba(0, 0, 0, 0.2), 0 2px 4px 0 rgba(0, 0, 0, 0.1);\n border-radius: 3px;\n margin-top: 3px;\n overflow: hidden; }\n\n.ap-suggestion {\n cursor: pointer;\n height: 46px;\n line-height: 46px;\n padding-left: 18px;\n overflow: hidden; }\n .ap-suggestion em {\n font-weight: bold;\n font-style: normal; }\n\n.ap-address {\n font-size: smaller;\n margin-left: 12px;\n color: #aaaaaa; }\n\n.ap-suggestion-icon {\n margin-right: 10px;\n width: 14px;\n height: 20px;\n vertical-align: middle; }\n .ap-suggestion-icon svg {\n transform: scale(0.9) translateY(2px);\n fill: #cfcfcf; }\n\n.ap-input-icon {\n border: 0;\n background: transparent;\n position: absolute;\n top: 0;\n bottom: 0;\n right: 16px;\n outline: none; }\n .ap-input-icon.ap-input-icon-pin {\n cursor: initial; }\n .ap-input-icon svg {\n fill: #cfcfcf;\n position: absolute;\n top: 50%;\n right: 0;\n transform: translateY(-50%); }\n\n.ap-cursor {\n background: #efefef; }\n .ap-cursor .ap-suggestion-icon svg {\n transform: scale(1) translateY(2px);\n fill: #aaaaaa; }\n\n.ap-footer {\n opacity: .8;\n text-align: right;\n padding: .5em 1em .5em 0;\n font-size: 12px;\n line-height: 12px; }\n .ap-footer a {\n color: inherit;\n text-decoration: none; }\n .ap-footer a svg {\n vertical-align: middle; }\n .ap-footer:hover {\n opacity: 1; }\n"
/***/ },
/***/ 66:
/***/ function(module, exports) {
var containers = []; // will store container HTMLElement references
var styleElements = []; // will store {prepend: HTMLElement, append: HTMLElement}
module.exports = function (css, options) {
options = options || {};
var position = options.prepend === true ? 'prepend' : 'append';
var container = options.container !== undefined ? options.container : document.querySelector('head');
var containerId = containers.indexOf(container);
// first time we see this container, create the necessary entries
if (containerId === -1) {
containerId = containers.push(container) - 1;
styleElements[containerId] = {};
}
// try to get the correponding container + position styleElement, create it otherwise
var styleElement;
if (styleElements[containerId] !== undefined && styleElements[containerId][position] !== undefined) {
styleElement = styleElements[containerId][position];
} else {
styleElement = styleElements[containerId][position] = createStyleElement();
if (position === 'prepend') {
container.insertBefore(styleElement, container.childNodes[0]);
} else {
container.appendChild(styleElement);
}
}
// actually add the stylesheet
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText += css
} else {
styleElement.textContent += css;
}
return styleElement;
};
function createStyleElement() {
var styleElement = document.createElement('style');
styleElement.setAttribute('type', 'text/css');
return styleElement;
}
/***/ }
/******/ })
});
;
//# sourceMappingURL=placesAutocompleteDataset.js.map