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,595 @@
1
+ import baseComponent from '../../src/baseComponent';
2
+ import characterType from '../../src/services/CharacterTypeService';
3
+
4
+ const validateSettings = [
5
+ {
6
+ setting : "content",
7
+ isRequired : true,
8
+ validate : "type",
9
+ possibleValues : ["string","object"],
10
+ errorMessage : ["GDK Credit Card : Content must be defined and set to a DOM selector or Node"]
11
+ },
12
+ {
13
+ setting : "alternateCard",
14
+ isRequired : false,
15
+ validate : "type",
16
+ possibleValues : ["object"],
17
+ errorMessage : ["GDK Credit Card : alternateCard must be defined as an object"]
18
+ }
19
+ ];
20
+
21
+ /**
22
+ * CreditCard Class
23
+ */
24
+ class CreditCard{
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 div form field containing the credit card input node
29
+ *
30
+ */
31
+
32
+ constructor(options) {
33
+
34
+ this._internalVars = {
35
+
36
+ creditCards : {
37
+ americanExpress : {
38
+ prefixes : ['34', '37'],
39
+ cardFormatArray : [4,6,5],
40
+ },
41
+ visa : {
42
+ prefixes : ['4'],
43
+ cardFormatArray : [4,4,4,4],
44
+ },
45
+ mastercard : {
46
+ prefixes : ['2221-2720', '51-55'],
47
+ cardFormatArray : [4,4,4,4],
48
+ },
49
+ discover : {
50
+ prefixes : ['6011', '64', '65'],
51
+ cardFormatArray : [4,4,4,4],
52
+ }
53
+ },
54
+
55
+ maskEntry: maskEntry.bind(this)
56
+ };
57
+
58
+ //options with defaults set
59
+ this._defaults = {};
60
+
61
+ // Create options by extending defaults with the passed in arugments
62
+ if (options && typeof options === "object") {
63
+ this._options = baseComponent.extendDefaults(this._defaults, options);
64
+ }
65
+
66
+ //if the required options are valid set up the environment
67
+ if( baseComponent.validateSettings(this._options, validateSettings) ){
68
+ this._internalVars.contentType = baseComponent.getContentType(this);
69
+ setLocalVars.call(this);
70
+ setEvents.call(this);
71
+ validateAlternateCards.call(this);
72
+ }
73
+ }
74
+
75
+ //Public Methods
76
+
77
+ /**
78
+ * getCardType()
79
+ * returns the card type
80
+ * @returns {*|string}
81
+ */
82
+ getCardType() {
83
+ switch (this._internalVars.creditCardType) {
84
+ case 'default':
85
+ this._internalVars.creditCardType = 'unknown';
86
+ break;
87
+ case undefined:
88
+ this._internalVars.creditCardType = 'unknown';
89
+ break;
90
+ }
91
+ return this._internalVars.creditCardType;
92
+ }
93
+
94
+ /**
95
+ * getCardNumber()
96
+ * returns the card input value without formatting
97
+ * @returns {*|string}
98
+ */
99
+ getCardNumber() {
100
+ if (this._internalVars.maskSet === true) {
101
+ return this._internalVars.creditCardInputHidden.value.replace(/ /g, '');
102
+ } else {
103
+ return this._internalVars.creditCardInput.value.replace(/ /g, '');
104
+ }
105
+ }
106
+
107
+ /**
108
+ * setCardNumber(cardNumber)
109
+ * sets the card number
110
+ * @param {number} cardNumber
111
+ * The card number to be populated in the input field
112
+ */
113
+ setCardNumber(cardNumber) {
114
+ if(cardNumber && typeof cardNumber === "number") {
115
+ this._internalVars.creditCardInput.value = cardNumber;
116
+ change.call(this);
117
+ maskEntry.call(this);
118
+ }
119
+ }
120
+
121
+ /**
122
+ * isComplete()
123
+ * returns boolean indicating a complete and recognized value
124
+ * @returns {boolean}
125
+ */
126
+ isComplete() {
127
+ this.getCardType();
128
+ if (this._internalVars.creditCardType !== 'unknown' ) {
129
+ if (this._internalVars.creditCardInput.value.length === parseInt(this._internalVars.creditCardInput.getAttribute('maxlength'))) {
130
+ return true;
131
+ } else {
132
+ return false;
133
+ }
134
+ } else {
135
+ return false;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * destroy()
141
+ * removes the node from the dom and any events attached
142
+ */
143
+ destroy(){
144
+ removeEvents.call(this);
145
+ this._internalVars.node.parentNode.removeChild(this._internalVars.node);
146
+
147
+ //a little garbage collection
148
+ for (var variableKey in this){
149
+ if (this.hasOwnProperty(variableKey)){
150
+ delete this[variableKey];
151
+ }
152
+ }
153
+ }
154
+
155
+ }
156
+
157
+ // Private Methods
158
+ /**
159
+ * setEvents()
160
+ * Sets all the events needed for the component
161
+ */
162
+ function setEvents() {
163
+ this._internalVars.creditCardInput.addEventListener('paste', paste.bind(this));
164
+ this._internalVars.creditCardInput.addEventListener('keydown', validateKeyPress.bind(this));
165
+ this._internalVars.creditCardInput.addEventListener('keyup', checkValue.bind(this));
166
+ this._internalVars.creditCardInput.addEventListener('input', change.bind(this));
167
+ this._internalVars.creditCardInput.addEventListener('blur', this._internalVars.maskEntry);
168
+ }
169
+
170
+
171
+ /**
172
+ * removeEvents()
173
+ * removes all events from the component
174
+ */
175
+ function removeEvents() {
176
+ this._internalVars.creditCardInput.removeEventListener('paste', paste.bind(this));
177
+ this._internalVars.creditCardInput.removeEventListener('keydown', validateKeyPress.bind(this));
178
+ this._internalVars.creditCardInput.removeEventListener('keyup', checkValue.bind(this));
179
+ this._internalVars.creditCardInput.removeEventListener('input', change.bind(this));
180
+ this._internalVars.creditCardInput.removeEventListener('blur', this._internalVars.maskEntry);
181
+ }
182
+
183
+ function parseRange(range) {
184
+ let hyphenPosition = range.indexOf('-');
185
+ let beginningPoint = range.substring(0, hyphenPosition);
186
+ let endPoint = range.substring(hyphenPosition + 1, range.length);
187
+ return {
188
+ "hyphenPosition": hyphenPosition,
189
+ "beginningPoint": beginningPoint,
190
+ "endPoint": endPoint
191
+ };
192
+ }
193
+
194
+ /**
195
+ * validateAlternateCards()
196
+ * validates the alternate card object and properties
197
+ */
198
+ function validateAlternateCards() {
199
+ //check if alternate cards have been set
200
+ if(this._options.alternateCard) {
201
+ //Loop through alternateCard object
202
+ for(var alternateCard in this._options.alternateCard) {
203
+ //check if alternateCard object has prefixes & cardFormatArray properties
204
+ if(this._options.alternateCard[alternateCard].prefixes && this._options.alternateCard[alternateCard].cardFormatArray) {
205
+ // Loop through prefixes property
206
+ for(var cardDigits in this._options.alternateCard[alternateCard].prefixes) {
207
+ //check if values are the correct type
208
+ if (typeof this._options.alternateCard[alternateCard].prefixes[cardDigits] !== 'string') {
209
+ this._options.alternateCard[alternateCard].valid = false;
210
+ } else {
211
+ if(this._options.alternateCard[alternateCard].prefixes[cardDigits].indexOf('-') >= 0) {
212
+ let parsedRange = parseRange.call(this, this._options.alternateCard[alternateCard].prefixes[cardDigits]);
213
+ if((parsedRange.beginningPoint > 0) === false || (parsedRange.endPoint > 0) === false) {
214
+ this._options.alternateCard[alternateCard].valid = false;
215
+ }
216
+ } else {
217
+ if ((this._options.alternateCard[alternateCard].prefixes[cardDigits] > 0) === false) {
218
+ this._options.alternateCard[alternateCard].valid = false;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ // Loop through cardFormatArray property
224
+ for (var formatArray in this._options.alternateCard[alternateCard].cardFormatArray) {
225
+ // check if value is the correct type
226
+ if (typeof this._options.alternateCard[alternateCard].cardFormatArray[formatArray] !== 'number') {
227
+ this._options.alternateCard[alternateCard].valid = false;
228
+ } else if (this._options.alternateCard[alternateCard].cardFormatArray[formatArray] < 0) {
229
+ this._options.alternateCard[alternateCard].valid = false;
230
+ }
231
+ }
232
+ } else {
233
+ this._options.alternateCard[alternateCard].valid = false;
234
+ }
235
+ // Set valid status if not defined as false
236
+ if(this._options.alternateCard[alternateCard].valid === undefined) {
237
+ this._options.alternateCard[alternateCard].valid = true;
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ /**
244
+ * paste(event)
245
+ * @param event
246
+ * removes non-numeric characters and formats numeric characters
247
+ */
248
+ function paste(event) {
249
+ let currentLength = this._internalVars.creditCardInput.value.length,
250
+ //currentLengthEndSpace,
251
+ endLength,
252
+ endLengthEndSpace,
253
+ caretPos = this._internalVars.creditCardInput.selectionStart,
254
+ pasteLength,
255
+ spaces = 0;
256
+ //allow time for value to be recognized
257
+ var delay = setTimeout(pasteComplete.bind(this), 100);
258
+ function pasteComplete() {
259
+ //remove non-numeric characters
260
+ this._internalVars.creditCardInput.value = this._internalVars.creditCardInput.value.replace(/\D/g,'');
261
+ change.call(this);
262
+ endLength = this._internalVars.creditCardInput.value.length;
263
+
264
+ for(var ind = 0; ind < this._internalVars.sequenceArray.length; ind++) {
265
+ if (endLength === this._internalVars.sequenceArray[ind] + (ind + 1)) {
266
+ endLengthEndSpace = true;
267
+ break;
268
+ } else {
269
+ endLengthEndSpace = false;
270
+ }
271
+ }
272
+ if (endLengthEndSpace === true) {
273
+ endLength = endLength - 1;
274
+ }
275
+ pasteLength = endLength - currentLength;
276
+ for(var index = 0; index < this._internalVars.sequenceArray.length; index++) {
277
+ if (caretPos <= this._internalVars.sequenceArray[index] + index) {
278
+ if (caretPos + pasteLength >= this._internalVars.sequenceArray[index] + index) {
279
+ spaces = spaces + 1;
280
+ }
281
+ }
282
+ }
283
+
284
+ let position = caretPos + pasteLength + spaces;
285
+
286
+ //set cursor position
287
+ this._internalVars.creditCardInput.setSelectionRange(position, position);
288
+ }
289
+ }
290
+
291
+ /**
292
+ * validateKeyPress(event)
293
+ * @param event
294
+ * restrict non-numeric characters
295
+ */
296
+ function validateKeyPress(event) {
297
+ let isValidCharacter = false;
298
+ const validCharacterTypes = ['number', 'tab', 'enter', 'minimize', 'copy', 'paste', 'delete', 'home', 'end', 'left arrow', 'up arrow', 'right arrow', 'down arrow', 'backspace'];
299
+
300
+ Array.prototype.forEach.call(validCharacterTypes, (type) => {
301
+ if(characterType._getCharacterType(event) === type) {
302
+ isValidCharacter = true;
303
+ }
304
+ });
305
+ if(characterType._getCharacterType(event) === 'n/a') {
306
+ let entryArray = this._internalVars.creditCardInput.value.split('');
307
+ let convertedArray = [];
308
+
309
+ Array.prototype.forEach.call(entryArray, (el, i)=> {
310
+ if (el === '0' || el === '1' || el === '2' || el === '3' || el === '4' || el === '5' || el === '6' || el === '7' || el === '8' || el === '9') {} else {
311
+ convertedArray.push(el);
312
+ }
313
+ });
314
+
315
+ let entry = convertedArray.join('');
316
+ this._internalVars.creditCardInput.value = entry;
317
+
318
+ }
319
+
320
+ if(isValidCharacter === false) {
321
+ event.preventDefault();
322
+ }
323
+
324
+ if (isValidCharacter === true && characterType._getCharacterType(event) !== 'tab') {
325
+ if (this._internalVars.maskSet === true) {
326
+ // unmask field
327
+ $(this._internalVars.creditCardInput).unmask();
328
+
329
+ //reset values
330
+ this._internalVars.creditCardInput.value = '';
331
+ this._internalVars.creditCardImageField.setAttribute('class', 'credit-card-image');
332
+ this._internalVars.creditCardType = 'default';
333
+ this._internalVars.maskSet = false;
334
+ }
335
+ }
336
+ }
337
+
338
+ /**
339
+ * checkValue(event)
340
+ * @param event
341
+ * set card properties, image, and format
342
+ */
343
+ function checkValue(event) {
344
+ let keyCode = event.which || event.keyCode;
345
+
346
+ if(keyCode === 8) {
347
+ setCardFormat.call(this, keyCode);
348
+ }
349
+ }
350
+
351
+ /**
352
+ * change()
353
+ * Triggers function when input value changes
354
+ */
355
+ function change() {
356
+ setCardProperties.call(this);
357
+ setCardImage.call(this);
358
+ setCardFormat.call(this);
359
+ }
360
+
361
+ /**
362
+ * setCardProperties()
363
+ * set card type/format etc.
364
+ */
365
+ function setCardProperties() {
366
+ // Set variable identifying a matching card
367
+ let cardIsSet = false;
368
+ let inputValue = this._internalVars.creditCardInput.value.replace(/ /g, '');
369
+
370
+ // loop through credit cards object
371
+ for (var key in this._internalVars.creditCards) {
372
+ if(this._internalVars.creditCards.hasOwnProperty(key)) {
373
+ //loop through the prefixes array inside credit card object
374
+ for(var digits in this._internalVars.creditCards[key].prefixes) {
375
+ //Set properties if entry matches valid digits
376
+ if(this._internalVars.creditCards[key].prefixes[digits].indexOf('-') >= 0) {
377
+ let parsedRange = parseRange.call(this, this._internalVars.creditCards[key].prefixes[digits]);
378
+ if(inputValue.substring(0, parsedRange.hyphenPosition) >= parsedRange.beginningPoint && inputValue.substring(0, parsedRange.hyphenPosition) <= parsedRange.endPoint) {
379
+ this._internalVars.creditCardType = key;
380
+ this._internalVars.cardFormatArray = this._internalVars.creditCards[key].cardFormatArray;
381
+ cardIsSet = true;
382
+ }
383
+ } else {
384
+ if(inputValue.substring(0,this._internalVars.creditCards[key].prefixes[digits].length) === this._internalVars.creditCards[key].prefixes[digits]) {
385
+ this._internalVars.creditCardType = key;
386
+ this._internalVars.cardFormatArray = this._internalVars.creditCards[key].cardFormatArray;
387
+ cardIsSet = true;
388
+ }
389
+ }
390
+ }
391
+ }
392
+ }
393
+
394
+ if(this._options.alternateCard) {
395
+ //Loop through alternateCard setting object
396
+ for(var alternateCard in this._options.alternateCard) {
397
+ if (this._options.alternateCard[alternateCard].valid === true) {
398
+ for (var cardDigits in this._options.alternateCard[alternateCard].prefixes) {
399
+ if(this._options.alternateCard[alternateCard].prefixes[cardDigits].indexOf('-') >= 0) {
400
+ let parsedRange = parseRange.call(this, this._options.alternateCard[alternateCard].prefixes[cardDigits]);
401
+ if(inputValue.substring(0, parsedRange.hyphenPosition) >= parsedRange.beginningPoint && inputValue.substring(0, parsedRange.hyphenPosition) <= parsedRange.endPoint) {
402
+ this._internalVars.creditCardType = alternateCard;
403
+ this._internalVars.cardFormatArray = this._options.alternateCard[alternateCard].cardFormatArray;
404
+ cardIsSet = true;
405
+ }
406
+ } else {
407
+ if(inputValue.substring(0,this._options.alternateCard[alternateCard].prefixes[cardDigits].length) === this._options.alternateCard[alternateCard].prefixes[cardDigits]) {
408
+ this._internalVars.creditCardType = alternateCard;
409
+ this._internalVars.cardFormatArray = this._options.alternateCard[alternateCard].cardFormatArray;
410
+ cardIsSet = true;
411
+ }
412
+ }
413
+ }
414
+ }
415
+ }
416
+ }
417
+
418
+ //Set default properties if entry does not match valid digits
419
+ if(cardIsSet === false) {
420
+ this._internalVars.creditCardType = 'default';
421
+ this._internalVars.creditCardInput.removeAttribute('maxlength');
422
+ } else {
423
+ //Set sequence array based on card format
424
+ this._internalVars.sequenceArray = [];
425
+
426
+ let sequenceNumber = 0;
427
+ Array.prototype.forEach.call(this._internalVars.cardFormatArray, (formatNumber)=> {
428
+ sequenceNumber += formatNumber;
429
+ this._internalVars.sequenceArray.push(sequenceNumber);
430
+ this._internalVars.cardMaxLenth = sequenceNumber + this._internalVars.cardFormatArray.length - 1;
431
+ });
432
+ }
433
+ }
434
+
435
+ /**
436
+ * setCardImage()
437
+ * sets the card type image on the view
438
+ */
439
+ function setCardImage() {
440
+ if(this._internalVars.creditCardType !== 'default') {
441
+ let newCardType = false;
442
+ if (this._options.alternateCard) {
443
+ for (var type in this._options.alternateCard) {
444
+ if (this._internalVars.creditCardType === type) {
445
+ newCardType = true;
446
+ }
447
+ }
448
+ }
449
+ if (newCardType === true) {
450
+ this._internalVars.creditCardImageField.setAttribute('class', 'credit-card-image');
451
+ } else {
452
+ this._internalVars.creditCardImageField.setAttribute('class', 'credit-card-image ' + this._internalVars.creditCardType);
453
+ }
454
+ } else {
455
+ this._internalVars.creditCardImageField.setAttribute('class', 'credit-card-image');
456
+ }
457
+ }
458
+
459
+ /**
460
+ * setCardFormat(key)
461
+ * @param key
462
+ * formats the entry based on the card type
463
+ */
464
+ function setCardFormat(key) {
465
+ //Set variables for cursor position
466
+ let caretPos = this._internalVars.creditCardInput.selectionStart;
467
+ let cursorPosition = caretPos;
468
+
469
+ if (this._internalVars.creditCardType === 'default') {
470
+ this._internalVars.creditCardInput.value = this._internalVars.creditCardInput.value.replace(/ /g, '');
471
+ } else {
472
+ //Set max length based on card type
473
+ this._internalVars.creditCardInput.setAttribute('maxlength', this._internalVars.cardMaxLenth);
474
+
475
+ //remove next available number if backspacing over a space
476
+ if(key === 8) {
477
+ for(var b = 0; b < this._internalVars.sequenceArray.length; b++) {
478
+ if(caretPos === this._internalVars.sequenceArray[b] + b) {
479
+ let first = this._internalVars.creditCardInput.value.slice(0, caretPos-1);
480
+ let second = this._internalVars.creditCardInput.value.slice(caretPos, this._internalVars.creditCardInput.value.length);
481
+ this._internalVars.creditCardInput.value = first + second;
482
+ cursorPosition = caretPos - 1;
483
+ }
484
+ }
485
+ }
486
+
487
+ //Set variable containing input value and previous value without spaces
488
+ let inputValue = this._internalVars.creditCardInput.value.replace(/ /g, '');
489
+ this._internalVars.creditCardInputValue = inputValue;
490
+ let prevInputValue = this._internalVars.creditCardInputPreviousValue.replace(/ /g, '');
491
+ let difference = inputValue.length - prevInputValue.length;
492
+
493
+ let newValueArray = [];
494
+ for(var v = 0; v < this._internalVars.sequenceArray.length; v++) {
495
+ if(inputValue.length >= this._internalVars.sequenceArray[v]-this._internalVars.cardFormatArray[v]) {
496
+ newValueArray.push(inputValue.substring(this._internalVars.sequenceArray[v]-this._internalVars.cardFormatArray[v],this._internalVars.sequenceArray[v]));
497
+ }
498
+ }
499
+
500
+ //check if multiple keys pressed
501
+ if (key !== 8) {
502
+ if(this._internalVars.creditCardInputPreviousValue.length + 1 < this._internalVars.creditCardInput.value.length) {
503
+ for(var i = 0; i < this._internalVars.sequenceArray.length; i++) {
504
+ if(caretPos - difference < this._internalVars.sequenceArray[i] + (i + 1) && caretPos > this._internalVars.sequenceArray[i] + (i + 1)) {
505
+ cursorPosition = caretPos + 1;
506
+ }
507
+ }
508
+ }
509
+ }
510
+
511
+ //combine value arrays with a space
512
+ let newValue = newValueArray.join(' ');
513
+ this._internalVars.creditCardInput.value = newValue;
514
+
515
+ //update cursor position and/or add a space if a number is pressed
516
+ if(key !== 8) {
517
+ for(var s = 0; s < this._internalVars.sequenceArray.length; s++) {
518
+ if(caretPos + (difference - 1) > this._internalVars.sequenceArray[s] + (s + 1) && caretPos <= this._internalVars.sequenceArray[s] + (s + 1)) {
519
+ cursorPosition = caretPos + 1;
520
+ }
521
+ if(s + 1 !== this._internalVars.cardFormatArray.length && caretPos === this._internalVars.sequenceArray[s] + s && this._internalVars.creditCardInputPreviousValue.length !== this._internalVars.creditCardInput.value.length) {
522
+ cursorPosition = caretPos + 1;
523
+ if(caretPos === this._internalVars.creditCardInput.value.length) {
524
+ this._internalVars.creditCardInput.value = this._internalVars.creditCardInput.value + ' ';
525
+ }
526
+ }
527
+ }
528
+ }
529
+
530
+ this._internalVars.creditCardInputPreviousValue = this._internalVars.creditCardInput.value;
531
+ }
532
+ this._internalVars.creditCardInput.setSelectionRange(cursorPosition, cursorPosition);
533
+ }
534
+
535
+ function maskEntry() {
536
+ let unmaskedCharacterLength = 4,
537
+ hasSpace = 0,
538
+ cardNumber = this.getCardNumber();
539
+
540
+ //check if value has 5 or more letters
541
+ if (cardNumber !== null && cardNumber.length > unmaskedCharacterLength) {
542
+ // create mask format
543
+ let maskArray = [];
544
+
545
+ // loop through field value
546
+ for (let i = 0; i < this._internalVars.creditCardInput.value.length; i++) {
547
+ let num = this._internalVars.creditCardInput.value.charAt(i);
548
+
549
+ if (num === ' ' && i === this._internalVars.creditCardInput.value.length - 1) {}
550
+ else if (num === ' ') {
551
+ maskArray.push(' ');
552
+ if(this._internalVars.creditCardInput.value.length - (i + 1) < unmaskedCharacterLength + 1) {
553
+ hasSpace = 1;
554
+ }
555
+ } else {
556
+ maskArray.push('9');
557
+ }
558
+ }
559
+
560
+ // create single string mask
561
+ let mask = maskArray.join('');
562
+
563
+ //set mask character length and apply mask
564
+ let maskedCharsLength = cardNumber.length - unmaskedCharacterLength - hasSpace;
565
+ $(this._internalVars.creditCardInput).maskSSN(mask, {maskedChar:'•', maskedCharsLength: maskedCharsLength});
566
+ this._internalVars.maskSet = true;
567
+ }
568
+ }
569
+
570
+ /**
571
+ * setLocalVars()
572
+ * set all the local vars to passed in options
573
+ */
574
+ function setLocalVars() {
575
+ //determine the type of content passed in
576
+ if(this._internalVars.contentType === 'string'){
577
+ this._internalVars.node = document.querySelector(this._options.content);
578
+ }else if(this._internalVars.contentType === 'domNode'){
579
+ this._internalVars.node = this._options.content;
580
+ }
581
+
582
+ this._internalVars.creditCardField = this._internalVars.node;
583
+ this._internalVars.creditCardClass = 'credit-card';
584
+ this._internalVars.creditCardInput = this._internalVars.creditCardField.querySelector('.' + this._internalVars.creditCardClass);
585
+ this._internalVars.creditCardInputHidden = this._internalVars.creditCardField.querySelector('.secureInput');
586
+ this._internalVars.creditCardImageClass = 'credit-card-image';
587
+ this._internalVars.creditCardImageField = this._internalVars.creditCardField.querySelector('.' + this._internalVars.creditCardImageClass);
588
+
589
+ this._internalVars.creditCardInputPreviousValue = this._internalVars.creditCardInput.value;
590
+ this._internalVars.creditCardInputValue = null;
591
+
592
+ this._internalVars.maskSet = false;
593
+ }
594
+
595
+ export default CreditCard;