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,533 @@
|
|
|
1
|
+
import appState from '../../src/appState';
|
|
2
|
+
import * as utils from '../../src/utils';
|
|
3
|
+
import baseComponent from '../../src/baseComponent';
|
|
4
|
+
import UserAgentService from '../../src/services/UserAgentService';
|
|
5
|
+
|
|
6
|
+
const validateSettings = [
|
|
7
|
+
{
|
|
8
|
+
setting : "content",
|
|
9
|
+
isRequired : true,
|
|
10
|
+
validate : "type",
|
|
11
|
+
possibleValues : ["string","object"],
|
|
12
|
+
errorMessage : ["GDK TimelineFilter : Content must be defined and set to a DOM selector or Node"]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
setting : "onFilterSubmit",
|
|
16
|
+
isRequired : false,
|
|
17
|
+
validate : "type",
|
|
18
|
+
possibleValues : ["function"],
|
|
19
|
+
errorMessage : ["GDK TimelineFilter : onFilterSubmit must be a function"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
setting : "onClearFilter",
|
|
23
|
+
isRequired : false,
|
|
24
|
+
validate : "type",
|
|
25
|
+
possibleValues : ["function"],
|
|
26
|
+
errorMessage : ["GDK TimelineFilter : onClearFilter must be a function"]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
setting : "setInitialFilters",
|
|
30
|
+
isRequired : false,
|
|
31
|
+
validate : "type",
|
|
32
|
+
possibleValues : ["object"],
|
|
33
|
+
errorMessage : ["GDK TimelineFilter : setInitialFilters must be an object"]
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
class TimelineFilter{
|
|
38
|
+
/**
|
|
39
|
+
* Refer to the design kit section of this component for JS examples and setting details.
|
|
40
|
+
* @param {string, Object} content
|
|
41
|
+
* A reference to the html timeline filter node
|
|
42
|
+
*
|
|
43
|
+
* @param {function} [onFilterSubmit]
|
|
44
|
+
* Callback function fired once a 'filter-submit' is clicked
|
|
45
|
+
*
|
|
46
|
+
* @param {function} [onClearFilter]
|
|
47
|
+
* Callback function fired once 'Clear Filters' is clicked
|
|
48
|
+
*
|
|
49
|
+
* @param {object} [setDefaultFilters]
|
|
50
|
+
* Accepts an array of objects containing checkbox IDs and an indicator to select or deselect them, selects or deselects them, and updates the count bubble
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
constructor(options) {
|
|
54
|
+
|
|
55
|
+
this._internalVars = {
|
|
56
|
+
node: null,//used for content item
|
|
57
|
+
dropdownTrigger: null,
|
|
58
|
+
checkbox: null,
|
|
59
|
+
dropdown: null,
|
|
60
|
+
mobileOpen: null,
|
|
61
|
+
//mobileClose: null,
|
|
62
|
+
mobileBar: null,
|
|
63
|
+
mobileText: null,
|
|
64
|
+
clear: null,
|
|
65
|
+
search: null,
|
|
66
|
+
submit: null,
|
|
67
|
+
dropdownContainer: null
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//options with defaults set
|
|
71
|
+
this._defaults = {};
|
|
72
|
+
|
|
73
|
+
// Create options by extending defaults with the passed in arugments
|
|
74
|
+
if (options && typeof options === "object") {
|
|
75
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//if the required options are valid set up the environment
|
|
79
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
|
80
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
|
81
|
+
setLocalVars.call(this);
|
|
82
|
+
setEvents.call(this);
|
|
83
|
+
|
|
84
|
+
if(appState.mode == "desktop")
|
|
85
|
+
Array.prototype.forEach.call(this._internalVars.dropdownTrigger, (el, i)=>{
|
|
86
|
+
el.setAttribute('aria-expanded', 'false');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if(this._options.setInitialFilters) {
|
|
90
|
+
this.setDefaultFilters.call(this, this._options.setInitialFilters);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//Public Methods
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* setDefaultFilters(obj)
|
|
99
|
+
* @param {object} [obj]
|
|
100
|
+
* Accepts an array of objects containing checkbox IDs and an indicator to select or deselect them, selects or deselects them, and updates the count bubble
|
|
101
|
+
*/
|
|
102
|
+
setDefaultFilters(obj) {
|
|
103
|
+
Array.prototype.forEach.call(obj, (el)=> {
|
|
104
|
+
if(el.id && el.action) {
|
|
105
|
+
let checkbox = document.querySelector('#' + el.id);
|
|
106
|
+
if(checkbox) {
|
|
107
|
+
if(el.action === 'select') {
|
|
108
|
+
checkbox.checked = true;
|
|
109
|
+
updateAllNotificationBubbles.call(this, checkbox);
|
|
110
|
+
} else if (el.action === 'deselect') {
|
|
111
|
+
checkbox.checked = false;
|
|
112
|
+
updateAllNotificationBubbles.call(this, checkbox);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* destroy()
|
|
121
|
+
* removes the node from the dom and any events attached
|
|
122
|
+
*/
|
|
123
|
+
destroy(){
|
|
124
|
+
removeEvents.call(this);
|
|
125
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
|
126
|
+
|
|
127
|
+
//a little garbage collection
|
|
128
|
+
for (var variableKey in this){
|
|
129
|
+
if (this.hasOwnProperty(variableKey)){
|
|
130
|
+
delete this[variableKey];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Private Methods
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* setLocalVars()
|
|
141
|
+
* set all the local vars to passed in options
|
|
142
|
+
*/
|
|
143
|
+
function setLocalVars() {
|
|
144
|
+
//determine the type of content passed in
|
|
145
|
+
if(this._internalVars.contentType === 'string'){
|
|
146
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
|
147
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
|
148
|
+
this._internalVars.node = this._options.content;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this._internalVars.dropdownTrigger = this._internalVars.node.querySelectorAll(".filter-dropdown-trigger");
|
|
152
|
+
this._internalVars.checkbox = this._internalVars.node.querySelectorAll(".filter-checkbox");
|
|
153
|
+
this._internalVars.dropdown = this._internalVars.node.querySelectorAll(".filter-dropdown");
|
|
154
|
+
this._internalVars.clear = this._internalVars.node.querySelector(".filter-clear");
|
|
155
|
+
this._internalVars.search = this._internalVars.node.querySelector(".filter-search");
|
|
156
|
+
this._internalVars.submit = this._internalVars.node.querySelector(".filter-submit");
|
|
157
|
+
this._internalVars.dropdownContainer = this._internalVars.node.querySelectorAll(".filter-container");
|
|
158
|
+
|
|
159
|
+
this._internalVars.mobileOpen = this._internalVars.node.querySelector(".filter-mobile-open");
|
|
160
|
+
//this._internalVars.mobileClose = this._internalVars.node.querySelector(".filter-mobile-close");
|
|
161
|
+
this._internalVars.mobileBar = this._internalVars.node.querySelector(".filter-mobile-bar");
|
|
162
|
+
this._internalVars.mobileText = this._internalVars.node.querySelector(".filter-mobile-bar-text");
|
|
163
|
+
|
|
164
|
+
this._internalVars.outsideHandler = outsideFieldClickHandler.bind(this);
|
|
165
|
+
this._internalVars.dropdownHandler = dropdownClickHandler.bind(this);
|
|
166
|
+
this._internalVars.checkTouchHandler = checkForTouch.bind(this);
|
|
167
|
+
this._internalVars.checkboxHandler = checkboxChangeHandler.bind(this);
|
|
168
|
+
this._internalVars.clearFilterHandler = clearFilter.bind(this);
|
|
169
|
+
this._internalVars.submitFilterHandler = submitFilter.bind(this);
|
|
170
|
+
this._internalVars.openDrawerHandler = openDrawer.bind(this);
|
|
171
|
+
this._internalVars.searchFocusHandler = searchFocus.bind(this);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* setEvents()
|
|
177
|
+
* Sets all the events needed for the component
|
|
178
|
+
*/
|
|
179
|
+
function setEvents() {
|
|
180
|
+
|
|
181
|
+
const eventName = UserAgentService._clickEventName();
|
|
182
|
+
|
|
183
|
+
//set click events
|
|
184
|
+
Array.prototype.forEach.call(this._internalVars.dropdownTrigger, (el, i)=>{
|
|
185
|
+
el.addEventListener(eventName,this._internalVars.dropdownHandler);
|
|
186
|
+
el.addEventListener("pointerdown", this._internalVars.checkTouchHandler );
|
|
187
|
+
});
|
|
188
|
+
Array.prototype.forEach.call(this._internalVars.dropdownContainer, (el, i)=>{
|
|
189
|
+
el.addEventListener("mouseleave",this._internalVars.outsideHandler);
|
|
190
|
+
});
|
|
191
|
+
Array.prototype.forEach.call(this._internalVars.checkbox, (el, i)=>{
|
|
192
|
+
el.addEventListener('change', this._internalVars.checkboxHandler);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
this._internalVars.clear.addEventListener(eventName, this._internalVars.clearFilterHandler);
|
|
196
|
+
if(this._internalVars.search){
|
|
197
|
+
this._internalVars.search.addEventListener('focus', this._internalVars.searchFocusHandler );
|
|
198
|
+
}
|
|
199
|
+
this._internalVars.submit.addEventListener(eventName, this._internalVars.submitFilterHandler );
|
|
200
|
+
|
|
201
|
+
// mobile
|
|
202
|
+
this._internalVars.mobileOpen.addEventListener(eventName, this._internalVars.openDrawerHandler);
|
|
203
|
+
//this._internalVars.mobileClose.addEventListener(eventName, closeDrawer.bind(this) );
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* removeEvents()
|
|
210
|
+
* removes all events from the component
|
|
211
|
+
*/
|
|
212
|
+
function removeEvents() {
|
|
213
|
+
|
|
214
|
+
const eventName = UserAgentService._clickEventName();
|
|
215
|
+
|
|
216
|
+
//remove click events
|
|
217
|
+
Array.prototype.forEach.call(this._internalVars.dropdownTrigger, (el, i)=>{
|
|
218
|
+
el.removeEventListener(eventName,this._internalVars.dropdownHandler);
|
|
219
|
+
el.removeEventListener("pointerdown", this._internalVars.checkTouchHandler);
|
|
220
|
+
});
|
|
221
|
+
Array.prototype.forEach.call(this._internalVars.dropdownContainer, (el, i)=>{
|
|
222
|
+
el.removeEventListener("mouseleave",this._internalVars.outsideHandler);
|
|
223
|
+
});
|
|
224
|
+
Array.prototype.forEach.call(this._internalVars.checkbox, (el, i)=>{
|
|
225
|
+
el.removeEventListener('change',this._internalVars.checkboxHandler);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
this._internalVars.clear.removeEventListener(eventName, this._internalVars.clearFilterHandler );
|
|
229
|
+
if(this._internalVars.search){
|
|
230
|
+
this._internalVars.search.removeEventListener('focus', this._internalVars.searchFocusHandler );
|
|
231
|
+
}
|
|
232
|
+
this._internalVars.submit.removeEventListener(eventName, this._internalVars.submitFilterHandler );
|
|
233
|
+
|
|
234
|
+
// mobile
|
|
235
|
+
this._internalVars.mobileOpen.removeEventListener(eventName, this._internalVars.openDrawerHandler);
|
|
236
|
+
//this._internalVars.mobileClose.removeEventListener(eventName, closeDrawer.bind(this) );
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
function checkForTouch(el){
|
|
241
|
+
if(el.pointerType=='touch'){
|
|
242
|
+
Array.prototype.forEach.call(this._internalVars.dropdownContainer, (el, i)=>{
|
|
243
|
+
el.removeEventListener("mouseleave",this._internalVars.outsideHandler);
|
|
244
|
+
});
|
|
245
|
+
}else{
|
|
246
|
+
Array.prototype.forEach.call(this._internalVars.dropdownContainer, (el, i)=>{
|
|
247
|
+
el.addEventListener("mouseleave",this._internalVars.outsideHandler);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* openDrawer()
|
|
254
|
+
* opens the mobile filter drawer
|
|
255
|
+
*/
|
|
256
|
+
function openDrawer(el){
|
|
257
|
+
if(utils.hasClass(this._internalVars.node, "-drawer-open")){
|
|
258
|
+
closeDrawer.call(this);
|
|
259
|
+
}else{
|
|
260
|
+
this._internalVars.node.classList.add("-drawer-open");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* closeDrawer()
|
|
268
|
+
* closes the mobile filter drawer
|
|
269
|
+
*/
|
|
270
|
+
function closeDrawer(el){
|
|
271
|
+
this._internalVars.node.classList.remove("-drawer-open");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* submitFilter()
|
|
276
|
+
* submits Filter form
|
|
277
|
+
*/
|
|
278
|
+
function submitFilter(el){
|
|
279
|
+
|
|
280
|
+
let data = serializeForm(this._internalVars.node);
|
|
281
|
+
|
|
282
|
+
// if mobile, close the drawer and update the filter text
|
|
283
|
+
if(appState.mode === "mobile"){
|
|
284
|
+
let fields = Object.keys(data).length;
|
|
285
|
+
|
|
286
|
+
if ((data.keywords !== '') || (fields > 1)) {
|
|
287
|
+
this._internalVars.mobileText.innerHTML = 'Showing filtered activities & policies';
|
|
288
|
+
} else {
|
|
289
|
+
this._internalVars.mobileText.innerHTML = 'Showing all activities & policies';
|
|
290
|
+
}
|
|
291
|
+
this._internalVars.node.classList.remove("-drawer-open");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// fire onFilterSubmit Callback if there is one
|
|
295
|
+
setTimeout( ()=> {
|
|
296
|
+
if(this._options.onFilterSubmit)
|
|
297
|
+
this._options.onFilterSubmit(data);
|
|
298
|
+
}, 10);
|
|
299
|
+
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* serializeForm()
|
|
305
|
+
* serialize form into object
|
|
306
|
+
*/
|
|
307
|
+
function serializeForm(form){
|
|
308
|
+
if (!form || form.nodeName !== "FORM") {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
var i, j,
|
|
312
|
+
obj = {};
|
|
313
|
+
for (i = form.elements.length - 1; i >= 0; i = i - 1) {
|
|
314
|
+
if (form.elements[i].name === "") {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
switch (form.elements[i].nodeName) {
|
|
318
|
+
case 'INPUT':
|
|
319
|
+
switch (form.elements[i].type) {
|
|
320
|
+
case 'text':
|
|
321
|
+
case 'hidden':
|
|
322
|
+
case 'password':
|
|
323
|
+
case 'button':
|
|
324
|
+
case 'reset':
|
|
325
|
+
case 'submit':
|
|
326
|
+
obj[form.elements[i].name] = encodeURIComponent(form.elements[i].value);
|
|
327
|
+
break;
|
|
328
|
+
case 'checkbox':
|
|
329
|
+
case 'radio':
|
|
330
|
+
if (form.elements[i].checked) {
|
|
331
|
+
obj[form.elements[i].name] = encodeURIComponent(form.elements[i].value);
|
|
332
|
+
}
|
|
333
|
+
break;
|
|
334
|
+
case 'file':
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
case 'TEXTAREA':
|
|
339
|
+
obj[form.elements[i].name] = encodeURIComponent(form.elements[i].value);
|
|
340
|
+
break;
|
|
341
|
+
case 'SELECT':
|
|
342
|
+
switch (form.elements[i].type) {
|
|
343
|
+
case 'select-one':
|
|
344
|
+
obj[form.elements[i].name] = encodeURIComponent(form.elements[i].value);
|
|
345
|
+
break;
|
|
346
|
+
case 'select-multiple':
|
|
347
|
+
for (j = form.elements[i].options.length - 1; j >= 0; j = j - 1) {
|
|
348
|
+
if (form.elements[i].options[j].selected) {
|
|
349
|
+
obj[form.elements[i].name] = encodeURIComponent(form.elements[i].options[j].value);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
case 'BUTTON':
|
|
356
|
+
switch (form.elements[i].type) {
|
|
357
|
+
case 'reset':
|
|
358
|
+
case 'submit':
|
|
359
|
+
case 'button':
|
|
360
|
+
obj[form.elements[i].name] = encodeURIComponent(form.elements[i].value);
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return obj;
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* clearFilter()
|
|
372
|
+
* clears the timeline filters and unchecks all checkboxes
|
|
373
|
+
*/
|
|
374
|
+
function clearFilter(e){
|
|
375
|
+
e.preventDefault();
|
|
376
|
+
// unchecks all checkboxes
|
|
377
|
+
Array.prototype.forEach.call(this._internalVars.checkbox, (el, i)=>{
|
|
378
|
+
|
|
379
|
+
el.checked = false;
|
|
380
|
+
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// update notification bubble to 0
|
|
384
|
+
Array.prototype.forEach.call(this._internalVars.dropdownTrigger, (el, i)=>{
|
|
385
|
+
|
|
386
|
+
updateNotificationBubble(el, 0);
|
|
387
|
+
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// clears search field
|
|
391
|
+
if(this._internalVars.search){
|
|
392
|
+
this._internalVars.search.value = '';
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
// fire onClearFilter Callback if there is one
|
|
397
|
+
setTimeout( ()=> {
|
|
398
|
+
if(this._options.onClearFilter)
|
|
399
|
+
this._options.onClearFilter();
|
|
400
|
+
}, 10);
|
|
401
|
+
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* checkboxChangeHandler()
|
|
406
|
+
* updates the notification of how many checkboxes are selected per dropdown
|
|
407
|
+
*/
|
|
408
|
+
function checkboxChangeHandler(el){
|
|
409
|
+
|
|
410
|
+
let currentNode = el.currentTarget;
|
|
411
|
+
|
|
412
|
+
let dropdownParent = findAncestor(currentNode, 'filter-dropdown');
|
|
413
|
+
let dropdownTrigger = dropdownParent.parentElement;
|
|
414
|
+
|
|
415
|
+
let total = dropdownParent.querySelectorAll('input[type="checkbox"]:checked').length;
|
|
416
|
+
|
|
417
|
+
updateNotificationBubble(dropdownTrigger, total);
|
|
418
|
+
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* findAncestor()
|
|
423
|
+
* Finds nearest ancestor with specified class
|
|
424
|
+
*/
|
|
425
|
+
function findAncestor (el, cls) {
|
|
426
|
+
while ((el = el.parentElement) && !el.classList.contains(cls));
|
|
427
|
+
return el;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* updateNotificationBubble()
|
|
432
|
+
* updates the notification of how many checkboxes are selected per dropdown
|
|
433
|
+
*/
|
|
434
|
+
function updateNotificationBubble(el, value){
|
|
435
|
+
|
|
436
|
+
let bubble = el.getElementsByClassName('dropdown-notify')[0];
|
|
437
|
+
bubble.innerHTML = value;
|
|
438
|
+
|
|
439
|
+
if (value > 0) {
|
|
440
|
+
bubble.classList.add("-visible");
|
|
441
|
+
} else {
|
|
442
|
+
bubble.classList.remove("-visible");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function updateAllNotificationBubbles(el) {
|
|
447
|
+
|
|
448
|
+
let dropdownParent = findAncestor(el, 'filter-dropdown');
|
|
449
|
+
let dropdownTrigger = dropdownParent.parentElement;
|
|
450
|
+
|
|
451
|
+
let total = dropdownParent.querySelectorAll('input[type="checkbox"]:checked').length;
|
|
452
|
+
|
|
453
|
+
updateNotificationBubble(dropdownTrigger, total);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* dropdownClickHandler()
|
|
458
|
+
* Opens tab content for clicked tab and hides the rest
|
|
459
|
+
*/
|
|
460
|
+
function dropdownClickHandler(el){
|
|
461
|
+
|
|
462
|
+
let currentNode = el.currentTarget;
|
|
463
|
+
currentNode.focus();
|
|
464
|
+
// add -active class
|
|
465
|
+
Array.prototype.map.call(this._internalVars.dropdownTrigger, (e, rank)=> {
|
|
466
|
+
if(e===currentNode&&e===document.activeElement){
|
|
467
|
+
// if already has active class, remove it
|
|
468
|
+
if (utils.hasClass(e,'filter-dropdown-trigger--active')) {
|
|
469
|
+
e.classList.remove("filter-dropdown-trigger--active");
|
|
470
|
+
if(appState.mode == 'desktop')
|
|
471
|
+
e.setAttribute('aria-expanded', 'false');
|
|
472
|
+
|
|
473
|
+
} else {
|
|
474
|
+
e.classList.add("filter-dropdown-trigger--active");
|
|
475
|
+
if(appState.mode == 'desktop'){
|
|
476
|
+
e.setAttribute('aria-expanded', 'true');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
} else {
|
|
482
|
+
e.classList.remove("filter-dropdown-trigger--active");
|
|
483
|
+
if(appState.mode == 'desktop')
|
|
484
|
+
e.setAttribute('aria-expanded', 'false');
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* dropdownClickHandler()
|
|
492
|
+
* Opens tab content for clicked tab and hides the rest
|
|
493
|
+
*/
|
|
494
|
+
function outsideFieldClickHandler(el){
|
|
495
|
+
|
|
496
|
+
let currentNode = el.currentTarget;
|
|
497
|
+
// add -active class
|
|
498
|
+
Array.prototype.map.call(this._internalVars.dropdownTrigger, (e, rank)=> {
|
|
499
|
+
if(e===currentNode){
|
|
500
|
+
// if already has active class, remove it
|
|
501
|
+
if (utils.hasClass(e,'filter-dropdown-trigger--active')) {
|
|
502
|
+
e.classList.remove("filter-dropdown-trigger--active");
|
|
503
|
+
if(appState.mode == 'desktop')
|
|
504
|
+
e.setAttribute('aria-expanded', 'false');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
} else {
|
|
508
|
+
e.classList.remove("filter-dropdown-trigger--active");
|
|
509
|
+
if(appState.mode == 'desktop')
|
|
510
|
+
e.setAttribute('aria-expanded', 'false');
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* searchFocus()
|
|
518
|
+
* Closes all dropdowns on search focus
|
|
519
|
+
*/
|
|
520
|
+
function searchFocus(el){
|
|
521
|
+
// add -active class
|
|
522
|
+
Array.prototype.map.call(this._internalVars.dropdownTrigger, (e, rank)=> {
|
|
523
|
+
e.classList.remove("filter-dropdown-trigger--active");
|
|
524
|
+
if(appState.mode == 'desktop')
|
|
525
|
+
e.setAttribute('aria-expanded', 'false');
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
export default TimelineFilter;
|
|
@@ -0,0 +1,153 @@
|
|
|
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 ToTopArrow : Content must be defined and set to a DOM selector or Node"]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
setting: "toTopArrowClicked",
|
|
13
|
+
isRequired: false,
|
|
14
|
+
validate: "type",
|
|
15
|
+
possibleValues: ["function"],
|
|
16
|
+
errorMessage: ["GDK ToTopArrow : toTopArrowClicked must be defined and set function"]
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
class ToTopArrow {
|
|
21
|
+
/**
|
|
22
|
+
* Refer to the design kit section of this component for JS examples and setting details.
|
|
23
|
+
* @param {string, Object} content
|
|
24
|
+
* A reference to the component node to toggle
|
|
25
|
+
*
|
|
26
|
+
* @param {function} [toTopArrowClicked]
|
|
27
|
+
* A callback function that gets fired when the To Top arrow is clicked
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
constructor(options) {
|
|
31
|
+
|
|
32
|
+
console.log('ToTopArrow has been initialized');
|
|
33
|
+
|
|
34
|
+
this._internalVars = {
|
|
35
|
+
node: null //used for current node
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//options with defaults set
|
|
39
|
+
this._defaults = {
|
|
40
|
+
"getDuration": function () {
|
|
41
|
+
return (pageYOffset <= 2000) ? 300 : 1200;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Create options by extending defaults with the passed in arguments
|
|
46
|
+
if (options && typeof options === "object") {
|
|
47
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
//if the required options are valid set up the environment
|
|
52
|
+
if (baseComponent.validateSettings(this._options, validateSettings)) {
|
|
53
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
|
54
|
+
setLocalVars.call(this);
|
|
55
|
+
setEvents.call(this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//Public Methods
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* removes the node from the dom and any events attached
|
|
63
|
+
*/
|
|
64
|
+
destroy() {
|
|
65
|
+
removeEvents.call(this);
|
|
66
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
|
67
|
+
|
|
68
|
+
//a little garbage collection
|
|
69
|
+
for (let variableKey in this) {
|
|
70
|
+
if (this.hasOwnProperty(variableKey)) {
|
|
71
|
+
delete this[variableKey];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Private Methods
|
|
78
|
+
/**
|
|
79
|
+
* setEvents()
|
|
80
|
+
* Sets all the events needed for the component
|
|
81
|
+
*/
|
|
82
|
+
function setEvents() {
|
|
83
|
+
this._internalVars.button.addEventListener("click", this._internalVars.handler);
|
|
84
|
+
window.addEventListener("scroll", toggleScrollBtnView.bind(this));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* removeEvents()
|
|
90
|
+
* removes all events from the component
|
|
91
|
+
*/
|
|
92
|
+
function removeEvents() {
|
|
93
|
+
this._internalVars.button.removeEventListener("click", this._internalVars.handler);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* toggleScrollBtnView()
|
|
98
|
+
* @param e
|
|
99
|
+
*/
|
|
100
|
+
function toggleScrollBtnView(e) {
|
|
101
|
+
if (((window.scrollY || screen.scrollY) > 200 && !this._internalVars.isDisplayed) || ((window.pageYOffset || screen.pageYOffset) > 200 && !this._internalVars.isDisplayed)) {
|
|
102
|
+
this._internalVars.button.classList.add('displayed');
|
|
103
|
+
this._internalVars.isDisplayed = true;
|
|
104
|
+
} else if ((window.scrollY <= 100 && this._internalVars.isDisplayed) || (window.pageYOffset <= 100 && this._internalVars.isDisplayed)) {
|
|
105
|
+
this._internalVars.button.classList.remove('displayed');
|
|
106
|
+
this._internalVars.isDisplayed = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* toggleView()
|
|
112
|
+
* instantiate To Top Arrow
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
function toggleScroll(e) {
|
|
116
|
+
//TODO: set correct Duration speed!
|
|
117
|
+
let duration = this._defaults.getDuration();
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
let scrollStep = -window.scrollY / (duration / 15) || -window.pageYOffset / (duration / 15),
|
|
120
|
+
scrollInterval = setInterval(function () {
|
|
121
|
+
if ((window.scrollY !== 0 && window.scrollY !== undefined) || (window.pageYOffset !== 0 && window.pageYOffset !== undefined)) {
|
|
122
|
+
window.scrollBy(0, scrollStep);
|
|
123
|
+
}
|
|
124
|
+
else clearInterval(scrollInterval);
|
|
125
|
+
}, 15);
|
|
126
|
+
|
|
127
|
+
if (this._options.toTopArrowClicked) {
|
|
128
|
+
this._options.toTopArrowClicked();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* setLocalVars()
|
|
134
|
+
* set local vars to the ones passed in options
|
|
135
|
+
*/
|
|
136
|
+
function setLocalVars() {
|
|
137
|
+
if (this._internalVars.contentType === 'string') {
|
|
138
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
|
139
|
+
} else if (this._internalVars.contentType === 'domNode') {
|
|
140
|
+
this._internalVars.node = this._options.content;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//add icon dom
|
|
144
|
+
this._internalVars.node.insertAdjacentHTML('beforeend', `<div class="icon-to-top-arrow"></div>`);
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
this._internalVars.button = this._internalVars.node;
|
|
148
|
+
this._internalVars.isDisplayed = false;
|
|
149
|
+
|
|
150
|
+
this._internalVars.handler = toggleScroll.bind(this);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default ToTopArrow;
|