geico_design_kit 0.0.1-security.1 → 15.1.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 (109) hide show
  1. package/.babelrc +5 -0
  2. package/LICENSE +0 -0
  3. package/alt.json +33 -0
  4. package/dist/analytics.js +119 -0
  5. package/dist/appState.js +56 -0
  6. package/dist/baseComponent.js +110 -0
  7. package/dist/components/Accordion.js +312 -0
  8. package/dist/components/AddressAutoComplete.js +220 -0
  9. package/dist/components/Alert.js +145 -0
  10. package/dist/components/BackgroundPattern.js +99 -0
  11. package/dist/components/BackgroundPatternPortfolio.js +242 -0
  12. package/dist/components/ButtonSwitch.js +236 -0
  13. package/dist/components/CardSelections.js +230 -0
  14. package/dist/components/CommonQuestionsSquares.js +169 -0
  15. package/dist/components/Confirmation.js +156 -0
  16. package/dist/components/ConsolidatedSummary.js +489 -0
  17. package/dist/components/CoverageGraph.js +201 -0
  18. package/dist/components/CreditCard.js +591 -0
  19. package/dist/components/CurrencyInput.js +302 -0
  20. package/dist/components/DatePicker.js +468 -0
  21. package/dist/components/DockedMessage.js +146 -0
  22. package/dist/components/DotNavigation.js +200 -0
  23. package/dist/components/EditComponent.js +128 -0
  24. package/dist/components/EditableTable.js +113 -0
  25. package/dist/components/InPageNavigation.js +360 -0
  26. package/dist/components/Loader.js +232 -0
  27. package/dist/components/MakePayment.js +361 -0
  28. package/dist/components/Modal.js +254 -0
  29. package/dist/components/MoreInfoButton.js +227 -0
  30. package/dist/components/MultipleSelectBox.js +217 -0
  31. package/dist/components/NavigationalBox.js +161 -0
  32. package/dist/components/Navigator.js +294 -0
  33. package/dist/components/PasswordMeter.js +201 -0
  34. package/dist/components/PayPlans.js +534 -0
  35. package/dist/components/SegmentedControl.js +327 -0
  36. package/dist/components/SortableTable.js +166 -0
  37. package/dist/components/Tabs.js +1 -0
  38. package/dist/components/TextAreaCountdown.js +219 -0
  39. package/dist/components/Timeline.js +498 -0
  40. package/dist/components/TimelineFilter.js +492 -0
  41. package/dist/components/ToTopArrow.js +153 -0
  42. package/dist/components/Tooltip.js +329 -0
  43. package/dist/components/Upsell.js +168 -0
  44. package/dist/components/VIN.js +271 -0
  45. package/dist/components/ValidateForm.js +938 -0
  46. package/dist/components/ViewMoreLess.js +191 -0
  47. package/dist/components/ZipCode.js +191 -0
  48. package/dist/components/portfolio.js +99 -0
  49. package/dist/geico-design-kit.js +141 -0
  50. package/dist/global/components.js +98 -0
  51. package/dist/global/footer.js +26 -0
  52. package/dist/global/nav.js +1257 -0
  53. package/dist/services/CharacterTypeService.js +106 -0
  54. package/dist/services/UserAgentService.js +73 -0
  55. package/dist/utils.js +79 -0
  56. package/package.json +29 -3
  57. package/src/analytics.js +82 -0
  58. package/src/appState.js +56 -0
  59. package/src/baseComponent.js +156 -0
  60. package/src/components/Accordion.js +336 -0
  61. package/src/components/AddressAutoComplete.js +236 -0
  62. package/src/components/Alert.js +135 -0
  63. package/src/components/BackgroundPattern.js +96 -0
  64. package/src/components/BackgroundPatternPortfolio.js +284 -0
  65. package/src/components/ButtonSwitch.js +241 -0
  66. package/src/components/CardSelections.js +240 -0
  67. package/src/components/CommonQuestionsSquares.js +179 -0
  68. package/src/components/Confirmation.js +160 -0
  69. package/src/components/ConsolidatedSummary.js +505 -0
  70. package/src/components/CoverageGraph.js +203 -0
  71. package/src/components/CreditCard.js +595 -0
  72. package/src/components/CurrencyInput.js +321 -0
  73. package/src/components/DatePicker.js +487 -0
  74. package/src/components/DockedMessage.js +142 -0
  75. package/src/components/DotNavigation.js +206 -0
  76. package/src/components/EditComponent.js +130 -0
  77. package/src/components/EditableTable.js +106 -0
  78. package/src/components/InPageNavigation.js +391 -0
  79. package/src/components/Loader.js +272 -0
  80. package/src/components/MakePayment.js +397 -0
  81. package/src/components/Modal.js +279 -0
  82. package/src/components/MoreInfoButton.js +243 -0
  83. package/src/components/MultipleSelectBox.js +211 -0
  84. package/src/components/NavigationalBox.js +163 -0
  85. package/src/components/Navigator.js +338 -0
  86. package/src/components/PasswordMeter.js +209 -0
  87. package/src/components/PayPlans.js +604 -0
  88. package/src/components/SegmentedControl.js +365 -0
  89. package/src/components/SortableTable.js +176 -0
  90. package/src/components/Tabs.js +0 -0
  91. package/src/components/TextAreaCountdown.js +231 -0
  92. package/src/components/Timeline.js +532 -0
  93. package/src/components/TimelineFilter.js +533 -0
  94. package/src/components/ToTopArrow.js +153 -0
  95. package/src/components/Tooltip.js +344 -0
  96. package/src/components/Upsell.js +196 -0
  97. package/src/components/VIN.js +289 -0
  98. package/src/components/ValidateForm.js +1030 -0
  99. package/src/components/ViewMoreLess.js +193 -0
  100. package/src/components/ZipCode.js +193 -0
  101. package/src/components/portfolio.js +106 -0
  102. package/src/geico-design-kit.js +144 -0
  103. package/src/global/components.js +92 -0
  104. package/src/global/footer.js +25 -0
  105. package/src/global/nav.js +1457 -0
  106. package/src/services/CharacterTypeService.js +107 -0
  107. package/src/services/UserAgentService.js +59 -0
  108. package/src/utils.js +82 -0
  109. package/README.md +0 -5
