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,604 @@
|
|
1
|
+
import baseComponent from '../../src/baseComponent';
|
2
|
+
import UserAgentService from '../../src/services/UserAgentService';
|
3
|
+
|
4
|
+
const validateSettings = [
|
5
|
+
{
|
6
|
+
setting: "content",
|
7
|
+
isRequired: true,
|
8
|
+
validate: "type",
|
9
|
+
possibleValues: ["string", "object"],
|
10
|
+
errorMessage: ["GDK Payment Plans : Content must be defined and set to a DOM selector or Node"]
|
11
|
+
},
|
12
|
+
{
|
13
|
+
setting: "initialActivePayPlan",
|
14
|
+
isRequired: false,
|
15
|
+
validate: "type",
|
16
|
+
possibleValues: ["number"],
|
17
|
+
errorMessage: ["GDK Payment Plans : Content must be defined and set to a number"]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
setting: "onPayPlanSelection",
|
21
|
+
isRequired: false,
|
22
|
+
validate: "type",
|
23
|
+
possibleValues: ["function"],
|
24
|
+
errorMessage: ["GDK Payment Plans : Content must be defined and set to a function"]
|
25
|
+
}
|
26
|
+
];
|
27
|
+
|
28
|
+
class PayPlans {
|
29
|
+
/**
|
30
|
+
* PayPlans Constructor
|
31
|
+
* @param {Object} options sets _internalVars, _defaults, creates options, validates settings, sets up the environment
|
32
|
+
*/
|
33
|
+
constructor(options) {
|
34
|
+
|
35
|
+
console.log('Payment Plans initialized');
|
36
|
+
|
37
|
+
this._internalVars = {
|
38
|
+
node: null //used for current node
|
39
|
+
};
|
40
|
+
|
41
|
+
//options with defaults set
|
42
|
+
this._defaults = {
|
43
|
+
|
44
|
+
};
|
45
|
+
|
46
|
+
// Create options by extending defaults with the passed in arugments
|
47
|
+
if (options && typeof options === "object") {
|
48
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
//if the required options are valid set up the environment
|
53
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
54
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
55
|
+
setLocalVars.call(this);
|
56
|
+
setEvents.call(this);
|
57
|
+
checkPayPlans.call(this);
|
58
|
+
|
59
|
+
Array.prototype.forEach.call(this._internalVars.payPlanCardTopObject, (element)=> {
|
60
|
+
if(!element.getAttribute('tabindex'))
|
61
|
+
element.setAttribute('tabindex', '0');
|
62
|
+
element.setAttribute('role', 'radio');
|
63
|
+
if(!element.getElementsByTagName('input')[0].getAttribute('tabindex'))
|
64
|
+
element.getElementsByTagName('input')[0].setAttribute('tabindex', '-1');
|
65
|
+
if(!element.getAttribute('aria-checked'))
|
66
|
+
element.setAttribute('aria-checked', 'false');
|
67
|
+
});
|
68
|
+
|
69
|
+
Array.prototype.forEach.call(this._internalVars.payPlanInnerWrapperObjects, (el)=> {
|
70
|
+
el.querySelectorAll('.payment-plan-row')[0].setAttribute('role', 'radiogroup');
|
71
|
+
});
|
72
|
+
|
73
|
+
Array.prototype.forEach.call(this._internalVars.payPlanCardTopObject, (element)=> {
|
74
|
+
element.getElementsByTagName('input')[0].setAttribute('tabindex', '-1');
|
75
|
+
});
|
76
|
+
|
77
|
+
if (this._options.initialActivePayPlan && this._options.initialActivePayPlan <= this._internalVars.payPlanCardTopObject.length) {
|
78
|
+
this.setPayPlan.call(this, this._options.initialActivePayPlan);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* setPayPlan(payPlanNumber)
|
85
|
+
* @param payPlanNumber
|
86
|
+
* Sets the selected pay plan.
|
87
|
+
*/
|
88
|
+
setPayPlan(payPlanNumber) {
|
89
|
+
setPayPlan.call(this, payPlanNumber);
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* getPayPlan()
|
94
|
+
* @returns {NodeListOf<Element>}
|
95
|
+
* Returns a node list of the selected payment plan (top card & bottom card)
|
96
|
+
*/
|
97
|
+
getPayPlan() {
|
98
|
+
let selectedPlan = document.querySelectorAll('.' + this._internalVars.payPlanSelectedClass);
|
99
|
+
return selectedPlan;
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* setCarouselArrows()
|
104
|
+
* Removes the carousel arrows if all pay plans can be viewed on the page.
|
105
|
+
*/
|
106
|
+
setCarouselArrows() {
|
107
|
+
checkPayPlans.call(this);
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* removes the node from the dom and any events attached
|
112
|
+
*/
|
113
|
+
destroy(){
|
114
|
+
removeEvents.call(this);
|
115
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
116
|
+
|
117
|
+
//a little garbage collection
|
118
|
+
for (var variableKey in this){
|
119
|
+
if (this.hasOwnProperty(variableKey)){
|
120
|
+
delete this[variableKey];
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
// Private Methods
|
127
|
+
|
128
|
+
/**
|
129
|
+
* setEvents()
|
130
|
+
* Sets all the events needed for the component
|
131
|
+
*/
|
132
|
+
function setEvents() {
|
133
|
+
let eventName = UserAgentService._clickEventName();
|
134
|
+
|
135
|
+
Array.prototype.forEach.call(this._internalVars.payPlanCards, (el)=> {
|
136
|
+
el.addEventListener(eventName, setPayPlan.bind(this));
|
137
|
+
el.addEventListener('keyup', setPayPlan.bind(this));
|
138
|
+
el.addEventListener('mouseover', setState.bind(this));
|
139
|
+
el.addEventListener('mouseout', resetState.bind(this));
|
140
|
+
el.addEventListener('focus', setState.bind(this));
|
141
|
+
el.addEventListener('blur', resetState.bind(this));
|
142
|
+
});
|
143
|
+
|
144
|
+
Array.prototype.forEach.call(this._internalVars.carouselBtnObjects, (el)=> {
|
145
|
+
el.addEventListener(eventName, carouselMovement.bind(this));
|
146
|
+
el.addEventListener('keyup', carouselMovement.bind(this));
|
147
|
+
});
|
148
|
+
|
149
|
+
Array.prototype.forEach.call(this._internalVars.expandLink, (el)=> {
|
150
|
+
el.addEventListener(eventName, expand.bind(this));
|
151
|
+
});
|
152
|
+
|
153
|
+
window.addEventListener('resize', resetCarouselDefaults.bind(this));
|
154
|
+
}
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Assigns a class to an internal variable based on the event type
|
158
|
+
* @param {Event} event Event type
|
159
|
+
*/
|
160
|
+
function setEventType(event) {
|
161
|
+
if (event === 'mouseover' || event === 'mouseout') {
|
162
|
+
this._internalVars.eventType = 'hover';
|
163
|
+
} else {
|
164
|
+
this._internalVars.eventType = 'focus';
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Evaluates which row (top or bottom of cards) and card in that row that should be targeted when setting states
|
170
|
+
* @param {Event} e Event type
|
171
|
+
*/
|
172
|
+
function setRowIndex(e) {
|
173
|
+
let currentNode = e.currentTarget,
|
174
|
+
payPlanWrapper = currentNode.parentNode.parentNode,
|
175
|
+
rowWrapper = currentNode.parentNode,
|
176
|
+
payPlanCard = rowWrapper.querySelectorAll(this._internalVars.payPlanCardClass),
|
177
|
+
index = [].indexOf.call(payPlanCard, currentNode),
|
178
|
+
rowIndex = [].indexOf.call(payPlanWrapper.querySelectorAll('.payment-plan-row'), rowWrapper);
|
179
|
+
|
180
|
+
if (currentNode.classList.contains(this._internalVars.payPlanCardTopClass)) {
|
181
|
+
rowIndex = rowIndex + 1;
|
182
|
+
} else {
|
183
|
+
rowIndex = rowIndex - 1;
|
184
|
+
}
|
185
|
+
|
186
|
+
this._internalVars.rowIndex = rowIndex;
|
187
|
+
this._internalVars.cardIndex = index;
|
188
|
+
}
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Sets state of card classes (hover, focus) based on the interaction with the card counterpart (top/bottom)
|
192
|
+
* @param {Event} e Event type
|
193
|
+
*/
|
194
|
+
function setOtherCardState(e) {
|
195
|
+
setRowIndex.call(this, e);
|
196
|
+
|
197
|
+
e.currentTarget.parentNode.parentNode.children[this._internalVars.rowIndex].children[this._internalVars.cardIndex].classList.add(this._internalVars.eventType);
|
198
|
+
}
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Sets the state of card classes (hover, focus) of the card interacted with (top/bottom)
|
202
|
+
* @param {Event} e Event type
|
203
|
+
*/
|
204
|
+
function setState(e) {
|
205
|
+
let event = e.type;
|
206
|
+
setEventType.call(this, event);
|
207
|
+
|
208
|
+
e.currentTarget.classList.add(this._internalVars.eventType);
|
209
|
+
|
210
|
+
setOtherCardState.call(this, e);
|
211
|
+
}
|
212
|
+
|
213
|
+
/**
|
214
|
+
* Removes the state of card classes (hover, focus) of the card (top and bottom) containing the state
|
215
|
+
* @param {Event} e Event type
|
216
|
+
*/
|
217
|
+
function resetState(e) {
|
218
|
+
let event = e.type;
|
219
|
+
setEventType.call(this, event);
|
220
|
+
|
221
|
+
Array.prototype.forEach.call(this._internalVars.node.querySelectorAll('.' + this._internalVars.eventType), (el)=> {
|
222
|
+
el.classList.remove(this._internalVars.eventType);
|
223
|
+
});
|
224
|
+
}
|
225
|
+
|
226
|
+
function setPayPlan(eventOrNumber) {
|
227
|
+
if (typeof eventOrNumber === 'number') {
|
228
|
+
let cardNumber = eventOrNumber;
|
229
|
+
let cardTop = this._internalVars.payPlanCardTopObject[cardNumber-1];
|
230
|
+
|
231
|
+
if(cardTop) {
|
232
|
+
resetSelected.call(this);
|
233
|
+
cardTop.classList.add(this._internalVars.payPlanSelectedClass);
|
234
|
+
cardTop.classList.add(this._internalVars.focusClass);
|
235
|
+
cardTop.children[0].checked = true;
|
236
|
+
cardTop.setAttribute('aria-checked', 'true');
|
237
|
+
cardTop.parentNode.parentNode.children[1].children[cardNumber-1].classList.add(this._internalVars.payPlanSelectedClass);
|
238
|
+
cardTop.parentNode.parentNode.children[1].children[cardNumber-1].classList.add(this._internalVars.focusClass);
|
239
|
+
payPlanInView.call(this);
|
240
|
+
}
|
241
|
+
} else {
|
242
|
+
let event = eventOrNumber;
|
243
|
+
if(event.type === 'keypress' || event.type === 'keyup' && ((event.keyCode || event.which) !== 13)){} else {
|
244
|
+
resetSelected.call(this);
|
245
|
+
|
246
|
+
event.currentTarget.classList.add(this._internalVars.payPlanSelectedClass);
|
247
|
+
event.currentTarget.classList.add(this._internalVars.focusClass);
|
248
|
+
|
249
|
+
setRowIndex.call(this, event);
|
250
|
+
|
251
|
+
if (event.currentTarget.classList.contains('card-top')) {
|
252
|
+
event.currentTarget.children[0].checked = true;
|
253
|
+
event.currentTarget.setAttribute('aria-checked', 'true');
|
254
|
+
} else {
|
255
|
+
event.currentTarget.parentNode.parentNode.children[this._internalVars.rowIndex].children[0].checked = true;
|
256
|
+
event.currentTarget.parentNode.parentNode.children[this._internalVars.rowIndex].setAttribute('aria-checked', 'true');
|
257
|
+
}
|
258
|
+
|
259
|
+
event.currentTarget.parentNode.parentNode.children[this._internalVars.rowIndex].children[this._internalVars.cardIndex].classList.add(this._internalVars.payPlanSelectedClass);
|
260
|
+
event.currentTarget.parentNode.parentNode.children[this._internalVars.rowIndex].children[this._internalVars.cardIndex].classList.add(this._internalVars.focusClass);
|
261
|
+
|
262
|
+
payPlanInView.call(this);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
|
266
|
+
if (this._options.onPayPlanSelection) {
|
267
|
+
this._options.onPayPlanSelection(this.getPayPlan.call(this));
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
function resetSelected() {
|
272
|
+
let selected = this._internalVars.payPlanObject.querySelectorAll('.' + this._internalVars.payPlanSelectedClass);
|
273
|
+
|
274
|
+
selected[0].children[0].checked = false;
|
275
|
+
selected[0].setAttribute('aria-checked', 'false');
|
276
|
+
|
277
|
+
Array.prototype.forEach.call(selected, (el) => {
|
278
|
+
el.classList.remove(this._internalVars.payPlanSelectedClass);
|
279
|
+
el.classList.remove(this._internalVars.focusClass);
|
280
|
+
});
|
281
|
+
}
|
282
|
+
|
283
|
+
function carouselMovement(event) {
|
284
|
+
event.preventDefault();
|
285
|
+
if(event.type == 'keypress' || event.type == 'keyup' && ((event.keyCode || event.which) != 13)){} else {
|
286
|
+
if(!event.target.hasAttribute('disabled')) {
|
287
|
+
if(!this._internalVars.defaultsSet) {
|
288
|
+
setCarouselDefault.call(this);
|
289
|
+
}
|
290
|
+
if(this._internalVars.carouselInMotion === false) {
|
291
|
+
this._internalVars.carouselInMotion = true;
|
292
|
+
carouselSlide.call(this, event);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
function setCarouselDefault() {
|
299
|
+
if(this._internalVars.payPlanWrapperObjects[1]) {
|
300
|
+
this._internalVars.carouselCardObejcts = this._internalVars.payPlanWrapperObjects[1].querySelectorAll(this._internalVars.payPlanCardClass);
|
301
|
+
} else {
|
302
|
+
this._internalVars.carouselCardObejcts = this._internalVars.payPlanWrapperObjects[0].querySelectorAll(this._internalVars.payPlanCardClass);
|
303
|
+
}
|
304
|
+
this._internalVars.corouselCardLength = this._internalVars.carouselCardObejcts.length / 2;
|
305
|
+
this._internalVars.carouselInitialWidth = this._internalVars.carouselMoveObject.clientWidth;
|
306
|
+
this._internalVars.carouselCardWidth = Math.ceil(this._internalVars.carouselCardObejcts[0].offsetWidth) + 10;
|
307
|
+
this._internalVars.carouselAcutalWidth = this._internalVars.carouselCardWidth * this._internalVars.corouselCardLength;
|
308
|
+
this._internalVars.cardsOnLeft = 0;
|
309
|
+
this._internalVars.cardsOnRight = this._internalVars.corouselCardLength - this._internalVars.cardsOnLeft - 3;
|
310
|
+
|
311
|
+
this._internalVars.defaultsSet = true;
|
312
|
+
}
|
313
|
+
|
314
|
+
function carouselSlide(event) {
|
315
|
+
let operand = null,
|
316
|
+
currentMarginValue = this._internalVars.carouselMoveObject.style.marginLeft,
|
317
|
+
currentMargin = currentMarginValue.slice(0, -2),
|
318
|
+
movementValue = this._internalVars.carouselCardWidth,
|
319
|
+
newMargin = null,
|
320
|
+
disableRightArrow = false,
|
321
|
+
disableLeftArrow = false;
|
322
|
+
|
323
|
+
let cardsRight = 0;
|
324
|
+
let cardsLeft = 0;
|
325
|
+
|
326
|
+
let currentNode = document.querySelectorAll('.' + this._internalVars.payPlanSelectedClass)[0],
|
327
|
+
payPlanWrapper = currentNode.parentNode.parentNode,
|
328
|
+
arrowWdith = document.querySelector('.carousel').offsetWidth,
|
329
|
+
payPlanWrapperLeft = payPlanWrapper.offsetLeft - arrowWdith,
|
330
|
+
outerWrapper = currentNode.parentNode.parentNode.parentNode;
|
331
|
+
|
332
|
+
Array.prototype.forEach.call(this._internalVars.payPlanCardTopObject, (card) => {
|
333
|
+
if (card.offsetLeft + (card.clientWidth + 5) + payPlanWrapperLeft > outerWrapper.clientWidth) {
|
334
|
+
cardsRight++;
|
335
|
+
}
|
336
|
+
if (card.offsetLeft + payPlanWrapper.offsetLeft < 0) {
|
337
|
+
cardsLeft--;
|
338
|
+
}
|
339
|
+
});
|
340
|
+
|
341
|
+
if (event.target.classList.contains('icon-chevron-right')) {
|
342
|
+
operand = '-';
|
343
|
+
cardsLeft = cardsLeft - 1;
|
344
|
+
cardsRight = cardsRight - 1;
|
345
|
+
} else {
|
346
|
+
operand = '+';
|
347
|
+
cardsLeft = cardsLeft + 1;
|
348
|
+
cardsRight = cardsRight + 1;
|
349
|
+
}
|
350
|
+
|
351
|
+
if (operand === '-') {
|
352
|
+
if (cardsRight === 0) {
|
353
|
+
newMargin = -(this._internalVars.corouselCardLength * this._internalVars.carouselCardWidth) + this._internalVars.carouselMoveObject.parentNode.clientWidth;
|
354
|
+
disableRightArrow = true;
|
355
|
+
} else {
|
356
|
+
newMargin = currentMargin - movementValue;
|
357
|
+
disableRightArrow = false;
|
358
|
+
}
|
359
|
+
} else {
|
360
|
+
if ( cardsLeft === 0 || cardsLeft === -0 ) {
|
361
|
+
newMargin = 0;
|
362
|
+
disableLeftArrow = true;
|
363
|
+
} else {
|
364
|
+
newMargin = Number(currentMargin) + movementValue;
|
365
|
+
disableLeftArrow = false;
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
369
|
+
this._internalVars.carouselMoveObject.style.marginLeft = newMargin + 'px';
|
370
|
+
|
371
|
+
this._internalVars.cardsOnLeft = cardsLeft;
|
372
|
+
this._internalVars.cardsOnRight = cardsRight;
|
373
|
+
|
374
|
+
setTimeout(enableArrows.bind(this), 360);
|
375
|
+
|
376
|
+
function enableArrows() {
|
377
|
+
this._internalVars.carouselInMotion = false;
|
378
|
+
}
|
379
|
+
|
380
|
+
setArrowState.call(this, disableRightArrow, disableLeftArrow);
|
381
|
+
}
|
382
|
+
|
383
|
+
function setArrowState(disableRightArrow, disableLeftArrow) {
|
384
|
+
let rightArrow = document.querySelector('.icon-chevron-right'),
|
385
|
+
leftArrow = document.querySelector('.icon-chevron-left');
|
386
|
+
|
387
|
+
if (disableRightArrow === true) {
|
388
|
+
rightArrow.setAttribute('disabled', 'disabled');
|
389
|
+
rightArrow.setAttribute('aria-label', 'Right button disabled');
|
390
|
+
rightArrow.parentNode.classList.add(this._internalVars.carouselDisabledClass);
|
391
|
+
} else {
|
392
|
+
rightArrow.removeAttribute('disabled');
|
393
|
+
rightArrow.parentNode.classList.remove(this._internalVars.carouselDisabledClass);
|
394
|
+
rightArrow.setAttribute('aria-label', 'Right button');
|
395
|
+
}
|
396
|
+
|
397
|
+
if (disableLeftArrow === true) {
|
398
|
+
leftArrow.setAttribute('disabled', 'disabled');
|
399
|
+
leftArrow.parentNode.classList.add(this._internalVars.carouselDisabledClass);
|
400
|
+
leftArrow.setAttribute('aria-label', 'Left button disabled');
|
401
|
+
} else {
|
402
|
+
leftArrow.removeAttribute('disabled');
|
403
|
+
leftArrow.parentNode.classList.remove(this._internalVars.carouselDisabledClass);
|
404
|
+
leftArrow.setAttribute('aria-label', 'Left button');
|
405
|
+
}
|
406
|
+
}
|
407
|
+
|
408
|
+
function resetCarouselDefaults() {
|
409
|
+
this._internalVars.defaultsSet = false;
|
410
|
+
|
411
|
+
if (window.innerWidth > 911) {
|
412
|
+
|
413
|
+
if(this._internalVars.viewPortCheck === true) {
|
414
|
+
let delay = setTimeout(resetCarouselPos.bind(this), 30);
|
415
|
+
this._internalVars.carouselMoveObject.style.position = 'absolute';
|
416
|
+
this._internalVars.carouselMoveObject.style.left = 0 + 'px';
|
417
|
+
this._internalVars.viewPortCheck = false;
|
418
|
+
|
419
|
+
let disableLeftArrow = true;
|
420
|
+
let disableRightArrow = false;
|
421
|
+
setArrowState.call(this, disableRightArrow, disableLeftArrow);
|
422
|
+
}
|
423
|
+
|
424
|
+
this._internalVars.cardsOnLeft = 0;
|
425
|
+
this._internalVars.cardsOnRight = this._internalVars.corouselCardLength - this._internalVars.cardsOnLeft - 2;
|
426
|
+
|
427
|
+
} else {
|
428
|
+
this._internalVars.carouselMoveObject.removeAttribute('style');
|
429
|
+
this._internalVars.viewPortCheck = true;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
function resetCarouselPos() {
|
434
|
+
this._internalVars.carouselMoveObject.style.position = 'relative';
|
435
|
+
this._internalVars.carouselMoveObject.style.marginLeft = 0 + 'px';
|
436
|
+
this._internalVars.carouselMoveObject.style.removeProperty('left');
|
437
|
+
}
|
438
|
+
|
439
|
+
function payPlanInView() {
|
440
|
+
let currentNode = document.querySelectorAll('.' + this._internalVars.payPlanSelectedClass)[0],
|
441
|
+
payPlanWrapper = currentNode.parentNode.parentNode,
|
442
|
+
arrowWdith = document.querySelector('.carousel').offsetWidth,
|
443
|
+
payPlanWrapperLeft = payPlanWrapper.offsetLeft - arrowWdith,
|
444
|
+
outerWrapper = currentNode.parentNode.parentNode.parentNode,
|
445
|
+
left = null,
|
446
|
+
disableRightArrow = false,
|
447
|
+
disableLeftArrow = false;
|
448
|
+
|
449
|
+
if (window.innerWidth > 911) {
|
450
|
+
if(!this._internalVars.defaultsSet) {
|
451
|
+
setCarouselDefault.call(this);
|
452
|
+
}
|
453
|
+
|
454
|
+
let cards = this._internalVars.payPlanCardTopObject.length;
|
455
|
+
let length = (this._internalVars.payPlanCardTopObject[0].offsetWidth + 5) * cards;
|
456
|
+
|
457
|
+
if (currentNode.offsetLeft + (currentNode.clientWidth + 5) + payPlanWrapperLeft > outerWrapper.clientWidth) {
|
458
|
+
left = currentNode.offsetLeft - (outerWrapper.clientWidth - currentNode.offsetWidth);
|
459
|
+
}
|
460
|
+
|
461
|
+
if (currentNode.offsetLeft + payPlanWrapper.offsetLeft < 0) {
|
462
|
+
left = currentNode.offsetLeft
|
463
|
+
}
|
464
|
+
|
465
|
+
this._internalVars.carouselMoveObject.style.marginLeft = '-' + left + 'px';
|
466
|
+
|
467
|
+
let cardsRight = 0;
|
468
|
+
let cardsLeft = 0;
|
469
|
+
|
470
|
+
Array.prototype.forEach.call(this._internalVars.payPlanCardTopObject, (card) => {
|
471
|
+
if (card.offsetLeft + (card.clientWidth + 5) + payPlanWrapperLeft > outerWrapper.clientWidth) {
|
472
|
+
cardsRight++;
|
473
|
+
}
|
474
|
+
if (card.offsetLeft + payPlanWrapper.offsetLeft < 0) {
|
475
|
+
cardsLeft--;
|
476
|
+
}
|
477
|
+
});
|
478
|
+
|
479
|
+
if (left !== null) {
|
480
|
+
if (left < 10) {
|
481
|
+
disableLeftArrow = true;
|
482
|
+
}
|
483
|
+
|
484
|
+
if (outerWrapper.clientWidth + left > length) {
|
485
|
+
disableRightArrow = true;
|
486
|
+
}
|
487
|
+
|
488
|
+
setArrowState.call(this, disableRightArrow, disableLeftArrow);
|
489
|
+
}
|
490
|
+
|
491
|
+
this._internalVars.cardsOnLeft = cardsLeft;
|
492
|
+
this._internalVars.cardsOnRight = cardsRight;
|
493
|
+
} else {
|
494
|
+
|
495
|
+
if (currentNode.offsetLeft + currentNode.clientWidth - outerWrapper.scrollLeft > outerWrapper.clientWidth) {
|
496
|
+
left = currentNode.offsetLeft - (outerWrapper.clientWidth - currentNode.clientWidth - 15);
|
497
|
+
$(outerWrapper).animate({
|
498
|
+
scrollLeft: left
|
499
|
+
}, 350);
|
500
|
+
}
|
501
|
+
|
502
|
+
if (outerWrapper.scrollLeft > currentNode.offsetLeft) {
|
503
|
+
left = currentNode.offsetLeft;
|
504
|
+
$(outerWrapper).animate({
|
505
|
+
scrollLeft: left
|
506
|
+
}, 350);
|
507
|
+
}
|
508
|
+
}
|
509
|
+
}
|
510
|
+
|
511
|
+
/**
|
512
|
+
* hides carousel arrows if 3 or less additional pay plans exist
|
513
|
+
*/
|
514
|
+
function checkPayPlans() {
|
515
|
+
let viewMorePayPlans = this._internalVars.carouselMoveObject.querySelectorAll('.' + this._internalVars.payPlanCardTopClass);
|
516
|
+
if (viewMorePayPlans.length < 4) {
|
517
|
+
Array.prototype.forEach.call(this._internalVars.carouselObjects, (array)=> {
|
518
|
+
array.style.display = 'none';
|
519
|
+
});
|
520
|
+
} else {
|
521
|
+
this._internalVars.carouselMoveObject.parentElement.classList.add('pay-plan-carousel');
|
522
|
+
}
|
523
|
+
}
|
524
|
+
|
525
|
+
function expand(event) {
|
526
|
+
event.preventDefault();
|
527
|
+
let wrapper = event.currentTarget.parentElement;
|
528
|
+
let icon = wrapper.querySelectorAll('span')[1];
|
529
|
+
if (wrapper.classList.contains('collapsed')) {
|
530
|
+
wrapper.classList.remove('collapsed');
|
531
|
+
$(this._internalVars.premiumClass).slideDown();
|
532
|
+
wrapper.querySelector('a').innerHTML = "Hide Payment Schedule";
|
533
|
+
wrapper.setAttribute('aria-expanded', 'true');
|
534
|
+
icon.classList.remove('icon-chevron-down');
|
535
|
+
icon.classList.add('icon-chevron-up');
|
536
|
+
|
537
|
+
} else {
|
538
|
+
wrapper.classList.add('collapsed');
|
539
|
+
$(this._internalVars.premiumClass).slideUp();
|
540
|
+
wrapper.querySelector('a').innerHTML = "Show Payment Schedule";
|
541
|
+
wrapper.setAttribute('aria-expanded', 'false');
|
542
|
+
icon.classList.remove('icon-chevron-up');
|
543
|
+
icon.classList.add('icon-chevron-down');
|
544
|
+
}
|
545
|
+
}
|
546
|
+
|
547
|
+
/**
|
548
|
+
* setLocalVars()
|
549
|
+
* set local vars to the ones passed in options
|
550
|
+
*/
|
551
|
+
function setLocalVars() {
|
552
|
+
if(this._internalVars.contentType === 'string') {
|
553
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
554
|
+
} else if (this._internalVars.contentType === 'domNode') {
|
555
|
+
this._internalVars.node = this._options.content;
|
556
|
+
}
|
557
|
+
|
558
|
+
this._internalVars.payPlanObject = this._internalVars.node;
|
559
|
+
|
560
|
+
this._internalVars.payPlanCardClass = '.payment-plan-card';
|
561
|
+
this._internalVars.payPlanCards = this._internalVars.payPlanObject.querySelectorAll(this._internalVars.payPlanCardClass);
|
562
|
+
|
563
|
+
this._internalVars.payPlanCardTopClass = 'card-top';
|
564
|
+
this._internalVars.payPlanCardTopObject = this._internalVars.node.querySelectorAll('.' + this._internalVars.payPlanCardTopClass);
|
565
|
+
|
566
|
+
this._internalVars.hoverClass = 'hover';
|
567
|
+
this._internalVars.focusClass = 'focus';
|
568
|
+
|
569
|
+
this._internalVars.payPlanSelectedClass = 'payment-plan-selected';
|
570
|
+
|
571
|
+
this._internalVars.carouselClass = 'carousel';
|
572
|
+
this._internalVars.carouselObjects = this._internalVars.node.querySelectorAll('.' + this._internalVars.carouselClass);
|
573
|
+
this._internalVars.carouselInMotion = false;
|
574
|
+
|
575
|
+
this._internalVars.carouselBtnClass = 'carousel-icon';
|
576
|
+
this._internalVars.carouselBtnObjects = this._internalVars.node.querySelectorAll('.' + this._internalVars.carouselBtnClass);
|
577
|
+
|
578
|
+
this._internalVars.carouselDisabledClass = 'disabled';
|
579
|
+
|
580
|
+
this._internalVars.payPlanWrapperClass = 'payment-plan-wrapper';
|
581
|
+
this._internalVars.payPlanWrapperObjects = this._internalVars.payPlanObject.querySelectorAll('.' + this._internalVars.payPlanWrapperClass);
|
582
|
+
|
583
|
+
this._internalVars.defaultsSet = false;
|
584
|
+
|
585
|
+
this._internalVars.payPlanInnerWrapperClass = 'payment-plan-inner-wrapper';
|
586
|
+
this._internalVars.payPlanInnerWrapperObjects = this._internalVars.payPlanObject.querySelectorAll('.' + this._internalVars.payPlanInnerWrapperClass);
|
587
|
+
if (this._internalVars.payPlanWrapperObjects[1]) {
|
588
|
+
this._internalVars.carouselMoveObject = this._internalVars.payPlanWrapperObjects[1].querySelector('.' + this._internalVars.payPlanInnerWrapperClass);
|
589
|
+
} else {
|
590
|
+
this._internalVars.carouselMoveObject = this._internalVars.payPlanWrapperObjects[0].querySelector('.' + this._internalVars.payPlanInnerWrapperClass);
|
591
|
+
}
|
592
|
+
|
593
|
+
this._internalVars.viewPortCheck = false;
|
594
|
+
this._internalVars.rowIndex = null;
|
595
|
+
this._internalVars.cardIndex = null;
|
596
|
+
this._internalVars.eventType = null;
|
597
|
+
|
598
|
+
this._internalVars.expandLinkClass = 'payment-schedule-link';
|
599
|
+
this._internalVars.expandLinkWrapper = this._internalVars.payPlanObject.querySelector('.' + this._internalVars.expandLinkClass);
|
600
|
+
this._internalVars.expandLink = this._internalVars.expandLinkWrapper.querySelectorAll('span');
|
601
|
+
this._internalVars.premiumClass = '.payment-schedule';
|
602
|
+
}
|
603
|
+
|
604
|
+
export default PayPlans;
|