{"version":3,"sources":["components/autocomplete/autocompleteComponent.js","components/autocomplete/observer/searchFieldObservable.js","components/autocomplete/searchAutocompleteComponent.js"],"names":["define","AutocompleteComponent","context","observable","engine","suggestionsComponent","this","_observable","_searchField","field","_engine","_suggestionsComponent","_context","suggestions","Object","defineProperty","get","getSelectedSuggestion","bind","add","_initEvents","prototype","_clickHandler","event","target","contains","close","document","body","addEventListener","passive","update","callback","value","getSuggestions","displaySuggestions","Function","clear","length","highlight","includeHighlightInSuggestion","RegExp","trim","index","htmlElement","parentElement","appendChild","open","selectSuggestion","hideSuggestions","name","SearchFieldObservable","inputElement","_observers","_debounceTimer","_lastValue","_initDomEvents","_fieldChangeHandler","key","code","toLowerCase","indexOf","notify","clearTimeout","setTimeout","observer","push","forEach","o","SearchAutocompleteComponent","call","querySelector","dependeciesRequested","includeCurrentLocation","hasAttribute","includeCurrentLocationIcon","_currentLocationSuggestion","onSelect","create","constructor","_loadDependencies","require","SuggestionsEngineConfig","SearchSuggestionsEngine","SearchSuggestionsComponent","SearchSuggestion","id","cssClass","dataAttributes","icon","_onSelect","removeCurrentLocation","currentLocationOption","remove","unshift","setAttribute","initAll","searchAutocompleteComponents","querySelectorAll","i","searchAutocompleteComponent"],"mappings":"AAAAA,OAAA,wBAAA,IAAA,WASA,SAAAC,sBAAAC,QAAAC,WAAAC,OAAAC,sBAIAC,KAAAC,YAAAJ,WAKAG,KAAAE,aAAAF,KAAAC,YAAAE,MAKAH,KAAAI,QAAAN,OAKAE,KAAAK,sBAAAN,qBAKAC,KAAAM,SAAAV,QAKAI,KAAAO,YAAA,GAKAC,OAAAC,eAAAT,KAAA,QAAA,CACAU,IAAA,WACA,OAAAV,KAAAK,sBAAAL,KAAAK,sBAAAM,wBAAA,MACAC,KAAAZ,QAGAA,KAAAC,YAAAY,IAAAb,MACAA,KAAAc,cA2EA,OAxEAnB,sBAAAoB,UAAAC,cAAA,SAAAC,OACAA,MAAAC,SAAAlB,KAAAM,UAAAN,KAAAM,SAAAa,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AAAsE,4BAEA3E,sBAAAoB,UAAAc,mBAAAmC,KAAAhE,OAGA+D,4BAAAhD,UAAA2B,iBAAA,SAAAL,OACA1C,sBAAAoB,UAAA2B,iBAAAsB,KAAAhE,KAAAqC,OACArC,KAAAE,aAAAuF,aAAA,wBAAApD,QAQA0B,4BAAA2B,QAAA,WAEA,IADA,IAAAC,6BAAAtE,SAAAuE,iBAAA,wCACAC,EAAA,EAAAA,EAAAF,6BAAA3D,OAAA6D,IACAF,6BAAAE,GAAAC,8BACAH,6BAAAE,GAAAC,4BAAA,IAAA/B,4BAAA4B,6BAAAE,MAIA9B,4BAAA2B,UACA3B","file":"../searchautocompletecomponent-1f21a651e9.js","sourceRoot":"..","sourcesContent":["define('AutocompleteComponent',[], function () {\r\n /**\r\n * @abstract\r\n * @class \r\n * @param {HTMLElement} context Element context\r\n * @param {Observable} observable Observable instance\r\n * @param {SuggestionsEngine} engine Suggestions Engine\r\n * @param {SuggestionsComponent} suggestionsComponent Suggestions Component\r\n */\r\n function AutocompleteComponent(context, observable, engine, suggestionsComponent) {\r\n /**\r\n * @property {Observable} _observable Observable \r\n */\r\n this._observable = observable;\r\n\r\n /**\r\n * @property {HTMLInputElement} _searchField Search field\r\n */\r\n this._searchField = this._observable.field;\r\n\r\n /**\r\n * @property {SuggestionsEngine} _engine Suggestions engine\r\n */\r\n this._engine = engine;\r\n\r\n /**\r\n * @property {SuggestionsComponent} _suggestionsComponent Suggestions component\r\n */\r\n this._suggestionsComponent = suggestionsComponent;\r\n\r\n /**\r\n * @property {HTMLElement} _context DOM Context\r\n */\r\n this._context = context;\r\n\r\n /**\r\n * @property {*[]}\r\n */\r\n this.suggestions = [];\r\n\r\n /**\r\n * @property {*} value Returns the selected suggestion of the suggestions conponent\r\n */\r\n Object.defineProperty(this, \"value\", {\r\n get: (function () {\r\n return this._suggestionsComponent ? this._suggestionsComponent.getSelectedSuggestion() : null;\r\n }).bind(this)\r\n });\r\n\r\n this._observable.add(this); // Add observer to observable \r\n this._initEvents(); // Init DOM events\r\n }\r\n\r\n AutocompleteComponent.prototype._clickHandler = function (event) {\r\n if (event.target === this._context || this._context.contains(event.target)) return;\r\n if (this._suggestionsComponent) {\r\n this._suggestionsComponent.close();\r\n }\r\n };\r\n\r\n /**\r\n * Initializes the DOM events\r\n * @method \r\n */\r\n AutocompleteComponent.prototype._initEvents = function () {\r\n document.body.addEventListener(\"click\", this._clickHandler.bind(this));\r\n document.body.addEventListener(\"touchstart\", this._clickHandler.bind(this), { passive: true });\r\n };\r\n\r\n /**\r\n * Updates the Autocomplete Suggestions\r\n * @method \r\n * @param {Function} callback Callback\r\n */\r\n AutocompleteComponent.prototype.update = function (callback) {\r\n if (this._searchField.value && this._suggestionsComponent.getSelectedSuggestion() === null) {\r\n this._engine.getSuggestions(this._searchField, (function (suggestions) {\r\n this.suggestions = suggestions;\r\n this.displaySuggestions();\r\n if (callback instanceof Function) {\r\n callback();\r\n }\r\n }).bind(this));\r\n } else if (!this._searchField.value) {\r\n this._suggestionsComponent.close();\r\n }\r\n };\r\n\r\n /**\r\n * Displays the suggestions\r\n * @method\r\n */\r\n AutocompleteComponent.prototype.displaySuggestions = function () {\r\n this._suggestionsComponent.close();\r\n this._suggestionsComponent.clear();\r\n if (!this.suggestions.length) {\r\n return;\r\n }\r\n var highlight = this.includeHighlightInSuggestion ? new RegExp(this._searchField.value.trim(), \"i\") : '';\r\n for (var index = 0; index < this.suggestions.length; index++) {\r\n this._suggestionsComponent.add(this.suggestions[index], highlight);\r\n }\r\n if (!this._suggestionsComponent.htmlElement.parentElement) {\r\n this._context.appendChild(this._suggestionsComponent.htmlElement);\r\n }\r\n this._suggestionsComponent.open();\r\n };\r\n\r\n /**\r\n * Selects a suggestion\r\n * @method\r\n * @param {Number} index Suggestion's index\r\n */\r\n AutocompleteComponent.prototype.selectSuggestion = function (index) {\r\n this.hideSuggestions();\r\n this._searchField.value = this.suggestions[index].name;\r\n };\r\n\r\n\r\n AutocompleteComponent.prototype.hideSuggestions = function () {\r\n if (this._suggestionsComponent) {\r\n this._suggestionsComponent.close();\r\n }\r\n };\r\n\r\n return AutocompleteComponent;\r\n});\r\n\r\n/**\r\n * Made with ♥ by NewHomeSource's team\r\n * Copyright (c) 2019-present, BuilderHomeSite Inc. All rights reserved.\r\n */;\n","define('SearchFieldObservable',[], function () {\r\n /**\r\n * @class \r\n * @param {HTMLInputElement} inputElement Input element to make observable\r\n */\r\n function SearchFieldObservable(inputElement) {\r\n /**\r\n * @property {Observer[]} _observers subscribed observers\r\n */\r\n this._observers = [];\r\n\r\n /**\r\n * @property {HTMLInputElement} field Field to observe\r\n */\r\n this.field = inputElement;\r\n\r\n /**\r\n * @property {Number} _debounceTimer Debounce Timeout\r\n */\r\n this._debounceTimer = null;\r\n\r\n this._lastValue = this.field.value;\r\n\r\n this._initDomEvents(); // Init DOM events\r\n }\r\n\r\n SearchFieldObservable.prototype._fieldChangeHandler = function (event) {\r\n if (event.key) {\r\n var code = event.key.toLowerCase();\r\n if (code.indexOf(\"down\") > -1 &&\r\n code.indexOf(\"up\") > -1 &&\r\n code.indexOf(\"enter\") > -1 &&\r\n code.indexOf(\"right\") > -1\r\n ) return;\r\n } \r\n if (this._lastValue !== this.field.value) {\r\n this._lastValue = this.field.value;\r\n this.notify();\r\n } \r\n };\r\n\r\n /**\r\n * Initializes the DOM events\r\n * @method\r\n */\r\n SearchFieldObservable.prototype._initDomEvents = function () {\r\n this.field.addEventListener(\"change\", this._fieldChangeHandler.bind(this));\r\n this.field.addEventListener(\"keyup\", this._fieldChangeHandler.bind(this));\r\n this.field.addEventListener(\"click\", this._fieldChangeHandler.bind(this));\r\n this.field.addEventListener(\"touchend\", this._fieldChangeHandler.bind(this)); \r\n this.field.addEventListener(\"search\", this._fieldChangeHandler.bind(this));\r\n };\r\n\r\n /**\r\n * Debounces the notify calls and notifies the observable observers\r\n * @method\r\n */\r\n SearchFieldObservable.prototype.notify = function () {\r\n clearTimeout(this._debounceTimer);\r\n this._debounceTimer = setTimeout((function () {\r\n this.notify();\r\n }).bind(this),\r\n 50);\r\n };\r\n\r\n SearchFieldObservable.prototype.add = function(observer) {\r\n this._observers.push(observer);\r\n };\r\n SearchFieldObservable.prototype.notify = function() {\r\n this._observers.forEach(function(o) {\r\n o.update();\r\n });\r\n };\r\n\r\n return SearchFieldObservable;\r\n});\r\n/**\r\n * Made with ♥ by NewHomeSource's team\r\n * Copyright (c) 2019-present, BuilderHomeSite Inc. All rights reserved.\r\n */;\n","define('SearchAutocompleteComponent',[\r\n \"AutocompleteComponent\",\r\n \"SearchFieldObservable\",\r\n], function (AutocompleteComponent, SearchFieldObservable) {\r\n /**\r\n * Creates a NewHomeSource search autocomplete component\r\n * @class\r\n * @extends AutocompleteComponent\r\n * @param {HTMLElement} context Element context\r\n */\r\n function SearchAutocompleteComponent(context) {\r\n AutocompleteComponent.call(this, context, new SearchFieldObservable(context.querySelector(\"[data-component-rol=target-input]\"))); // Call base class constructor\r\n /**\r\n * @property {Boolean} dependeciesRequested Flag to know if the dependencies were already requested\r\n */\r\n this.dependeciesRequested = false;\r\n this.includeCurrentLocation = context.hasAttribute(\"data-component-includeCurrentLocation\");\r\n this.includeCurrentLocationIcon = context.hasAttribute(\"data-component-include-current-location-icon\");\r\n this.includeHighlightInSuggestion = !context.hasAttribute(\"data-exclude-highlight\");\r\n Object.defineProperty(this, \"isCurrentLocation\", {\r\n get: (function () {\r\n return this._currentLocationSuggestion && this._currentLocationSuggestion === this.value;\r\n }).bind(this)\r\n });\r\n\r\n this.onSelect = null;\r\n }\r\n SearchAutocompleteComponent.prototype = Object.create(AutocompleteComponent.prototype, {\r\n constructor: {\r\n value: SearchAutocompleteComponent\r\n }\r\n });\r\n\r\n /**\r\n * Loads the dependencies\r\n * @method\r\n * @param {Function} callback Callback to execute when the dependencies are loaded\r\n */\r\n SearchAutocompleteComponent.prototype._loadDependencies = function (callback) {\r\n // If the dependencies hasn't been requested yet call them\r\n if (!this.dependeciesRequested) {\r\n require([\r\n \"SuggestionsEngineConfig\",\r\n \"SearchSuggestionsEngine\",\r\n \"SearchSuggestionsComponent\",\r\n \"SearchSuggestion\"\r\n ], (function (SuggestionsEngineConfig, SearchSuggestionsEngine, SearchSuggestionsComponent, SearchSuggestion) {\r\n this._engine = new SearchSuggestionsEngine(new SuggestionsEngineConfig());\r\n this._suggestionsComponent = new SearchSuggestionsComponent(this._searchField);\r\n if (this.includeCurrentLocation) {\r\n this._currentLocationSuggestion = new SearchSuggestion({ id: 0, name: \"Current Location\", cssClass: \"currentLocationSuggestion nhs-c-suggestion nhs-c-suggestion--icon\", dataAttributes: [\"data-current-location\"],\r\n icon: this.includeCurrentLocationIcon ? `
` : null\r\n });\r\n }\r\n this._suggestionsComponent.onSelect = this._onSelect.bind(this);\r\n callback();\r\n }).bind(this));\r\n this.dependeciesRequested = true; // Let me know that even when the dependencies are not loaded yet I've requested them to avoid doing it twice\r\n } else if (this._suggestionsComponent && this._engine) { // If the dependencies are there run the funcion\r\n callback();\r\n }\r\n };\r\n\r\n SearchAutocompleteComponent.prototype._onSelect = function () {\r\n if (this.onSelect instanceof Function) {\r\n this.onSelect();\r\n }\r\n };\r\n\r\n /**\r\n * removeCurrentLocation: removes the current location option from the component and sets the include current location flag to false\r\n * in order to avoid showing the current location option in further typeahead interactions.\r\n * @method\r\n */\r\n SearchAutocompleteComponent.prototype.removeCurrentLocation = function () {\r\n const currentLocationOption = this._suggestionsComponent.htmlElement.querySelector('[data-current-location]');\r\n\r\n if (!currentLocationOption) {\r\n return;\r\n }\r\n\r\n this.includeCurrentLocation = false;\r\n currentLocationOption.remove();\r\n };\r\n\r\n /**\r\n * Updates the Autocomplete Suggestions\r\n * @method\r\n * @param {Function} callback Callback\r\n */\r\n SearchAutocompleteComponent.prototype.update = function (callback) {\r\n this._loadDependencies((function () {\r\n AutocompleteComponent.prototype.update.call(this, callback); // Call the base implementation\r\n }).bind(this));\r\n };\r\n\r\n SearchAutocompleteComponent.prototype.displaySuggestions = function () {\r\n if (this.includeCurrentLocation) {\r\n this.suggestions.unshift(this._currentLocationSuggestion);\r\n }\r\n AutocompleteComponent.prototype.displaySuggestions.call(this);\r\n };\r\n\r\n SearchAutocompleteComponent.prototype.selectSuggestion = function (index) {\r\n AutocompleteComponent.prototype.selectSuggestion.call(this, index);\r\n this._searchField.setAttribute(\"data-suggestion-index\", index);\r\n };\r\n\r\n /**\r\n * Auto initializes all the components in the page\r\n * @method\r\n * @static\r\n */\r\n SearchAutocompleteComponent.initAll = function () {\r\n var searchAutocompleteComponents = document.querySelectorAll(\"[data-component=search-autocomplete]\");\r\n for (var i = 0; i < searchAutocompleteComponents.length; i++) {\r\n if (!searchAutocompleteComponents[i].searchAutocompleteComponent) {\r\n searchAutocompleteComponents[i].searchAutocompleteComponent = new SearchAutocompleteComponent(searchAutocompleteComponents[i]);\r\n }\r\n }\r\n };\r\n SearchAutocompleteComponent.initAll();\r\n return SearchAutocompleteComponent;\r\n});\r\n/**\r\n * Made with ♥ by NewHomeSource's team\r\n * Copyright (c) 2019-present, BuilderHomeSite Inc. All rights reserved.\r\n */;\n"]}