geico-design-kit 7.0.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/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,532 @@
|
|
1
|
+
//Module Imports
|
2
|
+
import baseComponent from '../../src/baseComponent';
|
3
|
+
import UserAgentService from '../../src/services/UserAgentService';
|
4
|
+
|
5
|
+
var interactjs = require('interact.js');
|
6
|
+
|
7
|
+
const validateSettings = [
|
8
|
+
{
|
9
|
+
setting : "content",
|
10
|
+
isRequired : true,
|
11
|
+
validate : "type",
|
12
|
+
possibleValues : ["string","object"],
|
13
|
+
errorMessage : ["GDK Time Input : Time Input must be defined and set to a DOM selector or Node"]
|
14
|
+
},
|
15
|
+
{
|
16
|
+
setting : "segmentedControlVar",
|
17
|
+
isRequired : true,
|
18
|
+
validate : "type",
|
19
|
+
possibleValues : ["string"],
|
20
|
+
errorMessage : ["GDK Time Input : segmentedControlVar must be defined as a string"]
|
21
|
+
},
|
22
|
+
{
|
23
|
+
setting : "callBackOnTimeChange",
|
24
|
+
isRequired : false,
|
25
|
+
validate : "type",
|
26
|
+
possibleValues : ["function"],
|
27
|
+
errorMessage : ["GDK Time Input : callBackOnTimeChange must be a defined and set function"]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
setting : "setInitialTime",
|
31
|
+
isRequired : false,
|
32
|
+
validate : "type",
|
33
|
+
possibleValues : ["string"],
|
34
|
+
errorMessage : ["GDK Time Input : setInitialTime must be defined as a string"]
|
35
|
+
}
|
36
|
+
];
|
37
|
+
|
38
|
+
/**
|
39
|
+
* TimeInput Class
|
40
|
+
*/
|
41
|
+
class TimeInput {
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Refer to the design kit section of this component for JS examples and setting details.
|
45
|
+
* @param {string|Object} content
|
46
|
+
* A reference to the time input component node
|
47
|
+
*
|
48
|
+
*
|
49
|
+
* @param {string} segmentedControlVar
|
50
|
+
* A name for the segmented control GDK Object
|
51
|
+
*
|
52
|
+
*
|
53
|
+
* @param {function} [callBackOnTimeChange]
|
54
|
+
* A callback function triggered when the time has changed
|
55
|
+
*
|
56
|
+
* @param {string} [setInitialTime]
|
57
|
+
* A string that will populate the time input field and adjust the segmented control if necessary
|
58
|
+
*
|
59
|
+
*
|
60
|
+
*/
|
61
|
+
constructor(options) {
|
62
|
+
|
63
|
+
this._internalVars = {};
|
64
|
+
|
65
|
+
//options with defaults set
|
66
|
+
this._defaults = {
|
67
|
+
|
68
|
+
};
|
69
|
+
|
70
|
+
// Create options by extending defaults with the passed in arguments
|
71
|
+
if (options && typeof options === "object") {
|
72
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
73
|
+
}
|
74
|
+
|
75
|
+
//if the required options are valid set up the environment
|
76
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
77
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
78
|
+
setLocalVars.call(this);
|
79
|
+
initSegmentedControl.call(this);
|
80
|
+
setEvents.call(this);
|
81
|
+
setValue.call(this);
|
82
|
+
initMask.call(this);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
//Public Methods
|
87
|
+
|
88
|
+
/**
|
89
|
+
* returns the time entered in a 24hr format
|
90
|
+
* @return {{time: (string)}}
|
91
|
+
*/
|
92
|
+
getTime() {
|
93
|
+
this._internalVars.publicMethodUsed = true;
|
94
|
+
getValue.call(this);
|
95
|
+
return this._internalVars.timeInputFieldValue;
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* sets the time value
|
100
|
+
* @param {string} time String containing the 24hr time format
|
101
|
+
*/
|
102
|
+
setTime(time) {
|
103
|
+
this._internalVars.publicMethodUsed = true;
|
104
|
+
getCurrentValue.call(this);
|
105
|
+
setValue.call(this, time);
|
106
|
+
getValue.call(this);
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* removes the node from the dom and any events attached
|
111
|
+
*/
|
112
|
+
destroy(){
|
113
|
+
removeEvents.call(this);
|
114
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
115
|
+
|
116
|
+
//a little garbage collection
|
117
|
+
for (var variableKey in this){
|
118
|
+
if (this.hasOwnProperty(variableKey)){
|
119
|
+
delete this[variableKey];
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
// Private Methods
|
126
|
+
|
127
|
+
/**
|
128
|
+
* setEvents()
|
129
|
+
* Sets all the events needed for the component
|
130
|
+
*/
|
131
|
+
function setEvents() {
|
132
|
+
this._internalVars.timeInputField.addEventListener('focus', getCurrentValue.bind(this));
|
133
|
+
this._internalVars.timeInputField.addEventListener('keyup', checkKey.bind(this));
|
134
|
+
this._internalVars.timeInputField.addEventListener('blur', getValue.bind(this));
|
135
|
+
|
136
|
+
const eventName = UserAgentService._clickEventName();
|
137
|
+
|
138
|
+
Array.prototype.forEach.call(this._internalVars.dropZoneObject, (element)=>{
|
139
|
+
element.addEventListener(eventName, setSegmentValue.bind(this));
|
140
|
+
interactjs(element)
|
141
|
+
.dropzone({
|
142
|
+
ondrop: segmentChange.bind(this)
|
143
|
+
});
|
144
|
+
});
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* removeEvents()
|
149
|
+
* removes all events from the component
|
150
|
+
*/
|
151
|
+
function removeEvents() {
|
152
|
+
this._internalVars.timeInputField.removeEventListener('focus', getCurrentValue.bind(this));
|
153
|
+
this._internalVars.timeInputField.removeEventListener('keyup', checkKey.bind(this));
|
154
|
+
this._internalVars.timeInputField.removeEventListener('blur', getValue.bind(this));
|
155
|
+
|
156
|
+
const eventName = UserAgentService._clickEventName();
|
157
|
+
|
158
|
+
Array.prototype.forEach.call(this._internalVars.dropZoneObject, (element)=>{
|
159
|
+
element.removeEventListener(eventName, setSegmentValue.bind(this));
|
160
|
+
});
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* initMask()
|
165
|
+
* instantiates the input field mask
|
166
|
+
*/
|
167
|
+
function initMask() {
|
168
|
+
$(this._internalVars.timeInputField).mask("99:99",{});
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* initSegmentedControl()
|
173
|
+
* instantiates the segmented control component
|
174
|
+
*/
|
175
|
+
function initSegmentedControl() {
|
176
|
+
this[this._options.segmentedControlVar] = new GDK.SegmentedControl({
|
177
|
+
"content": this._internalVars.segmentedControlObject
|
178
|
+
});
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* setValue()
|
183
|
+
* populates the input field value and calls a function to adjust the segmented control
|
184
|
+
*/
|
185
|
+
function setValue(time) {
|
186
|
+
let entry;
|
187
|
+
|
188
|
+
if(time) {
|
189
|
+
entry = time;
|
190
|
+
} else if(this._options.setInitialTime) {
|
191
|
+
entry = this._options.setInitialTime;
|
192
|
+
} else {
|
193
|
+
entry = ':';
|
194
|
+
}
|
195
|
+
|
196
|
+
if(entry.indexOf(":") > 0) {
|
197
|
+
let minutes = entry.substring(entry.indexOf(":")+1),
|
198
|
+
hour = entry.substring(0,entry.indexOf(":"));
|
199
|
+
|
200
|
+
if(minutes.length == 2 && hour.length < 3 && hour.length > 0) {
|
201
|
+
if(hour < 24 && minutes < 60) {
|
202
|
+
let numHour = parseInt(hour),
|
203
|
+
userEntry = false,
|
204
|
+
segmentVars = setChangeSegmentVars(numHour, userEntry);
|
205
|
+
|
206
|
+
updatePeriod.call(this, segmentVars.period, segmentVars.changeSegment);
|
207
|
+
|
208
|
+
let convertedTime = convertTo12hrFormat.call(this, numHour, minutes, segmentVars.changeSegment);
|
209
|
+
|
210
|
+
if(entry === time) {
|
211
|
+
$(this._internalVars.timeInputField).mask("",{});
|
212
|
+
this._internalVars.timeInputField.setAttribute('value', convertedTime);
|
213
|
+
this._internalVars.timeInputField.value = convertedTime;
|
214
|
+
$(this._internalVars.timeInputField).mask("99:99",{});
|
215
|
+
} else {
|
216
|
+
this._internalVars.timeInputField.setAttribute('value', convertedTime);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
/**
|
224
|
+
* setChangeSegmentVars(numHour, userEntry)
|
225
|
+
* @param numHour
|
226
|
+
* @param userEntry
|
227
|
+
* @returns {{period: string, changeSegment: boolean}}
|
228
|
+
* returns an object storing the time period and boolean indicating if the segmented control should be changed
|
229
|
+
*/
|
230
|
+
function setChangeSegmentVars(numHour, userEntry) {
|
231
|
+
if (numHour > 12 && numHour < 24) {
|
232
|
+
return {
|
233
|
+
"period": "PM",
|
234
|
+
"changeSegment": true
|
235
|
+
};
|
236
|
+
} else if (numHour < 1) {
|
237
|
+
return {
|
238
|
+
"period": "AM",
|
239
|
+
"changeSegment": true
|
240
|
+
};
|
241
|
+
} else {
|
242
|
+
if(userEntry === false) {
|
243
|
+
return {
|
244
|
+
"period": "AM",
|
245
|
+
"changeSegment": true
|
246
|
+
};
|
247
|
+
} else {
|
248
|
+
return {
|
249
|
+
"period": "AM",
|
250
|
+
"changeSegment": false
|
251
|
+
};
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* convertTo12hrFormat(numHour, minutes)
|
258
|
+
* @param numHour
|
259
|
+
* @param minutes
|
260
|
+
* @returns {string}
|
261
|
+
* returns a string converting a 24hr time format to a 12hr format
|
262
|
+
*/
|
263
|
+
function convertTo12hrFormat(numHour, minutes) {
|
264
|
+
if(numHour > 12) {
|
265
|
+
numHour = numHour - 12;
|
266
|
+
} else if(numHour < 1) {
|
267
|
+
numHour = numHour + 12;
|
268
|
+
}
|
269
|
+
|
270
|
+
let newHour = numHour.toString();
|
271
|
+
|
272
|
+
if (newHour.length < 2) {
|
273
|
+
newHour = "0" + newHour;
|
274
|
+
}
|
275
|
+
|
276
|
+
return newHour + minutes;
|
277
|
+
}
|
278
|
+
|
279
|
+
/**
|
280
|
+
* convertTo24hrFormat(activeSegment, hour, minutes)
|
281
|
+
* @param activeSegment
|
282
|
+
* @param hour
|
283
|
+
* @param minutes
|
284
|
+
* @returns {string}
|
285
|
+
* returns a string converting a 12hr time format to a 24hr format
|
286
|
+
*/
|
287
|
+
function convertTo24hrFormat(activeSegment, hour, minutes) {
|
288
|
+
let newHour = parseInt(hour);
|
289
|
+
if(activeSegment === 'PM') {
|
290
|
+
hour = newHour + 12;
|
291
|
+
if(hour === 24) {
|
292
|
+
hour = hour - 12;
|
293
|
+
}
|
294
|
+
} else {
|
295
|
+
if(newHour === 12) {
|
296
|
+
hour = newHour - 12 + "0";
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
return hour + ":" + minutes;
|
301
|
+
}
|
302
|
+
|
303
|
+
/**
|
304
|
+
* parseInputValue()
|
305
|
+
* Takes the time value and returns hours, minutes and the current segment
|
306
|
+
* @returns {{hours: string, minutes: string, segment: string}}
|
307
|
+
*/
|
308
|
+
function parseInputValue() {
|
309
|
+
this._internalVars.timeInputSegmentSelection = this._internalVars.timeInputObject.querySelector('.' + this._internalVars.activeClass);
|
310
|
+
let activeElementText = this._internalVars.timeInputSegmentSelection.innerHTML,
|
311
|
+
minutes = this._internalVars.timeInputField.value.slice(-2),
|
312
|
+
hours = this._internalVars.timeInputField.value.substring(0,2);
|
313
|
+
|
314
|
+
return {
|
315
|
+
"hours" : hours,
|
316
|
+
"minutes" : minutes,
|
317
|
+
"segment" : activeElementText
|
318
|
+
};
|
319
|
+
}
|
320
|
+
|
321
|
+
/**
|
322
|
+
* getCurrentValue()
|
323
|
+
* Set a local variable and stores the current time
|
324
|
+
*/
|
325
|
+
function getCurrentValue() {
|
326
|
+
let timeEntry = parseInputValue.call(this);
|
327
|
+
|
328
|
+
if (timeEntry.hours.length !== 0 && timeEntry.minutes.length !== 0) {
|
329
|
+
this._internalVars.timeInputFieldCurrentValue = convertTo24hrFormat.call(this, timeEntry.segment, timeEntry.hours, timeEntry.minutes);
|
330
|
+
} else {
|
331
|
+
this._internalVars.timeInputFieldCurrentValue = '__:__';
|
332
|
+
}
|
333
|
+
|
334
|
+
this._internalVars.timeInputCompare = true;
|
335
|
+
}
|
336
|
+
|
337
|
+
/**
|
338
|
+
* setSegmentValue()
|
339
|
+
* Sets a new value for the segmented control when the user changes the segment manually
|
340
|
+
*/
|
341
|
+
function setSegmentValue() {
|
342
|
+
let timeEntry = parseInputValue.call(this);
|
343
|
+
|
344
|
+
if(timeEntry.hours.length !== 0 && timeEntry.minutes.length !== 0) {
|
345
|
+
if(timeEntry.segment === "AM") {
|
346
|
+
timeEntry.segment = "PM";
|
347
|
+
} else {
|
348
|
+
timeEntry.segment = "AM";
|
349
|
+
}
|
350
|
+
|
351
|
+
this._internalVars.timeInputFieldCurrentValue = convertTo24hrFormat.call(this, timeEntry.segment, timeEntry.hours, timeEntry.minutes);
|
352
|
+
this._internalVars.timeInputCompare = true;
|
353
|
+
getValue.call(this);
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
/**
|
358
|
+
* checkKey(event)
|
359
|
+
* @param event
|
360
|
+
* check if numbers or backspace was pressed
|
361
|
+
*/
|
362
|
+
function checkKey(event) {
|
363
|
+
//Check the key pressed to trigger function (keys 0-9 and 'backspace')
|
364
|
+
|
365
|
+
if ( (event.which > 47 && event.which < 58) || (event.which === 8) || (event.which > 95 && event.which < 106) || event.which == 229) {
|
366
|
+
setTimePeriodVar.call(this);
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
/**
|
371
|
+
* setTimePeriodVar()
|
372
|
+
* set an AM or PM variable and evaluate if the segment should change
|
373
|
+
*/
|
374
|
+
function setTimePeriodVar() {
|
375
|
+
let hour,
|
376
|
+
userEntry = true;
|
377
|
+
|
378
|
+
//Desktops/iOS recognize the input mask as a value when checking the length, Android does not
|
379
|
+
if (this._internalVars.timeInputField.value.length > 3) {
|
380
|
+
hour = this._internalVars.timeInputField.value.substring(2, 0);
|
381
|
+
}
|
382
|
+
|
383
|
+
if (this._internalVars.timeInputField.value.length === 3) {
|
384
|
+
hour = this._internalVars.timeInputField.value.substring(1, 0);
|
385
|
+
}
|
386
|
+
|
387
|
+
let segmentVars = setChangeSegmentVars(hour, userEntry);
|
388
|
+
|
389
|
+
updatePeriod.call(this, segmentVars.period, segmentVars.changeSegment);
|
390
|
+
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* updatePeriod(period, changeSegment)
|
394
|
+
* @param period
|
395
|
+
* @param changeSegment
|
396
|
+
* changes the segmented control to AM or PM
|
397
|
+
*/
|
398
|
+
function updatePeriod(period, changeSegment) {
|
399
|
+
let activeIndex;
|
400
|
+
|
401
|
+
if (period === 'AM') {
|
402
|
+
activeIndex = 0;
|
403
|
+
} else {
|
404
|
+
activeIndex = 1;
|
405
|
+
}
|
406
|
+
|
407
|
+
this._internalVars.timeInputSegmentSelection = this._internalVars.timeInputObject.querySelector('.' + this._internalVars.activeClass);
|
408
|
+
|
409
|
+
if (period !== this._internalVars.timeInputSegmentSelection.innerHTML && changeSegment === true) {
|
410
|
+
let delay = setTimeout(setNewSegmentValue.bind(this), 350);
|
411
|
+
|
412
|
+
if(this._internalVars.timeInputSegmentSelection) {
|
413
|
+
this._internalVars.timeInputSegmentSelection.classList.remove(this._internalVars.activeClass);
|
414
|
+
this._internalVars.timeInputSegmentSelection.setAttribute('aria-checked', 'false');
|
415
|
+
}
|
416
|
+
|
417
|
+
this._internalVars.dropZoneObject[activeIndex].classList.add(this._internalVars.activeClass);
|
418
|
+
this._internalVars.dropZoneObject[activeIndex].setAttribute('aria-checked', 'true');
|
419
|
+
this._internalVars.draggableObject.classList.add(this._internalVars.animateClass);
|
420
|
+
this._internalVars.draggableObject.classList.add(this._internalVars.activeDragClass);
|
421
|
+
this._internalVars.draggableObject.innerText = '';
|
422
|
+
this._internalVars.draggableObject.style.zIndex = 1;
|
423
|
+
|
424
|
+
this._internalVars.timeInputSegmentSelection = this._internalVars.timeInputObject.querySelector('.' + this._internalVars.activeClass);
|
425
|
+
let activeElementLeft = this._internalVars.timeInputSegmentSelection.offsetLeft;
|
426
|
+
|
427
|
+
this._internalVars.draggableObject.style.left = activeElementLeft + 'px';
|
428
|
+
this._internalVars.draggableObject.setAttribute('data-x', activeElementLeft);
|
429
|
+
this._internalVars.timeInputSegmentChangeOnly = true;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
/**
|
434
|
+
* setNewSegmentValue()
|
435
|
+
* sets values of element after animation
|
436
|
+
*/
|
437
|
+
function setNewSegmentValue() {
|
438
|
+
this._internalVars.timeInputSegmentSelection = this._internalVars.timeInputObject.querySelector('.' + this._internalVars.activeClass);
|
439
|
+
let activeElementContent = this._internalVars.timeInputSegmentSelection.innerHTML;
|
440
|
+
|
441
|
+
this._internalVars.draggableObject.innerHTML = activeElementContent;
|
442
|
+
this._internalVars.draggableObject.style.zIndex = 2;
|
443
|
+
this._internalVars.draggableObject.classList.remove(this._internalVars.animateClass);
|
444
|
+
this._internalVars.draggableObject.classList.remove(this._internalVars.activeDragClass);
|
445
|
+
}
|
446
|
+
|
447
|
+
/**
|
448
|
+
* segmentChange(event)
|
449
|
+
* @param event
|
450
|
+
* updates the segment visually when the user drops the segment selector
|
451
|
+
*/
|
452
|
+
function segmentChange(event) {
|
453
|
+
let period = event.target.innerHTML,
|
454
|
+
changeSegment = true,
|
455
|
+
timeEntry = parseInputValue.call(this);
|
456
|
+
|
457
|
+
updatePeriod.call(this, period, changeSegment);
|
458
|
+
|
459
|
+
if(timeEntry.hours.length !== 0 && timeEntry.minutes.length !== 0){
|
460
|
+
getValue.call(this);
|
461
|
+
}
|
462
|
+
}
|
463
|
+
|
464
|
+
/**
|
465
|
+
* getValue()
|
466
|
+
* gets the value of the input field and segmented control selection
|
467
|
+
*/
|
468
|
+
function getValue() {
|
469
|
+
let timeEntry = parseInputValue.call(this);
|
470
|
+
|
471
|
+
if(timeEntry.hours < 24 && timeEntry.minutes < 60) {
|
472
|
+
if(timeEntry.hours < 13) {
|
473
|
+
this._internalVars.timeInputFieldValue = convertTo24hrFormat.call(this, timeEntry.segment, timeEntry.hours, timeEntry.minutes);
|
474
|
+
} else {
|
475
|
+
this._internalVars.timeInputFieldValue = timeEntry.hours + ":" + timeEntry.minutes;
|
476
|
+
}
|
477
|
+
}
|
478
|
+
else if(timeEntry.hours >= 24 || timeEntry.minutes >= 60){
|
479
|
+
this._internalVars.timeInputFieldValue = timeEntry.hours + ":" + timeEntry.minutes;
|
480
|
+
}
|
481
|
+
else {
|
482
|
+
this._internalVars.timeInputFieldValue = "";
|
483
|
+
}
|
484
|
+
|
485
|
+
if(this._options.callBackOnTimeChange && this._internalVars.publicMethodUsed === false) {
|
486
|
+
if ( (this._internalVars.timeInputFieldCurrentValue === '__:__') || (this._internalVars.timeInputFieldValue !== this._internalVars.timeInputFieldCurrentValue) && this._internalVars.timeInputCompare === true) {
|
487
|
+
this._options.callBackOnTimeChange(this._internalVars.timeInputFieldValue);
|
488
|
+
this._internalVars.timeInputCompare = false;
|
489
|
+
} else if (this._internalVars.timeInputSegmentChangeOnly === true) {
|
490
|
+
this._options.callBackOnTimeChange(this._internalVars.timeInputFieldValue);
|
491
|
+
this._internalVars.timeInputSegmentChangeOnly = false;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
this._internalVars.publicMethodUsed = false;
|
495
|
+
}
|
496
|
+
|
497
|
+
/**
|
498
|
+
* setLocalVars()
|
499
|
+
* set all the local vars to passed in options
|
500
|
+
*/
|
501
|
+
function setLocalVars() {
|
502
|
+
//determine the type of content passed in
|
503
|
+
if(this._internalVars.contentType === 'string'){
|
504
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
505
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
506
|
+
this._internalVars.node = this._options.content;
|
507
|
+
}
|
508
|
+
|
509
|
+
this._internalVars.timeInputObject = this._internalVars.node;
|
510
|
+
|
511
|
+
this._internalVars.timeInputFieldClass = 'time-input';
|
512
|
+
this._internalVars.segmentedControlClass = 'segmented-control-component';
|
513
|
+
this._internalVars.activeClass = 'active';
|
514
|
+
this._internalVars.dropZoneClass = '.dropzone';
|
515
|
+
this._internalVars.draggableClass = '.sc-draggable';
|
516
|
+
this._internalVars.activeDragClass = 'active-drag';
|
517
|
+
this._internalVars.animateClass = 'animate-drop';
|
518
|
+
|
519
|
+
this._internalVars.segmentedControlObject = this._internalVars.timeInputObject.querySelector('.' + this._internalVars.segmentedControlClass);
|
520
|
+
this._internalVars.timeInputField = this._internalVars.timeInputObject.querySelector('.' + this._internalVars.timeInputFieldClass);
|
521
|
+
this._internalVars.dropZoneObject = this._internalVars.timeInputObject.querySelectorAll(this._internalVars.dropZoneClass);
|
522
|
+
this._internalVars.draggableObject = this._internalVars.timeInputObject.querySelector(this._internalVars.draggableClass);
|
523
|
+
this._internalVars.timeInputFieldValue = this._internalVars.timeInputField.value;
|
524
|
+
|
525
|
+
this._internalVars.timeInputFieldCurrentValue = null;
|
526
|
+
this._internalVars.timeInputSegmentSelection = null;
|
527
|
+
this._internalVars.timeInputCompare = false;
|
528
|
+
this._internalVars.timeInputSegmentChangeOnly = null;
|
529
|
+
this._internalVars.publicMethodUsed = false;
|
530
|
+
}
|
531
|
+
|
532
|
+
export default TimeInput;
|