jqx-es 1.3.7 → 1.3.9
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/Bundle/jqx.browser.min.js +12 -11
- package/Bundle/jqx.min.js +12 -11
- package/Resource/Common/DOM.js +15 -14
- package/Resource/Common/Utilities.js +7 -0
- package/package.json +1 -1
- package/src/JQxInstanceMethods.js +337 -313
|
@@ -17,187 +17,210 @@ export default function(jqx) {
|
|
|
17
17
|
|
|
18
18
|
function factoryExtensionsFactory(jqx) {
|
|
19
19
|
return {
|
|
20
|
-
data
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
data(instance) {
|
|
21
|
+
return {
|
|
22
|
+
get all() {
|
|
23
|
+
return new Proxy(instance[0]?.dataset ?? {}, datasetKeyProxy);
|
|
24
|
+
},
|
|
25
|
+
set(valuesObj = {}) {
|
|
26
|
+
if (!instance.is.empty && IS(valuesObj, Object)) {
|
|
27
|
+
for (const [key, value] of Object.entries(valuesObj)) {
|
|
28
|
+
instance.setData({[key]: value});
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
return instance;
|
|
32
|
+
},
|
|
33
|
+
get(key, whenUndefined) {
|
|
34
|
+
return instance.data.all[key] ?? whenUndefined;
|
|
35
|
+
},
|
|
36
|
+
add(valuesObj = {}) {
|
|
37
|
+
if (!instance.is.empty && IS(valuesObj, Object)) {
|
|
38
|
+
for (const [key, value] of Object.entries(valuesObj)) {
|
|
39
|
+
instance.setData({[key]: value});
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
dimensions
|
|
42
|
+
return instance;
|
|
43
|
+
},
|
|
44
|
+
remove(key) {
|
|
45
|
+
instance[0]?.removeAttribute(`data-${toDashedNotation(key)}`);
|
|
46
|
+
return instance;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
dimensions(instance) {
|
|
45
51
|
if (instance.is.empty) {
|
|
46
|
-
|
|
52
|
+
systemLog.error(`[JQx instance].dimensions called on empty instance`);
|
|
53
|
+
return { error: `[JQx instance].dimensions: NO ELEMENTS` };
|
|
47
54
|
}
|
|
48
|
-
let node = instance
|
|
49
|
-
const boundingRect =
|
|
55
|
+
let {node} = instance;
|
|
56
|
+
const boundingRect = node.getBoundingClientRect().toJSON();
|
|
50
57
|
boundingRect.scrollTopDistance = findParentScrollDistance(node, 0);
|
|
51
58
|
boundingRect.scrollLeftDistance = findParentScrollDistance(node, 0, false);
|
|
52
59
|
return boundingRect;
|
|
53
60
|
},
|
|
54
|
-
node
|
|
55
|
-
HTML
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
content =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
content =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
content =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
!instance.is.empty && instance.toDOM() || (jqx.log(`[JQx.render]: empty collection`), undefined);
|
|
93
|
-
return instance;
|
|
61
|
+
node(instance) { return instance[0]; },
|
|
62
|
+
HTML(instance) {
|
|
63
|
+
return {
|
|
64
|
+
get(outer, escaped) {
|
|
65
|
+
if (instance.is.empty) {
|
|
66
|
+
return `NO ELEMENTS IN COLLECTION`;
|
|
67
|
+
}
|
|
68
|
+
const html = outer ? instance.outerHtml : instance.html();
|
|
69
|
+
return escaped ? escHtml(html) : html;
|
|
70
|
+
},
|
|
71
|
+
set(content, append = false, escape = false) {
|
|
72
|
+
content = content.isJQx ? content.HTML.get(1) : content;
|
|
73
|
+
const isString = IS(content, String);
|
|
74
|
+
content = isString && escape ? escHtml(content) : content;
|
|
75
|
+
if (isString && (content || ``).trim().length) { instance.html(content, append); }
|
|
76
|
+
return instance;
|
|
77
|
+
},
|
|
78
|
+
replace(content, escape = false) {
|
|
79
|
+
return instance.HTML.set(content, false, escape);
|
|
80
|
+
},
|
|
81
|
+
append(content, escape = false) {
|
|
82
|
+
content = IS(content, HTMLElement)
|
|
83
|
+
? jqx(content).HTML.get(1) : content.isJQx ? content.HTML.get(1) : content;
|
|
84
|
+
return instance.HTML.set(content, true, escape);
|
|
85
|
+
},
|
|
86
|
+
insert(content, escape = false) {
|
|
87
|
+
content = IS(content, HTMLElement)
|
|
88
|
+
? jqx(content).HTML.get(1) : content.isJQx ? content.HTML.get(1) : content;
|
|
89
|
+
return instance.HTML.set(content + instance.HTML.get(), false, escape);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
is(instance) { return instanceIs(instance); },
|
|
94
|
+
length(instance) { return instance.collection.length; },
|
|
95
|
+
outerHtml(instance) { return (instance.first() || {outerHTML: undefined}).outerHTML; },
|
|
96
|
+
parent(instance) {
|
|
97
|
+
const maybeParent = jqx(instance[0]?.parentNode);
|
|
98
|
+
return !maybeParent.is.empty ? maybeParent : instance;
|
|
94
99
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
render(instance) {
|
|
101
|
+
switch(true) {
|
|
102
|
+
case !instance.is.empty: return instance.toDOM();
|
|
103
|
+
default:
|
|
104
|
+
jqx.logger.warn(`[JQx.render]: empty collection`);
|
|
105
|
+
return instance;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
Style(instance) {
|
|
109
|
+
return {
|
|
110
|
+
get computed() { return !instance.is.empty ? getComputedStyle(instance[0]) : {}; },
|
|
111
|
+
inline(styleObj) {
|
|
112
|
+
return instance.style(styleObj);
|
|
113
|
+
},
|
|
114
|
+
inSheet(styleObj) {
|
|
115
|
+
return instance.css(styleObj)
|
|
116
|
+
},
|
|
117
|
+
valueOf(key) {
|
|
118
|
+
return !instance.is.empty ? getComputedStyle(instance[0])[toDashedNotation(key)] : undefined;
|
|
119
|
+
},
|
|
120
|
+
nwRule(rule) {
|
|
121
|
+
return instance.Style.byRule({rules: rule})
|
|
122
|
+
},
|
|
123
|
+
byRule({classes2Apply = [], rules = []} = {}) {
|
|
124
|
+
const isSingleRule = IS(rules, String);
|
|
125
|
+
const addClassNameOrID = isSingleRule && !classes2Apply.length ? rules.split(`{`)[0].trim() : ``;
|
|
126
|
+
rules = rules && IS(rules, String) ? [rules] : rules;
|
|
127
|
+
classes2Apply = classes2Apply && IS(classes2Apply, String) ? [classes2Apply] : classes2Apply;
|
|
128
|
+
|
|
129
|
+
if (rules?.length || classes2Apply?.length) {
|
|
130
|
+
rules?.length && jqx.editCssRules(...rules);
|
|
131
|
+
|
|
132
|
+
if (classes2Apply) {
|
|
133
|
+
for(const selector of classes2Apply) { instance.addClass(selector); }
|
|
134
|
+
}
|
|
114
135
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
136
|
+
|
|
137
|
+
if (addClassNameOrID?.startsWith(`.`)) {
|
|
138
|
+
instance.addClass(addClassNameOrID.slice(1));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (addClassNameOrID?.startsWith(`#`) && !instance.attr(`id`)) {
|
|
142
|
+
instance.prop({id: addClassNameOrID.slice(1)});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return instance;
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
129
150
|
}
|
|
130
151
|
|
|
131
152
|
function instanceExtensionsFactory(jqx) {
|
|
132
153
|
return {
|
|
133
|
-
addClass
|
|
154
|
+
addClass(instance, ...classNames) {
|
|
155
|
+
return loop(instance, el => el && classNames.forEach(cn => el.classList.add(cn)));
|
|
156
|
+
},
|
|
134
157
|
after,
|
|
135
158
|
afterMe: after,
|
|
136
|
-
andThen
|
|
159
|
+
andThen(instance, elem2Add, before = false) {
|
|
137
160
|
if (!elem2Add || !IS(elem2Add, String, Node, Proxy)) {
|
|
138
|
-
systemLog.log(`[JQx instance].[
|
|
161
|
+
systemLog.log(`[JQx instance].[before(Me) | after(Me) | andThen]: invalid/-sufficient input.`, );
|
|
139
162
|
return instance;
|
|
140
163
|
}
|
|
141
|
-
|
|
164
|
+
|
|
142
165
|
elem2Add = elem2Add?.isJQx
|
|
143
|
-
? elem2Add
|
|
144
|
-
: IS(elem2Add, Node)
|
|
145
|
-
|
|
146
|
-
|
|
166
|
+
? elem2Add
|
|
167
|
+
: IS(elem2Add, Node)
|
|
168
|
+
? jqx.virtual(elem2Add)
|
|
169
|
+
: jqx.virtual(createElementFromHtmlString(elem2Add));
|
|
170
|
+
|
|
147
171
|
const [index, method, reCollected] = before
|
|
148
|
-
? [0, `before`, elem2Add.concat(instance.collection)]
|
|
149
|
-
: [instance.collection.length - 1, `after`, instance.collection.concat(elem2Add)];
|
|
150
|
-
|
|
151
|
-
instance[index][method](...elem2Add);
|
|
172
|
+
? [0, `before`, elem2Add.collection.concat(instance.collection)]
|
|
173
|
+
: [instance.collection.length - 1, `after`, instance.collection.concat(elem2Add.collection)];
|
|
174
|
+
|
|
175
|
+
instance[index][method](...elem2Add.collection);
|
|
152
176
|
instance.collection = reCollected;
|
|
153
177
|
return instance;
|
|
154
178
|
},
|
|
155
|
-
append
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
179
|
+
append(instance, ...elems2Append) {
|
|
180
|
+
if (instance.is.empty || elems2Append.length < 1) { return instance;}
|
|
181
|
+
const shouldMove = instance.length === 1;
|
|
182
|
+
for (let elem2Append of elems2Append) {
|
|
183
|
+
if (!elem2Append.isJQx && isNonEmptyString(elem2Append)) {
|
|
184
|
+
const elem2Append4Test = elem2Append.trim();
|
|
185
|
+
const isPlainString = !/^<(.+)[^>]+>$/m.test(elem2Append4Test);
|
|
186
|
+
let toAppend = isPlainString ? jqx.text(elem2Append) : createElementFromHtmlString(elem2Append);
|
|
187
|
+
loop(instance, el => el.append(shouldMove ? toAppend : cloneAndDestroy(toAppend)));
|
|
188
|
+
}
|
|
166
189
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
190
|
+
if (isNode(elem2Append)) {
|
|
191
|
+
loop(instance, el => el.append(shouldMove ? elem2Append : cloneAndDestroy(elem2Append)));
|
|
192
|
+
}
|
|
170
193
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
194
|
+
if (elem2Append.isJQx && !elem2Append.is.empty) {
|
|
195
|
+
loop(instance, el =>
|
|
196
|
+
elem2Append.collection.forEach(elem =>
|
|
197
|
+
el.append(shouldMove ? elem : cloneAndDestroy(elem)))
|
|
198
|
+
);
|
|
177
199
|
}
|
|
178
200
|
}
|
|
179
201
|
return instance;
|
|
180
202
|
},
|
|
181
|
-
appendTo
|
|
182
|
-
|
|
183
|
-
appendTo
|
|
203
|
+
appendTo(instance, appendTo) {
|
|
204
|
+
switch(true) {
|
|
205
|
+
case !appendTo.isJQx && !IS(appendTo, HTMLElement):
|
|
206
|
+
$.warn(`[JQx instance].appendTo: invalid input`);
|
|
207
|
+
return instance;
|
|
208
|
+
default:
|
|
209
|
+
(!appendTo.isJQx ? jqx(appendTo) : appendTo).append(instance);
|
|
210
|
+
return instance;
|
|
184
211
|
}
|
|
185
|
-
appendTo.append(instance);
|
|
186
|
-
return instance;
|
|
187
212
|
},
|
|
188
|
-
attr
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (!firstElem) { return instance }
|
|
213
|
+
attr(instance, keyOrObj, value) {
|
|
214
|
+
if (!instance.node) { return instance }
|
|
192
215
|
|
|
193
216
|
if (!value && isNonEmptyString(keyOrObj)) {
|
|
194
217
|
keyOrObj = toDashedNotation(keyOrObj);
|
|
195
218
|
|
|
196
219
|
if (keyOrObj === `class`) {
|
|
197
|
-
return [...
|
|
220
|
+
return [...instance.node.classList]?.join(` `);
|
|
198
221
|
}
|
|
199
222
|
|
|
200
|
-
return
|
|
223
|
+
return instance.node.getAttribute(keyOrObj);
|
|
201
224
|
}
|
|
202
225
|
|
|
203
226
|
if (isNonEmptyString(keyOrObj) && value) {
|
|
@@ -212,141 +235,133 @@ function instanceExtensionsFactory(jqx) {
|
|
|
212
235
|
}
|
|
213
236
|
|
|
214
237
|
if (IS(keyOrObj, Object) && !instance.is.empty) {
|
|
215
|
-
assignAttrValues(
|
|
238
|
+
assignAttrValues(instance.node, keyOrObj);
|
|
216
239
|
}
|
|
217
240
|
|
|
218
241
|
return instance;
|
|
219
242
|
},
|
|
220
243
|
before,
|
|
221
244
|
beforeMe: before,
|
|
222
|
-
clear
|
|
223
|
-
closest
|
|
224
|
-
const theClosest = isNonEmptyString(selector) ? instance
|
|
225
|
-
return theClosest ? jqx(theClosest) : instance
|
|
226
|
-
},
|
|
227
|
-
computedStyle: (instance, property) => instance.first() && getComputedStyle(instance.first())[property],
|
|
228
|
-
css: (instance, keyOrKvPairs, value) => loop(instance, el => css(el, keyOrKvPairs, value, jqx)),
|
|
229
|
-
duplicate: (instance, toDOM = false, root = document.body) => {
|
|
230
|
-
if (instance.collection.length > 0) {
|
|
231
|
-
const clone = instance.collection[0].cloneNode(true);
|
|
232
|
-
clone.childNodes.forEach((node) => {
|
|
233
|
-
node.removeAttribute && node?.removeAttribute(`id`)
|
|
234
|
-
});
|
|
235
|
-
return toDOM ? jqx(clone).toDOM(root) : jqx.virtual(clone);
|
|
236
|
-
}
|
|
237
|
-
systemLog.error(`Duplicating an empty JQx instance is not possible`);
|
|
238
|
-
return instance;
|
|
245
|
+
clear(instance) { return loop(instance, emptyElement); },
|
|
246
|
+
closest(instance, selector) {
|
|
247
|
+
const theClosest = isNonEmptyString(selector) ? instance.node?.closest(selector) : undefined;
|
|
248
|
+
return theClosest ? jqx(theClosest) : instance;
|
|
239
249
|
},
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
hasClass: (instance, ...classNames) => {
|
|
257
|
-
const firstElem = instance[0];
|
|
258
|
-
return !firstElem || !firstElem.classList.length
|
|
259
|
-
? false : classNames.find(cn => firstElem.classList.contains(cn)) && true || false;
|
|
260
|
-
},
|
|
261
|
-
hide: instance => loop(instance, el => applyStyle(el, {display: `none !important`})),
|
|
262
|
-
html: (instance, htmlValue, append) => {
|
|
263
|
-
if (htmlValue === undefined) {
|
|
264
|
-
const node = instance.node;
|
|
265
|
-
return node?.getHTML && node.getHTML() || ``;
|
|
250
|
+
computedStyle(instance, property) {
|
|
251
|
+
const {node} = instance;
|
|
252
|
+
return node && getComputedStyle(node)[property];
|
|
253
|
+
},
|
|
254
|
+
css(instance, keyOrKvPairs, value) {
|
|
255
|
+
return loop(instance, el => css(el, keyOrKvPairs, value, jqx));
|
|
256
|
+
},
|
|
257
|
+
duplicate(instance, toDOM = false, root = document.body) {
|
|
258
|
+
switch(true) {
|
|
259
|
+
case instance.is.empty:
|
|
260
|
+
systemLog.error(`Duplicating an empty JQx instance is not possible`)
|
|
261
|
+
return instance;
|
|
262
|
+
default:
|
|
263
|
+
const clone = instance.collection[0].cloneNode(true);
|
|
264
|
+
clone.childNodes.forEach((node) => { node.removeAttribute && node?.removeAttribute(`id`) });
|
|
265
|
+
return toDOM ? jqx(clone).toDOM(root) : jqx.virtual(clone);
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
267
|
+
},
|
|
268
|
+
each(instance, cb) { return loop(instance, cb); },
|
|
269
|
+
empty(instance) { return loop(instance, emptyElement); },
|
|
270
|
+
find(instance, selector) {
|
|
271
|
+
return instance.collection.length > 0 ? [...instance.first()?.querySelectorAll(selector)] : [];
|
|
272
|
+
},
|
|
273
|
+
find$(instance, selector) {
|
|
274
|
+
return instance.collection.length > 0 ? jqx(selector, instance) : instance;
|
|
275
|
+
},
|
|
276
|
+
first(instance, asJQxInstance = false) {
|
|
277
|
+
return instance.collection.length > 0
|
|
278
|
+
? asJQxInstance ? instance.single() : instance.collection[0]
|
|
279
|
+
: undefined;
|
|
280
|
+
},
|
|
281
|
+
first$(instance, indexOrSelector) {
|
|
282
|
+
return instance.single(indexOrSelector);
|
|
283
|
+
},
|
|
284
|
+
getData(instance, dataAttribute, valueWhenFalsy) {
|
|
285
|
+
return instance.node?.dataset?.[dataAttribute] || valueWhenFalsy;
|
|
286
|
+
},
|
|
287
|
+
hasClass(instance, ...classNames) {
|
|
288
|
+
return instance.is.empty || !instance.node.classList.length
|
|
289
|
+
? false
|
|
290
|
+
: classNames.find(cn => instance.node.classList.contains(cn)) && true || false;
|
|
291
|
+
},
|
|
292
|
+
hide(instance) { return loop(instance, el => applyStyle(el, {display: `none !important`})); },
|
|
293
|
+
html(instance, htmlValue, append) {
|
|
294
|
+
switch(true) {
|
|
295
|
+
case instance.is.empty && !isNonEmptyString(htmlValue): return "";
|
|
296
|
+
case !isNonEmptyString(htmlValue): return instance.node?.getHTML ?? ``;
|
|
297
|
+
default:
|
|
298
|
+
const nwElement = createElementFromHtmlString(
|
|
299
|
+
`<div>${htmlValue.isJQx ? htmlValue.HTML.get(true) : htmlValue}</div>` );
|
|
274
300
|
const cb = el => {
|
|
275
|
-
|
|
276
|
-
|
|
301
|
+
el.textContent = !append ? `` : el.textContent;
|
|
277
302
|
return el.insertAdjacentHTML(jqx.at.end, nwElement.getHTML());
|
|
278
303
|
}
|
|
279
304
|
return loop(instance, cb);
|
|
280
|
-
}
|
|
281
305
|
}
|
|
282
|
-
|
|
283
|
-
return instance;
|
|
284
306
|
},
|
|
285
|
-
htmlFor
|
|
286
|
-
if (
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
el2Change.each(el => {
|
|
296
|
-
if (!append) { el.textContent = ``; }
|
|
297
|
-
el.insertAdjacentHTML(jqx.at.end, nwElement?.getHTML());
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
}
|
|
307
|
+
htmlFor(instance, forSelector, htmlString = "", append = false) {
|
|
308
|
+
if (instance.is.empty || !isNonEmptyString(forSelector) || !isNonEmptyString(htmlString)) { return instance; }
|
|
309
|
+
const el2Change = instance.find$(forSelector);
|
|
310
|
+
if (el2Change.length < 1) { return instance; }
|
|
311
|
+
const nwElement = createElementFromHtmlString(`<span>${htmlString}</span>`);
|
|
312
|
+
el2Change.each(el => {
|
|
313
|
+
if (!append) { el.textContent = ``; }
|
|
314
|
+
el.insertAdjacentHTML(jqx.at.end, nwElement?.getHTML());
|
|
315
|
+
});
|
|
301
316
|
|
|
302
317
|
return instance;
|
|
303
318
|
},
|
|
304
|
-
isEmpty
|
|
305
|
-
nth
|
|
306
|
-
on
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
319
|
+
isEmpty(instance) { return !!!instance.node; },
|
|
320
|
+
nth$(instance, indexOrSelector) { return instance.single(indexOrSelector); },
|
|
321
|
+
on(instance, type, ...callback) {
|
|
322
|
+
switch(true) {
|
|
323
|
+
case instance.is.empty || !IS(type, String, Array) || !isNonEmptyString(type) || callback.length < 1:
|
|
324
|
+
return instance;
|
|
325
|
+
default: jqx.handle({type, node: instance.node, handler: callback});
|
|
326
|
+
return instance;
|
|
310
327
|
}
|
|
311
|
-
|
|
312
|
-
return instance;
|
|
313
328
|
},
|
|
314
|
-
once
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
329
|
+
once(instance, type, ...callback) {
|
|
330
|
+
switch(true) {
|
|
331
|
+
case instance.is.empty || !IS(type, String, Array) || !isNonEmptyString(type) || callback.length < 1:
|
|
332
|
+
return instance;
|
|
333
|
+
default:
|
|
334
|
+
jqx.handle({type, once: true, node: instance.node, handler: callback});
|
|
335
|
+
return instance
|
|
318
336
|
}
|
|
319
|
-
|
|
320
|
-
return instance;
|
|
321
337
|
},
|
|
322
|
-
prepend
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
338
|
+
prepend(instance, ...elems2Prepend) {
|
|
339
|
+
if (instance.is.empty || !elems2Prepend) { return; }
|
|
340
|
+
const shouldMove = instance.length === 1;
|
|
341
|
+
|
|
342
|
+
for (let elem2Prepend of elems2Prepend) {
|
|
343
|
+
if (isNonEmptyString(elem2Prepend)) {
|
|
344
|
+
elem2Prepend = elem2Prepend.trim();
|
|
345
|
+
const isPlainString = !/^<(.+)[^>]+>$/m.test(elem2Prepend);
|
|
346
|
+
let toPrepend = isPlainString ? jqx.text(elem2Prepend) : createElementFromHtmlString(elem2Prepend);
|
|
347
|
+
toPrepend = shouldMove ? toPrepend : cloneAndDestroy(toPrepend);
|
|
348
|
+
loop(instance, el => el.prepend(toPrepend.cloneNode(true)));
|
|
349
|
+
}
|
|
334
350
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
351
|
+
if (isNode(elem2Prepend)) {
|
|
352
|
+
loop(instance, el => el.prepend(shouldMove ? elem2Prepend : cloneAndDestroy(elem2Prepend)));
|
|
353
|
+
}
|
|
338
354
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
355
|
+
if (elem2Prepend.isJQx && !elem2Prepend.is.empty) {
|
|
356
|
+
elem2Prepend.collection.length > 1 && elem2Prepend.collection.reverse();
|
|
357
|
+
loop(instance, el => loop( elem2Prepend, elem => el.prepend(shouldMove ? elem : cloneAndDestroy(elem)) ) );
|
|
358
|
+
elem2Prepend.collection.reverse();
|
|
344
359
|
}
|
|
345
360
|
}
|
|
346
|
-
|
|
361
|
+
|
|
347
362
|
return instance;
|
|
348
363
|
},
|
|
349
|
-
prependTo
|
|
364
|
+
prependTo(instance, prependTo) {
|
|
350
365
|
if (!prependTo.isJQx) {
|
|
351
366
|
prependTo = jqx.virtual(prependTo);
|
|
352
367
|
}
|
|
@@ -354,7 +369,7 @@ function instanceExtensionsFactory(jqx) {
|
|
|
354
369
|
prependTo.prepend(instance);
|
|
355
370
|
return instance;
|
|
356
371
|
},
|
|
357
|
-
prop
|
|
372
|
+
prop(instance, nameOrProperties, value) {
|
|
358
373
|
if (IS(nameOrProperties, String) && !value) {
|
|
359
374
|
return nameOrProperties.startsWith(`data`)
|
|
360
375
|
? instance[0]?.dataset[nameOrProperties.slice(nameOrProperties.indexOf(`-`)+1)]
|
|
@@ -384,7 +399,7 @@ function instanceExtensionsFactory(jqx) {
|
|
|
384
399
|
|
|
385
400
|
return instance;
|
|
386
401
|
},
|
|
387
|
-
remove
|
|
402
|
+
remove(instance, selector) {
|
|
388
403
|
systemLog.log(`remove ${truncateHtmlStr(instance.HTML.get(1), 40)}${selector ? ` /w selector ${selector}` : ``}`);
|
|
389
404
|
const remover = el => el.remove();
|
|
390
405
|
const removeFromCollection = () =>
|
|
@@ -402,29 +417,28 @@ function instanceExtensionsFactory(jqx) {
|
|
|
402
417
|
removeFromCollection();
|
|
403
418
|
return instance;
|
|
404
419
|
},
|
|
405
|
-
rmAttr
|
|
420
|
+
rmAttr(instance, ...attrNames) {
|
|
406
421
|
for (const attr of attrNames) { instance.node.removeAttribute(attr); }
|
|
407
422
|
return instance;
|
|
408
423
|
},
|
|
409
|
-
removeClass
|
|
410
|
-
loop(instance, el => { if (el) { for (const cn of classNames) { el.classList.remove(cn); } } })
|
|
411
|
-
|
|
412
|
-
|
|
424
|
+
removeClass(instance, ...classNames) {
|
|
425
|
+
return loop(instance, el => { if (el) { for (const cn of classNames) { el.classList.remove(cn); } } });
|
|
426
|
+
},
|
|
427
|
+
renderTo(instance, root, position) {
|
|
428
|
+
root = IS(root, HTMLElement) || root.isJQx ? root : document.body;
|
|
429
|
+
position = IS(position, String) && jqx.at[position] ? position : jqx.at.end;
|
|
430
|
+
instance.first$().toDOM(root, position);
|
|
413
431
|
return instance;
|
|
414
432
|
},
|
|
415
|
-
replace
|
|
416
|
-
const firstElem = instance
|
|
433
|
+
replace(instance, oldChild, newChild) {
|
|
434
|
+
const firstElem = instance.node;
|
|
417
435
|
|
|
418
|
-
if (!oldChild || (!
|
|
419
|
-
|
|
436
|
+
if (!oldChild || (!IS(newChild, HTMLElement) && !newChild?.isJQx)) {
|
|
437
|
+
jqx.logger.error(`JQx replace: invalid replacement value`);
|
|
420
438
|
return instance;
|
|
421
439
|
}
|
|
422
440
|
|
|
423
|
-
if (newChild.isJQx) {
|
|
424
|
-
newChild = newChild[0];
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (IS(newChild, NodeList)) {
|
|
441
|
+
if (newChild.isJQx || IS(newChild, NodeList)) {
|
|
428
442
|
newChild = newChild[0];
|
|
429
443
|
}
|
|
430
444
|
|
|
@@ -443,12 +457,16 @@ function instanceExtensionsFactory(jqx) {
|
|
|
443
457
|
|
|
444
458
|
return instance;
|
|
445
459
|
},
|
|
446
|
-
replaceClass
|
|
447
|
-
el
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
460
|
+
replaceClass(instance, className, ...nwClassNames) {
|
|
461
|
+
return loop( instance, el => {
|
|
462
|
+
el.classList.remove(className);
|
|
463
|
+
for (const name of nwClassNames) { el.classList.add(name); }
|
|
464
|
+
} )
|
|
465
|
+
},
|
|
466
|
+
replaceMe(instance, newChild) {
|
|
467
|
+
/*NODOC*/ return instance.replaceWith(newChild);
|
|
468
|
+
},
|
|
469
|
+
replaceWith(instance, newChild) {
|
|
452
470
|
newChild = IS(newChild, Element) ? newChild : newChild.isJQx ? newChild[0] : undefined;
|
|
453
471
|
|
|
454
472
|
if (newChild) {
|
|
@@ -458,67 +476,73 @@ function instanceExtensionsFactory(jqx) {
|
|
|
458
476
|
|
|
459
477
|
return instance;
|
|
460
478
|
},
|
|
461
|
-
setData
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
479
|
+
setData(instance, keyValuePairs) {
|
|
480
|
+
return loop(instance, el => setData(el, keyValuePairs));
|
|
481
|
+
},
|
|
482
|
+
show(instance) {
|
|
483
|
+
return loop(instance, el => applyStyle(el, {display: `revert-layer !important`}));
|
|
484
|
+
},
|
|
485
|
+
single(instance, indexOrSelector) {
|
|
486
|
+
const hasNodes = instance.collection.length > 0;
|
|
487
|
+
indexOrSelector = indexOrSelector ?? 0;
|
|
488
|
+
|
|
489
|
+
switch(true) {
|
|
490
|
+
case hasNodes && IS(indexOrSelector, String):
|
|
466
491
|
return instance.find$(indexOrSelector);
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (IS(indexOrSelector, Number)) {
|
|
492
|
+
case hasNodes && IS(indexOrSelector, Number):
|
|
470
493
|
return jqx(instance.collection[indexOrSelector]);
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return jqx(instance.collection[0]);
|
|
494
|
+
case hasNodes: return instance.collection[0];
|
|
495
|
+
default: return instance;
|
|
474
496
|
}
|
|
475
|
-
|
|
476
|
-
return instance;
|
|
477
497
|
},
|
|
478
|
-
style
|
|
498
|
+
style(instance, keyOrKvPairs, value) {
|
|
479
499
|
const loopCollectionLambda = el => {
|
|
480
500
|
if (value && IS(keyOrKvPairs, String)) {
|
|
481
501
|
keyOrKvPairs = { [keyOrKvPairs]: value || `none` };
|
|
482
502
|
}
|
|
483
|
-
|
|
484
503
|
applyStyle(el, keyOrKvPairs);
|
|
485
504
|
};
|
|
486
505
|
return loop(instance, loopCollectionLambda);
|
|
487
506
|
},
|
|
488
|
-
text
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
507
|
+
text(instance, textValue, append = false) {
|
|
508
|
+
switch(true) {
|
|
509
|
+
case instance.isEmpty(): return instance;
|
|
510
|
+
case !IS(textValue, String): return instance.node.textContent;
|
|
511
|
+
default: return loop(instance, el => el.textContent = append ? el.textContent + textValue : textValue);
|
|
512
|
+
}
|
|
493
513
|
},
|
|
494
|
-
toDOM
|
|
495
|
-
|
|
514
|
+
toDOM(instance, root = document.body, position = insertPositions.BeforeEnd) {
|
|
515
|
+
instance.isVirtual = false;
|
|
496
516
|
inject2DOMTree(instance.collection, root, position);
|
|
497
517
|
return instance;
|
|
498
518
|
},
|
|
499
|
-
toggleClass
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
519
|
+
toggleClass(instance, className) {
|
|
520
|
+
return loop(instance, el => el.classList.toggle(className));
|
|
521
|
+
},
|
|
522
|
+
toNodeList(instance) {
|
|
523
|
+
return [...instance.collection].map(el => document.importNode(el, true));
|
|
524
|
+
},
|
|
525
|
+
trigger(instance, evtType, SpecifiedEvent, options) {
|
|
526
|
+
SpecifiedEvent = /Event\]$/.test(IS(SpecifiedEvent)) ? SpecifiedEvent : Event;
|
|
527
|
+
options = IS(options, Object) ? { ...options, bubbles: options.bubbles??true} : {bubbles: true};
|
|
528
|
+
|
|
529
|
+
if (!instance.is.empty) {
|
|
530
|
+
const evObj = new SpecifiedEvent( evtType, options );
|
|
531
|
+
instance.each(el => el.dispatchEvent(evObj));
|
|
505
532
|
}
|
|
533
|
+
|
|
506
534
|
return instance;
|
|
507
535
|
},
|
|
508
|
-
val
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
536
|
+
val(instance, newValue) {
|
|
537
|
+
switch(true) {
|
|
538
|
+
case instance.is.empty || !IS(instance.node, HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement):
|
|
539
|
+
return instance;
|
|
540
|
+
case !IS(newValue, String):
|
|
541
|
+
return instance.node.value;
|
|
542
|
+
default:
|
|
543
|
+
instance.node.value = !IS(newValue, String) ? "" : newValue;
|
|
544
|
+
return instance;
|
|
517
545
|
}
|
|
518
|
-
|
|
519
|
-
firstElem.value = !IS(newValue, String) ? "" : newValue;
|
|
520
|
-
|
|
521
|
-
return instance;
|
|
522
546
|
},
|
|
523
547
|
};
|
|
524
548
|
}
|