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