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.
@@ -17,187 +17,210 @@ export default function(jqx) {
17
17
 
18
18
  function factoryExtensionsFactory(jqx) {
19
19
  return {
20
- data: instance => ({
21
- get all() { return new Proxy(instance[0]?.dataset ?? {}, datasetKeyProxy); },
22
- set: (valuesObj = {}) => {
23
- if (!instance.is.empty && IS(valuesObj, Object)) {
24
- for (const [key, value] of Object.entries(valuesObj)) {
25
- instance.setData( { [key]: value} );
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
- return instance;
29
- },
30
- get: (key, whenUndefined) => instance.data.all[key] ?? whenUndefined,
31
- add: (valuesObj = {}) => {
32
- if (!instance.is.empty && IS(valuesObj, Object)) {
33
- for (const [key, value] of Object.entries(valuesObj)) {
34
- instance.setData( { [key]: value} );
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
- return instance;
38
- },
39
- remove: key => {
40
- instance[0]?.removeAttribute(`data-${toDashedNotation(key)}`);
41
- return instance;
42
- },
43
- }),
44
- dimensions: instance => {
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
- return { error: `[instance].dimensions: NO ELEMENTS` };
52
+ systemLog.error(`[JQx instance].dimensions called on empty instance`);
53
+ return { error: `[JQx instance].dimensions: NO ELEMENTS` };
47
54
  }
48
- let node = instance[0];
49
- const boundingRect = instance.first()?.getBoundingClientRect().toJSON();
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: instance => { return instance[0]; },
55
- HTML: instance => ({
56
- get: (outer, escaped) => {
57
- if (instance.is.empty) {
58
- return `NO ELEMENTS IN COLLECTION`;
59
- }
60
- const html = outer ? instance.outerHtml : instance.html();
61
- return escaped ? escHtml(html) : html;
62
- },
63
- set: (content, append = false, escape = false) => {
64
- content = content.isJQx ? content.HTML.get(1) : content;
65
- const isString = IS(content, String);
66
- content = isString && escape ? escHtml(content) : content;
67
- if (isString && (content || ``).trim().length) { instance.html(content, append); }
68
- return instance;
69
- },
70
- replace: (content, escape = false) => {
71
- return instance.HTML.set(content, false, escape);
72
- },
73
- append: (content, escape = false) => {
74
- content = IS(content, HTMLElement)
75
- ? jqx(content).HTML.get(1) : content.isJQx ? content.HTML.get(1) : content;
76
- return instance.HTML.set(content, true, escape);
77
- },
78
- insert: (content, escape = false) => {
79
- content = IS(content, HTMLElement)
80
- ? jqx(content).HTML.get(1) : content.isJQx ? content.HTML.get(1) : content;
81
- return instance.HTML.set(content + instance.HTML.get(), false, escape);
82
- },
83
- }),
84
- is: instance => instanceIs(instance),
85
- length: instance => instance.collection.length,
86
- outerHtml: instance => (instance.first() || {outerHTML: undefined}).outerHTML,
87
- parent: instance =>{
88
- const tryParent = jqx(instance[0]?.parentNode);
89
- return !tryParent.is.empty ? tryParent : instance;
90
- },
91
- render: instance => {
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
- Style: instance => ({
96
- get computed() { return !instance.is.empty ? getComputedStyle(instance[0]) : {}; },
97
- inline: styleObj => instance.style(styleObj),
98
- inSheet: styleObj => instance.css(styleObj),
99
- valueOf: key => {
100
- return !instance.is.empty ? getComputedStyle(instance[0])[toDashedNotation(key)] : undefined;
101
- },
102
- nwRule: rule => instance.Style.byRule({rules: rule}),
103
- byRule: ({classes2Apply = [], rules = []} = {}) => {
104
- const isSingleRule = IS(rules, String);
105
- const addClassNameOrID = isSingleRule && !classes2Apply.length ? rules.split(`{`)[0].trim() : ``;
106
- rules = rules && IS(rules, String) ? [rules] : rules;
107
- classes2Apply = classes2Apply && IS(classes2Apply, String) ? [classes2Apply] : classes2Apply;
108
-
109
- if (rules?.length || classes2Apply?.length) {
110
- rules?.length && jqx.editCssRules(...rules);
111
-
112
- if (classes2Apply) {
113
- for(const selector of classes2Apply) { instance.addClass(selector); }
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
- if (addClassNameOrID?.startsWith(`.`)) {
118
- instance.addClass(addClassNameOrID.slice(1));
119
- }
120
-
121
- if (addClassNameOrID?.startsWith(`#`) && !instance.attr(`id`)) {
122
- instance.prop({id: addClassNameOrID.slice(1)});
123
- }
124
-
125
- return instance;
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: (instance, ...classNames) => loop(instance, el => el && classNames.forEach(cn => el.classList.add(cn))),
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: (instance, elem2Add, before = false) => {
159
+ andThen(instance, elem2Add, before = false) {
137
160
  if (!elem2Add || !IS(elem2Add, String, Node, Proxy)) {
138
- systemLog.log(`[JQx instance].[beforeMe | afterMe | andThen]: insufficient input [${elem2Add}]`, );
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.collection
144
- : IS(elem2Add, Node) ? jqx.virtual(elem2Add).collection
145
- : jqx.virtual(createElementFromHtmlString(elem2Add)).collection;
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: (instance, ...elems2Append) => {
156
- if (!instance.is.empty && elems2Append.length) {
157
- const shouldMove = instance.length === 1;
158
-
159
- for (let elem2Append of elems2Append) {
160
- if (!elem2Append.isJQx && isNonEmptyString(elem2Append)) {
161
- const elem2Append4Test = elem2Append.trim();
162
- const isPlainString = !/^<(.+)[^>]+>$/m.test(elem2Append4Test);
163
- let toAppend = isPlainString ? jqx.text(elem2Append) : createElementFromHtmlString(elem2Append);
164
- loop(instance, el => el.append(shouldMove ? toAppend : cloneAndDestroy(toAppend)));
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
- if (isNode(elem2Append)) {
168
- loop(instance, el => el.append(shouldMove ? elem2Append : cloneAndDestroy(elem2Append)));
169
- }
190
+ if (isNode(elem2Append)) {
191
+ loop(instance, el => el.append(shouldMove ? elem2Append : cloneAndDestroy(elem2Append)));
192
+ }
170
193
 
171
- if (elem2Append.isJQx && !elem2Append.is.empty) {
172
- loop(instance, el =>
173
- elem2Append.collection.forEach(elem =>
174
- el.append(shouldMove ? elem : cloneAndDestroy(elem)))
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: (instance, appendTo) => {
182
- if (!appendTo.isJQx) {
183
- appendTo = jqx(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: (instance, keyOrObj, value) => {
189
- const firstElem = instance[0];
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 [...firstElem?.classList]?.join(` `);
220
+ return [...instance.node.classList]?.join(` `);
198
221
  }
199
222
 
200
- return firstElem?.getAttribute(keyOrObj);
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(firstElem, keyOrObj);
238
+ assignAttrValues(instance.node, keyOrObj);
216
239
  }
217
240
 
218
241
  return instance;
219
242
  },
220
243
  before,
221
244
  beforeMe: before,
222
- clear: instance => loop(instance, emptyElement),
223
- closest: (instance, selector) => {
224
- const theClosest = isNonEmptyString(selector) ? instance[0].closest(selector) : null;
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
- each: (instance, cb) => loop(instance, cb),
241
- empty: instance => loop(instance, emptyElement),
242
- find: (instance, selector) =>
243
- instance.collection.length > 0 ? [...instance.first()?.querySelectorAll(selector)] : [],
244
- find$: (instance, selector) => { return instance.collection.length > 0 ? jqx(selector, instance) : instance; },
245
- first: (instance, asJQxInstance = false) => {
246
- if (instance.collection.length > 0) {
247
- return asJQxInstance
248
- ? instance.single()
249
- : instance.collection[0];
250
- }
251
- return undefined;
252
- },
253
- first$: (instance, indexOrSelector) => instance.single(indexOrSelector),
254
- getData: (instance, dataAttribute, valueWhenFalsy) =>
255
- instance.first() && instance.first().dataset?.[dataAttribute] || valueWhenFalsy,
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
- if (!instance.isEmpty()) {
269
- const nwElement = createElementFromHtmlString(
270
- `<div>${htmlValue.isJQx ? htmlValue.HTML.get(true) : htmlValue}</div>`
271
- );
272
-
273
- if (!IS(nwElement, Comment)) {
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
- if (!append) { el.textContent = ``; }
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: (instance, forQuery, htmlString = "", append = false) => {
286
- if (forQuery && instance.collection.length) {
287
- if (!forQuery || !isNonEmptyString(htmlString)) { return instance; }
288
-
289
- const el2Change = instance.find$(forQuery);
290
-
291
- if (el2Change.length < 1) { return instance; }
292
-
293
- const nwElement = createElementFromHtmlString(`<span>${htmlString}</span>`);
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: instance => instance.collection.length < 1,
305
- nth$: (instance, indexOrSelector) => instance.single(indexOrSelector),
306
- on: (instance, type, ...callback) => {
307
- if (instance.collection.length && IS(type, String, Array)) {
308
- if (!isNonEmptyString(type) || callback.length < 1) { return instance; }
309
- jqx.handle({type, node: instance.node, handler: callback});
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: (instance, type, ...callback) => {
315
- if (instance.collection.length && IS(type, String, Array)) {
316
- if (!isNonEmptyString(type) || callback.length < 1) { return instance; }
317
- jqx.handle({type, once: true, node: instance.node, handler: callback});
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: (instance, ...elems2Prepend) => {
323
- if (!instance.is.empty && elems2Prepend) {
324
- const shouldMove = instance.length === 1;
325
-
326
- for (let elem2Prepend of elems2Prepend) {
327
- if (isNonEmptyString(elem2Prepend)) {
328
- elem2Prepend = elem2Prepend.trim();
329
- const isPlainString = !/^<(.+)[^>]+>$/m.test(elem2Prepend);
330
- let toPrepend = isPlainString ? jqx.text(elem2Prepend) : createElementFromHtmlString(elem2Prepend);
331
- toPrepend = shouldMove ? toPrepend : cloneAndDestroy(toPrepend);
332
- loop(instance, el => el.prepend(toPrepend.cloneNode(true)));
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
- if (isNode(elem2Prepend)) {
336
- loop(instance, el => el.prepend(shouldMove ? elem2Prepend : cloneAndDestroy(elem2Prepend)));
337
- }
351
+ if (isNode(elem2Prepend)) {
352
+ loop(instance, el => el.prepend(shouldMove ? elem2Prepend : cloneAndDestroy(elem2Prepend)));
353
+ }
338
354
 
339
- if (elem2Prepend.isJQx && !elem2Prepend.is.empty) {
340
- elem2Prepend.collection.length > 1 && elem2Prepend.collection.reverse();
341
- loop(instance, el => loop( elem2Prepend, elem => el.prepend(shouldMove ? elem : cloneAndDestroy(elem)) ) );
342
- elem2Prepend.collection.reverse();
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: (instance, 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: (instance, nameOrProperties, value) => {
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: (instance, selector) => {
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: (instance, ...attrNames) => {
420
+ rmAttr(instance, ...attrNames) {
406
421
  for (const attr of attrNames) { instance.node.removeAttribute(attr); }
407
422
  return instance;
408
423
  },
409
- removeClass: (instance, ...classNames) =>
410
- loop(instance, el => { if (el) { for (const cn of classNames) { el.classList.remove(cn); } } }),
411
- renderTo: (instance, root = document.body, at = jqx.at.end) => {
412
- instance.first$().toDOM(root, at);
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: (instance, oldChild, newChild) => {
416
- const firstElem = instance[0];
433
+ replace(instance, oldChild, newChild) {
434
+ const firstElem = instance.node;
417
435
 
418
- if (!oldChild || (!newChild || !IS(newChild, HTMLElement) && !newChild.isJQx)) {
419
- console.error(`JQx replace: invalid replacement value`);
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: (instance, className, ...nwClassNames) => loop( instance, el => {
447
- el.classList.remove(className);
448
- for (const name of nwClassNames) { el.classList.add(name); }
449
- } ),
450
- replaceMe: (instance, newChild) => /*NODOC*/ instance.replaceWith(newChild),
451
- replaceWith: (instance, newChild) => {
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: (instance, keyValuePairs) => loop(instance, el => setData(el, keyValuePairs)),
462
- show: instance => loop(instance, el => applyStyle(el, {display: `revert-layer !important`})),
463
- single: (instance, indexOrSelector) => {
464
- if (instance.collection.length > 0) {
465
- if (IS(indexOrSelector, String)) {
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: (instance, keyOrKvPairs, value) => {
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: (instance, textValue, append = false) => {
489
- if (instance.isEmpty()) { return instance; }
490
- if (!IS(textValue, String)) { return instance.first().textContent; }
491
- const loopCollectionLambda = el => el.textContent = append ? el.textContent + textValue : textValue;
492
- return loop(instance, loopCollectionLambda);
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: (instance, root = document.body, position = insertPositions.BeforeEnd) => {
495
- if (instance.isVirtual) { instance.isVirtual = false; }
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: (instance, className) => loop(instance, el => el.classList.toggle(className)),
500
- toNodeList: instance => [...instance.collection].map(el => document.importNode(el, true)),
501
- trigger: (instance, evtType, SpecifiedEvent = Event, options = {}) => {
502
- if (instance.collection.length) {
503
- const evObj = new SpecifiedEvent( evtType, { ...options, bubbles: options.bubbles??true} );
504
- for( let elem of instance.collection ) { elem.dispatchEvent(evObj); }
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: (instance, newValue) => {
509
- const firstElem = instance[0];
510
-
511
- if (!firstElem || !IS(firstElem, HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement)) {
512
- return instance;
513
- }
514
-
515
- if (newValue === undefined) {
516
- return firstElem.value;
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
  }