jsquery_node 1.0.12 → 1.0.13
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/jsquery.ts +154 -170
- package/package.json +1 -1
package/jsquery.ts
CHANGED
|
@@ -1,72 +1,51 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
checked(): boolean[];
|
|
17
|
-
checked(val: boolean): this;
|
|
18
|
-
checked(val?: boolean): this | boolean[] {
|
|
19
|
-
if (val !== undefined) {
|
|
20
|
-
this.forEach((v) => v.checked(val));
|
|
21
|
-
return this;
|
|
1
|
+
export namespace JSQuery {
|
|
2
|
+
function toArray(elt: NodeList | HTMLCollection | HTMLElement) {
|
|
3
|
+
return elt instanceof NodeList || elt instanceof HTMLCollection;
|
|
4
|
+
}
|
|
5
|
+
function toElt(elt: Element): HTMLElement {
|
|
6
|
+
if (elt instanceof Element) return elt.elt;
|
|
7
|
+
return elt;
|
|
8
|
+
}
|
|
9
|
+
export class Extension {
|
|
10
|
+
constructor() {
|
|
11
|
+
if (this.constructor === Extension) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"you can't make an instance of class: JSQuery.Extension"
|
|
14
|
+
);
|
|
22
15
|
}
|
|
23
|
-
return this.map((v) => v.checked()) as any;
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.forEach((v) => v.props(props));
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
class(names: string | string[]) {
|
|
38
|
-
this.forEach((v) => v.class(names));
|
|
39
|
-
return this;
|
|
17
|
+
get() {
|
|
18
|
+
return {
|
|
19
|
+
$: this.$(),
|
|
20
|
+
Element: this.Element(),
|
|
21
|
+
static_Element: this.static_Element(),
|
|
22
|
+
static_ElementArray: this.static_ElementArray(),
|
|
23
|
+
ElementArray: this.ElementArray(),
|
|
24
|
+
JSQuery: this.JSQuery(),
|
|
25
|
+
};
|
|
40
26
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return this;
|
|
27
|
+
$() {
|
|
28
|
+
return {};
|
|
44
29
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return this;
|
|
30
|
+
Element() {
|
|
31
|
+
return {};
|
|
48
32
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return this;
|
|
33
|
+
ElementArray() {
|
|
34
|
+
return {};
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return temp;
|
|
36
|
+
|
|
37
|
+
static_Element() {
|
|
38
|
+
return {};
|
|
57
39
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.forEach((v) => v.click(func, s));
|
|
61
|
-
return this;
|
|
40
|
+
static_ElementArray() {
|
|
41
|
+
return {};
|
|
62
42
|
}
|
|
63
|
-
}
|
|
64
43
|
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
JSQuery() {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
67
47
|
}
|
|
68
|
-
|
|
69
|
-
class Element {
|
|
48
|
+
export class Element {
|
|
70
49
|
elt: HTMLElement;
|
|
71
50
|
#TriggerEvent(e: any, func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
|
|
72
51
|
if (!func) {
|
|
@@ -221,136 +200,141 @@ export const { $, JSQuery } = (() => {
|
|
|
221
200
|
return this;
|
|
222
201
|
}
|
|
223
202
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
203
|
+
export class Caching extends Extension {
|
|
204
|
+
$() {
|
|
205
|
+
return {
|
|
206
|
+
cache<T extends (...args:any[])=>any>(func: T): T {
|
|
207
|
+
const f = (...args: Parameters<T>): ReturnType<T> => {
|
|
208
|
+
const val = JSON.stringify(args);
|
|
209
|
+
if (f.cache.hasOwnProperty(val)) {
|
|
210
|
+
return f.cache[val];
|
|
211
|
+
}
|
|
212
|
+
const temp = func(...args);
|
|
213
|
+
f.cache[val] = temp;
|
|
214
|
+
return temp;
|
|
215
|
+
};
|
|
216
|
+
f.cache = {};
|
|
217
|
+
return f as any;
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
228
221
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
222
|
+
export class ElementArray extends Array<Element> {
|
|
223
|
+
on<K extends keyof DocumentEventMap>(e: K, func: (this: HTMLElement, ev: DocumentEventMap[K])=>any, s?: boolean | AddEventListenerOptions) {
|
|
224
|
+
this.forEach((v) => v.on(e, func, s));
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
rect() {
|
|
228
|
+
return this.map((v) => v.rect());
|
|
229
|
+
}
|
|
230
|
+
hasClass(c:string) {
|
|
231
|
+
return this.map((v) => v.hasClass(c));
|
|
232
|
+
}
|
|
233
|
+
is(q:string) {
|
|
234
|
+
return this.map((v) => v.is(q));
|
|
235
|
+
}
|
|
236
|
+
checked(): boolean[];
|
|
237
|
+
checked(val: boolean): this;
|
|
238
|
+
checked(val?: boolean): this | boolean[] {
|
|
239
|
+
if (val !== undefined) {
|
|
240
|
+
this.forEach((v) => v.checked(val));
|
|
241
|
+
return this;
|
|
236
242
|
}
|
|
243
|
+
return this.map((v) => v.checked()) as any;
|
|
237
244
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
Element: this.Element(),
|
|
242
|
-
static_Element: this.static_Element(),
|
|
243
|
-
static_ElementArray: this.static_ElementArray(),
|
|
244
|
-
ElementArray: this.ElementArray(),
|
|
245
|
-
JSQuery: this.JSQuery(),
|
|
246
|
-
};
|
|
245
|
+
trigger(e: any) {
|
|
246
|
+
this.forEach((v) => v.trigger(e));
|
|
247
|
+
return this;
|
|
247
248
|
}
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
css(styles: Record<string, any>) {
|
|
250
|
+
this.forEach((v) => v.css(styles));
|
|
251
|
+
return this;
|
|
250
252
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
+
props(props: Record<string, any>) {
|
|
254
|
+
this.forEach((v) => v.props(props));
|
|
255
|
+
return this;
|
|
253
256
|
}
|
|
254
|
-
|
|
255
|
-
|
|
257
|
+
class(names: string | string[]) {
|
|
258
|
+
this.forEach((v) => v.class(names));
|
|
259
|
+
return this;
|
|
256
260
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return
|
|
261
|
+
removeClass(names: string | string[]) {
|
|
262
|
+
this.forEach((v) => v.removeClass(names));
|
|
263
|
+
return this;
|
|
260
264
|
}
|
|
261
|
-
|
|
262
|
-
|
|
265
|
+
toggleClass(names: string | string[]) {
|
|
266
|
+
this.forEach((v) => v.toggleClass(names));
|
|
267
|
+
return this;
|
|
263
268
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return
|
|
269
|
+
remove() {
|
|
270
|
+
this.forEach((v) => v.remove());
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
new() {
|
|
274
|
+
const temp = new ElementArray();
|
|
275
|
+
this.forEach((v) => temp.push(v.new() as any));
|
|
276
|
+
return temp;
|
|
277
|
+
}
|
|
278
|
+
//events
|
|
279
|
+
click(func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
|
|
280
|
+
this.forEach((v) => v.click(func, s));
|
|
281
|
+
return this;
|
|
267
282
|
}
|
|
268
283
|
}
|
|
284
|
+
export const Plugin = Extension;
|
|
285
|
+
export type Plugin = Extension;
|
|
286
|
+
}
|
|
269
287
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
J.from = ((elt:any) => {
|
|
275
|
-
return Element.from(elt);
|
|
276
|
-
}) as typeof Element.from;
|
|
288
|
+
function J(q: any): JSQuery.Element | null {
|
|
289
|
+
return JSQuery.Element.from(document.querySelector(q)) as any;
|
|
290
|
+
}
|
|
277
291
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
292
|
+
J.from = ((elt:any) => {
|
|
293
|
+
return JSQuery.Element.from(elt);
|
|
294
|
+
}) as typeof JSQuery.Element.from;
|
|
281
295
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return head;
|
|
286
|
-
};
|
|
296
|
+
J.all = (q: any): JSQuery.ElementArray => {
|
|
297
|
+
return JSQuery.Element.from(document.querySelectorAll(q)) as any;
|
|
298
|
+
};
|
|
287
299
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
let head: JSQuery.Element;
|
|
301
|
+
J.head = () => {
|
|
302
|
+
if (!head) head = JSQuery.Element.from(document.head) as JSQuery.Element;
|
|
303
|
+
return head;
|
|
304
|
+
};
|
|
293
305
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
306
|
+
let body: JSQuery.Element;
|
|
307
|
+
J.body = () => {
|
|
308
|
+
if (!body) body = JSQuery.Element.from(document.body) as JSQuery.Element;
|
|
309
|
+
return body;
|
|
310
|
+
};
|
|
299
311
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
312
|
+
let doc: JSQuery.Element;
|
|
313
|
+
J.doc = () => {
|
|
314
|
+
if (!doc) doc = JSQuery.Element.from(document as any) as JSQuery.Element;
|
|
315
|
+
return doc;
|
|
316
|
+
};
|
|
303
317
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
Extension,
|
|
308
|
-
Plugin: Extension,
|
|
309
|
-
Caching: class Caching extends Extension {
|
|
310
|
-
$() {
|
|
311
|
-
return {
|
|
312
|
-
cache<T extends (...args:any[])=>any>(func: T): T {
|
|
313
|
-
const f = (...args: Parameters<T>): ReturnType<T> => {
|
|
314
|
-
const val = JSON.stringify(args);
|
|
315
|
-
if (f.cache.hasOwnProperty(val)) {
|
|
316
|
-
return f.cache[val];
|
|
317
|
-
}
|
|
318
|
-
const temp = func(...args);
|
|
319
|
-
f.cache[val] = temp;
|
|
320
|
-
return temp;
|
|
321
|
-
};
|
|
322
|
-
f.cache = {};
|
|
323
|
-
return f as any;
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
};
|
|
318
|
+
J.create = (t: any): JSQuery.Element => {
|
|
319
|
+
return JSQuery.Element.from(document.createElement(t)) as any;
|
|
320
|
+
};
|
|
329
321
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
body = undefined;
|
|
337
|
-
head = undefined;
|
|
338
|
-
const items = new extend().get();
|
|
339
|
-
Object.assign(J, items.$);
|
|
340
|
-
Object.assign(JSQuery, items.JSQuery);
|
|
341
|
-
Object.assign(Element.prototype, items.Element);
|
|
342
|
-
Object.assign(ElementArray.prototype, items.ElementArray);
|
|
343
|
-
Object.assign(Element, items.static_Element);
|
|
344
|
-
Object.assign(ElementArray, items.static_ElementArray);
|
|
322
|
+
J.loadExtension = (extend: new()=>JSQuery.Extension) => {
|
|
323
|
+
if (Object.getPrototypeOf(extend) !== JSQuery.Extension) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
"the class is not a child of JSQuery.Extension or the inputed class is an instance"
|
|
326
|
+
);
|
|
345
327
|
}
|
|
328
|
+
body = undefined;
|
|
329
|
+
head = undefined;
|
|
330
|
+
const items = new extend().get();
|
|
331
|
+
Object.assign(J, items.$);
|
|
332
|
+
Object.assign(JSQuery, items.JSQuery);
|
|
333
|
+
Object.assign(JSQuery.Element.prototype, items.Element);
|
|
334
|
+
Object.assign(JSQuery.ElementArray.prototype, items.ElementArray);
|
|
335
|
+
Object.assign(JSQuery.Element, items.static_Element);
|
|
336
|
+
Object.assign(JSQuery.ElementArray, items.static_ElementArray);
|
|
337
|
+
}
|
|
346
338
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return { $: J, JSQuery };
|
|
350
|
-
})();
|
|
351
|
-
|
|
352
|
-
export type ElementArray = typeof JSQuery.ElementArray;
|
|
353
|
-
export type Element = typeof JSQuery.Element;
|
|
354
|
-
export type Extension = typeof JSQuery.Extension;
|
|
355
|
-
export type Plugin = typeof JSQuery.Extension;
|
|
339
|
+
J.loadPlugin = J.loadExtension;
|
|
356
340
|
|