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,329 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports["default"] = void 0;
|
7
|
+
var _baseComponent = _interopRequireDefault(require("../../src/baseComponent"));
|
8
|
+
var _UserAgentService = _interopRequireDefault(require("../../src/services/UserAgentService"));
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
10
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
11
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
12
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
13
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
16
|
+
var validateSettings = [{
|
17
|
+
setting: "content",
|
18
|
+
isRequired: true,
|
19
|
+
validate: "type",
|
20
|
+
possibleValues: ["string", "object"],
|
21
|
+
errorMessage: ["GDK Tooltip : Content must be defined and set to a DOM selector or Node"]
|
22
|
+
}, {
|
23
|
+
setting: "toolTipText",
|
24
|
+
isRequired: false,
|
25
|
+
validate: "type",
|
26
|
+
possibleValues: ["string"],
|
27
|
+
errorMessage: ["GDK Tooltip : toolTipText must be set to a string"]
|
28
|
+
}, {
|
29
|
+
setting: "toolTipOpen",
|
30
|
+
isRequired: false,
|
31
|
+
validate: "type",
|
32
|
+
possibleValues: ["function"],
|
33
|
+
errorMessage: ["GDK Tooltip : toolTipOpen must be defined and set function"]
|
34
|
+
}, {
|
35
|
+
setting: "toolTipClose",
|
36
|
+
isRequired: false,
|
37
|
+
validate: "type",
|
38
|
+
possibleValues: ["function"],
|
39
|
+
errorMessage: ["GDK Tooltip : toolTipClose must be defined and set function"]
|
40
|
+
}];
|
41
|
+
var Tooltip = /*#__PURE__*/function () {
|
42
|
+
/**
|
43
|
+
* Refer to the design kit section of this component for JS examples and setting details.
|
44
|
+
* @param {string, Object} content
|
45
|
+
* A reference to the html Tooltip trigger's node
|
46
|
+
*
|
47
|
+
* @param {string} [toolTipText]
|
48
|
+
* Callback function fired once a 'filter-submit' is clicked
|
49
|
+
*
|
50
|
+
* @param {function} [toolTipOpen]
|
51
|
+
* A callback function triggered when a tooltip is displayed
|
52
|
+
*
|
53
|
+
* @param {function} [toolTipClose]
|
54
|
+
* A callback function triggered when a tooltip is closed manually
|
55
|
+
*
|
56
|
+
*/
|
57
|
+
function Tooltip(options) {
|
58
|
+
_classCallCheck(this, Tooltip);
|
59
|
+
this._internalVars = {
|
60
|
+
node: null,
|
61
|
+
//used for content item
|
62
|
+
toolTip: null,
|
63
|
+
triggerOffset: null,
|
64
|
+
timeout: null,
|
65
|
+
delay: 300,
|
66
|
+
// delay 0.3 seconds
|
67
|
+
breakpoint: 768,
|
68
|
+
margin: 12,
|
69
|
+
wrapperElementId: "wrapper",
|
70
|
+
toolTiplElementClass: "tooltip",
|
71
|
+
toolTipTriggerElementClass: "tooltip-trigger",
|
72
|
+
toolTipCloseElementClass: "icon-close-20",
|
73
|
+
toolTipActiveClass: "tooltip--active",
|
74
|
+
wrapper: null,
|
75
|
+
closeBtn: null
|
76
|
+
};
|
77
|
+
|
78
|
+
//options with defaults set
|
79
|
+
this._defaults = {
|
80
|
+
toolTipText: null
|
81
|
+
};
|
82
|
+
|
83
|
+
// Create options by extending defaults with the passed in arugments
|
84
|
+
if (options && _typeof(options) === "object") {
|
85
|
+
this._options = _baseComponent["default"].extendDefaults(this._defaults, options);
|
86
|
+
}
|
87
|
+
|
88
|
+
//if the required options are valid set up the environment
|
89
|
+
if (_baseComponent["default"].validateSettings(this._options, validateSettings)) {
|
90
|
+
this._internalVars.contentType = _baseComponent["default"].getContentType(this);
|
91
|
+
setLocalVars.call(this);
|
92
|
+
setEvents.call(this);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
//Public Methods
|
97
|
+
|
98
|
+
/**
|
99
|
+
* destroy()
|
100
|
+
* removes the node from the dom and any events attached
|
101
|
+
*/
|
102
|
+
return _createClass(Tooltip, [{
|
103
|
+
key: "destroy",
|
104
|
+
value: function destroy() {
|
105
|
+
removeEvents.call(this);
|
106
|
+
this._internalVars.node.parentNode.removeChild(this._internalVars.node);
|
107
|
+
this._internalVars.toolTip.parentNode.removeChild(this._internalVars.toolTip);
|
108
|
+
//a little garbage collection
|
109
|
+
for (var variableKey in this) {
|
110
|
+
if (this.hasOwnProperty(variableKey)) {
|
111
|
+
delete this[variableKey];
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}]);
|
116
|
+
}(); // Private Methods
|
117
|
+
/**
|
118
|
+
* setLocalVars()
|
119
|
+
* set all the local vars to passed in options
|
120
|
+
*/
|
121
|
+
function setLocalVars() {
|
122
|
+
//determine the type of content passed in
|
123
|
+
if (this._internalVars.contentType === 'string') {
|
124
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
125
|
+
} else if (this._internalVars.contentType === 'domNode') {
|
126
|
+
this._internalVars.node = this._options.content;
|
127
|
+
}
|
128
|
+
if (this._options.toolTipText === null) {
|
129
|
+
this._internalVars.toolTip = document.querySelector("#" + this._internalVars.node.getAttribute('data-tooltip-view'));
|
130
|
+
this._internalVars.node.parentNode.insertBefore(this._internalVars.toolTip, this._internalVars.node.nextSibling);
|
131
|
+
} else {
|
132
|
+
buildNewTooltip.call(this);
|
133
|
+
}
|
134
|
+
this._internalVars.wrapper = document.querySelector("#" + this._internalVars.wrapperElementId);
|
135
|
+
this._internalVars.closeBtn = this._internalVars.toolTip.querySelector("." + this._internalVars.toolTipCloseElementClass);
|
136
|
+
this._internalVars.toolTipClass = 'tooltip';
|
137
|
+
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
* setEvents()
|
141
|
+
* Sets all the events needed for the component
|
142
|
+
*/
|
143
|
+
function setEvents() {
|
144
|
+
var eventName = _UserAgentService["default"]._clickEventName();
|
145
|
+
if ("ontouchstart" in document.documentElement) {
|
146
|
+
this._internalVars.node.addEventListener(eventName, showToolTip.bind(this));
|
147
|
+
this._internalVars.node.addEventListener("mouseover", showToolTip.bind(this));
|
148
|
+
this._internalVars.closeBtn.addEventListener(eventName, closeBtnClickHandler.bind(this));
|
149
|
+
} else {
|
150
|
+
this._internalVars.node.addEventListener("mouseenter", showToolTip.bind(this));
|
151
|
+
this._internalVars.node.addEventListener(eventName, function (e) {
|
152
|
+
e.preventDefault();
|
153
|
+
});
|
154
|
+
this._internalVars.node.addEventListener("focus", showToolTip.bind(this));
|
155
|
+
this._internalVars.node.addEventListener("keydown", shiftTab.bind(this));
|
156
|
+
this._internalVars.closeBtn.addEventListener(eventName, closeBtnClickHandler.bind(this));
|
157
|
+
this._internalVars.closeBtn.addEventListener("blur", closeBtnClickHandler.bind(this));
|
158
|
+
}
|
159
|
+
}
|
160
|
+
function shiftTab(e) {
|
161
|
+
if (e.keyCode == '9' && e.shiftKey) {
|
162
|
+
hideToolTip.call(this);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* removeEvents()
|
168
|
+
* removes all events from the component
|
169
|
+
*/
|
170
|
+
function removeEvents() {
|
171
|
+
var eventName = _UserAgentService["default"]._clickEventName();
|
172
|
+
if ("ontouchstart" in document.documentElement) {
|
173
|
+
this._internalVars.node.removeEventListener(eventName, showToolTip.bind(this));
|
174
|
+
this._internalVars.node.removeEventListener("mouseover", showToolTip.bind(this));
|
175
|
+
this._internalVars.closeBtn.removeEventListener(eventName, closeBtnClickHandler.bind(this));
|
176
|
+
} else {
|
177
|
+
this._internalVars.node.removeEventListener("mouseenter", showToolTip.bind(this));
|
178
|
+
this._internalVars.closeBtn.removeEventListener(eventName, closeBtnClickHandler.bind(this));
|
179
|
+
this._internalVars.node.removeEventListener(eventName, function (e) {
|
180
|
+
e.preventDefault();
|
181
|
+
});
|
182
|
+
this._internalVars.node.removeEventListener("focus", showToolTip.bind(this));
|
183
|
+
this._internalVars.node.removeEventListener("keydown", shiftTab.bind(this));
|
184
|
+
this._internalVars.closeBtn.removeEventListener("blur", closeBtnClickHandler.bind(this));
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
/**
|
189
|
+
* closeBtnClickHandler()
|
190
|
+
* catches click on close button
|
191
|
+
*/
|
192
|
+
function closeBtnClickHandler(e) {
|
193
|
+
console.log("closeBtnClickHandler");
|
194
|
+
e.preventDefault();
|
195
|
+
hideToolTip.call(this);
|
196
|
+
if (this._options.toolTipClose) {
|
197
|
+
var tooltip = e.currentTarget.parentNode;
|
198
|
+
this._options.toolTipClose(tooltip);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* buildNewTooltip()
|
204
|
+
* use to dynamically create the tooltip
|
205
|
+
*/
|
206
|
+
function buildNewTooltip() {
|
207
|
+
var toolTipId = this._internalVars.node.getAttribute('data-tooltip-view');
|
208
|
+
var dynamicToolTip = document.createElement('div');
|
209
|
+
dynamicToolTip.setAttribute('id', toolTipId);
|
210
|
+
dynamicToolTip.classList.add("tooltip");
|
211
|
+
dynamicToolTip.innerHTML = '<div tabindex="0">' + this._options.toolTipText + '</div><button class="icon-close-20" aria-label="Close tooltip"></button>';
|
212
|
+
this._internalVars.node.parentNode.insertBefore(dynamicToolTip, this._internalVars.node.nextSibling);
|
213
|
+
this._internalVars.toolTip = document.querySelector("#" + toolTipId);
|
214
|
+
}
|
215
|
+
|
216
|
+
/**
|
217
|
+
* showToolTip()
|
218
|
+
* show tooltip on hover
|
219
|
+
*/
|
220
|
+
function showToolTip(e) {
|
221
|
+
var _this = this;
|
222
|
+
e.preventDefault();
|
223
|
+
|
224
|
+
// prep tooltip
|
225
|
+
|
226
|
+
var toolTipId = this._internalVars.node.getAttribute('data-tooltip-view');
|
227
|
+
var toolTip = document.querySelector("#" + toolTipId);
|
228
|
+
this._internalVars.node.parentNode.insertBefore(toolTip, this._internalVars.node.nextSibling);
|
229
|
+
this._internalVars.toolTip = toolTip;
|
230
|
+
try {
|
231
|
+
hideToolTip.call(this);
|
232
|
+
} catch (err) {
|
233
|
+
// clear existing tt
|
234
|
+
}
|
235
|
+
clearTimeout(this._internalVars.timeout);
|
236
|
+
var self = e.currentTarget;
|
237
|
+
self.classList.add(this._internalVars.toolTipActiveClass);
|
238
|
+
this._internalVars.activationArea = self;
|
239
|
+
self.addEventListener("mouseleave", settimeout.bind(this));
|
240
|
+
this._internalVars.toolTip.addEventListener("mouseleave", settimeout.bind(this));
|
241
|
+
this._internalVars.toolTip.addEventListener("mouseover", cleartimeout.bind(this));
|
242
|
+
this._internalVars.triggerOffset = self.getBoundingClientRect();
|
243
|
+
setTimeout(function () {
|
244
|
+
if (self.classList.contains("tooltip--active")) {
|
245
|
+
_this._internalVars.toolTip.style.display = "block";
|
246
|
+
//position the tooltip after setting to block
|
247
|
+
positionToolTip.call(_this);
|
248
|
+
//set opacity and let css transition fade it in
|
249
|
+
_this._internalVars.toolTip.style.opacity = 1;
|
250
|
+
}
|
251
|
+
}, this._internalVars.delay);
|
252
|
+
if (this._options.toolTipOpen) {
|
253
|
+
var triggerElement = e.currentTarget.parentNode,
|
254
|
+
tooltip = triggerElement.querySelector('.' + this._internalVars.toolTipClass);
|
255
|
+
this._options.toolTipOpen(tooltip);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* cleartimeout()
|
261
|
+
* clears set timeout
|
262
|
+
*/
|
263
|
+
function cleartimeout(e) {
|
264
|
+
clearTimeout(this._internalVars.timeout);
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* settimeout()
|
269
|
+
* sets a timeout to hide the tooltip
|
270
|
+
*/
|
271
|
+
function settimeout(e) {
|
272
|
+
if (document.activeElement != e.currentTarget) {
|
273
|
+
clearTimeout(this._internalVars.timeout);
|
274
|
+
this._internalVars.node.classList.remove(this._internalVars.toolTipActiveClass);
|
275
|
+
this._internalVars.timeout = setTimeout(hideToolTip.bind(this), 200);
|
276
|
+
// this._internalVars.timeout = hideToolTip.call(this);
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
/**
|
281
|
+
* hideToolTip()
|
282
|
+
* hides the tooltip
|
283
|
+
*/
|
284
|
+
function hideToolTip() {
|
285
|
+
var _this2 = this;
|
286
|
+
this._internalVars.toolTip.style.opacity = 0;
|
287
|
+
setTimeout(function () {
|
288
|
+
_this2._internalVars.toolTip.style.display = "none";
|
289
|
+
}, this._internalVars.delay);
|
290
|
+
}
|
291
|
+
|
292
|
+
/**
|
293
|
+
* positionToolTip()
|
294
|
+
* sets the position for the tooltip depending on trigger position
|
295
|
+
*/
|
296
|
+
function positionToolTip() {
|
297
|
+
this._internalVars.toolTip.classList.remove("arrow-right");
|
298
|
+
this._internalVars.toolTip.classList.remove("arrow-bottom");
|
299
|
+
var winWidth = document.body.clientWidth;
|
300
|
+
var winHeight = window.innerHeight || document.documentElement.clientHeight;
|
301
|
+
var containerOffset = this._internalVars.wrapper.getBoundingClientRect();
|
302
|
+
var containerOffsetLeft = containerOffset.left;
|
303
|
+
var containerWidth = this._internalVars.wrapper.offsetWidth;
|
304
|
+
var tooltipWidth = this._internalVars.toolTip.offsetWidth;
|
305
|
+
var tooltipHeight = this._internalVars.toolTip.offsetHeight;
|
306
|
+
var xpos = null;
|
307
|
+
var ypos = null;
|
308
|
+
if (winWidth < this._internalVars.breakpoint) {
|
309
|
+
ypos = 25;
|
310
|
+
if (this._internalVars.triggerOffset.left - containerOffsetLeft + tooltipWidth < containerWidth) {
|
311
|
+
xpos = 0;
|
312
|
+
} else {
|
313
|
+
xpos = -(this._internalVars.triggerOffset.left - containerOffsetLeft + tooltipWidth - containerWidth + 10);
|
314
|
+
}
|
315
|
+
} else {
|
316
|
+
xpos = 40;
|
317
|
+
ypos = -15;
|
318
|
+
if (this._internalVars.triggerOffset.left - containerOffsetLeft + tooltipWidth + 50 < containerWidth) {
|
319
|
+
xpos = 40;
|
320
|
+
ypos = -15;
|
321
|
+
} else {
|
322
|
+
xpos = -(tooltipWidth + 5);
|
323
|
+
this._internalVars.toolTip.classList.add("arrow-right");
|
324
|
+
}
|
325
|
+
}
|
326
|
+
this._internalVars.toolTip.style.left = xpos + "px";
|
327
|
+
this._internalVars.toolTip.style.top = ypos + "px";
|
328
|
+
}
|
329
|
+
var _default = exports["default"] = Tooltip;
|
@@ -0,0 +1,168 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports["default"] = void 0;
|
7
|
+
var utils = _interopRequireWildcard(require("../../src/utils"));
|
8
|
+
var _baseComponent = _interopRequireDefault(require("../../src/baseComponent"));
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
13
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
14
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
17
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
18
|
+
var validateSettings = [{
|
19
|
+
setting: "content",
|
20
|
+
isRequired: true,
|
21
|
+
validate: "type",
|
22
|
+
possibleValues: ["string", "object"],
|
23
|
+
errorMessage: ["GDK UpsellCarousel : Content must be defined and set to a DOM selector or Node"]
|
24
|
+
}];
|
25
|
+
var UpsellCarousel = /*#__PURE__*/_createClass(function UpsellCarousel(options) {
|
26
|
+
_classCallCheck(this, UpsellCarousel);
|
27
|
+
console.log('UpsellCarousel initialized');
|
28
|
+
this._internalVars = {
|
29
|
+
node: null
|
30
|
+
};
|
31
|
+
|
32
|
+
//options with defaults set
|
33
|
+
this._defaults = {};
|
34
|
+
|
35
|
+
// Create options by extending defaults with the passed in arguments
|
36
|
+
if (options && _typeof(options) === "object") {
|
37
|
+
this._options = _baseComponent["default"].extendDefaults(this._defaults, options);
|
38
|
+
}
|
39
|
+
|
40
|
+
//if the required options are valid set up the environment
|
41
|
+
if (_baseComponent["default"].validateSettings(this._options, validateSettings)) {
|
42
|
+
this._internalVars.contentType = _baseComponent["default"].getContentType(this);
|
43
|
+
setLocalVars.call(this);
|
44
|
+
setEvents.call(this);
|
45
|
+
if (this._internalVars.node) {
|
46
|
+
carouselDefaults.call(this);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}); // Private Methods
|
50
|
+
/**
|
51
|
+
* setEvents()
|
52
|
+
* Sets all the events needed for the component
|
53
|
+
*/
|
54
|
+
function setEvents() {
|
55
|
+
window.addEventListener("load", carouselDefaults.bind(this));
|
56
|
+
window.addEventListener("resize", carouselDefaults.bind(this));
|
57
|
+
for (var i = 0; i < this._internalVars.carouselChevronBtn.length; i++) {
|
58
|
+
this._internalVars.carouselChevronBtn[i].addEventListener("click", carouselClick.bind(this, this._internalVars.carouselChevronBtn[i]));
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* removeEvents()
|
64
|
+
* removes all events from the component
|
65
|
+
*/
|
66
|
+
function removeEvents() {
|
67
|
+
window.removeEventListener("load", carouselDefaults.bind(this));
|
68
|
+
window.removeEventListener("resize", carouselDefaults.bind(this));
|
69
|
+
for (var i = 0; i < this._internalVars.carouselChevronBtn.length; i++) {
|
70
|
+
this._internalVars.carouselChevronBtn[i].removeEventListener("click", carouselClick.bind(this, this._internalVars.carouselChevronBtn[i]));
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* toggleView()
|
76
|
+
* instantiate View More/Less
|
77
|
+
*/
|
78
|
+
function carouselDefaults() {
|
79
|
+
if (window.innerWidth > this._internalVars.carouselIconDisplay) {
|
80
|
+
this._internalVars.carouselIconNumber = 4;
|
81
|
+
} else if (window.innerWidth > this._internalVars.carouselIconSmallDisplay) {
|
82
|
+
this._internalVars.carouselIconNumber = 2;
|
83
|
+
} else {
|
84
|
+
this._internalVars.carouselIconNumber = 1;
|
85
|
+
}
|
86
|
+
this._internalVars.carouselIconWidth = this._internalVars.carouselObject.querySelector(this._internalVars.carouselIconClass).clientWidth;
|
87
|
+
this._internalVars.carouselObject.style.width = (this._internalVars.carouselIconNumber + 2) * this._internalVars.carouselIconWidth + 'px';
|
88
|
+
this._internalVars.carouselItemsLeft = this._internalVars.carouselUpsellNumber - this._internalVars.carouselIconNumber;
|
89
|
+
this._internalVars.carouselLeftVal = 0;
|
90
|
+
this._internalVars.carouselObject.querySelector(this._internalVars.carouselIconWrapperClass).style.left = 0 + 'px';
|
91
|
+
var wrapperWidth = this._internalVars.carouselIconWidth * this._internalVars.carouselIconNumber,
|
92
|
+
containerWidth = this._internalVars.carouselIconWidth * this._internalVars.carouselUpsellNumber;
|
93
|
+
document.querySelector(this._internalVars.carouselWrapperClass).style.width = wrapperWidth + 'px';
|
94
|
+
document.querySelector(this._internalVars.carouselIconWrapperClass).style.width = containerWidth + 'px';
|
95
|
+
chevronState.call(this);
|
96
|
+
}
|
97
|
+
function carouselClick(e) {
|
98
|
+
if (!e.classList.contains("disabled")) {
|
99
|
+
var itemsLeftWidth = document.querySelector(this._internalVars.carouselIconWrapperClass).style.getPropertyValue("left"),
|
100
|
+
itemsLeftWidthValue = itemsLeftWidth.slice(0, -2),
|
101
|
+
itemsLeftWidthVal = Number(itemsLeftWidthValue.replace(/^-/, "")),
|
102
|
+
itemsRightWidth = this._internalVars.carouselIconWidth * this._internalVars.carouselUpsellNumber - itemsLeftWidthVal - this._internalVars.carouselIconWidth * this._internalVars.carouselIconNumber;
|
103
|
+
var operand = null;
|
104
|
+
var totalScrollValue = null;
|
105
|
+
var movementValue = null;
|
106
|
+
if (e.querySelector("span").classList.contains("icon-chevron-right")) {
|
107
|
+
operand = "-";
|
108
|
+
totalScrollValue = itemsRightWidth;
|
109
|
+
} else {
|
110
|
+
operand = "+";
|
111
|
+
totalScrollValue = itemsLeftWidthVal;
|
112
|
+
}
|
113
|
+
if (this._internalVars.carouselIconWidth * this._internalVars.carouselIconNumber > totalScrollValue) {
|
114
|
+
movementValue = totalScrollValue;
|
115
|
+
} else {
|
116
|
+
movementValue = this._internalVars.carouselIconWidth * this._internalVars.carouselIconNumber;
|
117
|
+
}
|
118
|
+
if (operand === "+") {
|
119
|
+
this._internalVars.carouselObject.querySelector(this._internalVars.carouselIconWrapperClass).style.left = Number(itemsLeftWidthValue) + movementValue + 'px';
|
120
|
+
} else {
|
121
|
+
this._internalVars.carouselObject.querySelector(this._internalVars.carouselIconWrapperClass).style.left = Number(itemsLeftWidthValue) - movementValue + 'px';
|
122
|
+
}
|
123
|
+
chevronState.call(this);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
function chevronState() {
|
127
|
+
var itemsLeftWidth = document.querySelector(this._internalVars.carouselIconWrapperClass).style.getPropertyValue("left"),
|
128
|
+
itemsLeftWidthValue = itemsLeftWidth.slice(0, -2),
|
129
|
+
itemsLeftWidthVal = Number(itemsLeftWidthValue.replace(/^-/, "")),
|
130
|
+
itemsRightWidth = this._internalVars.carouselIconWidth * this._internalVars.carouselUpsellNumber - itemsLeftWidthVal - this._internalVars.carouselIconWidth * this._internalVars.carouselIconNumber;
|
131
|
+
if (itemsLeftWidthVal === 0) {
|
132
|
+
this._internalVars.carouselChevronBtn[0].classList.add("disabled");
|
133
|
+
this._internalVars.carouselChevronBtn[0].children[0].setAttribute("disabled", "disabled");
|
134
|
+
} else {
|
135
|
+
this._internalVars.carouselChevronBtn[0].classList.remove("disabled");
|
136
|
+
this._internalVars.carouselChevronBtn[0].children[0].removeAttribute("disabled");
|
137
|
+
}
|
138
|
+
if (itemsRightWidth === 0) {
|
139
|
+
this._internalVars.carouselChevronBtn[1].classList.add("disabled");
|
140
|
+
this._internalVars.carouselChevronBtn[1].children[0].setAttribute("disabled", "disabled");
|
141
|
+
} else {
|
142
|
+
this._internalVars.carouselChevronBtn[1].classList.remove("disabled");
|
143
|
+
this._internalVars.carouselChevronBtn[1].children[0].removeAttribute("disabled");
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* setLocalVars()
|
149
|
+
* set local vars to the ones passed in options
|
150
|
+
*/
|
151
|
+
function setLocalVars() {
|
152
|
+
if (this._internalVars.contentType === 'string') {
|
153
|
+
this._internalVars.node = document.querySelector(this._options.content);
|
154
|
+
} else if (this._internalVars.contentType === 'domNode') {
|
155
|
+
this._internalVars.node = this._options.content;
|
156
|
+
}
|
157
|
+
this._internalVars.carouselIconDisplay = 645;
|
158
|
+
this._internalVars.carouselIconSmallDisplay = 440;
|
159
|
+
this._internalVars.carouselIconNumber = 0;
|
160
|
+
this._internalVars.carouselIconClass = '.carousel-upsell-product';
|
161
|
+
this._internalVars.carouselWrapperClass = '.icon-carousel';
|
162
|
+
this._internalVars.carouselIconWrapperClass = '.icon-carousel-display';
|
163
|
+
this._internalVars.carouselIconChevronClass = '.carousel-upsell-chevron';
|
164
|
+
this._internalVars.carouselObject = this._internalVars.node;
|
165
|
+
this._internalVars.carouselUpsellNumber = this._internalVars.carouselObject.querySelectorAll(this._internalVars.carouselIconClass).length;
|
166
|
+
this._internalVars.carouselChevronBtn = this._internalVars.carouselObject.querySelectorAll(this._internalVars.carouselIconChevronClass);
|
167
|
+
}
|
168
|
+
var _default = exports["default"] = UpsellCarousel;
|