geico-design-kit 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/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 +32 -0
- 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
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import * as utils from '../../src/utils';
|
|
2
|
+
import baseComponent from '../../src/baseComponent';
|
|
3
|
+
import appState from '../../src/appState';
|
|
4
|
+
|
|
5
|
+
const validateSettings = [
|
|
6
|
+
{
|
|
7
|
+
setting: "content",
|
|
8
|
+
isRequired: true,
|
|
9
|
+
validate: "type",
|
|
10
|
+
possibleValues: ["string", "object"],
|
|
11
|
+
errorMessage: ["GDK CurrencyInput : Content must be defined and set to a DOM selector or Node"]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
setting: "numType",
|
|
15
|
+
isRequired: false,
|
|
16
|
+
validate: "value",
|
|
17
|
+
possibleValues: ["whole", "decimal"],
|
|
18
|
+
errorMessage: ["GDK CurrencyInput : numType must be set to whole or decimal"]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
setting: "onCompleteFormat",
|
|
22
|
+
isRequired: false,
|
|
23
|
+
validate: "type",
|
|
24
|
+
possibleValues: ["function"],
|
|
25
|
+
errorMessage: ["GDK CurrencyInput : onCompleteFormat must be a defined and set function"]
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* CurrencyInput Class
|
|
31
|
+
*/
|
|
32
|
+
class CurrencyInput {
|
|
33
|
+
/**
|
|
34
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
|
35
|
+
* @param {string|Object} content
|
|
36
|
+
* A reference to the component node of currency input field
|
|
37
|
+
*
|
|
38
|
+
* @param {string} [numType="decimal"]
|
|
39
|
+
* A string representing the number type of the currency input field
|
|
40
|
+
*
|
|
41
|
+
* @param {function} [onCompleteFormat]
|
|
42
|
+
* A callback function fired on blur after formatting is complete in the input field
|
|
43
|
+
*/
|
|
44
|
+
constructor(options) {
|
|
45
|
+
|
|
46
|
+
console.log('CurrencyInput initialized');
|
|
47
|
+
|
|
48
|
+
this._internalVars = {
|
|
49
|
+
node: null //used for current node
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//options with defaults set
|
|
53
|
+
this._defaults = {
|
|
54
|
+
numType: 'decimal'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Create options by extending defaults with the passed in arugments
|
|
58
|
+
if (options && typeof options === "object") {
|
|
59
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
//if the required options are valid set up the environment
|
|
64
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
|
65
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
|
66
|
+
setLocalVars.call(this);
|
|
67
|
+
setEvents.call(this);
|
|
68
|
+
|
|
69
|
+
if(this._internalVars.node.getAttribute('type') != 'text'){
|
|
70
|
+
this._internalVars.node.setAttribute('type', 'text');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if(!this._internalVars.node.hasAttribute('placeholder') && this._options.numType == 'decimal'){
|
|
74
|
+
this._internalVars.node.setAttribute('placeholder', '0.00');
|
|
75
|
+
}else if(!this._internalVars.node.hasAttribute('placeholder') && this._options.numType == 'whole'){
|
|
76
|
+
this._internalVars.node.setAttribute('placeholder', '0');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(this._internalVars.inputValue!==''){
|
|
80
|
+
this._internalVars.inputValue = parsedValue(this._internalVars.inputValue, this._options.numType);
|
|
81
|
+
this._internalVars.inputValue = insertCommas(this._internalVars.inputValue.toString());
|
|
82
|
+
this._internalVars.node.setAttribute('value', this._internalVars.inputValue);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//Public Methods
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* removes the node from the dom and any events attached
|
|
91
|
+
*/
|
|
92
|
+
destroy(){
|
|
93
|
+
removeEvents.call(this);
|
|
94
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
|
95
|
+
|
|
96
|
+
//a little garbage collection
|
|
97
|
+
for (var variableKey in this){
|
|
98
|
+
if (this.hasOwnProperty(variableKey)){
|
|
99
|
+
delete this[variableKey];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* getCurrencyInput()
|
|
106
|
+
* return a type float number from currency input field
|
|
107
|
+
* @returns {float}
|
|
108
|
+
*/
|
|
109
|
+
getCurrencyInput(){
|
|
110
|
+
return parseFloat(parsedValue(this._internalVars.node.value, this._options.numType));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Private Methods
|
|
115
|
+
/**
|
|
116
|
+
* setEvents()
|
|
117
|
+
* Sets all the events needed for the component
|
|
118
|
+
*/
|
|
119
|
+
function setEvents() {
|
|
120
|
+
this._internalVars.node.addEventListener("keydown", this._internalVars.keyDownHandler);
|
|
121
|
+
this._internalVars.node.addEventListener("keyup", this._internalVars.keyUpHandler);
|
|
122
|
+
this._internalVars.node.addEventListener("keypress", this._internalVars.keyPressHandler);
|
|
123
|
+
this._internalVars.node.addEventListener("blur", this._internalVars.blurHandler);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* removeEvents()
|
|
129
|
+
* removes all events from the component
|
|
130
|
+
*/
|
|
131
|
+
function removeEvents() {
|
|
132
|
+
this._internalVars.node.removeEventListener("keydown", this._internalVars.keyDownHandler);
|
|
133
|
+
this._internalVars.node.removeEventListener("keyup", this._internalVars.keyUpHandler);
|
|
134
|
+
this._internalVars.node.removeEventListener("keypress", this._internalVars.keyPressHandler);
|
|
135
|
+
this._internalVars.node.removeEventListener("blur", this._internalVars.blurHandler);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
function decimalExist(value){
|
|
141
|
+
if(value.indexOf('.') != -1){
|
|
142
|
+
return true;
|
|
143
|
+
}else{
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function numOfCharAfterDecimal(value){
|
|
149
|
+
return value.toString().substr(value.toString().indexOf(".") + 1).length;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function isCharacterValid(e, type){
|
|
153
|
+
var keyCode = e.which || e.keyCode;
|
|
154
|
+
//numeric arrow key backspace and tab enter
|
|
155
|
+
if((keyCode >= 48 && keyCode <= 57) || (keyCode >= 37 && keyCode <=40) || (keyCode >= 8 && keyCode <= 9) || keyCode == 13 || (type == 'decimal' && keyCode == 190 || keyCode == 46)){
|
|
156
|
+
return true;
|
|
157
|
+
}else{
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function parsedValue(value, type){
|
|
163
|
+
if(type == 'decimal'){
|
|
164
|
+
return parseFloat(removeCommas(value)).toFixed(2);
|
|
165
|
+
}else if(type == 'whole'){
|
|
166
|
+
return parseInt(removeCommas(value));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function insertCommas(value){
|
|
171
|
+
value = value.split('.');
|
|
172
|
+
if(value[1] !== undefined){
|
|
173
|
+
return value[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") + '.' + value[1];
|
|
174
|
+
}else{
|
|
175
|
+
return value[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function removeCommas(value){
|
|
180
|
+
return value.replace(/[^\d\.]/g,'');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function commaCount(value){
|
|
184
|
+
var counter = 0;
|
|
185
|
+
for(var i=0; i < value.length;i++){
|
|
186
|
+
if(value.charAt(i) == ','){
|
|
187
|
+
counter++;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return counter;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function isCaretBeforeDecimal(caretPos, decimalPos){
|
|
194
|
+
if(caretPos <= decimalPos){
|
|
195
|
+
return true;
|
|
196
|
+
}else if(caretPos > decimalPos){
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function isSelected(){
|
|
202
|
+
if(document.getSelection().toString() !== ''){
|
|
203
|
+
return true;
|
|
204
|
+
}else if(document.getSelection().toString === ''){
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//blur
|
|
210
|
+
function completeDisplay(){
|
|
211
|
+
this._internalVars.inputValue = this._internalVars.node.value;
|
|
212
|
+
|
|
213
|
+
if(this._internalVars.node.value !== ''){
|
|
214
|
+
this._internalVars.node.value = insertCommas(parsedValue(this._internalVars.inputValue, this._options.numType).toString());
|
|
215
|
+
|
|
216
|
+
if(this._options.onCompleteFormat){
|
|
217
|
+
this._options.onCompleteFormat(parsedValue(this._internalVars.node.value, this._options.numType));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//keydown-initial
|
|
223
|
+
function inputCharacters(e){
|
|
224
|
+
this._internalVars.inputValue = this._internalVars.node.value;
|
|
225
|
+
this._internalVars.caretLocation = this._internalVars.node.selectionStart;
|
|
226
|
+
this._internalVars.decimalLocation = this._internalVars.node.value.indexOf('.');
|
|
227
|
+
|
|
228
|
+
if(this._options.numType == 'decimal'){
|
|
229
|
+
if(decimalExist(this._internalVars.inputValue)){
|
|
230
|
+
this._internalVars.allowDecimal = false;
|
|
231
|
+
}else{
|
|
232
|
+
this._internalVars.allowDecimal = true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if(decimalExist(this._internalVars.inputValue) && !isCaretBeforeDecimal(this._internalVars.caretLocation, this._internalVars.decimalLocation) && numOfCharAfterDecimal(this._internalVars.inputValue) == 2 && !isSelected()){
|
|
236
|
+
this._internalVars.allowCharacters = false;
|
|
237
|
+
this._internalVars.node.setAttribute('maxlength', this._internalVars.inputValue.length);
|
|
238
|
+
}
|
|
239
|
+
else if(decimalExist(this._internalVars.inputValue) && isCaretBeforeDecimal(this._internalVars.caretLocation, this._internalVars.decimalLocation) && numOfCharAfterDecimal(this._internalVars.inputValue) <= 2 || isSelected()){
|
|
240
|
+
this._internalVars.allowCharacters = true;
|
|
241
|
+
this._internalVars.node.removeAttribute('maxlength');
|
|
242
|
+
}
|
|
243
|
+
else{
|
|
244
|
+
this._internalVars.allowCharacters = true;
|
|
245
|
+
this._internalVars.node.removeAttribute('maxlength');
|
|
246
|
+
}
|
|
247
|
+
}else if(this._options.numType == 'whole'){
|
|
248
|
+
this._internalVars.allowDecimal = false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
//keyup-after
|
|
254
|
+
function inputAutoCommas(e){
|
|
255
|
+
var keyCode = e.which || e.keyCode;
|
|
256
|
+
this._internalVars.inputValue = this._internalVars.node.value;
|
|
257
|
+
this._internalVars.caretLocation = this._internalVars.node.selectionStart;
|
|
258
|
+
var beforeCommaCount = commaCount(this._internalVars.inputValue);
|
|
259
|
+
|
|
260
|
+
if(keyCode != 9 && keyCode != 16 && !(keyCode >= 37 && keyCode <=40)) {
|
|
261
|
+
this._internalVars.node.value = insertCommas(removeCommas(this._internalVars.inputValue));
|
|
262
|
+
|
|
263
|
+
this._internalVars.inputValue = this._internalVars.node.value;
|
|
264
|
+
|
|
265
|
+
if(this._options.numType == 'whole'){
|
|
266
|
+
this._internalVars.node.value = this._internalVars.inputValue.replace('.', '');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var afterCommaCount = commaCount(this._internalVars.inputValue);
|
|
270
|
+
|
|
271
|
+
if (beforeCommaCount != afterCommaCount) {
|
|
272
|
+
this._internalVars.node.selectionStart = this._internalVars.caretLocation + 1;
|
|
273
|
+
this._internalVars.node.selectionEnd = this._internalVars.caretLocation + 1;
|
|
274
|
+
if (keyCode == 8) {
|
|
275
|
+
this._internalVars.node.selectionStart = this._internalVars.caretLocation - 1;
|
|
276
|
+
this._internalVars.node.selectionEnd = this._internalVars.caretLocation - 1;
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
this._internalVars.node.selectionStart = this._internalVars.caretLocation;
|
|
280
|
+
this._internalVars.node.selectionEnd = this._internalVars.caretLocation;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//keypress
|
|
286
|
+
function preventInput(event){
|
|
287
|
+
if(!isCharacterValid(event, this._options.numType) || !this._internalVars.allowCharacters && event.which != 8){
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
}
|
|
290
|
+
if(!this._internalVars.allowDecimal && event.which == 46){
|
|
291
|
+
event.preventDefault();
|
|
292
|
+
}
|
|
293
|
+
if((event.shiftKey) && event.which == 37 || event.which == 38){
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* setLocalVars()
|
|
300
|
+
* set local vars to the ones passed in options
|
|
301
|
+
*/
|
|
302
|
+
function setLocalVars() {
|
|
303
|
+
if(this._internalVars.contentType === 'string') {
|
|
304
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
|
305
|
+
} else if (this._internalVars.contentType === 'domNode') {
|
|
306
|
+
this._internalVars.node = this._options.content;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this._internalVars.keyDownHandler = inputCharacters.bind(this);
|
|
310
|
+
this._internalVars.keyUpHandler = inputAutoCommas.bind(this);
|
|
311
|
+
this._internalVars.keyPressHandler = preventInput.bind(this);
|
|
312
|
+
this._internalVars.blurHandler = completeDisplay.bind(this);
|
|
313
|
+
|
|
314
|
+
this._internalVars.inputValue = this._internalVars.node.value;
|
|
315
|
+
this._internalVars.caretLocation = this._internalVars.node.selectionStart;
|
|
316
|
+
this._internalVars.decimalLocation = this._internalVars.node.value.indexOf('.');
|
|
317
|
+
this._internalVars.allowCharacters = true;
|
|
318
|
+
this._internalVars.allowDecimal = true;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export default CurrencyInput;
|