jqx-es 1.3.7 → 1.3.8

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