@spothero/ui 15.0.0-beta.2 → 15.0.0-beta.3
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.
- package/README.md +2 -2
- package/backlog/Chart/Chart.js +2 -2
- package/backlog/DateTime/DatePicker.js +4 -4
- package/backlog/DateTime/DatePickerCalendar.js +8 -8
- package/backlog/DateTime/DatePickerCalendarWithRange.js +6 -6
- package/backlog/DateTime/DateTimeRangePicker.js +6 -4
- package/backlog/DateTime/TimePicker.js +3 -3
- package/backlog/ErrorBoundary/ErrorBoundary.js +7 -9
- package/backlog/Flyout/Flyout.js +5 -5
- package/backlog/Form/Form.js +5 -3
- package/backlog/GooglePlacesSearchInput/GooglePlacesSearchInput.js +1 -4
- package/backlog/Notification/Notification.js +4 -4
- package/backlog/Portal/Portal.js +3 -3
- package/backlog/RenderInBody/RenderInBody.js +2 -2
- package/backlog/Select/Select.js +3 -3
- package/backlog/SelectControlled/SelectControlled.js +3 -3
- package/backlog/Tooltip/Tooltip.js +6 -6
- package/backlog/utils/animation.js +84 -0
- package/backlog/utils/date.js +233 -0
- package/backlog/utils/dom.js +441 -0
- package/backlog/utils/environment.js +422 -0
- package/backlog/utils/number.js +43 -0
- package/backlog/utils/time.js +282 -0
- package/backlog/v1/components/Image/Image.js +2 -2
- package/backlog/v1/components/Modal/Modal.js +12 -12
- package/backlog/v1/components/Modal/ModalContent.js +3 -3
- package/package.json +1 -2
- package/styles/Chart/Chart.jsx +1 -1
- package/styles/DateTime/DatePicker.jsx +1 -1
- package/styles/DateTime/DatePickerCalendar.jsx +1 -1
- package/styles/DateTime/DatePickerCalendarWithRange.jsx +1 -1
- package/styles/DateTime/DateTimeRangePicker.jsx +2 -1
- package/styles/DateTime/TimePicker.jsx +1 -1
- package/styles/ErrorBoundary/ErrorBoundary.jsx +7 -6
- package/styles/Flyout/Flyout.jsx +1 -1
- package/styles/Form/Form.jsx +2 -1
- package/styles/GooglePlacesSearchInput/GooglePlacesSearchInput.jsx +2 -2
- package/styles/Notification/Notification.jsx +1 -1
- package/styles/Portal/Portal.jsx +1 -1
- package/styles/RenderInBody/RenderInBody.jsx +1 -1
- package/styles/Select/Select.jsx +1 -1
- package/styles/SelectControlled/SelectControlled.jsx +1 -1
- package/styles/Tooltip/Tooltip.jsx +1 -1
- package/styles/utils/animation.js +75 -0
- package/styles/utils/date.js +226 -0
- package/styles/utils/dom.js +428 -0
- package/styles/utils/environment.js +425 -0
- package/styles/utils/number.js +33 -0
- package/styles/utils/time.js +268 -0
- package/styles/v1/components/Image/Image.jsx +1 -1
- package/styles/v1/components/Modal/Modal.jsx +1 -1
- package/styles/v1/components/Modal/ModalContent.jsx +1 -1
- package/styles/v1/components/Modal/stories/Content.stories.js +1 -1
- package/styles/v2/components/Image/Image.jsx +1 -1
- package/v1/index.js +1 -1
- package/v1/index.js.LICENSE.txt +0 -29
- package/v1/index.js.map +1 -1
- package/v2/index.js +1 -1
- package/v2/index.js.LICENSE.txt +0 -29
- package/v2/index.js.map +1 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _ssrWindow = require("ssr-window");
|
|
11
|
+
|
|
12
|
+
var _isDate = _interopRequireDefault(require("lodash/isDate"));
|
|
13
|
+
|
|
14
|
+
var _isObject = _interopRequireDefault(require("lodash/isObject"));
|
|
15
|
+
|
|
16
|
+
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
17
|
+
|
|
18
|
+
var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
19
|
+
|
|
20
|
+
var splitTextDate = function splitTextDate(date, delimeter) {
|
|
21
|
+
var d = date.split(delimeter);
|
|
22
|
+
return new Date(d[2], d[0] - 1, d[1]);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var splitMobileDate = function splitMobileDate(date) {
|
|
26
|
+
var d = date.split('-');
|
|
27
|
+
return new Date(d[0], d[1] - 1, d[2]);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Utilities for working with dates.
|
|
31
|
+
* @module DateUtils
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var DateUtils = {
|
|
36
|
+
// /**
|
|
37
|
+
// * Check whether input type of 'date' is supported in the current browser.
|
|
38
|
+
// * @static
|
|
39
|
+
// * @function supportsDateInput
|
|
40
|
+
// * @example
|
|
41
|
+
// * DateUtils.supportsDateInput();
|
|
42
|
+
// * @returns {Boolean} - Whether the input type is supported.
|
|
43
|
+
// */
|
|
44
|
+
// supportsDateInput() {
|
|
45
|
+
// const fakeValue = 'not-a-date';
|
|
46
|
+
// const input = document.createElement('input');
|
|
47
|
+
//
|
|
48
|
+
// input.setAttribute('type', 'date');
|
|
49
|
+
// input.setAttribute('value', fakeValue);
|
|
50
|
+
//
|
|
51
|
+
// return input.value !== fakeValue;
|
|
52
|
+
// },
|
|
53
|
+
// /**
|
|
54
|
+
// * Gets the closest match to the user's current time zone.
|
|
55
|
+
// * @static
|
|
56
|
+
// * @function getTimeZone
|
|
57
|
+
// * @example
|
|
58
|
+
// * DateUtils.getTimeZone(); // 'America/Chicago'
|
|
59
|
+
// * @returns {String} - The user's current time zone.
|
|
60
|
+
// */
|
|
61
|
+
// getTimeZone() {
|
|
62
|
+
// if (
|
|
63
|
+
// window.Intl &&
|
|
64
|
+
// isObject(window.Intl) &&
|
|
65
|
+
// window.Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
66
|
+
// ) {
|
|
67
|
+
// return window.Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
68
|
+
// } else {
|
|
69
|
+
// return moment.tz.guess();
|
|
70
|
+
// }
|
|
71
|
+
// },
|
|
72
|
+
// /**
|
|
73
|
+
// * Converts a mobile input date to a string using the specified format.
|
|
74
|
+
// * @static
|
|
75
|
+
// * @function convertToDesktop
|
|
76
|
+
// * @param {String} date - The input value in the format YYYY-MM-DD.
|
|
77
|
+
// * @param {String} [format='MM/DD/YYYY'] - The output format.
|
|
78
|
+
// * @example
|
|
79
|
+
// * DateUtils.convertToDesktop('1983-01-19');
|
|
80
|
+
// * @returns {String} - The formatted date.
|
|
81
|
+
// */
|
|
82
|
+
// convertToDesktop(date, format = 'MM/DD/YYYY') {
|
|
83
|
+
// if (!isString(date)) {
|
|
84
|
+
// throw new Error('The supplied date is not a string.');
|
|
85
|
+
// }
|
|
86
|
+
//
|
|
87
|
+
// if (date.indexOf('-') !== -1) {
|
|
88
|
+
// return moment(splitMobileDate(date)).format(format);
|
|
89
|
+
// } else {
|
|
90
|
+
// return date;
|
|
91
|
+
// }
|
|
92
|
+
// },
|
|
93
|
+
// /**
|
|
94
|
+
// * Converts a desktop input date to the native mobile date format.
|
|
95
|
+
// * @static
|
|
96
|
+
// * @function convertToMobile
|
|
97
|
+
// * @param {String} date - The input value in the format MM/DD/YYYY.
|
|
98
|
+
// * @example
|
|
99
|
+
// * DateUtils.convertToMobile('01/19/1983');
|
|
100
|
+
// * @returns {String} - The mobile formatted date.
|
|
101
|
+
// */
|
|
102
|
+
// convertToMobile(date) {
|
|
103
|
+
// if (!isString(date)) {
|
|
104
|
+
// throw new Error('The supplied date is not a string.');
|
|
105
|
+
// }
|
|
106
|
+
//
|
|
107
|
+
// if (date.indexOf('/') !== -1) {
|
|
108
|
+
// return moment(splitTextDate(date, '/')).format('YYYY-MM-DD');
|
|
109
|
+
// } else {
|
|
110
|
+
// return date;
|
|
111
|
+
// }
|
|
112
|
+
// },
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Converts a string date from a text or date input to a date object.
|
|
116
|
+
* @static
|
|
117
|
+
* @function getAsDate
|
|
118
|
+
* @param {String} date - The date in the format MM/DD/YYYY (text input) or YYYY-MM-DD (date input).
|
|
119
|
+
* @example
|
|
120
|
+
* DateUtils.getAsDate('1983-01-19');
|
|
121
|
+
* DateUtils.getAsDate('01/19/1983');
|
|
122
|
+
* @returns {Date} - The date object.
|
|
123
|
+
*/
|
|
124
|
+
getAsDate: function getAsDate(date) {
|
|
125
|
+
if (!(0, _isString.default)(date)) {
|
|
126
|
+
throw new Error('The supplied date is not a string.');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (date.indexOf('-') !== -1) {
|
|
130
|
+
// date input
|
|
131
|
+
return splitMobileDate(date);
|
|
132
|
+
} else {
|
|
133
|
+
// text input
|
|
134
|
+
return splitTextDate(date, '/');
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Converts a string date from a text or date input to a moment instance.
|
|
140
|
+
* @static
|
|
141
|
+
* @function getAsMoment
|
|
142
|
+
* @param {String} date - The date in the format MM/DD/YYYY (text input) or YYYY-MM-DD (date input).
|
|
143
|
+
* @example
|
|
144
|
+
* DateUtils.getAsMoment('1983-01-19');
|
|
145
|
+
* DateUtils.getAsMoment('01/19/1983');
|
|
146
|
+
* @returns {Moment} - The moment instance.
|
|
147
|
+
*/
|
|
148
|
+
getAsMoment: function getAsMoment(date) {
|
|
149
|
+
if (!(0, _isString.default)(date)) {
|
|
150
|
+
throw new Error('The supplied date is not a string.');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (date.indexOf('-') !== -1) {
|
|
154
|
+
// date input
|
|
155
|
+
return (0, _momentTimezone.default)(splitMobileDate(date));
|
|
156
|
+
} else {
|
|
157
|
+
// text input
|
|
158
|
+
return (0, _momentTimezone.default)(splitTextDate(date, '/'));
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Combines a date moment with a time moment to return one moment instance.
|
|
164
|
+
* @static
|
|
165
|
+
* @function combineDateAndTime
|
|
166
|
+
* @param {Moment} date - The date as a moment instance.
|
|
167
|
+
* @param {Moment} time - The time as a moment instance.
|
|
168
|
+
* @example
|
|
169
|
+
* DateUtils.combineDateAndTime(moment(), moment().add(7, 'hours').add(23, 'minutes'));
|
|
170
|
+
* @returns {Moment} - The combined moment instance.
|
|
171
|
+
*/
|
|
172
|
+
combineDateAndTime: function combineDateAndTime(date, time) {
|
|
173
|
+
if (!_momentTimezone.default.isMoment(date) || !_momentTimezone.default.isMoment(time)) {
|
|
174
|
+
throw new Error('The date and/or time supplied was not an instance of Moment.');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return date.hours(time.hours()).minutes(time.minutes());
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Checks if one date is before another.
|
|
182
|
+
* @static
|
|
183
|
+
* @function isBefore
|
|
184
|
+
* @param {Date} dateToCheck - The date to check.
|
|
185
|
+
* @param {Date} dateToCompare - The date to check against.
|
|
186
|
+
* @param {Boolean} [useTime=false] - Whether to use the time in the comparison.
|
|
187
|
+
* @example
|
|
188
|
+
* DateUtils.isBefore(new Date(2016, 1, 19), new Date(2016, 3, 14));
|
|
189
|
+
* @returns {Boolean} - Whether the provided date is before the one being checked against.
|
|
190
|
+
*/
|
|
191
|
+
isBefore: function isBefore(dateToCheck, dateToCompare) {
|
|
192
|
+
var useTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
193
|
+
|
|
194
|
+
if (!(0, _isDate.default)(dateToCheck) || !(0, _isDate.default)(dateToCompare)) {
|
|
195
|
+
throw new Error('The dates supplied must be instances of the Date object.');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!useTime) {
|
|
199
|
+
dateToCheck.setHours(0, 0, 0, 0);
|
|
200
|
+
dateToCompare.setHours(0, 0, 0, 0);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return dateToCheck < dateToCompare;
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Checks if one date is after another.
|
|
208
|
+
* @static
|
|
209
|
+
* @function isAfter
|
|
210
|
+
* @param {Date} dateToCheck - The date to check.
|
|
211
|
+
* @param {Date} dateToCompare - The date to check against.
|
|
212
|
+
* @param {Boolean} [useTime=false] - Whether to use the time in the comparison.
|
|
213
|
+
* @example
|
|
214
|
+
* DateUtils.isAfter(new Date(2016, 1, 19), new Date(2016, 3, 14));
|
|
215
|
+
* @returns {Boolean} - Whether the provided date is after the one being checked against.
|
|
216
|
+
*/
|
|
217
|
+
isAfter: function isAfter(dateToCheck, dateToCompare) {
|
|
218
|
+
var useTime = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
219
|
+
|
|
220
|
+
if (!(0, _isDate.default)(dateToCheck) || !(0, _isDate.default)(dateToCompare)) {
|
|
221
|
+
throw new Error('The dates supplied must be instances of the Date object.');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!useTime) {
|
|
225
|
+
dateToCheck.setHours(0, 0, 0, 0);
|
|
226
|
+
dateToCompare.setHours(0, 0, 0, 0);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return dateToCheck > dateToCompare;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
var _default = DateUtils;
|
|
233
|
+
exports.default = _default;
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
11
|
+
|
|
12
|
+
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
13
|
+
|
|
14
|
+
var _includes = _interopRequireDefault(require("lodash/includes"));
|
|
15
|
+
|
|
16
|
+
// import {document, window} from 'ssr-window';
|
|
17
|
+
// import forEach from 'lodash/forEach';
|
|
18
|
+
// import isArrayLikeObject from 'lodash/isArrayLikeObject';
|
|
19
|
+
// import CustomEvent from 'custom-event';
|
|
20
|
+
// import EnvironmentUtils from '../environment/environment';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Utilities for working with the Document Object Model (DOM).
|
|
24
|
+
* @module DOMUtils
|
|
25
|
+
*/
|
|
26
|
+
var DOMUtils = {
|
|
27
|
+
// /**
|
|
28
|
+
// * Returns the tag name of the specified element.
|
|
29
|
+
// * @static
|
|
30
|
+
// * @function tag
|
|
31
|
+
// * @param {Element} el - The element to check the tag of.
|
|
32
|
+
// * @param {Boolean} [lowercase=true] - Whether to normalize the tag name for comparison as lowercase.
|
|
33
|
+
// * @example
|
|
34
|
+
// * DOMUtils.tag(document.querySelector('.foo'));
|
|
35
|
+
// * @returns {String} - The tag of the specified element.
|
|
36
|
+
// */
|
|
37
|
+
// tag(el, lowercase = true) {
|
|
38
|
+
// return lowercase ? el.nodeName.toLowerCase() : el.nodeName;
|
|
39
|
+
// },
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns the element(s) matching the specified selector.
|
|
43
|
+
* @static
|
|
44
|
+
* @function el
|
|
45
|
+
* @param {String} selector - The selector of the element to query.
|
|
46
|
+
* @example
|
|
47
|
+
* DOMUtils.el('.foo');
|
|
48
|
+
* @returns {Element|Array} - The element or array of elements matching the selector.
|
|
49
|
+
*/
|
|
50
|
+
el: function el(selector) {
|
|
51
|
+
var els = document.querySelectorAll(selector);
|
|
52
|
+
|
|
53
|
+
if (els.length > 1) {
|
|
54
|
+
return els;
|
|
55
|
+
} else {
|
|
56
|
+
return els[0];
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns the element's parent or the closest ancestor matching the specified selector if provided.
|
|
62
|
+
* @static
|
|
63
|
+
* @function parent
|
|
64
|
+
* @param {String|Element} item - The selector or element to find the parent of.
|
|
65
|
+
* @param {String} [parentSelector] - The selector of the ancestor to find.
|
|
66
|
+
* @example
|
|
67
|
+
* DOMUtils.parent('.foo', '.bar');
|
|
68
|
+
* @returns {Element} - The parent of the item.
|
|
69
|
+
*/
|
|
70
|
+
parent: function parent(item, parentSelector) {
|
|
71
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
72
|
+
|
|
73
|
+
if (!el) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (parentSelector) {
|
|
78
|
+
var allParents = document.querySelectorAll(parentSelector);
|
|
79
|
+
var currentParent = el.parentNode;
|
|
80
|
+
|
|
81
|
+
while (currentParent && !(0, _includes.default)(allParents, currentParent)) {
|
|
82
|
+
currentParent = currentParent.parentNode;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return currentParent;
|
|
86
|
+
} else {
|
|
87
|
+
return el.parentNode;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the attribute of the specified element.
|
|
93
|
+
* @static
|
|
94
|
+
* @function attr
|
|
95
|
+
* @param {String|Element} item - The selector or element to query.
|
|
96
|
+
* @param {String} attribute - The attribute to query.
|
|
97
|
+
* @example
|
|
98
|
+
* DOMUtils.attr('.foo', 'data-baz');
|
|
99
|
+
* @returns {String} - The value of the attribute.
|
|
100
|
+
*/
|
|
101
|
+
attr: function attr(item, attribute) {
|
|
102
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
103
|
+
|
|
104
|
+
if (!el) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return el.getAttribute(attribute);
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Adds a class to the specified element.
|
|
113
|
+
* @static
|
|
114
|
+
* @function addClass
|
|
115
|
+
* @param {String|Element} item - The selector or element to add the class to.
|
|
116
|
+
* @param {String|Array.<String>} className - The class(es) to add.
|
|
117
|
+
* @example
|
|
118
|
+
* DOMUtils.addClass(evt.currentTarget, 'foo');
|
|
119
|
+
* @returns {void}
|
|
120
|
+
*/
|
|
121
|
+
addClass: function addClass(item, className) {
|
|
122
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
123
|
+
|
|
124
|
+
if (!el) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var classes = (0, _isString.default)(className) ? className.split(' ') : className;
|
|
129
|
+
classes.forEach(function (itemClassName) {
|
|
130
|
+
el.classList.add(itemClassName);
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Removes a class from the specified element.
|
|
136
|
+
* @static
|
|
137
|
+
* @function removeClass
|
|
138
|
+
* @param {String|Element} item - The selector or element to remove the class from.
|
|
139
|
+
* @param {String|Array.<String>} className - The class(es) to remove.
|
|
140
|
+
* @example
|
|
141
|
+
* DOMUtils.removeClass(evt.currentTarget, 'foo');
|
|
142
|
+
* @returns {void}
|
|
143
|
+
*/
|
|
144
|
+
removeClass: function removeClass(item, className) {
|
|
145
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
146
|
+
|
|
147
|
+
if (!el) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
var classes = (0, _isString.default)(className) ? className.split(' ') : className;
|
|
152
|
+
classes.forEach(function (itemClassName) {
|
|
153
|
+
el.classList.remove(itemClassName);
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Checks if an element has a specified class.
|
|
159
|
+
* @static
|
|
160
|
+
* @function hasClass
|
|
161
|
+
* @param {String|Element} item - The selector or element to check.
|
|
162
|
+
* @param {String} className - The class to check for.
|
|
163
|
+
* @example
|
|
164
|
+
* DOMUtils.hasClass(evt.currentTarget, 'foo');
|
|
165
|
+
* @returns {Boolean} - Whether the element has the class or not.
|
|
166
|
+
*/
|
|
167
|
+
hasClass: function hasClass(item, className) {
|
|
168
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
169
|
+
|
|
170
|
+
if (!el) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return el.classList.contains(className) || false;
|
|
175
|
+
},
|
|
176
|
+
// /**
|
|
177
|
+
// * Toggles a class on or off for the specified element.
|
|
178
|
+
// * @static
|
|
179
|
+
// * @function toggleClass
|
|
180
|
+
// * @param {String|Element} item - The selector or element to toggle the class on.
|
|
181
|
+
// * @param {String} className - The class to toggle.
|
|
182
|
+
// * @example
|
|
183
|
+
// * DOMUtils.toggleClass(evt.currentTarget, 'foo');
|
|
184
|
+
// * @returns {void}
|
|
185
|
+
// */
|
|
186
|
+
// toggleClass(item, className) {
|
|
187
|
+
// if (DOMUtils.hasClass(item, className)) {
|
|
188
|
+
// DOMUtils.removeClass(item, className);
|
|
189
|
+
// } else {
|
|
190
|
+
// DOMUtils.addClass(item, className);
|
|
191
|
+
// }
|
|
192
|
+
// },
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Get the height of the specified element.
|
|
196
|
+
* @static
|
|
197
|
+
* @function height
|
|
198
|
+
* @param {String|Element} item - The selector or element to find the height of.
|
|
199
|
+
* @param {Boolean} [includeMargin=true] - Whether to include the margins in the calculation effectively getting the outerHeight.
|
|
200
|
+
* @param {Boolean} [includePadding=true] - Whether to include the padding in the calculation.
|
|
201
|
+
* @example
|
|
202
|
+
* DOMUtils.height('.foo');
|
|
203
|
+
* @returns {Number} - The height of the element.
|
|
204
|
+
*/
|
|
205
|
+
height: function height(item) {
|
|
206
|
+
var includeMargin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
207
|
+
var includePadding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
208
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
209
|
+
|
|
210
|
+
if (!el) {
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
var _window$getComputedSt = window.getComputedStyle(el),
|
|
215
|
+
marginTop = _window$getComputedSt.marginTop,
|
|
216
|
+
marginBottom = _window$getComputedSt.marginBottom,
|
|
217
|
+
paddingTop = _window$getComputedSt.paddingTop,
|
|
218
|
+
paddingBottom = _window$getComputedSt.paddingBottom;
|
|
219
|
+
|
|
220
|
+
var height = el.offsetHeight;
|
|
221
|
+
|
|
222
|
+
if (includeMargin) {
|
|
223
|
+
height += parseInt(marginTop, 10) + parseInt(marginBottom, 10);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!includePadding) {
|
|
227
|
+
height -= parseInt(paddingTop, 10) + parseInt(paddingBottom, 10);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return height;
|
|
231
|
+
},
|
|
232
|
+
// /**
|
|
233
|
+
// * Get the width of the specified element.
|
|
234
|
+
// * @static
|
|
235
|
+
// * @function width
|
|
236
|
+
// * @param {String|Element} item - The selector or element to find the width of.
|
|
237
|
+
// * @param {Boolean} [includeMargin=true] - Whether to include the margins in the calculation effectively getting the outerWidth.
|
|
238
|
+
// * @param {Boolean} [includePadding=true] - Whether to include the padding in the calculation.
|
|
239
|
+
// * @example
|
|
240
|
+
// * DOMUtils.width('.foo');
|
|
241
|
+
// * @returns {Number} - The width of the element.
|
|
242
|
+
// */
|
|
243
|
+
// width(item, includeMargin = true, includePadding = true) {
|
|
244
|
+
// const el = isString(item) ? DOMUtils.el(item) : item;
|
|
245
|
+
//
|
|
246
|
+
// if (!el) {
|
|
247
|
+
// return 0;
|
|
248
|
+
// }
|
|
249
|
+
//
|
|
250
|
+
// const {
|
|
251
|
+
// marginLeft,
|
|
252
|
+
// marginRight,
|
|
253
|
+
// paddingLeft,
|
|
254
|
+
// paddingRight,
|
|
255
|
+
// } = window.getComputedStyle(el);
|
|
256
|
+
// let width = el.offsetWidth;
|
|
257
|
+
//
|
|
258
|
+
// if (includeMargin) {
|
|
259
|
+
// width += parseInt(marginLeft, 10) + parseInt(marginRight, 10);
|
|
260
|
+
// }
|
|
261
|
+
//
|
|
262
|
+
// if (!includePadding) {
|
|
263
|
+
// width -= parseInt(paddingLeft, 10) + parseInt(paddingRight, 10);
|
|
264
|
+
// }
|
|
265
|
+
//
|
|
266
|
+
// return width;
|
|
267
|
+
// },
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Removes element(s) from the DOM.
|
|
271
|
+
* @static
|
|
272
|
+
* @function remove
|
|
273
|
+
* @param {String|Element|Array} items - The selector or element(s) to remove from the DOM.
|
|
274
|
+
* @example
|
|
275
|
+
* DOMUtils.remove('.class-to-remove');
|
|
276
|
+
* @returns {void}
|
|
277
|
+
*/
|
|
278
|
+
remove: function remove(items) {
|
|
279
|
+
var el = (0, _isString.default)(items) ? DOMUtils.el(items) : items;
|
|
280
|
+
|
|
281
|
+
if (!el) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if ((0, _isArray.default)(el) || el instanceof NodeList) {
|
|
286
|
+
var len = el.length;
|
|
287
|
+
var i = 0;
|
|
288
|
+
|
|
289
|
+
for (i; i < len; ++i) {
|
|
290
|
+
el.outerHTML = '';
|
|
291
|
+
}
|
|
292
|
+
} else {
|
|
293
|
+
el.outerHTML = '';
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
//
|
|
297
|
+
// /**
|
|
298
|
+
// * Adds event listener for an element or NodeList.
|
|
299
|
+
// * @static
|
|
300
|
+
// * @function addEventListener
|
|
301
|
+
// * @param {Object} data - The data to pass to the function.
|
|
302
|
+
// * @param {String} data.event - The DOM event to take action on.
|
|
303
|
+
// * @param {String|Element} [data.target='document'] - The selector or element to attach the event to.
|
|
304
|
+
// * @param {Function} data.handler - The function to run when the event triggers.
|
|
305
|
+
// * @example
|
|
306
|
+
// * DOMUtils.addEventListener({target: '.foo', event: 'click', handler: functionName});
|
|
307
|
+
// * @returns {void}
|
|
308
|
+
// */
|
|
309
|
+
// addEventListener({event, target = 'document', handler}) {
|
|
310
|
+
// if (target && target !== 'document') {
|
|
311
|
+
// const el = isString(target) ? DOMUtils.el(target) : target;
|
|
312
|
+
//
|
|
313
|
+
// if (!el) {
|
|
314
|
+
// return;
|
|
315
|
+
// }
|
|
316
|
+
//
|
|
317
|
+
// if (isArrayLikeObject(el)) {
|
|
318
|
+
// forEach(el, thisEl => {
|
|
319
|
+
// thisEl.addEventListener(event, handler);
|
|
320
|
+
// });
|
|
321
|
+
// } else {
|
|
322
|
+
// el.addEventListener(event, handler);
|
|
323
|
+
// }
|
|
324
|
+
// } else {
|
|
325
|
+
// document.addEventListener(event, handler, {capture: true});
|
|
326
|
+
// }
|
|
327
|
+
// },
|
|
328
|
+
//
|
|
329
|
+
// /**
|
|
330
|
+
// * Removes event listener for an element or NodeList.
|
|
331
|
+
// * @static
|
|
332
|
+
// * @function removeEventListener
|
|
333
|
+
// * @param {Object} data - The data to pass to the function.
|
|
334
|
+
// * @param {String} data.event - The DOM event to remove.
|
|
335
|
+
// * @param {String|Element} [data.target='document'] - The selector or element to remove the event from.
|
|
336
|
+
// * @param {Function} data.handler - The function that is triggered to handle the event.
|
|
337
|
+
// * @example
|
|
338
|
+
// * DOMUtils.removeEventListener({target: '.foo', event: 'click', handler: functionName});
|
|
339
|
+
// * @returns {void}
|
|
340
|
+
// */
|
|
341
|
+
// removeEventListener({event, target = 'document', handler}) {
|
|
342
|
+
// if (target && target !== 'document') {
|
|
343
|
+
// const el = isString(target) ? DOMUtils.el(target) : target;
|
|
344
|
+
//
|
|
345
|
+
// if (!el) {
|
|
346
|
+
// return;
|
|
347
|
+
// }
|
|
348
|
+
//
|
|
349
|
+
// if (isArrayLikeObject(el)) {
|
|
350
|
+
// forEach(el, thisEl => {
|
|
351
|
+
// thisEl.removeEventListener(event, handler);
|
|
352
|
+
// });
|
|
353
|
+
// } else {
|
|
354
|
+
// el.removeEventListener(event, handler);
|
|
355
|
+
// }
|
|
356
|
+
// } else {
|
|
357
|
+
// document.removeEventListener(event, handler);
|
|
358
|
+
// }
|
|
359
|
+
// },
|
|
360
|
+
//
|
|
361
|
+
// /**
|
|
362
|
+
// * Creates and dispatches a custom event, with or without data.
|
|
363
|
+
// * @static
|
|
364
|
+
// * @function sendCustomEvent
|
|
365
|
+
// * @param {String} eventName - The name for the custom event.
|
|
366
|
+
// * @param {Object} [data=null] - The data to send with the custom event.
|
|
367
|
+
// * @example
|
|
368
|
+
// * DOMUtils.sendCustomEvent('open-my-mind', {mind: 'free'});
|
|
369
|
+
// * @returns {void}
|
|
370
|
+
// */
|
|
371
|
+
// sendCustomEvent(eventName, data = null) {
|
|
372
|
+
// if (!eventName) {
|
|
373
|
+
// throw new Error(
|
|
374
|
+
// `The 'eventName' is required when sending custom events.`
|
|
375
|
+
// );
|
|
376
|
+
// }
|
|
377
|
+
//
|
|
378
|
+
// const customEvent = new CustomEvent(eventName, {detail: data});
|
|
379
|
+
//
|
|
380
|
+
// document.dispatchEvent(customEvent);
|
|
381
|
+
// },
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Gets the offset of an element relative to the document.
|
|
385
|
+
* @static
|
|
386
|
+
* @function getDocumentOffset
|
|
387
|
+
* @param {String|Element} item - The selector or element to get the offset of.
|
|
388
|
+
* @example
|
|
389
|
+
* DOMUtils.getDocumentOffset('.foo');
|
|
390
|
+
* @returns {Object} - The top and left values of the offset.
|
|
391
|
+
*/
|
|
392
|
+
getDocumentOffset: function getDocumentOffset(item) {
|
|
393
|
+
var el = (0, _isString.default)(item) ? DOMUtils.el(item) : item;
|
|
394
|
+
var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
|
395
|
+
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
396
|
+
var rect = el ? el.getBoundingClientRect() : {
|
|
397
|
+
top: 0,
|
|
398
|
+
left: 0
|
|
399
|
+
};
|
|
400
|
+
return {
|
|
401
|
+
top: rect.top + scrollTop,
|
|
402
|
+
left: rect.left + scrollLeft
|
|
403
|
+
};
|
|
404
|
+
} //
|
|
405
|
+
// /**
|
|
406
|
+
// * Loads a script into an element in the document. Pass a fully qualified, exact URL to enable proper matching against a pre-existing script of the same path.
|
|
407
|
+
// * @static
|
|
408
|
+
// * @function loadScript
|
|
409
|
+
// * @param {String} src - The exact script path to load.
|
|
410
|
+
// * @param {String} [appendTo='head'] - Where to append the script ('head', 'body') in the document.
|
|
411
|
+
// * @example
|
|
412
|
+
// * DOMUtils.loadScript({src: 'https://js.stripe.com/v3/'});
|
|
413
|
+
// * @returns {Promise} - The promise that is either fulfilled or rejected as a result of loading the script.
|
|
414
|
+
// */
|
|
415
|
+
// loadScript({src, appendTo = 'head'}) {
|
|
416
|
+
// if (!EnvironmentUtils.isBrowser()) {
|
|
417
|
+
// return;
|
|
418
|
+
// }
|
|
419
|
+
//
|
|
420
|
+
// const isDuplicate = [...document.querySelectorAll('script')].some(
|
|
421
|
+
// script => {
|
|
422
|
+
// return script.src === src;
|
|
423
|
+
// }
|
|
424
|
+
// );
|
|
425
|
+
//
|
|
426
|
+
// return new Promise((resolve, reject) => {
|
|
427
|
+
// const s = document.createElement('script');
|
|
428
|
+
//
|
|
429
|
+
// s.src = src;
|
|
430
|
+
// s.onload = resolve;
|
|
431
|
+
// s.onerror = reject;
|
|
432
|
+
//
|
|
433
|
+
// if (!isDuplicate) {
|
|
434
|
+
// document[appendTo].appendChild(s);
|
|
435
|
+
// }
|
|
436
|
+
// });
|
|
437
|
+
// },
|
|
438
|
+
|
|
439
|
+
};
|
|
440
|
+
var _default = DOMUtils;
|
|
441
|
+
exports.default = _default;
|