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.

Files changed (107) hide show
  1. package/.babelrc +5 -0
  2. package/LICENSE +0 -0
  3. package/dist/analytics.js +119 -0
  4. package/dist/appState.js +56 -0
  5. package/dist/baseComponent.js +110 -0
  6. package/dist/components/Accordion.js +312 -0
  7. package/dist/components/AddressAutoComplete.js +220 -0
  8. package/dist/components/Alert.js +145 -0
  9. package/dist/components/BackgroundPattern.js +99 -0
  10. package/dist/components/BackgroundPatternPortfolio.js +242 -0
  11. package/dist/components/ButtonSwitch.js +236 -0
  12. package/dist/components/CardSelections.js +230 -0
  13. package/dist/components/CommonQuestionsSquares.js +169 -0
  14. package/dist/components/Confirmation.js +156 -0
  15. package/dist/components/ConsolidatedSummary.js +489 -0
  16. package/dist/components/CoverageGraph.js +201 -0
  17. package/dist/components/CreditCard.js +591 -0
  18. package/dist/components/CurrencyInput.js +302 -0
  19. package/dist/components/DatePicker.js +468 -0
  20. package/dist/components/DockedMessage.js +146 -0
  21. package/dist/components/DotNavigation.js +200 -0
  22. package/dist/components/EditComponent.js +128 -0
  23. package/dist/components/EditableTable.js +113 -0
  24. package/dist/components/InPageNavigation.js +360 -0
  25. package/dist/components/Loader.js +232 -0
  26. package/dist/components/MakePayment.js +361 -0
  27. package/dist/components/Modal.js +254 -0
  28. package/dist/components/MoreInfoButton.js +227 -0
  29. package/dist/components/MultipleSelectBox.js +217 -0
  30. package/dist/components/NavigationalBox.js +161 -0
  31. package/dist/components/Navigator.js +294 -0
  32. package/dist/components/PasswordMeter.js +201 -0
  33. package/dist/components/PayPlans.js +534 -0
  34. package/dist/components/SegmentedControl.js +327 -0
  35. package/dist/components/SortableTable.js +166 -0
  36. package/dist/components/Tabs.js +1 -0
  37. package/dist/components/TextAreaCountdown.js +219 -0
  38. package/dist/components/Timeline.js +498 -0
  39. package/dist/components/TimelineFilter.js +492 -0
  40. package/dist/components/ToTopArrow.js +153 -0
  41. package/dist/components/Tooltip.js +329 -0
  42. package/dist/components/Upsell.js +168 -0
  43. package/dist/components/VIN.js +271 -0
  44. package/dist/components/ValidateForm.js +938 -0
  45. package/dist/components/ViewMoreLess.js +191 -0
  46. package/dist/components/ZipCode.js +191 -0
  47. package/dist/components/portfolio.js +99 -0
  48. package/dist/geico-design-kit.js +141 -0
  49. package/dist/global/components.js +98 -0
  50. package/dist/global/footer.js +26 -0
  51. package/dist/global/nav.js +1257 -0
  52. package/dist/services/CharacterTypeService.js +106 -0
  53. package/dist/services/UserAgentService.js +73 -0
  54. package/dist/utils.js +79 -0
  55. package/package.json +32 -0
  56. package/src/analytics.js +82 -0
  57. package/src/appState.js +56 -0
  58. package/src/baseComponent.js +156 -0
  59. package/src/components/Accordion.js +336 -0
  60. package/src/components/AddressAutoComplete.js +236 -0
  61. package/src/components/Alert.js +135 -0
  62. package/src/components/BackgroundPattern.js +96 -0
  63. package/src/components/BackgroundPatternPortfolio.js +284 -0
  64. package/src/components/ButtonSwitch.js +241 -0
  65. package/src/components/CardSelections.js +240 -0
  66. package/src/components/CommonQuestionsSquares.js +179 -0
  67. package/src/components/Confirmation.js +160 -0
  68. package/src/components/ConsolidatedSummary.js +505 -0
  69. package/src/components/CoverageGraph.js +203 -0
  70. package/src/components/CreditCard.js +595 -0
  71. package/src/components/CurrencyInput.js +321 -0
  72. package/src/components/DatePicker.js +487 -0
  73. package/src/components/DockedMessage.js +142 -0
  74. package/src/components/DotNavigation.js +206 -0
  75. package/src/components/EditComponent.js +130 -0
  76. package/src/components/EditableTable.js +106 -0
  77. package/src/components/InPageNavigation.js +391 -0
  78. package/src/components/Loader.js +272 -0
  79. package/src/components/MakePayment.js +397 -0
  80. package/src/components/Modal.js +279 -0
  81. package/src/components/MoreInfoButton.js +243 -0
  82. package/src/components/MultipleSelectBox.js +211 -0
  83. package/src/components/NavigationalBox.js +163 -0
  84. package/src/components/Navigator.js +338 -0
  85. package/src/components/PasswordMeter.js +209 -0
  86. package/src/components/PayPlans.js +604 -0
  87. package/src/components/SegmentedControl.js +365 -0
  88. package/src/components/SortableTable.js +176 -0
  89. package/src/components/Tabs.js +0 -0
  90. package/src/components/TextAreaCountdown.js +231 -0
  91. package/src/components/Timeline.js +532 -0
  92. package/src/components/TimelineFilter.js +533 -0
  93. package/src/components/ToTopArrow.js +153 -0
  94. package/src/components/Tooltip.js +344 -0
  95. package/src/components/Upsell.js +196 -0
  96. package/src/components/VIN.js +289 -0
  97. package/src/components/ValidateForm.js +1030 -0
  98. package/src/components/ViewMoreLess.js +193 -0
  99. package/src/components/ZipCode.js +193 -0
  100. package/src/components/portfolio.js +106 -0
  101. package/src/geico-design-kit.js +144 -0
  102. package/src/global/components.js +92 -0
  103. package/src/global/footer.js +25 -0
  104. package/src/global/nav.js +1457 -0
  105. package/src/services/CharacterTypeService.js +107 -0
  106. package/src/services/UserAgentService.js +59 -0
  107. package/src/utils.js +82 -0
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _baseComponent = _interopRequireDefault(require("../../src/baseComponent"));
8
+ var _UserAgentService = _interopRequireDefault(require("../../src/services/UserAgentService"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } //Module Imports
16
+ var interact = require('interact.js');
17
+ var validateSettings = [{
18
+ setting: "content",
19
+ isRequired: true,
20
+ validate: "type",
21
+ possibleValues: ["string", "object"],
22
+ errorMessage: ["GDK Segmented Control : Segmented Control must be defined and set to a DOM selector or Node"]
23
+ }, {
24
+ setting: "initialActive",
25
+ isRequired: false,
26
+ validate: "type",
27
+ possibleValues: ["number"],
28
+ errorMessage: ["GDK Segmented Control : initialActive must be set to a number"]
29
+ }, {
30
+ setting: "segmentedControlChange",
31
+ isRequired: false,
32
+ validate: "type",
33
+ possibleValues: ["function"],
34
+ errorMessage: ["GDK Segmented Control : segmentedControlChange must be a defined and set function"]
35
+ }];
36
+ var SegmentedControl = /*#__PURE__*/function () {
37
+ /**
38
+ * Refer to the design kit section of this component for JS examples and setting details.
39
+ * @param {string, Object} content
40
+ * A reference to the segmented control component node
41
+ *
42
+ * @param {number} [initialActive=1]
43
+ * The number of the item to set as the active selection on initialization. Must be greater than 0 and equal to or less than the number of segment options
44
+ *
45
+ * @param {function} [segmentedControlChange]
46
+ * A callback function that is triggered when the Segmented Control selection is changed
47
+ */
48
+ function SegmentedControl(options) {
49
+ _classCallCheck(this, SegmentedControl);
50
+ this._internalVars = {};
51
+
52
+ //options with defaults set
53
+ this._defaults = {
54
+ initialActive: 1
55
+ };
56
+
57
+ // Create options by extending defaults with the passed in arugments
58
+ if (options && _typeof(options) === "object") {
59
+ this._options = _baseComponent["default"].extendDefaults(this._defaults, options);
60
+ }
61
+
62
+ //if the required options are valid set up the environment
63
+ if (_baseComponent["default"].validateSettings(this._options, validateSettings)) {
64
+ this._internalVars.contentType = _baseComponent["default"].getContentType(this);
65
+ setLocalVars.call(this);
66
+ init.call(this);
67
+ setEvents.call(this);
68
+ Array.prototype.forEach.call(this._internalVars.dropZoneObject, function (element) {
69
+ element.setAttribute('role', 'switch');
70
+ if (element.classList.contains('active')) {
71
+ element.setAttribute('aria-checked', 'true');
72
+ } else {
73
+ element.setAttribute('aria-checked', 'false');
74
+ }
75
+ });
76
+ }
77
+ }
78
+
79
+ //Public Methods
80
+
81
+ /**
82
+ * setInitialActiveOpt(index)
83
+ * @param {number} index
84
+ * sets the initial active segment
85
+ */
86
+ return _createClass(SegmentedControl, [{
87
+ key: "setInitialActiveOpt",
88
+ value: function setInitialActiveOpt(index) {
89
+ setInitialActive.call(this, index);
90
+ }
91
+
92
+ /**
93
+ * activeSegment()
94
+ * returns the current active segment anchor element
95
+ * @returns {Element}
96
+ */
97
+ }, {
98
+ key: "activeSegment",
99
+ value: function activeSegment() {
100
+ return this._internalVars.selectedSegment;
101
+ }
102
+
103
+ /**
104
+ * removes the node from the dom and any events attached
105
+ */
106
+ }, {
107
+ key: "destroy",
108
+ value: function destroy() {
109
+ removeEvents.call(this);
110
+ this._internalVars.node.parentNode.removeChild(this._internalVars.node);
111
+
112
+ //a little garbage collection
113
+ for (var variableKey in this) {
114
+ if (this.hasOwnProperty(variableKey)) {
115
+ delete this[variableKey];
116
+ }
117
+ }
118
+ }
119
+ }]);
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
+ this._internalVars.segmentedControlObject = this._internalVars.node;
129
+ this._internalVars.draggableClass = '.sc-draggable';
130
+ this._internalVars.dropZoneClass = '.dropzone';
131
+ this._internalVars.animateClass = 'animate-drop';
132
+ this._internalVars.dropActiveClass = 'drop-active';
133
+ this._internalVars.dropTargetClass = 'drop-target';
134
+ this._internalVars.activeClass = 'active';
135
+ this._internalVars.activeDragClass = 'active-drag';
136
+ this._internalVars.dropZoneObject = this._internalVars.segmentedControlObject.querySelectorAll(this._internalVars.dropZoneClass);
137
+ this._internalVars.draggableObject = this._internalVars.segmentedControlObject.querySelector(this._internalVars.draggableClass);
138
+ this._internalVars.selectedSegment = null;
139
+ }
140
+ function init() {
141
+ var _this = this;
142
+ var index = this._options.initialActive;
143
+ setInitialActive.call(this, index);
144
+ interact(this._internalVars.draggableObject).draggable({
145
+ inertia: true,
146
+ restrict: {
147
+ restriction: 'parent',
148
+ endOnly: false,
149
+ elementRect: {
150
+ top: 0,
151
+ left: 0,
152
+ bottom: 0,
153
+ right: 1
154
+ }
155
+ },
156
+ autoScroll: false,
157
+ snap: {
158
+ targets: [{
159
+ y: 0,
160
+ range: Infinity
161
+ }]
162
+ },
163
+ onmove: scDragMoveListener.bind(this)
164
+ });
165
+ function scDragMoveListener(event) {
166
+ var target = event.target,
167
+ x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
168
+ y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
169
+ target.style.left = x + "px";
170
+ target.setAttribute('data-x', x);
171
+ target.setAttribute('data-y', 0);
172
+ target.innerText = '';
173
+ target.style.zIndex = 1;
174
+ target.classList.add(this._internalVars.activeDragClass);
175
+ }
176
+ Array.prototype.forEach.call(this._internalVars.dropZoneObject, function (element) {
177
+ interact(element).dropzone({
178
+ accept: _this._internalVars.draggableClass,
179
+ overlap: 0.4,
180
+ ondropactivate: dropActivate.bind(_this),
181
+ ondragenter: dragEnter.bind(_this),
182
+ ondragleave: dragLeave.bind(_this),
183
+ ondrop: onDrop.bind(_this),
184
+ ondropdeactivate: dropDeactivate.bind(_this)
185
+ });
186
+ });
187
+ function dropActivate(event) {
188
+ event.target.classList.add(this._internalVars.dropActiveClass);
189
+ }
190
+ function dragEnter(event) {
191
+ var dropzoneElement = event.target;
192
+ dropzoneElement.classList.add(this._internalVars.dropTargetClass);
193
+ }
194
+ function dragLeave(event) {
195
+ event.target.classList.remove(this._internalVars.dropTargetClass);
196
+ }
197
+ function onDrop(event) {
198
+ var xcord = event.target.offsetLeft,
199
+ delay = setTimeout(setNewSelection.bind(this), 350),
200
+ current = event.target.offsetParent.querySelector('.' + this._internalVars.activeClass);
201
+ current.classList.remove(this._internalVars.activeClass);
202
+ current.setAttribute('aria-checked', 'false');
203
+ event.target.classList.add(this._internalVars.activeClass);
204
+ event.target.setAttribute('aria-checked', 'true');
205
+ event.relatedTarget.classList.add(this._internalVars.animateClass);
206
+ event.relatedTarget.setAttribute('data-x', xcord);
207
+ event.relatedTarget.style.left = xcord + 'px';
208
+ function setNewSelection() {
209
+ event.relatedTarget.textContent = event.target.textContent;
210
+ event.relatedTarget.style.zIndex = 2;
211
+ event.relatedTarget.classList.remove(this._internalVars.animateClass);
212
+ event.relatedTarget.classList.remove(this._internalVars.activeDragClass);
213
+ this._internalVars.segmentedControlObject.querySelector('.' + this._internalVars.activeClass).focus();
214
+ }
215
+ this._internalVars.selectedSegment = event.target;
216
+ if (this._options.segmentedControlChange) {
217
+ this._options.segmentedControlChange(event.target);
218
+ }
219
+ }
220
+ function dropDeactivate(event) {
221
+ event.target.classList.remove(this._internalVars.dropActiveClass);
222
+ event.target.classList.remove(this._internalVars.dropTargetClass);
223
+ }
224
+ }
225
+ function setEvents() {
226
+ var _this2 = this;
227
+ var eventName = _UserAgentService["default"]._clickEventName();
228
+ Array.prototype.forEach.call(this._internalVars.dropZoneObject, function (element) {
229
+ element.addEventListener(eventName, setActiveSelection.bind(_this2));
230
+ element.addEventListener('focus', function () {
231
+ if (element.classList.contains('active')) {
232
+ element.parentNode.firstElementChild.style.textDecoration = 'underline';
233
+ } else {
234
+ element.parentNode.firstElementChild.style.textDecoration = 'none';
235
+ }
236
+ });
237
+ element.addEventListener('blur', function () {
238
+ element.parentNode.firstElementChild.style.textDecoration = 'none';
239
+ });
240
+ });
241
+ this._internalVars.draggableObject.addEventListener(eventName, function () {
242
+ this.parentNode.querySelector('.active').focus();
243
+ this.style.textDecoration = 'underline';
244
+ });
245
+ window.addEventListener('resize', resetActiveSelection.bind(this));
246
+ }
247
+
248
+ /**
249
+ * removeEvents()
250
+ * removes all events from the component
251
+ */
252
+ function removeEvents() {
253
+ var _this3 = this;
254
+ var eventName = _UserAgentService["default"]._clickEventName();
255
+ Array.prototype.forEach.call(this._internalVars.dropZoneObject, function (element) {
256
+ element.removeEventListener(eventName, setActiveSelection.bind(_this3));
257
+ element.removeEventListener('focus', function () {
258
+ if (element.classList.contains('active')) {
259
+ element.parentNode.firstElementChild.style.textDecoration = 'underline';
260
+ } else {
261
+ element.parentNode.firstElementChild.style.textDecoration = 'none';
262
+ }
263
+ });
264
+ element.removeEventListener('blur', function () {
265
+ element.parentNode.firstElementChild.style.textDecoration = 'none';
266
+ });
267
+ });
268
+ this._internalVars.draggableObject.removeEventListener(eventName, function () {
269
+ this.parentNode.querySelector('.active').focus();
270
+ this.style.textDecoration = 'underline';
271
+ });
272
+ window.removeEventListener('resize', resetActiveSelection.bind(this));
273
+ }
274
+ function setInitialActive(activeIndex) {
275
+ var activeElement = this._internalVars.segmentedControlObject.querySelector('.' + this._internalVars.activeClass);
276
+ if (activeElement) {
277
+ activeElement.classList.remove(this._internalVars.activeClass);
278
+ activeElement.setAttribute('aria-checked', 'false');
279
+ }
280
+ if (activeIndex <= this._internalVars.dropZoneObject.length && activeIndex > 0) {
281
+ this._internalVars.dropZoneObject[activeIndex - 1].classList.add(this._internalVars.activeClass);
282
+ } else {
283
+ this._internalVars.dropZoneObject[0].classList.add(this._internalVars.activeClass);
284
+ }
285
+ activeElement = this._internalVars.segmentedControlObject.querySelector('.' + this._internalVars.activeClass);
286
+ var activeElementLeft = activeElement.offsetLeft,
287
+ activeElementContent = activeElement.innerHTML;
288
+ activeElement.setAttribute('aria-checked', 'true');
289
+ this._internalVars.draggableObject.style.left = activeElementLeft + 'px';
290
+ this._internalVars.draggableObject.innerHTML = activeElementContent;
291
+ this._internalVars.draggableObject.setAttribute('data-x', activeElementLeft);
292
+ this._internalVars.selectedSegment = activeElement;
293
+ }
294
+ function setActiveSelection(event) {
295
+ event.preventDefault();
296
+ var left = event.target.offsetLeft,
297
+ delay = setTimeout(setNewSelection.bind(this), 350),
298
+ current = event.target.offsetParent.querySelector('.' + this._internalVars.activeClass);
299
+ current.classList.remove(this._internalVars.activeClass);
300
+ current.setAttribute('aria-checked', 'false');
301
+ event.target.classList.add(this._internalVars.activeClass);
302
+ event.target.setAttribute('aria-checked', 'true');
303
+ this._internalVars.draggableObject.classList.add(this._internalVars.animateClass);
304
+ this._internalVars.draggableObject.classList.add(this._internalVars.activeDragClass);
305
+ this._internalVars.draggableObject.innerText = '';
306
+ this._internalVars.draggableObject.style.zIndex = 1;
307
+ this._internalVars.draggableObject.setAttribute('data-x', left);
308
+ this._internalVars.draggableObject.style.left = left + 'px';
309
+ function setNewSelection() {
310
+ this._internalVars.draggableObject.innerHTML = event.target.innerHTML;
311
+ this._internalVars.draggableObject.style.zIndex = 2;
312
+ this._internalVars.draggableObject.classList.remove(this._internalVars.animateClass);
313
+ this._internalVars.draggableObject.classList.remove(this._internalVars.activeDragClass);
314
+ this._internalVars.draggableObject.style.textDecoration = 'underline';
315
+ }
316
+ this._internalVars.selectedSegment = event.target;
317
+ if (this._options.segmentedControlChange) {
318
+ this._options.segmentedControlChange(event.target);
319
+ }
320
+ }
321
+ function resetActiveSelection() {
322
+ var current = this._internalVars.segmentedControlObject.querySelector('.' + this._internalVars.activeClass),
323
+ left = current.offsetLeft;
324
+ this._internalVars.draggableObject.setAttribute('data-x', left);
325
+ this._internalVars.draggableObject.style.left = left + 'px';
326
+ }
327
+ var _default = exports["default"] = SegmentedControl;
@@ -0,0 +1,166 @@
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
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ 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); }
10
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
+ 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); } }
12
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ 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); }
15
+ var Tablesort = require("tablesort");
16
+ var validateSettings = [{
17
+ setting: "content",
18
+ isRequired: true,
19
+ validate: "type",
20
+ possibleValues: ["string", "object"],
21
+ errorMessage: ["GDK SortableTableDeprecated : Content must be defined and set to a DOM selector or Node"]
22
+ }, {
23
+ setting: "descending",
24
+ isRequired: false,
25
+ validate: "type",
26
+ possibleValues: ["boolean"],
27
+ errorMessage: ["GDK SortableTableDeprecated : descending must be a boolean"]
28
+ }];
29
+ var SortableTable = /*#__PURE__*/function () {
30
+ /**
31
+ * Refer to the design kit section of this component for JS examples and setting details.
32
+ * @param {string, Object} content
33
+ * A reference to the sortable table node
34
+ *
35
+ * @param {boolean} [descending=false]
36
+ * The number of the item to set as the active selection on initialization. Must be greater than 0 and equal to or less than the number of segment options
37
+ *
38
+ */
39
+ function SortableTable(options) {
40
+ _classCallCheck(this, SortableTable);
41
+ this._internalVars = {
42
+ node: null,
43
+ //used for current node
44
+ sortableTable: null //hold reference to the sortable table
45
+ };
46
+
47
+ //options with defaults set
48
+ this._defaults = {
49
+ descending: false
50
+ };
51
+
52
+ // Create options by extending defaults with the passed in arugments
53
+ if (options && _typeof(options) === "object") {
54
+ this._options = _baseComponent["default"].extendDefaults(this._defaults, options);
55
+ }
56
+
57
+ //if the required options are valid set up the environment
58
+ if (_baseComponent["default"].validateSettings(this._options, validateSettings)) {
59
+ this._internalVars.contentType = _baseComponent["default"].getContentType(this);
60
+ setLocalVars.call(this);
61
+ init.call(this);
62
+ }
63
+ }
64
+
65
+ /**
66
+ * update()
67
+ * Updates the sort if you have added content
68
+ */
69
+ return _createClass(SortableTable, [{
70
+ key: "update",
71
+ value: function update() {
72
+ this._internalVars.sortableTable.refresh();
73
+ }
74
+
75
+ /**
76
+ * destroy()
77
+ * removes the node from the dom and any events attached
78
+ */
79
+ }, {
80
+ key: "destroy",
81
+ value: function destroy() {
82
+ this._internalVars.node.parentNode.removeChild(this._internalVars.node);
83
+
84
+ //a little garbage collection
85
+ for (var variableKey in this) {
86
+ if (this.hasOwnProperty(variableKey)) {
87
+ delete this[variableKey];
88
+ }
89
+ }
90
+ }
91
+ }]);
92
+ }();
93
+ /**
94
+ * init()
95
+ * instantiate the Tablesort
96
+ */
97
+ function init() {
98
+ var options = {};
99
+ if (this._options.descending) {
100
+ options.descending = true;
101
+ }
102
+ Tablesort.extend('date', function (item) {
103
+ return (item.search(/(Mon|Tue|Wed|Thu|Fri|Sat|Sun)\.?\,?\s*/i) !== -1 || item.search(/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/) !== -1 || item.search(/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i) !== -1) && !isNaN(parseDate.call(this, item));
104
+ }, function (a, b) {
105
+ a = a.toLowerCase();
106
+ b = b.toLowerCase();
107
+ return parseDate.call(this, b) - parseDate.call(this, a);
108
+ });
109
+ Tablesort.extend('number', function (item) {
110
+ return item.match(/^-?[£\x24Û¢´€]?\d+\s*([,\.]\d{0,2})/) ||
111
+ // Prefixed currency
112
+ item.match(/^-?\d+\s*([,\.]\d{0,2})?[£\x24Û¢´€]/) ||
113
+ // Suffixed currency
114
+ item.match(/^-?(\d)*-?([,\.]){0,1}-?(\d)+([E,e][\-+][\d]+)?%?$/); // Number
115
+ }, function (a, b) {
116
+ a = cleanNumber.call(this, a);
117
+ b = cleanNumber.call(this, b);
118
+ return compareNumber.call(this, b, a);
119
+ });
120
+ this._internalVars.sortableTable = new Tablesort(this._internalVars.node, options);
121
+ }
122
+
123
+ /**
124
+ * cleanNumber()
125
+ * regex replace for extending Tablsort to sort by numbers (and currency)
126
+ */
127
+ function cleanNumber(i) {
128
+ return i.replace(/[^\-?0-9.]/g, '');
129
+ }
130
+
131
+ /**
132
+ * compareNumber()
133
+ * sort function for numbers
134
+ */
135
+ function compareNumber(a, b) {
136
+ a = parseFloat(a);
137
+ b = parseFloat(b);
138
+ a = isNaN(a) ? 0 : a;
139
+ b = isNaN(b) ? 0 : b;
140
+ return a - b;
141
+ }
142
+
143
+ /**
144
+ * parseDate()
145
+ * prepares date for sorting
146
+ */
147
+ function parseDate(date) {
148
+ date = date.replace(/\-/g, '/');
149
+ date = date.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, '$1/$2/$3'); // format before getTime
150
+
151
+ return new Date(date).getTime();
152
+ }
153
+
154
+ /**
155
+ * setLocalVars()
156
+ * set all the local vars to passed in options
157
+ */
158
+ function setLocalVars() {
159
+ //determine the type of content passed in
160
+ if (this._internalVars.contentType === 'string') {
161
+ this._internalVars.node = document.querySelector(this._options.content);
162
+ } else if (this._internalVars.contentType === 'domNode') {
163
+ this._internalVars.node = this._options.content;
164
+ }
165
+ }
166
+ var _default = exports["default"] = SortableTable;
@@ -0,0 +1 @@
1
+ "use strict";