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,241 @@
|
|
|
1
|
+
import baseComponent from '../../src/baseComponent';
|
|
2
|
+
import UserAgentService from '../../src/services/UserAgentService';
|
|
3
|
+
|
|
4
|
+
const validateSettings = [
|
|
5
|
+
{
|
|
6
|
+
setting : "content",
|
|
7
|
+
isRequired : true,
|
|
8
|
+
validate : "type",
|
|
9
|
+
possibleValues : ["string","object"],
|
|
10
|
+
errorMessage : ["GDK ButtonSwitch : Content must be defined and set to a DOM selector or Node"]
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
setting : "initialActiveSide",
|
|
14
|
+
isRequired : false,
|
|
15
|
+
validate : "value",
|
|
16
|
+
possibleValues : ["left","right"],
|
|
17
|
+
errorMessage : ["GDK ButtonSwitch : initialActiveSide must be set to left or right"]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
setting : "leftSideClicked",
|
|
21
|
+
isRequired : false,
|
|
22
|
+
validate : "type",
|
|
23
|
+
possibleValues : ["function"],
|
|
24
|
+
errorMessage : ["GDK ButtonSwitch : leftSideClicked must be a function"]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
setting : "rightSideClicked",
|
|
28
|
+
isRequired : false,
|
|
29
|
+
validate : "type",
|
|
30
|
+
possibleValues : ["function"],
|
|
31
|
+
errorMessage : ["GDK ButtonSwitch : rightSideClicked must be a function"]
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
class ButtonSwitch{
|
|
36
|
+
/**
|
|
37
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
|
38
|
+
* @param {string|Object} content
|
|
39
|
+
* A reference to the button node to switch
|
|
40
|
+
*
|
|
41
|
+
* @param {string} [initialActiveSide="left"]
|
|
42
|
+
* Used to designate which side of the button is initially active. Options: "left" || "right"
|
|
43
|
+
*
|
|
44
|
+
* @param {function} [leftSideClicked]
|
|
45
|
+
* A callback function that gets fired when the left side of the button is clicked
|
|
46
|
+
*
|
|
47
|
+
* @param {function} [rightSideClicked]
|
|
48
|
+
* A callback function that gets fired when the left side of the button is clicked
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
constructor(options) {
|
|
52
|
+
|
|
53
|
+
this._internalVars = {
|
|
54
|
+
node: null,//used for content item
|
|
55
|
+
left: null,//clickable node on the left side of the button
|
|
56
|
+
right: null,//clickable node on the right side of the button
|
|
57
|
+
sideOptions: ["left","right"],
|
|
58
|
+
side: null
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
//options with defaults set
|
|
62
|
+
this._defaults = {
|
|
63
|
+
initialActiveSide: this._internalVars.sideOptions[0]
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Create options by extending defaults with the passed in arugments
|
|
67
|
+
if (options && typeof options === "object") {
|
|
68
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//if the required options are valid set up the environment
|
|
72
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
|
73
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
|
74
|
+
setLocalVars.call(this);
|
|
75
|
+
setEvents.call(this);
|
|
76
|
+
if(!this._internalVars.node.getAttribute('tabindex'))
|
|
77
|
+
this._internalVars.node.setAttribute('tabindex', '0');
|
|
78
|
+
|
|
79
|
+
this._internalVars.node.setAttribute('role', 'checkbox');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//Public Methods
|
|
84
|
+
/**
|
|
85
|
+
* currentSide()
|
|
86
|
+
* returns the side the switch button is currently on
|
|
87
|
+
* @returns {string} "left" | "right"
|
|
88
|
+
*/
|
|
89
|
+
currentSide() {
|
|
90
|
+
return this._internalVars.side;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* slideLeft()
|
|
95
|
+
* invokes a click on the left side of the switch button
|
|
96
|
+
*/
|
|
97
|
+
slideLeft(){
|
|
98
|
+
if( this._internalVars.node.classList.contains("button-switch--slide-right")){
|
|
99
|
+
this._internalVars.node.classList.remove("button-switch--slide-right");
|
|
100
|
+
switchLeft.call(this);
|
|
101
|
+
}
|
|
102
|
+
else if(this._internalVars.node.classList.contains("button-switch--start-right")&&!this._internalVars.node.classList.contains("button-switch--slide-right")&&!this._internalVars.node.classList.contains("button-switch--slide-left")){
|
|
103
|
+
switchLeft.call(this);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* slideRight()
|
|
109
|
+
* invokes a click on the right side of the switch button
|
|
110
|
+
*/
|
|
111
|
+
slideRight(){
|
|
112
|
+
if(this._internalVars.node.classList.contains("button-switch--slide-left")){
|
|
113
|
+
this._internalVars.node.classList.remove("button-switch--slide-left");
|
|
114
|
+
switchRight.call(this);
|
|
115
|
+
}
|
|
116
|
+
else if(this._internalVars.node.classList.contains("button-switch--start-left")&&!this._internalVars.node.classList.contains("button-switch--slide-right")&&!this._internalVars.node.classList.contains("button-switch--slide-left")){
|
|
117
|
+
switchRight.call(this);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* destroy()
|
|
123
|
+
* removes the node from the dom and any events attached
|
|
124
|
+
*/
|
|
125
|
+
destroy(){
|
|
126
|
+
removeEvents.call(this);
|
|
127
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
|
128
|
+
|
|
129
|
+
//a little garbage collection
|
|
130
|
+
for (var variableKey in this){
|
|
131
|
+
if (this.hasOwnProperty(variableKey)){
|
|
132
|
+
delete this[variableKey];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Private Methods
|
|
140
|
+
/**
|
|
141
|
+
* setEvents()
|
|
142
|
+
* Sets all the events needed for the component
|
|
143
|
+
*/
|
|
144
|
+
function setEvents() {
|
|
145
|
+
const eventName = UserAgentService._clickEventName();
|
|
146
|
+
|
|
147
|
+
this._internalVars.node.addEventListener(eventName, this._internalVars.handler);
|
|
148
|
+
this._internalVars.node.addEventListener("keyup", this._internalVars.handler);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* removeEvents()
|
|
154
|
+
* removes all events from the component
|
|
155
|
+
*/
|
|
156
|
+
function removeEvents() {
|
|
157
|
+
const eventName = UserAgentService._clickEventName();
|
|
158
|
+
|
|
159
|
+
this._internalVars.node.removeEventListener(eventName, this._internalVars.handler);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* switchClick()
|
|
164
|
+
* if you click on button it will switch
|
|
165
|
+
*/
|
|
166
|
+
function switchClick(e){
|
|
167
|
+
if(e.type == 'keypress' || e.type == 'keyup' && ((e.keyCode || e.which) != 13)){
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if(this._internalVars.node.classList.contains('disabled')){
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if( this._internalVars.node.classList.contains("button-switch--slide-right")){
|
|
175
|
+
this._internalVars.node.classList.remove("button-switch--slide-right");
|
|
176
|
+
switchLeft.call(this);
|
|
177
|
+
}
|
|
178
|
+
else if(this._internalVars.node.classList.contains("button-switch--slide-left")){
|
|
179
|
+
this._internalVars.node.classList.remove("button-switch--slide-left");
|
|
180
|
+
switchRight.call(this);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if(this._internalVars.node.classList.contains("button-switch--start-left")&&!this._internalVars.node.classList.contains("button-switch--slide-right")&&!this._internalVars.node.classList.contains("button-switch--slide-left")){
|
|
184
|
+
switchRight.call(this);
|
|
185
|
+
}
|
|
186
|
+
else if(this._internalVars.node.classList.contains("button-switch--start-right")&&!this._internalVars.node.classList.contains("button-switch--slide-right")&&!this._internalVars.node.classList.contains("button-switch--slide-left")){
|
|
187
|
+
switchLeft.call(this);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function switchLeft(){
|
|
192
|
+
this._internalVars.node.classList.add("button-switch--slide-left");
|
|
193
|
+
this._internalVars.side = this._internalVars.sideOptions[0];
|
|
194
|
+
this._internalVars.node.setAttribute('aria-checked', 'false');
|
|
195
|
+
if(this._options.leftSideClicked)
|
|
196
|
+
this._options.leftSideClicked();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function switchRight(){
|
|
200
|
+
this._internalVars.node.classList.add("button-switch--slide-right");
|
|
201
|
+
this._internalVars.side = this._internalVars.sideOptions[1];
|
|
202
|
+
this._internalVars.node.setAttribute('aria-checked', 'true');
|
|
203
|
+
if(this._options.rightSideClicked)
|
|
204
|
+
this._options.rightSideClicked();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* setLocalVars()
|
|
210
|
+
* set all the local vars to passed in options
|
|
211
|
+
*/
|
|
212
|
+
function setLocalVars() {
|
|
213
|
+
//determine the type of content passed in
|
|
214
|
+
if(this._internalVars.contentType === 'string'){
|
|
215
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
|
216
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
|
217
|
+
this._internalVars.node = this._options.content;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
//get the child spans to add click events too
|
|
221
|
+
let spans = this._internalVars.node.querySelectorAll("span");
|
|
222
|
+
this._internalVars.left = spans[0];
|
|
223
|
+
this._internalVars.right = spans[1];
|
|
224
|
+
|
|
225
|
+
//init the current side and add the class
|
|
226
|
+
this._internalVars.side = this._options.initialActiveSide.toLowerCase();
|
|
227
|
+
//check for right else use the default left
|
|
228
|
+
if(this._internalVars.side === this._internalVars.sideOptions[1]) {
|
|
229
|
+
this._internalVars.node.classList.add("button-switch--start-right");
|
|
230
|
+
this._internalVars.node.setAttribute('aria-checked', 'true');
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
this._internalVars.node.classList.add("button-switch--start-left");
|
|
234
|
+
this._internalVars.node.setAttribute('aria-checked', 'false');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this._internalVars.handler = switchClick.bind(this);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
export default ButtonSwitch;
|
|
@@ -0,0 +1,240 @@
|
|
|
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 CardSelections : Content must be defined and set to a DOM selector or Node"]
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
setting : "initialActiveCard",
|
|
13
|
+
isRequired : false,
|
|
14
|
+
validate : "type",
|
|
15
|
+
possibleValues : ["number"],
|
|
16
|
+
errorMessage : ["GDK CardSelections : initialActiveCard must be set to a number"]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
setting : "cardSelectionSet",
|
|
20
|
+
isRequired : false,
|
|
21
|
+
validate : "type",
|
|
22
|
+
possibleValues : ["function"],
|
|
23
|
+
errorMessage : ["GDK CardSelections : cardSelectionClick must be a function"]
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
class CardSelections{
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
|
31
|
+
* @param {string|Object} content
|
|
32
|
+
* A reference to the html More Background Pattern node
|
|
33
|
+
*
|
|
34
|
+
* @param {number} [initialActiveCard=1]
|
|
35
|
+
* The number of the item to set as the active card on initialization. Must be greater than 0 and equal to or less than the number of cards.
|
|
36
|
+
*
|
|
37
|
+
* @param {function} [cardSelectionSet]
|
|
38
|
+
* A callback function that is triggered when any card is set to active.
|
|
39
|
+
*/
|
|
40
|
+
constructor(options) {
|
|
41
|
+
|
|
42
|
+
this._internalVars = {
|
|
43
|
+
node: null//used for content item
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//options with defaults set
|
|
47
|
+
this._defaults = {
|
|
48
|
+
initialActiveCard: 1
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Create options by extending defaults with the passed in arugments
|
|
52
|
+
if (options && typeof options === "object") {
|
|
53
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//if the required options are valid set up the environment
|
|
57
|
+
if( baseComponent.validateSettings(this._options, validateSettings) ){
|
|
58
|
+
this._internalVars.contentType = baseComponent.getContentType(this);
|
|
59
|
+
setLocalVars.call(this);
|
|
60
|
+
setEvents.call(this);
|
|
61
|
+
init.call(this);
|
|
62
|
+
|
|
63
|
+
this._internalVars.cardSelectionSection.setAttribute('role', 'radiogroup');
|
|
64
|
+
|
|
65
|
+
Array.prototype.forEach.call(this._internalVars.cardSelectionsCards, (element)=> {
|
|
66
|
+
if(!element.getAttribute('tabindex'))
|
|
67
|
+
element.setAttribute('tabindex', '0');
|
|
68
|
+
|
|
69
|
+
if(!element.getElementsByTagName('input')[0].getAttribute('tabindex'))
|
|
70
|
+
element.getElementsByTagName('input')[0].setAttribute('tabindex', '-1');
|
|
71
|
+
|
|
72
|
+
element.setAttribute('role', 'radio');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//Public Methods
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns the active selected card
|
|
81
|
+
* @return {Element}
|
|
82
|
+
*/
|
|
83
|
+
currentActiveCard() {
|
|
84
|
+
return this._internalVars.selectedCard;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* sets the initial active card using an index parameter
|
|
89
|
+
* @param {Number} index Number indicating what the active card should be set to
|
|
90
|
+
*/
|
|
91
|
+
setActiveCard(index){
|
|
92
|
+
setInitialActiveCard.call(this, index);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* removes the node from the dom and any events attached
|
|
97
|
+
*/
|
|
98
|
+
destroy(){
|
|
99
|
+
removeEvents.call(this);
|
|
100
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
|
101
|
+
|
|
102
|
+
//a little garbage collection
|
|
103
|
+
for (var variableKey in this){
|
|
104
|
+
if (this.hasOwnProperty(variableKey)){
|
|
105
|
+
delete this[variableKey];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Private Methods
|
|
113
|
+
/**
|
|
114
|
+
* setEvents()
|
|
115
|
+
* Sets all the events needed for the component
|
|
116
|
+
*/
|
|
117
|
+
function setEvents() {
|
|
118
|
+
let eventName = "click";
|
|
119
|
+
|
|
120
|
+
Array.prototype.forEach.call(this._internalVars.cardSelectionsCards, (element)=> {
|
|
121
|
+
element.addEventListener(eventName, this._internalVars.handler);
|
|
122
|
+
element.addEventListener('keyup', this._internalVars.handler);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* removeEvents()
|
|
129
|
+
* removes all events from the component
|
|
130
|
+
*/
|
|
131
|
+
function removeEvents() {
|
|
132
|
+
let eventName = "click";
|
|
133
|
+
|
|
134
|
+
Array.prototype.forEach.call(this._internalVars.cardSelectionsCards, (element)=> {
|
|
135
|
+
element.removeEventListener(eventName, this._internalVars.handler);
|
|
136
|
+
element.removeEventListener('keyup', this._internalVars.handler);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* init()
|
|
142
|
+
* Sets the initial values
|
|
143
|
+
*/
|
|
144
|
+
function init() {
|
|
145
|
+
let index = null;
|
|
146
|
+
|
|
147
|
+
if (this._options.initialActiveCard) {
|
|
148
|
+
index = this._options.initialActiveCard;
|
|
149
|
+
} else {
|
|
150
|
+
index = this._defaults.initialActiveCard;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
setInitialActiveCard.call(this, index);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Removes the class and attributes identifying the card as selected
|
|
158
|
+
*/
|
|
159
|
+
function resetSelected() {
|
|
160
|
+
let selected = this._internalVars.cardSelectionsObject.querySelectorAll('.' + this._internalVars.cardSelectedClass);
|
|
161
|
+
|
|
162
|
+
if (selected) {
|
|
163
|
+
Array.prototype.forEach.call(selected, (el) => {
|
|
164
|
+
el.classList.remove(this._internalVars.cardSelectedClass);
|
|
165
|
+
el.getElementsByTagName('input')[0].checked = false;
|
|
166
|
+
el.setAttribute('aria-checked', 'false');
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Adds attributes identifying the card as selected
|
|
173
|
+
*/
|
|
174
|
+
function setActiveCardAttributes() {
|
|
175
|
+
this._internalVars.selectedCard = this._internalVars.cardSelectionsObject.querySelector('.' + this._internalVars.cardSelectedClass);
|
|
176
|
+
|
|
177
|
+
this._internalVars.selectedCard.getElementsByTagName('input')[0].checked = true;
|
|
178
|
+
this._internalVars.selectedCard.setAttribute('aria-checked', 'true');
|
|
179
|
+
|
|
180
|
+
if (this._options.cardSelectionSet) {
|
|
181
|
+
this._options.cardSelectionSet(this._internalVars.selectedCard);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* setInitialActiveCard()
|
|
187
|
+
* Sets the initial active card
|
|
188
|
+
*/
|
|
189
|
+
function setInitialActiveCard(index){
|
|
190
|
+
resetSelected.call(this);
|
|
191
|
+
|
|
192
|
+
if (index <= this._internalVars.cardSelectionsCards.length && index > 0) {
|
|
193
|
+
this._internalVars.cardSelectionsCards[index-1].classList.add(this._internalVars.cardSelectedClass);
|
|
194
|
+
} else {
|
|
195
|
+
this._internalVars.cardSelectionsCards[0].classList.add(this._internalVars.cardSelectedClass);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
setActiveCardAttributes.call(this);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* setActiveCard()
|
|
203
|
+
* Sets the active card
|
|
204
|
+
*/
|
|
205
|
+
function setActiveCard(event){
|
|
206
|
+
if(event.type == 'keypress' || event.type == 'keyup' && ((event.keyCode || event.which) != 13)){} else {
|
|
207
|
+
resetSelected.call(this);
|
|
208
|
+
|
|
209
|
+
event.currentTarget.classList.add(this._internalVars.cardSelectedClass);
|
|
210
|
+
|
|
211
|
+
setActiveCardAttributes.call(this);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* setLocalVars()
|
|
217
|
+
* set all the local vars to passed in options
|
|
218
|
+
*/
|
|
219
|
+
function setLocalVars() {
|
|
220
|
+
//determine the type of content passed in
|
|
221
|
+
if(this._internalVars.contentType === 'string'){
|
|
222
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
|
223
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
|
224
|
+
this._internalVars.node = this._options.content;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
this._internalVars.cardSelectionsObject = this._internalVars.node;
|
|
228
|
+
|
|
229
|
+
this._internalVars.cardSelectionSectionClass = 'card-selections';
|
|
230
|
+
this._internalVars.cardSelectedClass = 'card-selections-selected';
|
|
231
|
+
this._internalVars.cardSelectionsCardClass = 'card-selections-card';
|
|
232
|
+
this._internalVars.selectedCard = null;
|
|
233
|
+
|
|
234
|
+
this._internalVars.cardSelectionSection = this._internalVars.cardSelectionsObject.querySelector('.' + this._internalVars.cardSelectionSectionClass);
|
|
235
|
+
this._internalVars.cardSelectionsCards = this._internalVars.cardSelectionsObject.querySelectorAll('.' + this._internalVars.cardSelectionsCardClass);
|
|
236
|
+
|
|
237
|
+
this._internalVars.handler = setActiveCard.bind(this);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export default CardSelections;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import appState from '../../src/appState';
|
|
2
|
+
|
|
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 CommonQuestionsSquares : Content must be defined and set to a DOM selector or Node"]
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
class CommonQuestionsSquares{
|
|
17
|
+
/**
|
|
18
|
+
* These are settings for the instantiation. Refer to the design kit section of this component for JS setting examples.
|
|
19
|
+
* @param {string|Object} content
|
|
20
|
+
* A reference to the common questions squares node
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
|
|
24
|
+
this._internalVars = {
|
|
25
|
+
node: null,//used for content item
|
|
26
|
+
individualBoxes: null
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//options with defaults set
|
|
30
|
+
this._defaults = {
|
|
31
|
+
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Create options by extending defaults with the passed in arugments
|
|
35
|
+
if (options && typeof options === "object") {
|
|
36
|
+
this._options = baseComponent.extendDefaults(this._defaults, options);
|
|
37
|
+
}
|
|
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
|
+
setEvents.call(this);
|
|
44
|
+
|
|
45
|
+
let allSquares = this._internalVars.node.querySelectorAll('.square');
|
|
46
|
+
Array.prototype.forEach.call(allSquares, function(el, i){
|
|
47
|
+
if(!el.classList.contains('square-link'))
|
|
48
|
+
el.setAttribute('tabindex', '0');
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//Public Methods
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* destroy()
|
|
57
|
+
* removes the node from the dom and any events attached
|
|
58
|
+
*/
|
|
59
|
+
destroy(){
|
|
60
|
+
removeEvents.call(this);
|
|
61
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
|
62
|
+
|
|
63
|
+
//a little garbage collection
|
|
64
|
+
for (var variableKey in this){
|
|
65
|
+
if (this.hasOwnProperty(variableKey)){
|
|
66
|
+
delete this[variableKey];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Private Methods
|
|
74
|
+
/**
|
|
75
|
+
* setEvents()
|
|
76
|
+
* Sets all the events needed for the component
|
|
77
|
+
*/
|
|
78
|
+
function setEvents() {
|
|
79
|
+
const eventName = UserAgentService._clickEventName();
|
|
80
|
+
|
|
81
|
+
console.log( this._internalVars.individualBoxes);
|
|
82
|
+
|
|
83
|
+
for (var j = 0; j < this._internalVars.individualBoxes.length - 1; j++) {
|
|
84
|
+
this._internalVars.individualBoxes[j].addEventListener('mouseover', removeStyleAttr.bind(this, this._internalVars.individualBoxes[j]));
|
|
85
|
+
this._internalVars.individualBoxes[j].addEventListener(eventName, openPanel.bind(this, this._internalVars.individualBoxes[j]));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for(var h = 0; h < this._internalVars.node.querySelectorAll('a').length; h++ ){
|
|
89
|
+
this._internalVars.anchorArray[h].addEventListener('focus', linkFocus.bind(this, this._internalVars.anchorArray[h]));
|
|
90
|
+
this._internalVars.anchorArray[h].addEventListener('blur', linkUnfocus.bind(this, this._internalVars.anchorArray[h]));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function linkFocus(e){
|
|
95
|
+
var squareParent = e.parentNode.parentNode;
|
|
96
|
+
squareParent.classList.add('flip-back');
|
|
97
|
+
squareParent.previousElementSibling.classList.add('flip-front');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function linkUnfocus(e){
|
|
101
|
+
var squareParent = e.parentNode.parentNode;
|
|
102
|
+
squareParent.classList.remove('flip-back');
|
|
103
|
+
squareParent.previousElementSibling.classList.remove('flip-front');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function removeStyleAttr(e){
|
|
107
|
+
if(appState.mode !== "mobile") {
|
|
108
|
+
var el = e.querySelector('.back');
|
|
109
|
+
el.removeAttribute('style');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
function openPanel(e){
|
|
115
|
+
var el = e.querySelector('.back');
|
|
116
|
+
if(appState.mode === "mobile"){
|
|
117
|
+
e.classList.toggle('open');
|
|
118
|
+
if(e.classList.contains('open')){
|
|
119
|
+
el.style.display = "block";
|
|
120
|
+
let paragraph = el.querySelector("p");
|
|
121
|
+
el.style.maxHeight = outerHeight.call(this,paragraph) + "px";
|
|
122
|
+
}else{
|
|
123
|
+
el.removeAttribute('style');
|
|
124
|
+
el.style.display = "block";
|
|
125
|
+
el.style.maxHeight="0px";
|
|
126
|
+
}
|
|
127
|
+
}else{
|
|
128
|
+
el.removeAttribute('style');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* removeEvents()
|
|
134
|
+
* removes all events from the component
|
|
135
|
+
*/
|
|
136
|
+
function removeEvents() {
|
|
137
|
+
const eventName = UserAgentService._clickEventName();
|
|
138
|
+
|
|
139
|
+
for (var j = 0; j < this._internalVars.individualBoxes.length - 1; j++) {
|
|
140
|
+
this._internalVars.individualBoxes[j].removeEventListener('mouseover', removeStyleAttr.bind(this, this._internalVars.individualBoxes[j]));
|
|
141
|
+
this._internalVars.individualBoxes[j].removeEventListener(eventName, openPanel.bind(this, this._internalVars.individualBoxes[j]));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* setLocalVars()
|
|
150
|
+
* set all the local vars to passed in options
|
|
151
|
+
*/
|
|
152
|
+
function setLocalVars() {
|
|
153
|
+
//determine the type of content passed in
|
|
154
|
+
if(this._internalVars.contentType === 'string'){
|
|
155
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
|
156
|
+
}else if(this._internalVars.contentType === 'domNode'){
|
|
157
|
+
this._internalVars.node = this._options.content;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
this._internalVars.individualBoxes = this._internalVars.node.children;
|
|
161
|
+
this._internalVars.anchorArray = this._internalVars.node.querySelectorAll('a');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* outerHeight()
|
|
166
|
+
* used to get the height of an element that is the same across all browsers
|
|
167
|
+
*
|
|
168
|
+
* @param {Object} node DOM node
|
|
169
|
+
* @return {number}
|
|
170
|
+
*/
|
|
171
|
+
function outerHeight(el) {
|
|
172
|
+
let height = el.offsetHeight;
|
|
173
|
+
let style = getComputedStyle(el);
|
|
174
|
+
|
|
175
|
+
height += parseInt(style.marginTop) + parseInt(style.marginBottom);
|
|
176
|
+
return height;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export default CommonQuestionsSquares;
|