@@ -0,0 +1,338 @@
1
+ import * as utils from '../../src/utils';
2
+ import baseComponent from '../../src/baseComponent';
3
+
4
+ const validateSettings = [
5
+ {
6
+ setting: "content",
7
+ isRequired: true,
8
+ validate: "type",
9
+ possibleValues: ["string", "object"],
10
+ errorMessage: ["GDK Navigator : Content must be defined and set to a DOM selector or Node"]
11
+ },
12
+ {
13
+ setting: "contentMobile",
14
+ isRequired: true,
15
+ validate: "type",
16
+ possibleValues: ["string", "object"],
17
+ errorMessage: ["GDK Navigator : Content Mobile must be defined and set to the DOM selector or Node of the mobile Navigator container HTML"]
18
+ }
19
+ ];
20
+
21
+ /**
22
+ * View More/Less Class
23
+ */
24
+ class Navigator {
25
+ /**
26
+ * These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
27
+ * @param {string|Object} content
28
+ * A reference to the component node
29
+ *
30
+ * @param {string|Object} contentMobile
31
+ * A reference to the component mobile node to toggle
32
+ *
33
+ */
34
+ constructor(options) {
35
+
36
+ console.log('Navigator initialized');
37
+
38
+ this._internalVars = {
39
+ node: null //used for current node
40
+ };
41
+
42
+ //options with defaults set
43
+ this._defaults = {
44
+
45
+ };
46
+
47
+ // Create options by extending defaults with the passed in arugments
48
+ if (options && typeof options === "object") {
49
+ this._options = baseComponent.extendDefaults(this._defaults, options);
50
+ }
51
+
52
+
53
+ //if the required options are valid set up the environment
54
+ if( baseComponent.validateSettings(this._options, validateSettings) ){
55
+ this._internalVars.contentType = baseComponent.getContentType(this);
56
+ setLocalVars.call(this);
57
+ init.call(this);
58
+ assignEvents.call(this);
59
+ setEvents.call(this);
60
+ }
61
+ }
62
+
63
+ //Public Methods
64
+
65
+ /**
66
+ * removes the node from the dom and any events attached
67
+ */
68
+ destroy(){
69
+ removeEvents.call(this);
70
+ this._internalVars.node.nextElementSibling.classList.remove('navigator-enabled');
71
+ if(document.querySelector('footer')){
72
+ document.querySelector('footer').classList.remove('navigator-page-footer');
73
+ }
74
+ this._internalVars.node.parentNode.removeChild(this._internalVars.node);
75
+ this._internalVars.nodeMobile.parentNode.removeChild(this._internalVars.nodeMobile);
76
+
77
+ //a little garbage collection
78
+ for (var variableKey in this){
79
+ if (this.hasOwnProperty(variableKey)){
80
+ delete this[variableKey];
81
+ }
82
+ }
83
+ }
84
+ }
85
+
86
+ // Private Methods
87
+ /**
88
+ * setEvents()
89
+ * Sets all the events needed for the component
90
+ */
91
+ function setEvents() {
92
+ window.addEventListener('resize', this._internalVars.assignEventsHandler);
93
+ }
94
+
95
+
96
+ /**
97
+ * removeEvents()
98
+ * removes all events from the component
99
+ */
100
+ function removeEvents() {
101
+ window.removeEventListener('resize', this._internalVars.assignEventsHandler);
102
+
103
+ this._internalVars.node.removeEventListener('mouseover', this._internalVars.openNavHandler);
104
+ this._internalVars.node.removeEventListener('mouseout', this._internalVars.closeNavHandler);
105
+
106
+ this._internalVars.navigatorMobileBarExpand.removeEventListener('click', this._internalVars.toggleDisplayHandler);
107
+ this._internalVars.navigatorMobileCollapse.removeEventListener('click', this._internalVars.toggleDisplayHandler);
108
+
109
+ this._internalVars.navigatorMobileList.lastElementChild.removeEventListener('mouseover', this._internalVars.addHoverColorHandler);
110
+
111
+ this._internalVars.navigatorMobileList.lastElementChild.removeEventListener('mouseout', this._internalVars.removeHoverColorHandler);
112
+
113
+ window.removeEventListener('scroll', this._internalVars.scrollHandler);
114
+ }
115
+
116
+ function assignEvents(){
117
+ var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
118
+
119
+ if(width > 480 && width <= 767){
120
+ closeNav.call(this);
121
+ this._internalVars.node.addEventListener('mouseover', this._internalVars.openNavHandler);
122
+ this._internalVars.node.addEventListener('mouseout', this._internalVars.closeNavHandler);
123
+ window.removeEventListener('scroll', this._internalVars.scrollHandler);
124
+ window.addEventListener('scroll', this._internalVars.scrollHandler);
125
+ }
126
+ else if(width <= 480){
127
+ this._internalVars.node.removeEventListener('mouseover', this._internalVars.openNavHandler);
128
+ this._internalVars.node.removeEventListener('mouseout', this._internalVars.closeNavHandler);
129
+
130
+ this._internalVars.navigatorMobileBarExpand.addEventListener('click', this._internalVars.toggleDisplayHandler);
131
+ this._internalVars.navigatorMobileCollapse.addEventListener('click', this._internalVars.toggleDisplayHandler);
132
+
133
+ this._internalVars.navigatorMobileList.lastElementChild.addEventListener('mouseover', this._internalVars.addHoverColorHandler);
134
+
135
+ this._internalVars.navigatorMobileList.lastElementChild.addEventListener('mouseout', this._internalVars.removeHoverColorHandler);
136
+
137
+ window.removeEventListener('scroll', this._internalVars.scrollHandler);
138
+
139
+ }
140
+ else{
141
+ openNav.call(this);
142
+ this._internalVars.node.removeEventListener('mouseover', this._internalVars.openNavHandler);
143
+ this._internalVars.node.removeEventListener('mouseout', this._internalVars.closeNavHandler);
144
+
145
+ this._internalVars.navigatorMobileBarExpand.removeEventListener('click', this._internalVars.toggleDisplayHandler);
146
+ this._internalVars.navigatorMobileCollapse.removeEventListener('click', this._internalVars.toggleDisplayHandler);
147
+
148
+ this._internalVars.navigatorMobileList.lastElementChild.removeEventListener('mouseover', this._internalVars.addHoverColorHandler);
149
+
150
+ this._internalVars.navigatorMobileList.lastElementChild.removeEventListener('mouseout', this._internalVars.removeHoverColorHandler);
151
+ window.removeEventListener('scroll', this._internalVars.scrollHandler);
152
+ window.addEventListener('scroll', this._internalVars.scrollHandler);
153
+ }
154
+ }
155
+
156
+ function addHoverColor(){
157
+ this._internalVars.navigatorMobileCollapse.querySelector('.geico-icon').classList.add('last-item-hover');
158
+ }
159
+
160
+ function removeHoverColor(){
161
+ this._internalVars.navigatorMobileCollapse.querySelector('.geico-icon').classList.remove('last-item-hover');
162
+ }
163
+
164
+ function toggleFixedScroll(){
165
+ if (document.querySelector('.navigator-enabled').getBoundingClientRect().top - 65 < 0) {
166
+ if(this._internalVars.node.classList.contains('static-scroll')&& this._internalVars.navigatorOrderedList.classList.contains('static-scroll')){
167
+ this._internalVars.node.classList.remove('static-scroll');
168
+ this._internalVars.navigatorOrderedList.classList.remove('static-scroll');
169
+ }
170
+ this._internalVars.node.classList.add('fixed-scroll');
171
+ this._internalVars.navigatorOrderedList.classList.add('fixed-scroll');
172
+ }else{
173
+ if(this._internalVars.node.classList.contains('fixed-scroll')&& this._internalVars.navigatorOrderedList.classList.contains('fixed-scroll')){
174
+ this._internalVars.node.classList.remove('fixed-scroll');
175
+ this._internalVars.navigatorOrderedList.classList.remove('fixed-scroll');
176
+ }
177
+ this._internalVars.node.classList.add('static-scroll');
178
+ this._internalVars.navigatorOrderedList.classList.add('static-scroll');
179
+ }
180
+ }
181
+
182
+ function init(){
183
+ $('.navigator-menu').slideUp();
184
+ this._internalVars.node.nextElementSibling.classList.add('navigator-enabled');
185
+
186
+ buildMobileContent.call(this);
187
+
188
+ if(this._internalVars.navigatorMobileList.querySelector('.active') == this._internalVars.navigatorMobileList.lastElementChild){
189
+ this._internalVars.navigatorMobileCollapse.querySelector('.geico-icon').classList.add('color-change');
190
+ }
191
+
192
+ if(document.querySelector('footer')){
193
+ document.querySelector('footer').classList.add('navigator-page-footer');
194
+ }
195
+ }
196
+
197
+ function buildMobileContent(){
198
+ var current = this._internalVars.navigatorActive.querySelector('a span:last-child').innerHTML;
199
+ var currentIcon = this._internalVars.navigatorActive.querySelector('.geico-icon').cloneNode(true);
200
+
201
+ if(this._internalVars.navigatorActive.classList.contains('alert')){
202
+ currentIcon.setAttribute('class', 'geico-icon icon-alert-exclamation');
203
+ }
204
+
205
+ this._internalVars.navigatorMobileBarExpand.querySelector('h3').innerHTML = current;
206
+ this._internalVars.navigatorMobileBarExpand.querySelector('.active-icon').appendChild(currentIcon);
207
+
208
+ var currentSubtext = document.createElement('P');
209
+ if(this._internalVars.navigatorActive.querySelector('p')){
210
+ var subtext = document.querySelector('.active p').innerHTML;
211
+ currentSubtext.innerHTML = subtext;
212
+ this._internalVars.navigatorMobileBarExpand.querySelector('aside').appendChild(currentSubtext);
213
+ }else if(!this._internalVars.navigatorActive.querySelector(('p'))){
214
+ this._internalVars.navigatorMobileBarExpand.querySelector('aside').classList.add('no-current-subtext');
215
+ }
216
+
217
+ for(var h=0; h < this._internalVars.navigatorOrderedList.children.length; h++){
218
+ var li = this._internalVars.navigatorOrderedList.children[h];
219
+
220
+ var div = document.createElement('div');
221
+ var a = document.createElement('a');
222
+ var span1 = document.createElement('span');
223
+ var span2 = document.createElement('span');
224
+ var span3 = document.createElement('span');
225
+
226
+ span1.setAttribute('class', li.querySelector('span:first-child').getAttribute('class'));
227
+
228
+ if(li.classList.contains('alert')){
229
+ span1.setAttribute('class', 'icon-alert-exclamation');
230
+ if(li.classList.contains('active')){
231
+ span1.classList.add('geico-icon');
232
+ }
233
+ }
234
+
235
+ if(!li.classList.contains('active')){
236
+ span1.classList.remove('geico-icon');
237
+ span1.classList.remove('geico-icon--actionable');
238
+ }
239
+ span1.classList.remove('geico-icon--dotted');
240
+
241
+
242
+
243
+ if(li.classList.contains('disabled')){
244
+ div.classList.add('disabled');
245
+ }
246
+
247
+ if(li.classList.contains('active')){
248
+ div.classList.add('active');
249
+ }
250
+
251
+ span2.appendChild(document.createTextNode(li.querySelector('a').innerText));
252
+ if(li.querySelector('p')){
253
+ var br = document.createElement('br');
254
+ var aside = document.createElement('aside');
255
+ aside.appendChild(document.createTextNode(li.querySelector('p').innerText));
256
+ span2.appendChild(br);
257
+ span2.appendChild(aside);
258
+ }else{
259
+ div.classList.add("no-subtext");
260
+ }
261
+ span3.setAttribute('class', 'icon-chevron-right');
262
+
263
+ for (var i = li.querySelector('a').attributes.length - 1; i > -1; -- i) {
264
+
265
+ var attribute = li.querySelector('a').attributes[i];
266
+ a.setAttribute(attribute.name, attribute.value);
267
+
268
+ }
269
+
270
+ a.appendChild(span1);
271
+ a.appendChild(span3);
272
+ a.appendChild(span2);
273
+
274
+
275
+ div.appendChild(a);
276
+
277
+ this._internalVars.navigatorMobileList.appendChild(div);
278
+ }
279
+ }
280
+
281
+ /* Set the width of the side navigation to 250px */
282
+ function openNav() {
283
+ if(this._internalVars.node.classList.contains('close')&& this._internalVars.navigatorOrderedList.classList.contains('close')){
284
+ this._internalVars.node.classList.remove('close');
285
+ this._internalVars.navigatorOrderedList.classList.remove('close');
286
+ }
287
+ this._internalVars.node.classList.add('open');
288
+ this._internalVars.navigatorOrderedList.classList.add('open');
289
+ }
290
+
291
+ /* Set the width of the side navigation to 0 */
292
+ function closeNav() {
293
+ if(this._internalVars.node.classList.contains('open')&& this._internalVars.navigatorOrderedList.classList.contains('open')){
294
+ this._internalVars.node.classList.remove('open');
295
+ this._internalVars.navigatorOrderedList.classList.remove('open');
296
+ }
297
+ this._internalVars.node.classList.add('close');
298
+ this._internalVars.navigatorOrderedList.classList.add('close');
299
+ }
300
+
301
+ function toggleDisplay(){
302
+ document.querySelector('.navigator-menu').classList.toggle('expanded');
303
+ $('.navigator-menu').slideToggle();
304
+ this._internalVars.navigatorMobileBarExpand.classList.toggle('hidden-sm');
305
+ }
306
+
307
+ /**
308
+ * setLocalVars()
309
+ * set local vars to the ones passed in options
310
+ */
311
+ function setLocalVars() {
312
+ if(this._internalVars.contentType === 'string') {
313
+ this._internalVars.node = document.querySelector(this._options.content);
314
+ this._internalVars.nodeMobile = document.querySelector(this._options.contentMobile);
315
+ } else if (this._internalVars.contentType === 'domNode') {
316
+ this._internalVars.node = this._options.content;
317
+ this._internalVars.nodeMobile = this._options.contentMobile;
318
+ }
319
+
320
+ this._internalVars.navigatorOrderedList = this._internalVars.node.querySelector('ol');
321
+ this._internalVars.navigatorActive = this._internalVars.node.querySelector('.active');
322
+
323
+ this._internalVars.navigatorMobileBarExpand = this._internalVars.nodeMobile.querySelector('.navigator-bar-expand');
324
+
325
+ this._internalVars.navigatorMobileMenuContainer = this._internalVars.nodeMobile.querySelector('.navigator-menu');
326
+ this._internalVars.navigatorMobileList = this._internalVars.nodeMobile.querySelector('.navigator-list');
327
+ this._internalVars.navigatorMobileCollapse = this._internalVars.nodeMobile.querySelector('.navigator-collapse');
328
+
329
+ this._internalVars.assignEventsHandler = assignEvents.bind(this);
330
+ this._internalVars.toggleDisplayHandler = toggleDisplay.bind(this);
331
+ this._internalVars.openNavHandler = openNav.bind(this);
332
+ this._internalVars.closeNavHandler = closeNav.bind(this);
333
+ this._internalVars.scrollHandler = toggleFixedScroll.bind(this);
334
+ this._internalVars.addHoverColorHandler = addHoverColor.bind(this);
335
+ this._internalVars.removeHoverColorHandler = removeHoverColor.bind(this);
336
+ }
337
+
338
+ export default Navigator;
@@ -0,0 +1,209 @@
1
+ import baseComponent from '../../src/baseComponent';
2
+
3
+ const validateSettings = [
4
+ {
5
+ setting: 'content',
6
+ isRequired: true,
7
+ validate: 'type',
8
+ possibleValues: ['string', 'object'],
9
+ errorMessage: ['GDK PasswordMeter : Content must be defined and set to a DOM selector or Node']
10
+ },
11
+ {
12
+ setting: 'fairRegex',
13
+ isRequired: true,
14
+ validate: 'type',
15
+ possibleValues: ['string', 'object'],
16
+ errorMessage: ['GDK PasswordMeter : fairRegex must be a regex string to pass into the RegExp object constructor function or a regex literal']
17
+ },
18
+ {
19
+ setting: 'strongRegex',
20
+ isRequired: true,
21
+ validate: 'type',
22
+ possibleValues: ['string', 'object'],
23
+ errorMessage: ['GDK PasswordMeter : strongRegex must be a regex string to pass into the RegExp object constructor function or a regex literal']
24
+ },
25
+ {
26
+ setting: 'weakString',
27
+ isRequired: false,
28
+ validate: 'type',
29
+ possibleValues: ['string'],
30
+ errorMessage: ['GDK PasswordMeter : weakString must be a string to specify another term instead of the default Weak']
31
+ },
32
+ {
33
+ setting: 'fairString',
34
+ isRequired: false,
35
+ validate: 'type',
36
+ possibleValues: ['string'],
37
+ errorMessage: ['GDK PasswordMeter : fairString must be a string to specify another term instead of the default Fair']
38
+ },
39
+ {
40
+ setting: 'strongString',
41
+ isRequired: false,
42
+ validate: 'type',
43
+ possibleValues: ['string'],
44
+ errorMessage: ['GDK PasswordMeter : strongString must be a string to specify another term instead of the default Strong']
45
+ },
46
+ {
47
+ setting: 'onInputChange',
48
+ isRequired: false,
49
+ validate: 'type',
50
+ possibleValues: ['function'],
51
+ errorMessage: ['GDK PasswordMeter : onInputChange must be a defined and set function']
52
+ },
53
+
54
+ ];
55
+
56
+ class PasswordMeter {
57
+ /**
58
+ * These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
59
+ * @param {string|Object} content
60
+ * A reference to the password form field container wrapping both the field and meter
61
+ *
62
+ * @param {string|Object} fairRegex
63
+ * A regex string to pass into the RegExp object constructor function or a regex literal for fair password strength
64
+ *
65
+ * @param {string|Object} strongRegex
66
+ * A regex string to pass into the RegExp object constructor function or a regex literal for strong password strength
67
+ *
68
+ * @param {string} [weakString="Weak"]
69
+ * A string to indicate a Weak password strength
70
+ *
71
+ * @param {string} [fairString="Fair"]
72
+ * A string to indicate a Fair password strength
73
+ *
74
+ * @param {string} [strongString="Strong"]
75
+ * A string to indicate a Strong password strength
76
+ *
77
+ * @param {function} [onInputChange]
78
+ * A callback function with each password character input
79
+ */
80
+ constructor(options) {
81
+ this._internalVars = {
82
+ node: null //used for current node
83
+ };
84
+
85
+ //options with defaults set
86
+ this._defaults = {
87
+ weakString: 'Weak',
88
+ fairString: 'Fair',
89
+ strongString: 'Strong'
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
+
103
+ if(!this._internalVars.meterContainerParent.getAttribute('aria-live'))
104
+ this._internalVars.meterContainerParent.setAttribute('aria-live', 'polite');
105
+ }
106
+ }
107
+
108
+ //Public Methods
109
+
110
+ /**
111
+ * getCurrentStrength()
112
+ * returns a string indicating the current password strength level
113
+ * @returns {string}
114
+ */
115
+
116
+ getCurrentStrength(){
117
+ return this._internalVars.meterContainer.getAttribute('class');
118
+ }
119
+
120
+ /**
121
+ * removes the node from the dom and any events attached
122
+ */
123
+ destroy(){
124
+ removeEvents.call(this);
125
+ this._internalVars.node.parentNode.removeChild(this._internalVars.node);
126
+
127
+ //a little garbage collection
128
+ for (var variableKey in this){
129
+ if (this.hasOwnProperty(variableKey)){
130
+ delete this[variableKey];
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ // Private Methods
137
+ function setLocalVars() {
138
+ if(this._internalVars.contentType === 'string') {
139
+ this._internalVars.node = document.querySelector(this._options.content);
140
+ } else if (this._internalVars.contentType === 'domNode') {
141
+ this._internalVars.node = this._options.content;
142
+ }
143
+
144
+ this._internalVars.meterContainerParent = this._internalVars.node.querySelector('.password-meter-container');
145
+ this._internalVars.meterContainer = this._internalVars.node.querySelector('.password-meter-container > div');
146
+ this._internalVars.passwordField = this._internalVars.node.querySelector('input[type="password"]');
147
+ this._internalVars.weakBar = this._internalVars.meterContainer.querySelector('.weak');
148
+ this._internalVars.fairBar = this._internalVars.meterContainer.querySelector('.fair');
149
+ this._internalVars.strongBar = this._internalVars.meterContainer.querySelector('.strong');
150
+ this._internalVars.handler = meterChange.bind(this);
151
+
152
+ this._internalVars.strongRegexObj = new RegExp(this._options.strongRegex);
153
+ if(this._options.strongRegex.toString().charAt(0)==='/'){
154
+ this._internalVars.strongRegexObj = this._options.strongRegex;
155
+ }
156
+ this._internalVars.fairRegexObj = new RegExp(this._options.fairRegex);
157
+ if(this._options.fairRegex.toString().charAt(0)==='/'){
158
+ this._internalVars.fairRegexObj = this._options.fairRegex;
159
+ }
160
+
161
+ }
162
+
163
+ /**
164
+ * setEvents()
165
+ * Sets all the events needed for the component
166
+ */
167
+ function setEvents() {
168
+ this._internalVars.passwordField.addEventListener('input', this._internalVars.handler);
169
+ }
170
+
171
+ function removeEvents(){
172
+ this._internalVars.passwordField.removeEventListener('input', this._internalVars.handler);
173
+ }
174
+
175
+
176
+ /**
177
+ * whatever()
178
+ * whatever about the function
179
+ */
180
+ function removeAll(){
181
+ this._internalVars.meterContainer.removeAttribute('class');
182
+ }
183
+
184
+ function meterChange(e){
185
+ if(this._internalVars.strongRegexObj.test(e.target.value)){
186
+ removeAll.call(this);
187
+ this._internalVars.meterContainer.classList.add('password-strong');
188
+ this._internalVars.strongBar.innerHTML = this._options.strongString;
189
+ }
190
+ else if(this._internalVars.fairRegexObj.test(e.target.value)){
191
+ removeAll.call(this);
192
+ this._internalVars.meterContainer.classList.add('password-fair');
193
+ this._internalVars.fairBar.innerHTML = this._options.fairString;
194
+ }
195
+ else if(e.target.value===""){
196
+ removeAll.call(this);
197
+ }
198
+ else{
199
+ removeAll.call(this);
200
+ this._internalVars.meterContainer.classList.add('password-weak');
201
+ this._internalVars.weakBar.innerHTML = this._options.weakString;
202
+ }
203
+
204
+ if(this._options.onInputChange){
205
+ this._options.onInputChange();
206
+ }
207
+ }
208
+
209
+ export default PasswordMeter;