jqx-es 1.3.6 → 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.
- package/Bundle/jqx.browser.min.js +12 -11
- package/Bundle/jqx.min.js +12 -11
- package/README.md +1 -1
- package/Resource/Common/DOM.js +15 -14
- package/Resource/Common/HandlerFactory.js +1 -1
- package/Resource/Common/Utilities.js +29 -4
- package/package.json +1 -1
- package/src/JQxCreatorFactory.js +2 -1
- package/src/JQxInstanceMethods.js +280 -278
- package/src/JQxUtilities.js +13 -13
|
@@ -17,33 +17,39 @@ 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
|
-
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
|
|
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
|
-
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
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
|
|
152
|
+
andThen(instance, elem2Add, before = false) {
|
|
137
153
|
if (!elem2Add || !IS(elem2Add, String, Node, Proxy)) {
|
|
138
|
-
systemLog.log(`[JQx instance].[
|
|
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
|
|
144
|
-
: IS(elem2Add, Node)
|
|
145
|
-
|
|
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
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
183
|
+
if (isNode(elem2Append)) {
|
|
184
|
+
loop(instance, el => el.append(shouldMove ? elem2Append : cloneAndDestroy(elem2Append)));
|
|
185
|
+
}
|
|
170
186
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
|
182
|
-
|
|
183
|
-
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
|
|
189
|
-
|
|
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 [...
|
|
213
|
+
return [...instance.node.classList]?.join(` `);
|
|
198
214
|
}
|
|
199
215
|
|
|
200
|
-
return
|
|
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(
|
|
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
|
|
224
|
-
const theClosest = isNonEmptyString(selector) ? instance
|
|
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
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
|
245
|
-
|
|
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
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return node?.getHTML
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
}
|
|
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
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
+
if (isNode(elem2Prepend)) {
|
|
339
|
+
loop(instance, el => el.prepend(shouldMove ? elem2Prepend : cloneAndDestroy(elem2Prepend)));
|
|
340
|
+
}
|
|
338
341
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
412
|
-
|
|
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
|
|
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
|
|
464
|
-
|
|
465
|
-
|
|
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
|
|
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
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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
|
|
495
|
-
|
|
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
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
}
|