geico-design-kit 7.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geico-design-kit might be problematic. Click here for more details.

Files changed (107) hide show
  1. package/.babelrc +5 -0
  2. package/LICENSE +0 -0
  3. package/dist/analytics.js +119 -0
  4. package/dist/appState.js +56 -0
  5. package/dist/baseComponent.js +110 -0
  6. package/dist/components/Accordion.js +312 -0
  7. package/dist/components/AddressAutoComplete.js +220 -0
  8. package/dist/components/Alert.js +145 -0
  9. package/dist/components/BackgroundPattern.js +99 -0
  10. package/dist/components/BackgroundPatternPortfolio.js +242 -0
  11. package/dist/components/ButtonSwitch.js +236 -0
  12. package/dist/components/CardSelections.js +230 -0
  13. package/dist/components/CommonQuestionsSquares.js +169 -0
  14. package/dist/components/Confirmation.js +156 -0
  15. package/dist/components/ConsolidatedSummary.js +489 -0
  16. package/dist/components/CoverageGraph.js +201 -0
  17. package/dist/components/CreditCard.js +591 -0
  18. package/dist/components/CurrencyInput.js +302 -0
  19. package/dist/components/DatePicker.js +468 -0
  20. package/dist/components/DockedMessage.js +146 -0
  21. package/dist/components/DotNavigation.js +200 -0
  22. package/dist/components/EditComponent.js +128 -0
  23. package/dist/components/EditableTable.js +113 -0
  24. package/dist/components/InPageNavigation.js +360 -0
  25. package/dist/components/Loader.js +232 -0
  26. package/dist/components/MakePayment.js +361 -0
  27. package/dist/components/Modal.js +254 -0
  28. package/dist/components/MoreInfoButton.js +227 -0
  29. package/dist/components/MultipleSelectBox.js +217 -0
  30. package/dist/components/NavigationalBox.js +161 -0
  31. package/dist/components/Navigator.js +294 -0
  32. package/dist/components/PasswordMeter.js +201 -0
  33. package/dist/components/PayPlans.js +534 -0
  34. package/dist/components/SegmentedControl.js +327 -0
  35. package/dist/components/SortableTable.js +166 -0
  36. package/dist/components/Tabs.js +1 -0
  37. package/dist/components/TextAreaCountdown.js +219 -0
  38. package/dist/components/Timeline.js +498 -0
  39. package/dist/components/TimelineFilter.js +492 -0
  40. package/dist/components/ToTopArrow.js +153 -0
  41. package/dist/components/Tooltip.js +329 -0
  42. package/dist/components/Upsell.js +168 -0
  43. package/dist/components/VIN.js +271 -0
  44. package/dist/components/ValidateForm.js +938 -0
  45. package/dist/components/ViewMoreLess.js +191 -0
  46. package/dist/components/ZipCode.js +191 -0
  47. package/dist/components/portfolio.js +99 -0
  48. package/dist/geico-design-kit.js +141 -0
  49. package/dist/global/components.js +98 -0
  50. package/dist/global/footer.js +26 -0
  51. package/dist/global/nav.js +1257 -0
  52. package/dist/services/CharacterTypeService.js +106 -0
  53. package/dist/services/UserAgentService.js +73 -0
  54. package/dist/utils.js +79 -0
  55. package/package.json +32 -0
  56. package/src/analytics.js +82 -0
  57. package/src/appState.js +56 -0
  58. package/src/baseComponent.js +156 -0
  59. package/src/components/Accordion.js +336 -0
  60. package/src/components/AddressAutoComplete.js +236 -0
  61. package/src/components/Alert.js +135 -0
  62. package/src/components/BackgroundPattern.js +96 -0
  63. package/src/components/BackgroundPatternPortfolio.js +284 -0
  64. package/src/components/ButtonSwitch.js +241 -0
  65. package/src/components/CardSelections.js +240 -0
  66. package/src/components/CommonQuestionsSquares.js +179 -0
  67. package/src/components/Confirmation.js +160 -0
  68. package/src/components/ConsolidatedSummary.js +505 -0
  69. package/src/components/CoverageGraph.js +203 -0
  70. package/src/components/CreditCard.js +595 -0
  71. package/src/components/CurrencyInput.js +321 -0
  72. package/src/components/DatePicker.js +487 -0
  73. package/src/components/DockedMessage.js +142 -0
  74. package/src/components/DotNavigation.js +206 -0
  75. package/src/components/EditComponent.js +130 -0
  76. package/src/components/EditableTable.js +106 -0
  77. package/src/components/InPageNavigation.js +391 -0
  78. package/src/components/Loader.js +272 -0
  79. package/src/components/MakePayment.js +397 -0
  80. package/src/components/Modal.js +279 -0
  81. package/src/components/MoreInfoButton.js +243 -0
  82. package/src/components/MultipleSelectBox.js +211 -0
  83. package/src/components/NavigationalBox.js +163 -0
  84. package/src/components/Navigator.js +338 -0
  85. package/src/components/PasswordMeter.js +209 -0
  86. package/src/components/PayPlans.js +604 -0
  87. package/src/components/SegmentedControl.js +365 -0
  88. package/src/components/SortableTable.js +176 -0
  89. package/src/components/Tabs.js +0 -0
  90. package/src/components/TextAreaCountdown.js +231 -0
  91. package/src/components/Timeline.js +532 -0
  92. package/src/components/TimelineFilter.js +533 -0
  93. package/src/components/ToTopArrow.js +153 -0
  94. package/src/components/Tooltip.js +344 -0
  95. package/src/components/Upsell.js +196 -0
  96. package/src/components/VIN.js +289 -0
  97. package/src/components/ValidateForm.js +1030 -0
  98. package/src/components/ViewMoreLess.js +193 -0
  99. package/src/components/ZipCode.js +193 -0
  100. package/src/components/portfolio.js +106 -0
  101. package/src/geico-design-kit.js +144 -0
  102. package/src/global/components.js +92 -0
  103. package/src/global/footer.js +25 -0
  104. package/src/global/nav.js +1457 -0
  105. package/src/services/CharacterTypeService.js +107 -0
  106. package/src/services/UserAgentService.js +59 -0
  107. package/src/utils.js +82 -0
