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,487 @@
|
|
1
|
+
import baseComponent from '../../src/baseComponent';
|
2
|
+
import appState from '../../src/appState';
|
3
|
+
import * as utils from '../../src/utils';
|
4
|
+
import $ from 'jquery';
|
5
|
+
import datepickerFactory from 'jquery-datepicker';
|
6
|
+
datepickerFactory($);
|
7
|
+
|
8
|
+
const validateSettings = [
|
9
|
+
{
|
10
|
+
setting : "content",
|
11
|
+
isRequired : true,
|
12
|
+
validate : "type",
|
13
|
+
possibleValues : ["string","object"],
|
14
|
+
errorMessage : ["GDK DatePicker : Content must be defined and set to a DOM selector or Node"]
|
15
|
+
},
|
16
|
+
{
|
17
|
+
setting : "monthYearDropdowns",
|
18
|
+
isRequired : false,
|
19
|
+
validate : "type",
|
20
|
+
possibleValues : ["boolean"],
|
21
|
+
errorMessage : ["GDK DatePicker : monthYearDropdowns must be set to a boolean"]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
setting : "dateFormatShort",
|
25
|
+
isRequired : false,
|
26
|
+
validate : "type",
|
27
|
+
possibleValues : ["boolean"],
|
28
|
+
errorMessage : ["GDK DatePicker : dateFormatShort must be set to a boolean"]
|
29
|
+
},
|
30
|
+
{
|
31
|
+
setting : "minDate",
|
32
|
+
isRequired : false,
|
33
|
+
validate : "type",
|
34
|
+
possibleValues : ["number","date","string","object"],
|
35
|
+
errorMessage : ["GDK DatePicker : minDate must be set to a number, date, or string"]
|
36
|
+
},
|
37
|
+
{
|
38
|
+
setting : "maxDate",
|
39
|
+
isRequired : false,
|
40
|
+
validate : "type",
|
41
|
+
possibleValues : ["number","date","string","object"],
|
42
|
+
errorMessage : ["GDK DatePicker : maxDate must be set to a number, date, or string"]
|
43
|
+
},
|
44
|
+
{
|
45
|
+
setting : "showWeekends",
|
46
|
+
isRequired : false,
|
47
|
+
validate : "type",
|
48
|
+
possibleValues : ["boolean"],
|
49
|
+
errorMessage : ["GDK DatePicker : showWeekends must be set to a boolean"]
|
50
|
+
},
|
51
|
+
{
|
52
|
+
setting : "dateSelected",
|
53
|
+
isRequired : false,
|
54
|
+
validate : "type",
|
55
|
+
possibleValues : ["function"],
|
56
|
+
errorMessage : ["GDK DatePicker : dateSelected must be a callback function"]
|
57
|
+
},
|
58
|
+
{
|
59
|
+
setting : "disabled",
|
60
|
+
isRequired : false,
|
61
|
+
validate : "type",
|
62
|
+
possibleValues : ["boolean"],
|
63
|
+
errorMessage : ["GDK DatePicker : disabled must be a boolean"]
|
64
|
+
}
|
65
|
+
];
|
66
|
+
|
67
|
+
/**
|
68
|
+
* DatePicker Class
|
69
|
+
*/
|
70
|
+
class DatePicker{
|
71
|
+
|
72
|
+
/**
|
73
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
74
|
+
* @param {string|Object} content
|
75
|
+
* A reference to the html date node
|
76
|
+
*
|
77
|
+
* @param {boolean} [monthYearDropdowns=false]
|
78
|
+
* Determines whether or not to show select boxes for the month and year
|
79
|
+
*
|
80
|
+
* @param {boolean} [dateFormatShort=false]
|
81
|
+
* Determines whether to use the short format date instead of the default long format
|
82
|
+
*
|
83
|
+
* @param {function} [dateSelected]
|
84
|
+
* Callback gets fired when a user selects a date
|
85
|
+
*
|
86
|
+
* @param {Date|number|string} [minDate=null]
|
87
|
+
* The minimum selectable date. When set to null, there is no minimum.
|
88
|
+
*
|
89
|
+
* @param {Date|number|string} [maxDate=null]
|
90
|
+
* The maximum selectable date. When set to null, there is no maximum.
|
91
|
+
*
|
92
|
+
* @param {boolean} [hideWeekends=false]
|
93
|
+
* Set to true if you would like to disable the weekends in the calender.
|
94
|
+
*
|
95
|
+
* @param {boolean} [disabled]
|
96
|
+
* Set to true if you would like to disable the input and calendar button.
|
97
|
+
*
|
98
|
+
*/
|
99
|
+
constructor(options) {
|
100
|
+
|
101
|
+
this._internalVars = {
|
102
|
+
node: null,//used for content item
|
103
|
+
button: null,
|
104
|
+
wrapper : null,
|
105
|
+
wrapperElementId : "wrapper",
|
106
|
+
marginLeft : 15,
|
107
|
+
marginTopBottomLeft : 10,
|
108
|
+
marginTopBottomRight : 28,
|
109
|
+
breakpoint : 768,
|
110
|
+
calendarWidth: 300,
|
111
|
+
borderWidth: 4
|
112
|
+
};
|
113
|
+
|
114
|
+
//options with defaults set
|
115
|
+
this._defaults = {
|
116
|
+
monthYearDropdowns: false,
|
117
|
+
dateFormatShort: false,
|
118
|
+
minDate: null,
|
119
|
+
maxDate: null,
|
120
|
+
hideWeekends : false
|
121
|
+
};
|
122
|
+
|
123
|
+
// Create options by extending defaults with the passed in arugments
|
124
|
+
if (options && typeof options === "object") {
|
125
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
126
|
+
}
|
127
|
+
|
128
|
+
//if the required options are valid set up the environment
|
129
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
130
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
131
|
+
setLocalVars.call(this);
|
132
|
+
setEvents.call(this);
|
133
|
+
init.call(this);
|
134
|
+
this._internalVars.button.setAttribute('tabindex', '-1');
|
135
|
+
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
//Public Methods
|
140
|
+
|
141
|
+
/**
|
142
|
+
* removes the node from the dom and any events attached
|
143
|
+
*/
|
144
|
+
destroy(){
|
145
|
+
removeEvents.call(this);
|
146
|
+
$(this._internalVars.node).datepicker("destroy");
|
147
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
148
|
+
|
149
|
+
//a little garbage collection
|
150
|
+
for (var variableKey in this){
|
151
|
+
if (this.hasOwnProperty(variableKey)){
|
152
|
+
delete this[variableKey];
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Set Min Date for the DatePicker Instance
|
159
|
+
* @param {number|Date|string|object} minDate The starting date for the date picker instance
|
160
|
+
*/
|
161
|
+
setMinDate(minDate) {
|
162
|
+
this._options.minDate = new Date(minDate);
|
163
|
+
}
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Set Max Date for the DatePicker Instance
|
167
|
+
* @param {number|Date|string|object} maxDate The ending date for the date picker instance
|
168
|
+
*/
|
169
|
+
setMaxDate(maxDate) {
|
170
|
+
this._options.maxDate = new Date(maxDate);
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Set Min and Max Dates for the DatePicker Instance
|
175
|
+
* @param {number|Date|string|object} minDate The starting date for the date picker instance
|
176
|
+
* @param {number|Date|string|object} maxDate The ending date for the date picker instance
|
177
|
+
*/
|
178
|
+
setMinMaxDateLimits(minDate, maxDate) {
|
179
|
+
this._options.minDate = new Date(minDate);
|
180
|
+
this._options.maxDate = new Date(maxDate);
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Disables a specific date picker
|
185
|
+
* @param {String} datePickerId ID of the date picker to be disabled
|
186
|
+
*/
|
187
|
+
disableDatePicker() {
|
188
|
+
let option = 'disable';
|
189
|
+
datePickerState.call(this, option);
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Enable a specif date picker
|
194
|
+
* @param {Object} datePickerId ID of the date picker to be enabled
|
195
|
+
*/
|
196
|
+
enableDatePicker(datePickerId) {
|
197
|
+
let option = 'enable';
|
198
|
+
datePickerState.call(this, option);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
/**
|
204
|
+
* set all the local vars to passed in options
|
205
|
+
*/
|
206
|
+
function setLocalVars() {
|
207
|
+
|
208
|
+
var _this = this;
|
209
|
+
|
210
|
+
try{
|
211
|
+
//determine the type of content passed in
|
212
|
+
if(this._internalVars.contentType === 'string'){
|
213
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
214
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
215
|
+
this._internalVars.node = this._options.content;
|
216
|
+
}
|
217
|
+
|
218
|
+
let dpOptions = {
|
219
|
+
showOtherMonths: false,
|
220
|
+
showOn: "button",
|
221
|
+
buttonText: "",
|
222
|
+
nextText: "",
|
223
|
+
prevText: "",
|
224
|
+
dayNamesMin: [ "S", "M", "T", "W", "T", "F", "S" ],
|
225
|
+
changeMonth: false,
|
226
|
+
changeYear: false,
|
227
|
+
showOptions: { direction: "left" },
|
228
|
+
beforeShow: updateDatepicker.bind(this),
|
229
|
+
onClose: closedDatepicker.bind(this),
|
230
|
+
onSelect: function(dateText, inst) {
|
231
|
+
var date = $(this).val();
|
232
|
+
|
233
|
+
_this._internalVars.node.parentNode.classList.remove("form-field--error");
|
234
|
+
|
235
|
+
// Get all spans and remove ones bearing class "form-message"
|
236
|
+
var spans = _this._internalVars.node.parentNode.getElementsByTagName('span');
|
237
|
+
for(var e = 0; spans.length > e; e++) {
|
238
|
+
if(-1 !== spans[e].className.indexOf("form-message")) {
|
239
|
+
spans[e].parentNode.removeChild(spans[e]);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
if(_this._options.dateSelected){
|
244
|
+
_this._options.dateSelected(date);
|
245
|
+
}
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
if(this._options.hideWeekends){
|
250
|
+
dpOptions.beforeShowDay = $.datepicker.noWeekends;
|
251
|
+
}
|
252
|
+
|
253
|
+
$( this._internalVars.node ).datepicker(dpOptions);
|
254
|
+
|
255
|
+
this._internalVars.button = this._internalVars.node.nextElementSibling;
|
256
|
+
this._internalVars.wrapper = document.querySelector("#" + this._internalVars.wrapperElementId);
|
257
|
+
this._internalVars.handler = toggleHover.bind(this);
|
258
|
+
this._internalVars.handlerOverride = calendarPositionOverride.bind(this);
|
259
|
+
|
260
|
+
let $datapicker = $(".ui-datepicker");
|
261
|
+
|
262
|
+
if($datapicker.data("initialized") !== true){
|
263
|
+
$datapicker.data("initialized", true);
|
264
|
+
document.addEventListener("animationstart", insertListener, false); // standard + firefox
|
265
|
+
document.addEventListener("MSAnimationStart", insertListener, false); // IE
|
266
|
+
document.addEventListener("webkitAnimationStart", insertListener, false); // Chrome + Safari
|
267
|
+
}
|
268
|
+
} catch (ex) {
|
269
|
+
console.error("Error : ", ex.message);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
/**
|
274
|
+
* Sets all the events needed for the component
|
275
|
+
*/
|
276
|
+
function setEvents() {
|
277
|
+
this._internalVars.button.addEventListener("mouseover", this._internalVars.handler, false);
|
278
|
+
this._internalVars.button.addEventListener("mouseout", this._internalVars.handler, false);
|
279
|
+
window.addEventListener('resize', handleResize.bind(this));
|
280
|
+
|
281
|
+
//special case if a datepicker exist in a modal - override third party jquery snippet
|
282
|
+
if(utils.isChild('modal', this._internalVars.button)){
|
283
|
+
this._internalVars.button.addEventListener("click", this._internalVars.handlerOverride);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
function init() {
|
288
|
+
if (this._options.disabled === true) {
|
289
|
+
let option = 'disable';
|
290
|
+
|
291
|
+
datePickerState.call(this, option);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* removes all events from the component
|
297
|
+
*/
|
298
|
+
function removeEvents(){
|
299
|
+
this._internalVars.button.removeEventListener("mouseoout", this._internalVars.handler, false);
|
300
|
+
}
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Checks if the ID passed from the enable or disable public method exists
|
304
|
+
* @param {string} option Variable identifying enable or disable
|
305
|
+
*/
|
306
|
+
function datePickerState(option) {
|
307
|
+
let datePickerId = this._internalVars.node.id,
|
308
|
+
datePicker = document.getElementById(datePickerId),
|
309
|
+
parent = datePicker.parentNode,
|
310
|
+
button = parent.querySelector(".ui-datepicker-trigger"),
|
311
|
+
hasButton = false;
|
312
|
+
|
313
|
+
if(button) {
|
314
|
+
hasButton = true;
|
315
|
+
}
|
316
|
+
|
317
|
+
if (option === 'disable') {
|
318
|
+
disable.call(this, datePicker, button, hasButton);
|
319
|
+
} else if (option === 'enable') {
|
320
|
+
enable.call(this, datePicker, button, hasButton);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
|
324
|
+
/**
|
325
|
+
* Disables the specified date picker
|
326
|
+
* @param {object} datePicker The date picker HTML element
|
327
|
+
* @param {object} button The date picker calendar button HTML element
|
328
|
+
* @param {boolean} hasButton Boolean indicating if calendar button exists
|
329
|
+
*/
|
330
|
+
function disable(datePicker, button, hasButton) {
|
331
|
+
datePicker.setAttribute('disabled', 'disabled');
|
332
|
+
if(hasButton === true) {
|
333
|
+
button.setAttribute('disabled', 'disabled');
|
334
|
+
}
|
335
|
+
}
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Enables the specified date picker
|
339
|
+
* @param {object} datePicker The date picker HTML element
|
340
|
+
* @param {object} button The date picker calendar button HTML element
|
341
|
+
* @param {boolean} hasButton Boolean indicating if calendar button exists
|
342
|
+
*/
|
343
|
+
function enable(datePicker, button, hasButton) {
|
344
|
+
datePicker.removeAttribute('disabled');
|
345
|
+
if(hasButton === true) {
|
346
|
+
button.removeAttribute('disabled');
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
/**
|
351
|
+
* toggles the active state of the neighboring input field
|
352
|
+
*/
|
353
|
+
function toggleHover(){
|
354
|
+
if(this._internalVars.node.classList.contains("active"))
|
355
|
+
this._internalVars.node.classList.remove("active");
|
356
|
+
else
|
357
|
+
this._internalVars.node.classList.add("active");
|
358
|
+
}
|
359
|
+
|
360
|
+
/**
|
361
|
+
* listens for the select box to be inserted and wraps it in a container
|
362
|
+
*/
|
363
|
+
function insertListener(event){
|
364
|
+
if (event.animationName == "nodeInserted") {
|
365
|
+
if(!$(".ui-datepicker-year").parent().hasClass("select-box"))
|
366
|
+
$(".ui-datepicker-year").wrap( "<div class=\"select-box\"></div>" );
|
367
|
+
|
368
|
+
if(!$(".ui-datepicker-month").parent().hasClass("select-box"))
|
369
|
+
$(".ui-datepicker-month").wrap( "<div class=\"select-box\"></div>" );
|
370
|
+
}
|
371
|
+
}
|
372
|
+
|
373
|
+
/**
|
374
|
+
* runs when the datepicker window closes
|
375
|
+
*/
|
376
|
+
function closedDatepicker() {
|
377
|
+
//re-assign button variable since datepicker replaces the original node
|
378
|
+
this._internalVars.button = this._internalVars.node.nextElementSibling;
|
379
|
+
setEvents.call(this);
|
380
|
+
this._internalVars.button.setAttribute('tabindex', '-1');
|
381
|
+
}
|
382
|
+
|
383
|
+
/**
|
384
|
+
* runs before displaying the datapicker and updates it based on the current options
|
385
|
+
*/
|
386
|
+
function updateDatepicker(el,obj) {
|
387
|
+
|
388
|
+
let changeOptions = {};
|
389
|
+
|
390
|
+
changeOptions.minDate = this._options.minDate;
|
391
|
+
changeOptions.maxDate = this._options.maxDate;
|
392
|
+
|
393
|
+
if(this._options.monthYearDropdowns){
|
394
|
+
//adds the month and year dropdowns
|
395
|
+
changeOptions.changeMonth = true;
|
396
|
+
changeOptions.changeYear = true;
|
397
|
+
|
398
|
+
//hide the month arrows
|
399
|
+
$(".ui-datepicker").addClass("date-picker-hide-arrows");
|
400
|
+
|
401
|
+
} else {
|
402
|
+
//removes the month and year dropdowns
|
403
|
+
changeOptions.changeMonth = false;
|
404
|
+
changeOptions.changeYear = false;
|
405
|
+
|
406
|
+
//displays the month arrows
|
407
|
+
$(".ui-datepicker").removeClass("date-picker-hide-arrows");
|
408
|
+
}
|
409
|
+
|
410
|
+
//set the date format to full or short
|
411
|
+
if(this._options.dateFormatShort){
|
412
|
+
changeOptions.dateFormat = "mm/yy";
|
413
|
+
} else {
|
414
|
+
changeOptions.dateFormat = "mm/dd/yy";
|
415
|
+
}
|
416
|
+
|
417
|
+
$(el).datepicker(
|
418
|
+
"change",
|
419
|
+
changeOptions
|
420
|
+
);
|
421
|
+
|
422
|
+
|
423
|
+
positionDatePicker.call(this, el);
|
424
|
+
|
425
|
+
|
426
|
+
$.datepicker._shouldFocusInput = function(){return false;};
|
427
|
+
|
428
|
+
}
|
429
|
+
|
430
|
+
/**
|
431
|
+
* Positions calendar
|
432
|
+
* @param {object} el HTML element
|
433
|
+
*/
|
434
|
+
function positionDatePicker(el){
|
435
|
+
//need to add code to check if position has changed before recalculating
|
436
|
+
let winWidth = document.body.clientWidth;
|
437
|
+
let winHeight = window.innerHeight || document.documentElement.clientHeight;
|
438
|
+
let inputOffset = this._internalVars.node.getBoundingClientRect();
|
439
|
+
let containerOffset = this._internalVars.wrapper.getBoundingClientRect();
|
440
|
+
let containerOffsetLeft = containerOffset.left;
|
441
|
+
let containerWidth = this._internalVars.wrapper.offsetWidth;
|
442
|
+
let inputWidth = this._internalVars.node.offsetWidth + this._internalVars.node.nextElementSibling.offsetWidth;
|
443
|
+
let isRight = false;
|
444
|
+
|
445
|
+
if(winWidth >= this._internalVars.breakpoint){
|
446
|
+
|
447
|
+
$.datepicker._pos = $.datepicker._findPos(el);
|
448
|
+
//figure out correct horizontal direction
|
449
|
+
if( $.datepicker._pos[0] + this._internalVars.calendarWidth + inputWidth < containerWidth){
|
450
|
+
$.datepicker._pos[0] += (inputWidth + this._internalVars.marginLeft);
|
451
|
+
}else{
|
452
|
+
$.datepicker._pos[0] -= (this._internalVars.calendarWidth-inputWidth);
|
453
|
+
isRight = true;
|
454
|
+
}
|
455
|
+
|
456
|
+
//figure out correct vertical direction
|
457
|
+
if( inputOffset.top + this._internalVars.calendarWidth < winHeight ){
|
458
|
+
if(!isRight){
|
459
|
+
$.datepicker._pos[1] -= this._internalVars.marginTopBottomLeft;
|
460
|
+
} else {
|
461
|
+
$.datepicker._pos[1] += ((inputOffset.bottom - inputOffset.top) - this._internalVars.borderWidth) + this._internalVars.marginTopBottomLeft;
|
462
|
+
}
|
463
|
+
}else{
|
464
|
+
if(!isRight){
|
465
|
+
$.datepicker._pos[1] -= (this._internalVars.calendarWidth - this._internalVars.marginTopBottomRight);
|
466
|
+
} else {
|
467
|
+
$.datepicker._pos[1] -= (this._internalVars.calendarWidth + this._internalVars.marginTopBottomRight);
|
468
|
+
}
|
469
|
+
}
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
/**
|
474
|
+
* handles window resize
|
475
|
+
*/
|
476
|
+
function handleResize(){
|
477
|
+
$( this._internalVars.node ).datepicker( "hide" );
|
478
|
+
}
|
479
|
+
|
480
|
+
function calendarPositionOverride(){
|
481
|
+
if(appState.mode == 'desktop'){
|
482
|
+
document.querySelector('#ui-datepicker-div').style.top = document.querySelector('.modal .hasDatepicker').offsetTop + 'px';
|
483
|
+
}
|
484
|
+
}
|
485
|
+
|
486
|
+
|
487
|
+
export default DatePicker;
|
@@ -0,0 +1,142 @@
|
|
1
|
+
import baseComponent from "../../src/baseComponent";
|
2
|
+
|
3
|
+
const validateSettings = [
|
4
|
+
{
|
5
|
+
setting: "content",
|
6
|
+
isRequired: true,
|
7
|
+
validate: "type",
|
8
|
+
possibleValues: ["string", "object"],
|
9
|
+
errorMessage: ["GDK DockedMessage : Content must be defined and set to a DOM selector or Node"]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
setting: "autoHide",
|
13
|
+
isRequired: false,
|
14
|
+
validate: "type",
|
15
|
+
possibleValues: ["boolean"],
|
16
|
+
errorMessage: ["GDK DockedMessage : AutoHide must be defined as true or false"]
|
17
|
+
}
|
18
|
+
];
|
19
|
+
|
20
|
+
class DockedMessage {
|
21
|
+
/**
|
22
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
23
|
+
* @param {string|Object} content
|
24
|
+
* A reference to the docked real time message node
|
25
|
+
*/
|
26
|
+
constructor(options) {
|
27
|
+
this._internalVars = {
|
28
|
+
node: null//used for current node
|
29
|
+
};
|
30
|
+
|
31
|
+
//options with defaults set
|
32
|
+
this._defaults = {
|
33
|
+
autoHide: false
|
34
|
+
};
|
35
|
+
// Create options by extending defaults with the passed in arugments
|
36
|
+
if (options && typeof options === "object") {
|
37
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
38
|
+
}
|
39
|
+
//if the required options are valid set up the environment
|
40
|
+
if (baseComponent.validateSettings(this._options, validateSettings)) {
|
41
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
42
|
+
setLocalVars.call(this);
|
43
|
+
init.call(this);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
//Public Methods
|
48
|
+
|
49
|
+
/**
|
50
|
+
* hides/shows the component
|
51
|
+
*/
|
52
|
+
toggleDockedMessage() {
|
53
|
+
toggleComponent.call(this);
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* removes the node from the dom and any events attached
|
58
|
+
*/
|
59
|
+
destroy(){
|
60
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
61
|
+
|
62
|
+
//a little garbage collection
|
63
|
+
for (var variableKey in this){
|
64
|
+
if (this.hasOwnProperty(variableKey)){
|
65
|
+
delete this[variableKey];
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
function init() {
|
73
|
+
if (this._options.autoHide) {
|
74
|
+
if (this._options.autoHide === true) {
|
75
|
+
hideComponent.call(this);
|
76
|
+
} else {
|
77
|
+
showComponent.call(this);
|
78
|
+
}
|
79
|
+
} else {
|
80
|
+
showComponent.call(this);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Toggle Component Function
|
86
|
+
* Displays and hides the component
|
87
|
+
*/
|
88
|
+
function toggleComponent() {
|
89
|
+
if(this._internalVars.node.classList.contains('hidden')){
|
90
|
+
showComponent.call(this);
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
hideComponent.call(this);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
function showComponent() {
|
98
|
+
this._internalVars.node.classList.remove('hidden');
|
99
|
+
this._internalVars.main.classList.add("docked-message-on");
|
100
|
+
if (this._internalVars.toTopExists === true) {
|
101
|
+
this._internalVars.toTop.classList.add("docked-message-on");
|
102
|
+
}
|
103
|
+
if (!this._internalVars.footer) {
|
104
|
+
this._internalVars.footerPush.classList.add('no-footer');
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
this._internalVars.footer.classList.add("docked-message-on");
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
function hideComponent() {
|
112
|
+
this._internalVars.node.classList.add('hidden');
|
113
|
+
this._internalVars.main.classList.remove("docked-message-on");
|
114
|
+
if (this._internalVars.toTopExists === true) {
|
115
|
+
this._internalVars.toTop.classList.remove("docked-message-on");
|
116
|
+
}
|
117
|
+
if (!this._internalVars.footer) {
|
118
|
+
this._internalVars.footerPush.classList.remove('no-footer');
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
this._internalVars.footer.classList.remove("docked-message-on");
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
function setLocalVars() {
|
126
|
+
if (this._internalVars.contentType === 'string') {
|
127
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
128
|
+
} else if (this._internalVars.contentType === 'domNode') {
|
129
|
+
this._internalVars.node = this._options.content;
|
130
|
+
}
|
131
|
+
this._internalVars.toTopExists = false;
|
132
|
+
if(document.querySelector(".to-top-arrow") !== null && document.querySelector(".to-top-arrow") !== 'undefined') {
|
133
|
+
this._internalVars.toTopExists = true;
|
134
|
+
this._internalVars.toTop = document.querySelector(".to-top-arrow");
|
135
|
+
}
|
136
|
+
this._internalVars.main = document.querySelector('#wrapper');
|
137
|
+
this._internalVars.footer = document.querySelector('#primary-footer');
|
138
|
+
this._internalVars.footerPush = document.querySelector('.footer-push');
|
139
|
+
}
|
140
|
+
|
141
|
+
export default DockedMessage;
|
142
|
+
|