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