@@ -0,0 +1,336 @@
1
+ import baseComponent from '../../src/baseComponent';
2
+ import UserAgentService from '../../src/services/UserAgentService';
3
+
4
+ const validateSettings = [
5
+ {
6
+ setting : "content",
7
+ isRequired : true,
8
+ validate : "type",
9
+ possibleValues : ["string","object"],
10
+ errorMessage : ["GDK Accordion : Content must be defined and set to a DOM selector or Node"]
11
+ },
12
+ {
13
+ setting : "initiallyOpenedElement",
14
+ isRequired : false,
15
+ validate : "type",
16
+ possibleValues : ["string","object"],
17
+ errorMessage : ["GDK Accordion : Content must be defined and set to a DOM selector or Node"]
18
+ },
19
+ {
20
+ setting : "shouldCloseOthers",
21
+ isRequired : false,
22
+ validate : "type",
23
+ possibleValues : ["boolean"],
24
+ errorMessage : ["GDK Accordion : shouldCloseOthers must be set to a boolean"]
25
+ },
26
+ /**
27
+ * Design Kit DEVELOPERS USE ONLY:
28
+ *
29
+ * forceOpenSingleAccordionElement is to be used only when there is a single, forced opened element of the accordion
30
+ * Case Study: Mobile Navigation when there is a single Tier 1 element, which is forcefully opened in the mobile view,
31
+ * so it won't require additional click to open when user use the navigation.
32
+ *
33
+ * NOTE: The force-open element DO NOT have accordion functionality to retract and stays expanded at all times.
34
+ */
35
+ {
36
+ setting : "forceOpenSingleAccordionElement",
37
+ isRequired : false,
38
+ validate : "type",
39
+ possibleValues : ["boolean"],
40
+ errorMessage : ["GDK Accordion : forceOpenSingleAccordionElement must be set as a boolean"]
41
+ },
42
+ {
43
+ setting : "accordionOpenClicked",
44
+ isRequired : false,
45
+ validate : "type",
46
+ possibleValues : ["function"],
47
+ errorMessage : ["GDK Accordion : accordionOpenClicked must be a function"]
48
+ },
49
+ {
50
+ setting : "accordionCloseClicked",
51
+ isRequired : false,
52
+ validate : "type",
53
+ possibleValues : ["function"],
54
+ errorMessage : ["GDK Accordion : accordionCloseClicked must be a function"]
55
+ }
56
+ ];
57
+
58
+ class Accordion{
59
+
60
+ /**
61
+ * These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
62
+ * @param {string|Object} content
63
+ * A reference to the html accordion node
64
+ *
65
+ * @param {string|Object} initiallyOpenedElement
66
+ * A reference to the html accordion li tag element that should be opened on start
67
+ *
68
+ * @param {boolean} [shouldCloseOthers="true"]
69
+ * Used to set URL target to open in same page or in a new window/tab
70
+ *
71
+ * @param {function} [accordionOpenClicked]
72
+ * A callback function that gets fired when an accordion tab opens up. Param currentNode is optional and refers to the target clicked.
73
+ *
74
+ * @param {function} [accordionCloseClicked]
75
+ * A callback function that gets fired when an accordion tab closes. Param currentNode is optional and refers to the target clicked.
76
+ */
77
+ constructor(options) {
78
+
79
+ this._internalVars = {
80
+ node: null,//used for content item
81
+ headline:null,
82
+ contentContainer:null,
83
+ content:null
84
+ };
85
+
86
+ //options with defaults set
87
+ this._defaults = {
88
+ shouldCloseOthers : true,
89
+ forceOpenSingleAccordionElement : false
90
+ };
91
+
92
+ // Create options by extending defaults with the passed in arugments
93
+ if (options && typeof options === "object") {
94
+ this._options = baseComponent.extendDefaults(this._defaults, options);
95
+ }
96
+
97
+ //if the required options are valid set up the environment
98
+ if( baseComponent.validateSettings(this._options, validateSettings) ){
99
+ this._internalVars.contentType = baseComponent.getContentType(this);
100
+ setLocalVars.call(this);
101
+ setEvents.call(this);
102
+ if (this._options.initiallyOpenedElement) {
103
+ openInitialElements.call(this);
104
+ }
105
+ let allAccordionHeadlines = this._internalVars.node.querySelectorAll('.accordion-headline');
106
+ Array.prototype.forEach.call(allAccordionHeadlines, function(el, i){
107
+ if(!el.getAttribute('tabindex'))
108
+ el.setAttribute('tabindex', '0');
109
+
110
+ el.setAttribute('role', 'button');
111
+ });
112
+ }
113
+
114
+ window.addEventListener('resize', () => {
115
+ //handleResize.call(this);
116
+ });
117
+ }
118
+
119
+ //Public Methods
120
+
121
+ /**
122
+ * destroy()
123
+ * removes the node from the dom and any events attached
124
+ */
125
+ destroy(){
126
+ removeEvents.call(this);
127
+ this._internalVars.node.parentNode.removeChild(this._internalVars.node);
128
+
129
+ //a little garbage collection
130
+ for (var variableKey in this){
131
+ if (this.hasOwnProperty(variableKey)){
132
+ delete this[variableKey];
133
+ }
134
+ }
135
+ }
136
+
137
+ }
138
+
139
+ // Private Methods
140
+ /**
141
+ * openInitialElement()
142
+ * a private method which is only invoked when the initiallyOpenedElement property is set.
143
+ */
144
+ function openInitialElements() {
145
+ let element;
146
+ if(typeof this._options.initiallyOpenedElement === 'string') {
147
+ element = this._internalVars.node.querySelector(this._options.initiallyOpenedElement);
148
+ openAccordionElement.call(this, element);
149
+ } else if(typeof this._options.initiallyOpenedElement === 'object') {
150
+ element = this._options.initiallyOpenedElement;
151
+ openAccordionElement.call(this, element);
152
+ }
153
+ }
154
+
155
+ /**
156
+ * setEvents()
157
+ * Sets all the events needed for the component
158
+ */
159
+ function setEvents() {
160
+
161
+ if (this._internalVars.node.childElementCount == 1 && this._options.forceOpenSingleAccordionElement) {
162
+ console.log("The single element will be forced opened");
163
+ forceOpenAccordion(this._internalVars.node.children[0]);
164
+ } else {
165
+ const eventName = UserAgentService._clickEventName();
166
+
167
+ Array.prototype.forEach.call(this._internalVars.headline, (el, i)=>{
168
+ el.addEventListener(eventName,this._internalVars.handler);
169
+ el.addEventListener("keyup", this._internalVars.handler);
170
+ el.addEventListener('keyup', function(e){
171
+ if(e.shiftKey && e.keyCode == 9 || e.keyCode == 9){
172
+ el.classList.add('keyboard-focus');
173
+ }
174
+
175
+ });
176
+ el.addEventListener('blur', function(e){
177
+ el.classList.remove('keyboard-focus');
178
+
179
+
180
+ });
181
+ });
182
+ }
183
+ }
184
+
185
+
186
+ /**
187
+ * removeEvents()
188
+ * removes all events from the component
189
+ */
190
+ function removeEvents() {
191
+ const eventName = UserAgentService._clickEventName();
192
+
193
+ Array.prototype.forEach.call(this._internalVars.headline, (el, i)=>{
194
+ el.removeEventListener(eventName,this._internalVars.handler);
195
+ });
196
+ }
197
+
198
+ /**
199
+ * toggleAccordion()
200
+ * opens or closes an accordions content
201
+ *
202
+ * @param {Object} node DOM node that was clicked
203
+ */
204
+ function toggleAccordion(el) {
205
+ if(el.type == 'keypress' || el.type == 'keyup' && ((el.keyCode || el.which) != 13)){
206
+ return;
207
+ }
208
+
209
+ let currentNode = el.currentTarget;
210
+ let parentNode = currentNode.parentNode;
211
+ let contentContainer = parentNode.querySelector(".accordion-content-container");
212
+ let content = contentContainer.querySelector(".accordion-content");
213
+
214
+ if(!contentContainer.parentNode.classList.contains('open')){
215
+ if (this._options.accordionOpenClicked)
216
+ if(this._options.accordionOpenClicked(currentNode)===false) return false;
217
+ if(this._options.shouldCloseOthers){
218
+ closeAccordions.call(this);
219
+ }
220
+
221
+ parentNode.classList.add("open");
222
+ $(contentContainer).slideDown();
223
+ currentNode.setAttribute('aria-expanded', 'true');
224
+ contentContainer.setAttribute('aria-hidden', 'false');
225
+ } else {
226
+ if (this._options.accordionCloseClicked)
227
+ if(this._options.accordionCloseClicked(currentNode)===false) return false;
228
+ parentNode.classList.remove("open");
229
+ $(contentContainer).slideUp();
230
+ currentNode.setAttribute('aria-expanded', 'false');
231
+ contentContainer.setAttribute('aria-hidden', 'true');
232
+ }
233
+
234
+ }
235
+
236
+ /**
237
+ * openAccordionElement(element)
238
+ * @param element
239
+ * @returns {boolean}
240
+ *
241
+ * private method to simply open the element that have been passed as parameter (no events)
242
+ */
243
+ function openAccordionElement(element) {
244
+ let contentContainer = element.querySelector(".accordion-content-container");
245
+ let nodeHeadline = element.querySelector('.accordion-headline');
246
+ let content = contentContainer.querySelector(".accordion-content");
247
+
248
+ if(!contentContainer.parentNode.classList.contains('open')){
249
+ if (this._options.accordionOpenClicked)
250
+ if(this._options.accordionOpenClicked(nodeHeadline)===false) return false;
251
+ if(this._options.shouldCloseOthers){
252
+ closeAccordions.call(this);
253
+ }
254
+
255
+ $(contentContainer).slideDown();
256
+ element.classList.add("open");
257
+ nodeHeadline.setAttribute('aria-expanded', 'true');
258
+ contentContainer.setAttribute('aria-hidden', 'false');
259
+ } else {
260
+ if (this._options.accordionCloseClicked)
261
+ if(this._options.accordionCloseClicked(nodeHeadline)===false) return false;
262
+ element.classList.remove("open");
263
+ $(contentContainer).slideUp();
264
+ nodeHeadline.setAttribute('aria-expanded', 'false');
265
+ contentContainer.setAttribute('aria-hidden', 'true');
266
+ }
267
+ }
268
+
269
+ function forceOpenAccordion(el) {
270
+ el.classList.add('force-open');
271
+ }
272
+
273
+ /**
274
+ * closeAccordions()
275
+ * closes all open accordains
276
+ */
277
+ function closeAccordions() {
278
+
279
+ let openAccordians = this._internalVars.node.parentNode.querySelectorAll(".accordion > li.open");
280
+ Array.prototype.forEach.call(openAccordians, (el, i)=>{
281
+ el.classList.remove("open");
282
+ let contentContainer = el.querySelector(".accordion-content-container");
283
+ el.querySelector('.accordion-headline').setAttribute('aria-expanded', 'false');
284
+ contentContainer.setAttribute('aria-hidden', 'true');
285
+ $(contentContainer).slideUp();
286
+ });
287
+
288
+ }
289
+
290
+ /**
291
+ * setLocalVars()
292
+ * recalulates the max height when you resize the browser
293
+ */
294
+ function handleResize() {
295
+ if(this._internalVars.node.parentNode){
296
+ let openAccordions = this._internalVars.node.parentNode.querySelectorAll(".accordion > li.open");
297
+ Array.prototype.forEach.call(openAccordions, (el, i)=>{
298
+
299
+ let contentContainer = el.querySelector(".accordion-content-container");
300
+ let content = contentContainer.querySelector(".accordion-content");
301
+
302
+
303
+
304
+ });}
305
+ }
306
+
307
+ /**
308
+ * setLocalVars()
309
+ * set all the local vars to passed in options
310
+ */
311
+ function setLocalVars() {
312
+ //determine the type of content passed in
313
+ if(this._internalVars.contentType === 'string'){
314
+ this._internalVars.node = document.querySelector(this._options.content);
315
+ }else if(this._internalVars.contentType === 'domNode'){
316
+ this._internalVars.node = this._options.content;
317
+ }
318
+
319
+ this._internalVars.headline = this._internalVars.node.querySelectorAll(".accordion-headline");
320
+ let allLIAccordions = this._internalVars.node.parentNode.querySelectorAll(".accordion > li");
321
+
322
+ Array.prototype.forEach.call(allLIAccordions, (el, i)=>{
323
+ if(el.classList.contains('open')){
324
+ el.querySelector('.accordion-headline').setAttribute('aria-expanded', 'true');
325
+ el.querySelector('.accordion-content-container').setAttribute('aria-hidden', 'false');
326
+ }else{
327
+ el.querySelector('.accordion-headline').setAttribute('aria-expanded', 'false');
328
+ el.querySelector('.accordion-content-container').setAttribute('aria-hidden', 'true');
329
+ }
330
+ });
331
+
332
+ this._internalVars.handler = toggleAccordion.bind(this);
333
+ }
334
+
335
+
336
+ export default Accordion;
@@ -0,0 +1,236 @@
1
+ //Require static assets
2
+
3
+ /*
4
+ Problems:
5
+ 1) Requiring a specific ID – The code as-is requires a specific ID for the search field (code: let input = document.querySelector('#address-search-field');). This requires that we only use 1 instance of this address autocomplete on the screen at one time and forces us to use specific IDs. I’ve complained about this pattern repeatedly over the last couple years and it still seems to be the go to solution for the design team implementations of things. (NOTE: it also requires specific IDs for each and every field of the address that directly match data coming back from google’s apis.)
6
+ 2) The implementation doesn’t seem to keep in mind anything related to single-page application design (regardless of technology):
7
+ a. The implementation requires a global javascript function to be present at page load time.
8
+ b. It presumes to know what the IDs and types of all the input fields are and auto-populates them with no ability to notify client code when this has occurred. This screws up any kind of data binding technology (angular, knockout, etc)
9
+ 3) It does not seem to include Zip +4 (which it looks like the Google APIs don’t return)
10
+ 4) It hard codes English text (code: message.innerHTML = 'No Results Found';)
11
+ 5) It watches the entire document body for changes to see if a DOM node is inserted. (code: document.body.addEventListener('DOMNodeInserted', function (event)…). That can’t possibly be necessary.
12
+
13
+ Questions:
14
+ 1) Is this supposed to be the new way all addresses are entered in the system, or just an optional component for teams to use? (did you talk to multiple teams to gather requirements or was this just implemented at the request of one team?)
15
+ */
16
+ import baseComponent from '../../src/baseComponent';
17
+ import UserAgentService from '../../src/services/UserAgentService';
18
+
19
+
20
+ const validateSettings = [
21
+ {
22
+ setting: "content",
23
+ isRequired: true,
24
+ validate: "type",
25
+ possibleValues: ["string", "object"],
26
+ errorMessage: ["GDK AddressAutoComplete : Content must be defined and set to a DOM selector or Node"]
27
+ }
28
+ ];
29
+
30
+ const ieVersion = UserAgentService._detectIE();
31
+
32
+ let ValueSelected = false;
33
+ let selector;
34
+ let event;
35
+
36
+ if(ieVersion) {
37
+ //set event for IE
38
+ console.log('This is the Windows IE Setup: ' + ieVersion);
39
+ event = document.createEvent('HTMLEvents');
40
+ event.initEvent('gdk-address-updated', true, true);
41
+ } else {
42
+ //set event for non IE
43
+ event = new Event('gdk-address-updated');
44
+ }
45
+
46
+
47
+
48
+ class AddressAutoComplete {
49
+
50
+
51
+ constructor(options) {
52
+
53
+ this._internalVars = {
54
+ node: null//used for content item
55
+ };
56
+
57
+ //options with defaults set
58
+ this._defaults = {};
59
+
60
+ // Create options by extending defaults with the passed in arugments
61
+ if (options && typeof options === "object") {
62
+ this._options = baseComponent.extendDefaults(this._defaults, options);
63
+ }
64
+
65
+ //if the required options are valid set up the environment
66
+ if (baseComponent.validateSettings(this._options, validateSettings)) {
67
+ if (document.querySelector(this._options.content)) {
68
+ selector = this._options.content;
69
+ this._internalVars.contentType = baseComponent.getContentType(this);
70
+ setLocalVars.call(this);
71
+ setEvents.call(this);
72
+ init.call(this);
73
+ }
74
+ }
75
+
76
+
77
+ }
78
+
79
+ //Public Methods
80
+
81
+ // Bias the autocomplete object to the user's geographical location,
82
+ // as supplied by the browser's 'navigator.geolocation' object.
83
+ geolocate() {
84
+ if (navigator.geolocation) {
85
+ navigator.geolocation.getCurrentPosition(function (position) {
86
+ let geolocation = {
87
+ lat: position.coords.latitude,
88
+ lng: position.coords.longitude
89
+ };
90
+ let circle = new google.maps.Circle({
91
+ center: geolocation,
92
+ radius: position.coords.accuracy
93
+ });
94
+ this.autoComplete.setBounds(circle.getBounds());
95
+ });
96
+ }
97
+ }
98
+
99
+ getAddressObject() {
100
+ let formattedAddress = {
101
+ formatted_address: this._internalVars.placesObject.formatted_address,
102
+ address_components: this._internalVars.placesObject.address_components,
103
+ geolocation: this._internalVars.placesObject.geometry.location
104
+ };
105
+ return formattedAddress;
106
+ }
107
+ }
108
+
109
+
110
+ /**
111
+ * setLocalVars()
112
+ * set all the local vars to passed in options
113
+ */
114
+ function setLocalVars() {
115
+ //determine the type of content passed in
116
+ if (this._internalVars.contentType === 'string') {
117
+ this._internalVars.node = document.querySelector(this._options.content);
118
+ } else if (this._internalVars.contentType === 'domNode') {
119
+ this._internalVars.node = this._options.content;
120
+ }
121
+ this._internalVars.addressSearchField = this._internalVars.node.querySelector('.address-search-field');
122
+ this._internalVars.searchClearBtn = this._internalVars.node.querySelector('.btn--search-clear');
123
+
124
+ // Create the autocomplete object, restricting the search to geographical
125
+ // location types.
126
+ this.autoComplete = new google.maps.places.Autocomplete(
127
+ /** @type {!HTMLInputElement} */(this._internalVars.addressSearchField), {types: ['geocode']});
128
+ this._internalVars.componentForm = {
129
+ street_number: 'short_name',
130
+ route: 'long_name',
131
+ locality: 'long_name',
132
+ administrative_area_level_1: 'short_name',
133
+ country: 'long_name',
134
+ postal_code: 'short_name'
135
+ };
136
+ this._internalVars.placesObject = {};
137
+ }
138
+
139
+ /**
140
+ * setEvents()
141
+ * Sets all the events needed for the component
142
+ */
143
+ function setEvents() {
144
+ this._internalVars.searchClearBtn.addEventListener('click', clearSearch.bind(this));
145
+ this._internalVars.addressSearchField.addEventListener('input', toggleClearButton.bind(this));
146
+ }
147
+
148
+ function clearSearch() {
149
+ this._internalVars.addressSearchField.value = '';
150
+ toggleClearButton.call(this);
151
+ }
152
+
153
+ function toggleClearButton() {
154
+
155
+ if(this._internalVars.addressSearchField.value !== '') {
156
+ this._internalVars.searchClearBtn.classList.remove('hidden');
157
+ } else {
158
+ this._internalVars.searchClearBtn.classList.add('hidden');
159
+ }
160
+
161
+ }
162
+
163
+ function init() {
164
+ console.log('stop here');
165
+ // Hide the search close button
166
+ if(this._internalVars.addressSearchField.value === '' && !this._internalVars.searchClearBtn.classList.contains('hidden')) {
167
+ this._internalVars.searchClearBtn.classList.add('hidden');
168
+ }
169
+
170
+ // When the user selects an address from the dropdown, populate the address
171
+ // fields in the form.
172
+ this.autoComplete.addListener('place_changed', fillInAddress.bind(this));
173
+
174
+ let styleInitialized = false;
175
+
176
+ if (document.querySelector(selector).querySelector('.address-search-field') !== null) {
177
+ document.querySelector(selector).querySelector('.address-search-field').addEventListener('blur', function (event) {
178
+ if (document.querySelector('.pac-container') && document.querySelector('.pac-container').children.length === 0 && event.target.value.length !== 0 && document.querySelector('.address_1').value.length === 0) {
179
+ document.querySelector('.address_1').value = event.target.value;
180
+ event.target.value = '';
181
+ }
182
+ });
183
+ }
184
+
185
+ }
186
+
187
+
188
+ function fillInAddress() {
189
+
190
+ console.log('new results :) ');
191
+
192
+ ValueSelected = true;
193
+
194
+ // Get the place details from the autocomplete object.
195
+ let place = this.autoComplete.getPlace();
196
+ this._internalVars.placesObject = place;
197
+
198
+ document.dispatchEvent(event);
199
+
200
+ // Reset All Fields
201
+ let address1Element = this._internalVars.node.querySelector('.address_1');
202
+ address1Element.value = '';
203
+ address1Element.disabled = false;
204
+ for (let component in this._internalVars.componentForm) {
205
+ if (component !== 'street_number' && component !== 'route' && this._internalVars.node.querySelector('.' + component) !== null) {
206
+ let element = this._internalVars.node.querySelector('.' + component);
207
+ element.value = '';
208
+ element.disabled = false;
209
+ }
210
+ }
211
+
212
+ // Get each component of the address from the place details
213
+ // and fill the corresponding field on the form.
214
+ for (let i = 0; i < place.address_components.length; i++) {
215
+ let addressType = place.address_components[i].types[0];
216
+ if (this._internalVars.componentForm[addressType]) {
217
+ let val = place.address_components[i][this._internalVars.componentForm[addressType]];
218
+ if (addressType === 'street_number') {
219
+ address1Element.value = val + ' ';
220
+ } else if (addressType === 'route') {
221
+ address1Element.value = address1Element.value + val;
222
+ } else {
223
+ if (this._internalVars.node.querySelector('.' + addressType)) {
224
+ this._internalVars.node.querySelector('.' + addressType).value = val;
225
+ }
226
+ }
227
+ }
228
+ }
229
+
230
+ clearSearch.call(this);
231
+
232
+ // document.querySelector(selector).value = '';
233
+ }
234
+
235
+ export default AddressAutoComplete;
236
+