-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathjquery.js
253 lines (231 loc) · 6.79 KB
/
jquery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/**
* Includes utility methods and lodash / jQuery shims
*/
export * from './baseutil';
export * from './lazyLoad';
export * from './browser';
import getSDKAnalyticsSignature from "../sdkAnalytics/getSDKAnalyticsSignature";
import getAnalyticsOptions from "../sdkAnalytics/getAnalyticsOptions";
export {getSDKAnalyticsSignature , getAnalyticsOptions};
/**
* Get data from the DOM element.
*
* This method will use jQuery's `data()` method if it is available, otherwise it will get the `data-` attribute
* @param {Element} element - the element to get the data from
* @param {string} name - the name of the data item
* @returns the value associated with the `name`
* @function Util.getData
*/
export var getData = function(element, name) {
return jQuery(element).data(name);
};
/**
* Set data in the DOM element.
*
* This method will use jQuery's `data()` method if it is available, otherwise it will set the `data-` attribute
* @function Util.setData
* @param {Element} element - the element to set the data in
* @param {string} name - the name of the data item
* @param {*} value - the value to be set
*
*/
export var setData = function(element, name, value) {
return jQuery(element).data(name, value);
};
/**
* Get attribute from the DOM element.
*
* This method will use jQuery's `attr()` method if it is available, otherwise it will get the attribute directly
* @function Util.getAttribute
* @param {Element} element - the element to set the attribute for
* @param {string} name - the name of the attribute
* @returns {*} the value of the attribute
*
*/
export var getAttribute = function(element, name) {
return jQuery(element).attr(name);
};
/**
* Set attribute in the DOM element.
*
* This method will use jQuery's `attr()` method if it is available, otherwise it will set the attribute directly
* @function Util.setAttribute
* @param {Element} element - the element to set the attribute for
* @param {string} name - the name of the attribute
* @param {*} value - the value to be set
*/
export var setAttribute = function(element, name, value) {
return jQuery(element).attr(name, value);
};
/**
* Remove an attribute in the DOM element.
*
* @function Util.removeAttribute
* @param {Element} element - the element to set the attribute for
* @param {string} name - the name of the attribute
*/
export var removeAttribute = function(element, name) {
return jQuery(element).removeAttr(name);
};
/**
* Set a group of attributes to the element
* @function Util.setAttributes
* @param {Element} element - the element to set the attributes for
* @param {Object} attributes - a hash of attribute names and values
*/
export var setAttributes = function(element, attributes) {
return jQuery(element).attr(attributes);
};
/**
* Checks if element has a css class
* @function Util.hasClass
* @param {Element} element - the element to check
* @param {string} name - the class name
@returns {boolean} true if the element has the class
*/
export var hasClass = function(element, name) {
return jQuery(element).hasClass(name);
};
/**
* Add class to the element
* @function Util.addClass
* @param {Element} element - the element
* @param {string} name - the class name to add
*/
export var addClass = function(element, name) {
return jQuery(element).addClass(name);
};
export var width = function(element) {
return jQuery(element).width();
};
/**
* Returns true if item is a string
* @param item
* @returns {boolean} true if item is a string
*/
export var isString = function(item) {
return typeof item === 'string' || (item != null ? item.toString() : void 0) === '[object String]';
};
/**
* Recursively assign source properties to destination
* @function Util.merge
* @param {Object} destination - the object to assign to
* @param {...Object} [sources] The source objects.
*/
export var merge = function() {
var args, i;
args = (function() {
var j, len, results;
results = [];
for (j = 0, len = arguments.length; j < len; j++) {
i = arguments[j];
results.push(i);
}
return results;
}).apply(this, arguments);
args.unshift(true); // deep extend
return jQuery.extend.apply(this, args);
};
/**
* Creates a new array from the parameter with "falsey" values removed
* @function Util.compact
* @param {Array} array - the array to remove values from
* @return {Array} a new array without falsey values
*/
export var compact = function(arr) {
var item, j, len, results;
results = [];
for (j = 0, len = arr.length; j < len; j++) {
item = arr[j];
if (item) {
results.push(item);
}
}
return results;
};
/**
* Create a new copy of the given object, including all internal objects.
* @function Util.cloneDeep
* @param {Object} value - the object to clone
* @return {Object} a new deep copy of the object
*/
export var cloneDeep = function() {
var args;
args = jQuery.makeArray(arguments);
args.unshift({}); // add "fresh" destination
args.unshift(true); // deep
return jQuery.extend.apply(this, args);
};
/**
* Check if a given item is included in the given array
* @function Util.contains
* @param {Array} array - the array to search in
* @param {*} item - the item to search for
* @return {boolean} true if the item is included in the array
*/
export var contains = function(arr, item) {
var i, j, len;
for (j = 0, len = arr.length; j < len; j++) {
i = arr[j];
if (i === item) {
return true;
}
}
return false;
};
/**
* Returns values in the given array that are not included in the other array
* @function Util.difference
* @param {Array} arr - the array to select from
* @param {Array} values - values to filter from arr
* @return {Array} the filtered values
*/
export var difference = function(arr, values) {
var item, j, len, results;
results = [];
for (j = 0, len = arr.length; j < len; j++) {
item = arr[j];
if (!contains(values, item)) {
results.push(item);
}
}
return results;
};
/**
* Returns a list of all the function names in obj
* @function Util.functions
* @param {Object} object - the object to inspect
* @return {Array} a list of functions of object
*/
export var functions = function(object) {
var i, results;
results = [];
for (i in object) {
if (jQuery.isFunction(object[i])) {
results.push(i);
}
}
return results;
};
/**
* Returns the provided value. This functions is used as a default predicate function.
* @function Util.identity
* @param {*} value
* @return {*} the provided value
*/
export var identity = function(value) {
return value;
};
/**
* @class Util
*/
export var isArray = Array.isArray;
export var assign = jQuery.extend;
export var isPlainObject = jQuery.isPlainObject;
/**
* Remove leading or trailing spaces from text
* @function Util.trim
* @param {string} text
* @return {string} the `text` without leading or trailing spaces
*/
export var trim = jQuery.trim;