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,397 @@
|
|
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 Make a Payment : Content must be defined and set to a DOM selector or Node"]
|
10
|
+
}
|
11
|
+
];
|
12
|
+
|
13
|
+
/**
|
14
|
+
* MakePayment Class
|
15
|
+
*/
|
16
|
+
class MakePayment{
|
17
|
+
/**
|
18
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
19
|
+
* @param {string|Object} content
|
20
|
+
* A reference to the div form field containing the make payment input node
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
|
24
|
+
constructor(options) {
|
25
|
+
|
26
|
+
this._internalVars = {};
|
27
|
+
|
28
|
+
//options with defaults set
|
29
|
+
this._defaults = {};
|
30
|
+
|
31
|
+
// Create options by extending defaults with the passed in arugments
|
32
|
+
if (options && typeof options === "object") {
|
33
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
34
|
+
}
|
35
|
+
|
36
|
+
//if the required options are valid set up the environment
|
37
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
38
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
39
|
+
setLocalVars.call(this);
|
40
|
+
setEvents.call(this);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
//Public Methods
|
45
|
+
|
46
|
+
/**
|
47
|
+
* destroy()
|
48
|
+
* removes the node from the dom and any events attached
|
49
|
+
*/
|
50
|
+
destroy(){
|
51
|
+
removeEvents.call(this);
|
52
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
53
|
+
|
54
|
+
//a little garbage collection
|
55
|
+
for (var variableKey in this){
|
56
|
+
if (this.hasOwnProperty(variableKey)){
|
57
|
+
delete this[variableKey];
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
}
|
63
|
+
|
64
|
+
// Private Methods
|
65
|
+
/**
|
66
|
+
* setEvents()
|
67
|
+
* Sets all the events needed for the component
|
68
|
+
*/
|
69
|
+
function setEvents() {
|
70
|
+
Array.prototype.forEach.call(this._internalVars.radios, (radio)=> {
|
71
|
+
radio.addEventListener('change', paymentTypeFieldsDisplay.bind(this));
|
72
|
+
});
|
73
|
+
|
74
|
+
Array.prototype.forEach.call(this._internalVars.paymentAmountRadios, (radio)=> {
|
75
|
+
radio.addEventListener('change', enableDisableOtherAmount.bind(this));
|
76
|
+
});
|
77
|
+
|
78
|
+
this._internalVars.creditCardcarddholderSelect.addEventListener('change', mailingAddressDisplay.bind(this));
|
79
|
+
this._internalVars.checkAccountholderSelect.addEventListener('change', mailingAddressDisplay.bind(this));
|
80
|
+
|
81
|
+
this._internalVars.creditCardcarddholderSelect.addEventListener('change', prefillName.bind(this));
|
82
|
+
this._internalVars.checkAccountholderSelect.addEventListener('change', prefillName.bind(this));
|
83
|
+
|
84
|
+
Array.prototype.forEach.call(this._internalVars.newAddressRadios, (radio)=> {
|
85
|
+
radio.addEventListener('change', newAddressFieldsDisplay.bind(this));
|
86
|
+
});
|
87
|
+
|
88
|
+
if(this._internalVars.nameOnCheckInput) {
|
89
|
+
this._internalVars.nameOnCheckInput.addEventListener('blur', parseFirstName.bind(this));
|
90
|
+
}
|
91
|
+
if(this._internalVars.nameOnCardInput) {
|
92
|
+
this._internalVars.nameOnCardInput.addEventListener('blur', parseFirstName.bind(this));
|
93
|
+
}
|
94
|
+
|
95
|
+
this._internalVars.saveMethodRadio.addEventListener('change', saveMethodFieldDisplay.bind(this));
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
/**
|
100
|
+
* removeEvents()
|
101
|
+
* removes all events from the component
|
102
|
+
*/
|
103
|
+
function removeEvents() {
|
104
|
+
Array.prototype.forEach.call(this._internalVars.radios, (radio)=> {
|
105
|
+
radio.removeEventListener('change', paymentTypeFieldsDisplay.bind(this));
|
106
|
+
});
|
107
|
+
|
108
|
+
Array.prototype.forEach.call(this._internalVars.paymentAmountRadios, (radio)=> {
|
109
|
+
radio.removeEventListener('change', enableDisableOtherAmount.bind(this));
|
110
|
+
});
|
111
|
+
|
112
|
+
this._internalVars.creditCardcarddholderSelect.removeEventListener('change', mailingAddressDisplay.bind(this));
|
113
|
+
this._internalVars.checkAccountholderSelect.removeEventListener('change', mailingAddressDisplay.bind(this));
|
114
|
+
|
115
|
+
Array.prototype.forEach.call(this._internalVars.newAddressRadios, (radio)=> {
|
116
|
+
radio.removeEventListener('change', newAddressFieldsDisplay.bind(this));
|
117
|
+
});
|
118
|
+
|
119
|
+
if(this._internalVars.nameOnCheckInput) {
|
120
|
+
this._internalVars.nameOnCheckInput.removeEventListener('blur', parseFirstName.bind(this));
|
121
|
+
}
|
122
|
+
if(this._internalVars.nameOnCardInput) {
|
123
|
+
this._internalVars.nameOnCardInput.removeEventListener('blur', parseFirstName.bind(this));
|
124
|
+
}
|
125
|
+
|
126
|
+
this._internalVars.saveMethodRadio.removeEventListener('change', saveMethodFieldDisplay.bind(this));
|
127
|
+
}
|
128
|
+
|
129
|
+
function enableDisableOtherAmount(event) {
|
130
|
+
if (event.target.value === 'other') {
|
131
|
+
this._internalVars.currencyInput.removeAttribute('disabled');
|
132
|
+
} else if (event.target.value !== 'other') {
|
133
|
+
this._internalVars.currencyInput.setAttribute('disabled', 'disabled');
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
function paymentTypeFieldsDisplay(event) {
|
138
|
+
//Set variable values for which fields should be displayed
|
139
|
+
let creditCardFieldsDisplay = false,
|
140
|
+
checkFieldsDisplay = false,
|
141
|
+
generalFieldsDisplay = false,
|
142
|
+
saveMethodFieldsDisplay = false;
|
143
|
+
|
144
|
+
this._internalVars.creditCardSelected = false;
|
145
|
+
this._internalVars.checkSelected = false;
|
146
|
+
|
147
|
+
if(event.target.value === 'card') {
|
148
|
+
generalFieldsDisplay = true;
|
149
|
+
creditCardFieldsDisplay = true;
|
150
|
+
checkFieldsDisplay = false;
|
151
|
+
this._internalVars.creditCardSelected = true;
|
152
|
+
this._internalVars.addressFieldLabel.innerHTML = "Cardholder's";
|
153
|
+
}
|
154
|
+
|
155
|
+
if(event.target.value === 'check') {
|
156
|
+
generalFieldsDisplay = true;
|
157
|
+
checkFieldsDisplay = true;
|
158
|
+
creditCardFieldsDisplay = false;
|
159
|
+
this._internalVars.checkSelected = true;
|
160
|
+
this._internalVars.addressFieldLabel.innerHTML = "Account holder's";
|
161
|
+
}
|
162
|
+
|
163
|
+
//Reset values if payment method is changed
|
164
|
+
this._internalVars.creditCardcarddholderSelect.options[0].selected = true;
|
165
|
+
this._internalVars.checkAccountholderSelect.options[0].selected = true;
|
166
|
+
|
167
|
+
Array.prototype.forEach.call(this._internalVars.newAddressRadios, (radio)=> {
|
168
|
+
radio.checked = false;
|
169
|
+
});
|
170
|
+
|
171
|
+
this._internalVars.saveMethodRadio.checked = false;
|
172
|
+
|
173
|
+
toggleFieldDisplay.call(this, creditCardFieldsDisplay, checkFieldsDisplay, generalFieldsDisplay, saveMethodFieldsDisplay);
|
174
|
+
}
|
175
|
+
|
176
|
+
function toggleFieldDisplay(creditCardFieldsDisplay, checkFieldsDisplay, generalFieldsDisplay, saveMethodFieldsDisplay) {
|
177
|
+
if($(this._internalVars.dynamicAddressField).is(':visible')) {
|
178
|
+
$(this._internalVars.dynamicAddressField).slideUp();
|
179
|
+
}
|
180
|
+
if($(this._internalVars.dynamicNewAddressFields).is(':visible')) {
|
181
|
+
$(this._internalVars.dynamicNewAddressFields).slideUp();
|
182
|
+
}
|
183
|
+
if(generalFieldsDisplay === true) {
|
184
|
+
if($(this._internalVars.dynamicFieldGeneral).is(':hidden')) {
|
185
|
+
$(this._internalVars.dynamicFieldGeneral).slideDown();
|
186
|
+
}
|
187
|
+
} else {
|
188
|
+
if($(this._internalVars.dynamicFieldGeneral).is(':visible')) {
|
189
|
+
$(this._internalVars.dynamicFieldGeneral).slideUp();
|
190
|
+
}
|
191
|
+
}
|
192
|
+
if(creditCardFieldsDisplay === true) {
|
193
|
+
if($(this._internalVars.dynamicCardFields).is(':hidden')) {
|
194
|
+
$(this._internalVars.dynamicCardFields).slideDown();
|
195
|
+
}
|
196
|
+
} else {
|
197
|
+
if($(this._internalVars.dynamicCardFields).is(':visible')) {
|
198
|
+
$(this._internalVars.dynamicCardFields).slideUp();
|
199
|
+
}
|
200
|
+
}
|
201
|
+
if(checkFieldsDisplay === true) {
|
202
|
+
if($(this._internalVars.dynamicCheckFields).is(':hidden')) {
|
203
|
+
$(this._internalVars.dynamicCheckFields).slideDown();
|
204
|
+
}
|
205
|
+
} else {
|
206
|
+
if($(this._internalVars.dynamicCheckFields).is(':visible')) {
|
207
|
+
$(this._internalVars.dynamicCheckFields).slideUp();
|
208
|
+
}
|
209
|
+
}
|
210
|
+
if(saveMethodFieldsDisplay === true) {
|
211
|
+
if($(this._internalVars.dynamicFieldSaveFields).is(':hidden')) {
|
212
|
+
$(this._internalVars.dynamicFieldSaveFields).slideDown();
|
213
|
+
}
|
214
|
+
} else {
|
215
|
+
if($(this._internalVars.dynamicFieldSaveFields).is(':visible')) {
|
216
|
+
$(this._internalVars.dynamicFieldSaveFields).slideUp();
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
function mailingAddressDisplay(event) {
|
222
|
+
let mailingAddressFields = false;
|
223
|
+
if(event.target.value === 'Other Payee') {
|
224
|
+
mailingAddressFields = true;
|
225
|
+
}
|
226
|
+
toggleMailingAddressFieldDisplay.call(this, mailingAddressFields);
|
227
|
+
}
|
228
|
+
|
229
|
+
function prefillName(event) {
|
230
|
+
let addressLabel;
|
231
|
+
if (this._internalVars.checkSelected === true) {
|
232
|
+
addressLabel = "Account holder's";
|
233
|
+
} else if (this._internalVars.creditCardSelected === true) {
|
234
|
+
addressLabel = "Cardholder's";
|
235
|
+
}
|
236
|
+
if(event.target.value !== 'Other Payee' && event.target.value !== 'Please Select') {
|
237
|
+
let value;
|
238
|
+
for (var i = 0; i < event.target.length; i++) {
|
239
|
+
if(event.target.options[i].value === event.target.value) {
|
240
|
+
value = event.target.options[i].text;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
if (this._internalVars.creditCardSelected === true) {
|
244
|
+
this._internalVars.nameOnCardInput.value = value;
|
245
|
+
} else if (this._internalVars.checkSelected === true) {
|
246
|
+
this._internalVars.nameOnCheckInput.value = value;
|
247
|
+
}
|
248
|
+
} else {
|
249
|
+
this._internalVars.nameOnCardInput.value = '';
|
250
|
+
this._internalVars.nameOnCheckInput.value = '';
|
251
|
+
this._internalVars.addressFieldLabel.innerHTML = addressLabel;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
function toggleMailingAddressFieldDisplay(mailingAddressFields) {
|
256
|
+
if(mailingAddressFields === true) {
|
257
|
+
if($(this._internalVars.dynamicAddressField).is(':hidden')) {
|
258
|
+
$(this._internalVars.dynamicAddressField).slideDown();
|
259
|
+
}
|
260
|
+
} else {
|
261
|
+
if($(this._internalVars.dynamicAddressField).is(':visible')) {
|
262
|
+
$(this._internalVars.dynamicAddressField).slideUp();
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
function newAddressFieldsDisplay(event) {
|
268
|
+
let newAddressFields = false;
|
269
|
+
if(event.target.value === 'new') {
|
270
|
+
newAddressFields = true;
|
271
|
+
}
|
272
|
+
toggleNewAddressFieldsDisplay.call(this, newAddressFields);
|
273
|
+
}
|
274
|
+
|
275
|
+
function toggleNewAddressFieldsDisplay(newAddressFields) {
|
276
|
+
if(newAddressFields === true) {
|
277
|
+
if($(this._internalVars.dynamicNewAddressFields).is(':hidden')) {
|
278
|
+
$(this._internalVars.dynamicNewAddressFields).slideDown();
|
279
|
+
}
|
280
|
+
} else {
|
281
|
+
if($(this._internalVars.dynamicNewAddressFields).is(':visible')) {
|
282
|
+
$(this._internalVars.dynamicNewAddressFields).slideUp();
|
283
|
+
}
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
function parseFirstName(event) {
|
288
|
+
let nameField,
|
289
|
+
addressLabel;
|
290
|
+
if (this._internalVars.checkSelected === true) {
|
291
|
+
nameField = this._internalVars.nameOnCheckInput;
|
292
|
+
addressLabel = "Account holder's";
|
293
|
+
} else if (this._internalVars.creditCardSelected === true) {
|
294
|
+
nameField = this._internalVars.nameOnCardInput;
|
295
|
+
addressLabel = "Cardholder's";
|
296
|
+
}
|
297
|
+
if (nameField.value.length > 0) {
|
298
|
+
let firstName = event.target.value.split(" ")[0];
|
299
|
+
if (firstName.slice(-1) === 's' || firstName.slice(-1) === 'S') {
|
300
|
+
this._internalVars.addressFieldLabel.innerHTML = firstName + "'";
|
301
|
+
} else {
|
302
|
+
this._internalVars.addressFieldLabel.innerHTML = firstName + "'s";
|
303
|
+
}
|
304
|
+
|
305
|
+
} else {
|
306
|
+
this._internalVars.addressFieldLabel.innerHTML = addressLabel;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
|
310
|
+
function saveMethodFieldDisplay(event) {
|
311
|
+
if(event.target.checked === true) {
|
312
|
+
if($(this._internalVars.dynamicFieldSaveFields).is(':hidden')) {
|
313
|
+
$(this._internalVars.dynamicFieldSaveFields).slideDown();
|
314
|
+
}
|
315
|
+
} else {
|
316
|
+
if($(this._internalVars.dynamicFieldSaveFields).is(':visible')) {
|
317
|
+
$(this._internalVars.dynamicFieldSaveFields).slideUp();
|
318
|
+
}
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
/**
|
323
|
+
* setLocalVars()
|
324
|
+
* set all the local vars to passed in options
|
325
|
+
*/
|
326
|
+
function setLocalVars() {
|
327
|
+
//determine the type of content passed in
|
328
|
+
if(this._internalVars.contentType === 'string'){
|
329
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
330
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
331
|
+
this._internalVars.node = this._options.content;
|
332
|
+
}
|
333
|
+
|
334
|
+
this._internalVars.makePaymentFields = this._internalVars.node;
|
335
|
+
|
336
|
+
this._internalVars.paymentAmountID = 'payment-amount';
|
337
|
+
this._internalVars.paymentAmountFields = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.paymentAmountID);
|
338
|
+
this._internalVars.paymentAmountRadios = this._internalVars.paymentAmountFields.querySelectorAll("input[type='radio']");
|
339
|
+
|
340
|
+
this._internalVars.currencyInputClass = 'currency-input';
|
341
|
+
this._internalVars.currencyInput = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.currencyInputClass);
|
342
|
+
|
343
|
+
this._internalVars.paymentMethodID = 'payment-method-selection';
|
344
|
+
this._internalVars.paymentMethodFields = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.paymentMethodID);
|
345
|
+
this._internalVars.radios = this._internalVars.paymentMethodFields.querySelectorAll('input');
|
346
|
+
|
347
|
+
this._internalVars.dynamicFieldCheckClass = 'dynamic-fields-check';
|
348
|
+
this._internalVars.dynamicCheckFields = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.dynamicFieldCheckClass);
|
349
|
+
|
350
|
+
this._internalVars.dynamicFieldCardClass = 'dynamic-fields-card';
|
351
|
+
this._internalVars.dynamicCardFields = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.dynamicFieldCardClass);
|
352
|
+
|
353
|
+
this._internalVars.dynamicFieldGeneralClass = 'dynamic-fields-general';
|
354
|
+
this._internalVars.dynamicFieldGeneral = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.dynamicFieldGeneralClass);
|
355
|
+
|
356
|
+
this._internalVars.creditCardCardholderID = 'cardholder-credit-card';
|
357
|
+
this._internalVars.creditCardCardholderField = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.creditCardCardholderID);
|
358
|
+
this._internalVars.creditCardcarddholderSelect = this._internalVars.creditCardCardholderField.querySelector('select');
|
359
|
+
|
360
|
+
this._internalVars.checkAccountholderID = 'accountholder-check';
|
361
|
+
this._internalVars.checkAccountholderField = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.checkAccountholderID);
|
362
|
+
this._internalVars.checkAccountholderSelect = this._internalVars.checkAccountholderField.querySelector('select');
|
363
|
+
|
364
|
+
this._internalVars.nameOnCheckID = 'name-on-check';
|
365
|
+
if(this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.nameOnCheckID)) {
|
366
|
+
this._internalVars.nameOnCheckFields = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.nameOnCheckID);
|
367
|
+
this._internalVars.nameOnCheckInput = this._internalVars.nameOnCheckFields.querySelector('input');
|
368
|
+
}
|
369
|
+
|
370
|
+
this._internalVars.nameOnCardID = 'name-credit-card';
|
371
|
+
if(this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.nameOnCardID)) {
|
372
|
+
this._internalVars.nameOnCardFields = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.nameOnCardID);
|
373
|
+
this._internalVars.nameOnCardInput = this._internalVars.nameOnCardFields.querySelector('input');
|
374
|
+
}
|
375
|
+
|
376
|
+
this._internalVars.dynamicFieldAddressClass = 'dynamic-fields-address';
|
377
|
+
this._internalVars.dynamicAddressField = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.dynamicFieldAddressClass);
|
378
|
+
|
379
|
+
this._internalVars.addressFieldNameLabelID = 'address-name';
|
380
|
+
this._internalVars.addressFieldLabel = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.addressFieldNameLabelID);
|
381
|
+
|
382
|
+
this._internalVars.newAddressID = 'address';
|
383
|
+
this._internalVars.newAddressFields = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.newAddressID);
|
384
|
+
this._internalVars.newAddressRadios = this._internalVars.newAddressFields.querySelectorAll('input');
|
385
|
+
|
386
|
+
this._internalVars.dynamicFieldNewAddressClass = 'dynamic-fields-new-address';
|
387
|
+
this._internalVars.dynamicNewAddressFields = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.dynamicFieldNewAddressClass);
|
388
|
+
|
389
|
+
this._internalVars.saveMethodId = 'save-method';
|
390
|
+
this._internalVars.saveMethodField = this._internalVars.makePaymentFields.querySelector('#' + this._internalVars.saveMethodId);
|
391
|
+
this._internalVars.saveMethodRadio = this._internalVars.saveMethodField.querySelector('input');
|
392
|
+
|
393
|
+
this._internalVars.dynamicFieldSaveClass = 'dynamic-fields-save-method';
|
394
|
+
this._internalVars.dynamicFieldSaveFields = this._internalVars.makePaymentFields.querySelector('.' + this._internalVars.dynamicFieldSaveClass);
|
395
|
+
}
|
396
|
+
|
397
|
+
export default MakePayment;
|
@@ -0,0 +1,279 @@
|
|
1
|
+
import * as utils from '../../src/utils';
|
2
|
+
import baseComponent from '../../src/baseComponent';
|
3
|
+
import UserAgentService from '../../src/services/UserAgentService';
|
4
|
+
|
5
|
+
let PromiseIE = require('es6-promise-polyfill').Promise;
|
6
|
+
|
7
|
+
const validateSettings = [
|
8
|
+
{
|
9
|
+
setting : "content",
|
10
|
+
isRequired : true,
|
11
|
+
validate : "type",
|
12
|
+
possibleValues : ["string","object"],
|
13
|
+
errorMessage : ["GDK Modal : Content must be defined and set to a DOM selector or Node"]
|
14
|
+
},
|
15
|
+
{
|
16
|
+
setting : "autoShow",
|
17
|
+
isRequired : false,
|
18
|
+
validate : "type",
|
19
|
+
possibleValues : ["boolean"],
|
20
|
+
errorMessage : ["GDK Modal : autoShow must be a boolean"]
|
21
|
+
},
|
22
|
+
{
|
23
|
+
setting : "overlayShouldCloseModal",
|
24
|
+
isRequired : false,
|
25
|
+
validate : "type",
|
26
|
+
possibleValues : ["boolean"],
|
27
|
+
errorMessage : ["GDK Modal : overlayShouldCloseModal must be a boolean"]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
setting : "hideCloseButton",
|
31
|
+
isRequired : false,
|
32
|
+
validate : "type",
|
33
|
+
possibleValues : ["boolean"],
|
34
|
+
errorMessage : ["GDK Modal : hideCloseButton must be a boolean"]
|
35
|
+
},
|
36
|
+
{
|
37
|
+
setting : "onOpened",
|
38
|
+
isRequired : false,
|
39
|
+
validate : "type",
|
40
|
+
possibleValues : ["function"],
|
41
|
+
errorMessage : ["GDK Modal : onOpened must be a function"]
|
42
|
+
},
|
43
|
+
{
|
44
|
+
setting : "onClosed",
|
45
|
+
isRequired : false,
|
46
|
+
validate : "type",
|
47
|
+
possibleValues : ["function"],
|
48
|
+
errorMessage : ["GDK Modal : onClosed must be a function"]
|
49
|
+
}
|
50
|
+
|
51
|
+
];
|
52
|
+
|
53
|
+
|
54
|
+
const modalCloseBtn = '<button class="btn-close icon-close" type="button" aria-label="Close modal"></button>';
|
55
|
+
|
56
|
+
|
57
|
+
class Modal{
|
58
|
+
/**
|
59
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
60
|
+
* @param {string|Object} content
|
61
|
+
* A reference to the modal node
|
62
|
+
*
|
63
|
+
* @param {boolean} [autoShow=false]
|
64
|
+
* Use if you want to model to auto show when instantiated
|
65
|
+
*
|
66
|
+
* @param {boolean} [overlayShouldCloseModal=true]
|
67
|
+
* Set to false if you do not want the overlay to have click to close functionality
|
68
|
+
*
|
69
|
+
* @param {boolean} [hideCloseButton=false]
|
70
|
+
* Set to true if you want to hide the close button in the upper right corner of the modal
|
71
|
+
*
|
72
|
+
* @param {function} [onOpened]
|
73
|
+
* A callback function that gets fired when the modal has been opened
|
74
|
+
*
|
75
|
+
* @param {function} [onClosed]
|
76
|
+
* A callback function that gets fired when the modal has been closed
|
77
|
+
*
|
78
|
+
*/
|
79
|
+
constructor(options) {
|
80
|
+
|
81
|
+
this._internalVars = {
|
82
|
+
node: null,//used for current node
|
83
|
+
closeBtn : null
|
84
|
+
};
|
85
|
+
|
86
|
+
//options with defaults set
|
87
|
+
this._defaults = {
|
88
|
+
autoShow : false,
|
89
|
+
overlayShouldCloseModal : true,
|
90
|
+
hideCloseButton : false
|
91
|
+
};
|
92
|
+
|
93
|
+
// Create options by extending defaults with the passed in arugments
|
94
|
+
if (options && typeof options === "object") {
|
95
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
96
|
+
}
|
97
|
+
|
98
|
+
//if the required options are valid set up the environment
|
99
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
100
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
101
|
+
setLocalVars.call(this);
|
102
|
+
buildModal.call(this);
|
103
|
+
setEvents.call(this);
|
104
|
+
|
105
|
+
if(this._options.autoShow){
|
106
|
+
this.show();
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
}
|
111
|
+
|
112
|
+
//Public Methods
|
113
|
+
|
114
|
+
/**
|
115
|
+
* show()
|
116
|
+
* shows the modal
|
117
|
+
*/
|
118
|
+
show(){
|
119
|
+
|
120
|
+
this._internalVars.node.style.display = "block";
|
121
|
+
|
122
|
+
setTimeout( ()=> {
|
123
|
+
this._internalVars.node.classList.add("modal--show");
|
124
|
+
if(this._options.onOpened)
|
125
|
+
this._options.onOpened();
|
126
|
+
}, 10);
|
127
|
+
this._internalVars.inModalArray = [];
|
128
|
+
document.addEventListener('keyup', this._internalVars.modalTabHandler);
|
129
|
+
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* hide()
|
134
|
+
* hides the modal
|
135
|
+
*/
|
136
|
+
hide(duration = 500){
|
137
|
+
this._internalVars.inModalArray = [];
|
138
|
+
document.removeEventListener('keyup', this._internalVars.modalTabHandler);
|
139
|
+
|
140
|
+
return new PromiseIE((resolve, reject) => {
|
141
|
+
setTimeout( ()=> {
|
142
|
+
this._internalVars.node.classList.remove("modal--show");
|
143
|
+
this._internalVars.node.style.display = "none";
|
144
|
+
if(this._options.onClosed)
|
145
|
+
this._options.onClosed();
|
146
|
+
resolve();
|
147
|
+
}, duration);
|
148
|
+
});
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* destroy()
|
153
|
+
* removes the node from the dom and any events attached
|
154
|
+
*/
|
155
|
+
destroy(){
|
156
|
+
removeEvents.call(this);
|
157
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
158
|
+
|
159
|
+
//a little garbage collection
|
160
|
+
for (var variableKey in this){
|
161
|
+
if (this.hasOwnProperty(variableKey)){
|
162
|
+
delete this[variableKey];
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
/**
|
171
|
+
* setLocalVars()
|
172
|
+
* set all the local vars to passed in options
|
173
|
+
*/
|
174
|
+
function setLocalVars() {
|
175
|
+
//determine the type of content passed in
|
176
|
+
if(this._internalVars.contentType === 'string'){
|
177
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
178
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
179
|
+
this._internalVars.node = this._options.content;
|
180
|
+
}
|
181
|
+
|
182
|
+
this._internalVars.modalTabHandler = isolateTab.bind(this);
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
/**
|
187
|
+
* modalClicked()
|
188
|
+
* Gets fired when you click anywhere on a model
|
189
|
+
*/
|
190
|
+
function modalClicked(e) {
|
191
|
+
|
192
|
+
//NodeList of items that the mouse is currently over in document order.
|
193
|
+
//The last element in the NodeList is the most specific, each preceding
|
194
|
+
//one should be a parent, grandparent, and so on.
|
195
|
+
let nodes = document.querySelectorAll( ":hover" );
|
196
|
+
|
197
|
+
if(this._internalVars.node == nodes[nodes.length- 1]){
|
198
|
+
this.hide();
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
}
|
203
|
+
|
204
|
+
/**
|
205
|
+
* setEvents()
|
206
|
+
* Sets all the events needed for this component
|
207
|
+
*/
|
208
|
+
function setEvents() {
|
209
|
+
|
210
|
+
const eventName = UserAgentService._clickEventName();
|
211
|
+
|
212
|
+
if(this._options.overlayShouldCloseModal){
|
213
|
+
this._internalVars.node.addEventListener(eventName, modalClicked.bind(this) );
|
214
|
+
}
|
215
|
+
|
216
|
+
if(this._options.hideCloseButton){
|
217
|
+
this._internalVars.closeBtn.classList.add("hidden");
|
218
|
+
}
|
219
|
+
else {
|
220
|
+
this._internalVars.closeBtn.addEventListener(eventName, this.hide.bind(this) );
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* removeEvents()
|
231
|
+
* removes all events from this component
|
232
|
+
*/
|
233
|
+
function removeEvents() {
|
234
|
+
|
235
|
+
const eventName = UserAgentService._clickEventName();
|
236
|
+
|
237
|
+
if(this._options.overlayShouldCloseModal){
|
238
|
+
this._internalVars.node.removeEventListener(eventName, modalClicked.bind(this) );
|
239
|
+
}
|
240
|
+
this._internalVars.closeBtn.removeEventListener(eventName, this.hide.bind(this) );
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
/**
|
247
|
+
* buildModal()
|
248
|
+
* Adds needed markup this component
|
249
|
+
*/
|
250
|
+
function buildModal() {
|
251
|
+
let modalContentDom = this._internalVars.node.querySelector(".modal-container");
|
252
|
+
modalContentDom.insertAdjacentHTML('afterBegin', modalCloseBtn);
|
253
|
+
|
254
|
+
this._internalVars.closeBtn = this._internalVars.node.querySelector(".btn-close");
|
255
|
+
|
256
|
+
let spanTab = document.createElement('span');
|
257
|
+
spanTab.setAttribute('tabindex', '0');
|
258
|
+
spanTab.setAttribute('class', 'tab-filler');
|
259
|
+
let cloneSpanTab = spanTab.cloneNode(true);
|
260
|
+
modalContentDom.appendChild(spanTab);
|
261
|
+
modalContentDom.insertBefore(cloneSpanTab, modalContentDom.children[0]);
|
262
|
+
}
|
263
|
+
|
264
|
+
function isolateTab(e){
|
265
|
+
if(e.keyCode == 9 || (e.keyCode == 9 && e.shiftKey)){
|
266
|
+
if (utils.isChild("modal", document.activeElement) && !document.activeElement.classList.contains('tab-filler') && !this._internalVars.inModalArray.includes(document.activeElement)) {
|
267
|
+
this._internalVars.inModalArray.push(document.activeElement);
|
268
|
+
}
|
269
|
+
|
270
|
+
if (document.activeElement.classList.contains('tab-filler')) {
|
271
|
+
if (this._internalVars.inModalArray.length > 0) {
|
272
|
+
this._internalVars.inModalArray[0].focus();
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
|
279
|
+
export default Modal;
|