@wiajs/core 1.0.5 → 1.0.6

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/dist/core.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * wia core v1.0.5
2
+ * wia core v1.0.6
3
3
  * (c) 2015-2023 Sibyl Yu and contributors
4
4
  * Released under the MIT License.
5
5
  */
@@ -90,3305 +90,6 @@ function objToParam(obj) {
90
90
  return rs;
91
91
  }
92
92
 
93
- function getDefaultExportFromCjs (x) {
94
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
95
- }
96
-
97
- var dom = {exports: {}};
98
-
99
- /*!
100
- * wia dom v1.0.1
101
- * (c) 2022-2023 Sibyl Yu and contributors
102
- * Released under the MIT License.
103
- */
104
-
105
- var dom_cmn;
106
- var hasRequiredDom_cmn;
107
-
108
- function requireDom_cmn () {
109
- if (hasRequiredDom_cmn) return dom_cmn;
110
- hasRequiredDom_cmn = 1;
111
-
112
- /*
113
- * Expand $.fn
114
- * 扩展 $.fn
115
- * same syntax as well known jQuery library
116
- */
117
-
118
- const emptyArray = [];
119
- const elementDisplay = {};
120
- const rootNodeRE = /^(?:body|html)$/i;
121
- const propMap = {
122
- tabindex: 'tabIndex',
123
- readonly: 'readOnly',
124
- for: 'htmlFor',
125
- class: 'className',
126
- maxlength: 'maxLength',
127
- cellspacing: 'cellSpacing',
128
- cellpadding: 'cellPadding',
129
- rowspan: 'rowSpan',
130
- colspan: 'colSpan',
131
- usemap: 'useMap',
132
- frameborder: 'frameBorder',
133
- contenteditable: 'contentEditable',
134
- };
135
-
136
- // 返回数组
137
- function concat(...arg) {
138
- const args = [];
139
- for (let i = 0; i < arg.length; i++) {
140
- const v = arg[i];
141
- args[i] = $.isDom(v) ? v.toArray() : v;
142
- }
143
- return emptyArray.concat.apply($.isDom(this) ? this.toArray() : this, args);
144
- }
145
-
146
- function ready(cb) {
147
- if (/complete|loaded|interactive/.test(document.readyState) && document.body) cb($);
148
- else
149
- document.addEventListener(
150
- 'DOMContentLoaded',
151
- function () {
152
- cb($);
153
- },
154
- false
155
- );
156
- return this;
157
- }
158
-
159
- // 转为节点数组,或指定索引节点
160
- function get(idx) {
161
- return idx === undefined ? emptyArray.slice.call(this) : this[idx >= 0 ? idx : idx + this.length];
162
- }
163
-
164
- function toArray() {
165
- return this.get();
166
- }
167
-
168
- function size() {
169
- return this.length;
170
- }
171
-
172
- /**
173
- * 删除或设置dom属性
174
- * @param {*} node
175
- * @param {*} n attr name
176
- * @param {*} value null or undefined
177
- */
178
- function setAttr(node, n, value) {
179
- if (node && node.nodeType === 1) {
180
- if (value == null) node.removeAttribute(n);
181
- else node.setAttribute(n, value);
182
- }
183
- }
184
-
185
- function attr(n, value) {
186
- let R;
187
- const el = this[0];
188
-
189
- // Get attr
190
- if (arguments.length === 1 && typeof n === 'string') {
191
- if (el.nodeType === 1 && el) R = el.getAttribute(n);
192
- } else {
193
- // Set attr
194
- R = this.each(function (idx) {
195
- if ($.isObject(n)) {
196
- Object.keys(n).forEach(k => {
197
- this[k] = n[k]; // f7
198
- setAttr(this, k, n[k]);
199
- });
200
- } else setAttr(this, n, $.funcArg(this, value, idx, this.getAttribute(n)));
201
- });
202
- }
203
-
204
- return R;
205
- }
206
-
207
- function removeAttr(n) {
208
- return this.each(function () {
209
- this.nodeType === 1 &&
210
- n.split(' ').forEach(function (v) {
211
- setAttr(this, v);
212
- }, this);
213
- });
214
- }
215
-
216
- function hasAttr(n) {
217
- return emptyArray.some.call(this, function (el) {
218
- return el.hasAttribute(n);
219
- });
220
- }
221
-
222
- function prop(n, value) {
223
- try {
224
- n = propMap[n] || n;
225
- // Get prop
226
- if (arguments.length === 1 && typeof n === 'string') this[0] && this[0][n];
227
- else {
228
- // Set props
229
- return this.each(function (idx) {
230
- if (arguments.length === 2) this[n] = $.funcArg(this, value, idx, this[n]);
231
- else if ($.isObject(n)) {
232
- // eslint-disable-next-line
233
- for (const prop in n) {
234
- this[prop] = n[prop];
235
- }
236
- }
237
- });
238
- }
239
- } catch (ex) {
240
- console.log('prop exp:', ex.message);
241
- }
242
- }
243
-
244
- function removeProp(n) {
245
- n = propMap[n] || n;
246
- return this.each(function () {
247
- delete this[n];
248
- });
249
- }
250
-
251
- // 读取或设置 data-* 属性值,保持与jQuery 兼容
252
- // 在dom节点上自定义 domElementDataStorage 对象存储数据
253
- function data(key, value) {
254
- let R;
255
- let el;
256
- const attrName = 'data-' + key.replace(/([A-Z])/g, '-$1').toLowerCase();
257
-
258
- if (typeof value === 'undefined') {
259
- [el] = this;
260
- // Get value
261
- if (el) {
262
- if (el.domElementDataStorage && key in el.domElementDataStorage) {
263
- R = el.domElementDataStorage[key];
264
- } else R = this.attr(attrName);
265
- }
266
- if (R) R = $.deserializeValue(R);
267
- } else {
268
- // Set value
269
- for (let i = 0; i < this.length; i += 1) {
270
- el = this[i];
271
- if (!el.domElementDataStorage) el.domElementDataStorage = {};
272
- el.domElementDataStorage[key] = value;
273
- this.attr(attrName, value);
274
- }
275
- R = this;
276
- }
277
-
278
- return R;
279
- }
280
-
281
- function removeData(key) {
282
- const attrName = 'data-' + key.replace(/([A-Z])/g, '-$1').toLowerCase();
283
-
284
- for (let i = 0; i < this.length; i += 1) {
285
- const el = this[i];
286
- if (el.domElementDataStorage && el.domElementDataStorage[key]) {
287
- el.domElementDataStorage[key] = null;
288
- delete el.domElementDataStorage[key];
289
- }
290
- el.removeAttribute(attrName);
291
- }
292
-
293
- return this;
294
- }
295
-
296
- function dataset() {
297
- const el = this[0];
298
- if (!el) return undefined;
299
-
300
- const dataset = {}; // eslint-disable-line
301
- if (el.dataset) {
302
- // eslint-disable-next-line
303
- for (const dataKey in el.dataset) {
304
- dataset[dataKey] = el.dataset[dataKey];
305
- }
306
- } else {
307
- for (let i = 0; i < el.attributes.length; i += 1) {
308
- // eslint-disable-next-line
309
- const attr = el.attributes[i];
310
- if (attr.name.indexOf('data-') >= 0) {
311
- dataset[$.camelCase(attr.name.split('data-')[1])] = attr.value;
312
- }
313
- }
314
- }
315
-
316
- // eslint-disable-next-line
317
- for (const key in dataset) dataset[key] = $.deserializeValue(dataset[key]);
318
-
319
- return dataset;
320
- }
321
-
322
- /**
323
- * 表单节点值的获取、设置
324
- * 获取时,只获取第一个dom对象value
325
- * 设置时,对节点数组同时设置
326
- * 支持 select单选、多选,checkbox,radio
327
- * @param {*} value 值
328
- * value 为Dom对象时,表示节点容器,带容器参数时,支持容器内radio、checkbox有效值获取
329
- * @param {*} el 节点容器,带容器参数时,支持容器内radio、checkbox赋值
330
- * @returns
331
- */
332
- function val(value, el) {
333
- let R;
334
- // 设置值
335
- if (0 in arguments && !$.isDom(value)) {
336
- if (value == null) value = '';
337
- return this.each(function (idx) {
338
- let vs = $.funcArg(this, value, idx, this.value);
339
- const dom = this;
340
-
341
- // 注意,节点value是字符串!
342
- // select 多选,单选直接赋值即可
343
- if (dom.multiple && dom.nodeName.toLowerCase() === 'select') {
344
- if (Array.isArray(vs)) vs = vs.map(v => v.toString());
345
- else vs = [vs.toString()];
346
- dom.options.forEach(o => (o.selected = vs.includes(o.value)));
347
- } else if (dom.type === 'checkbox' && el) {
348
- if (Array.isArray(vs)) vs = vs.map(v => v.toString());
349
- else vs = [vs.toString()];
350
-
351
- const name = $(dom).attr('name');
352
- const ns = $(`input[name=${name}]`, el);
353
- ns.forEach(n => (n.checked = vs.includes(n.value)));
354
- } else if (dom.type === 'radio' && el) {
355
- if (Array.isArray(vs)) vs = vs[0];
356
-
357
- const name = $(dom).attr('name');
358
- const ns = $(`input[name=${name}]`, el);
359
- ns.forEach(n => {
360
- n.checked = n.value === vs.toString();
361
- });
362
- } else dom.value = vs.toString();
363
- });
364
- } else if (this[0]) {
365
- // 获取值
366
- const dom = this[0];
367
- R = dom.value;
368
- // 多选
369
- if (dom.multiple && dom.nodeName.toLowerCase() === 'select')
370
- R = $(dom)
371
- .find('option')
372
- .filter(function () {
373
- return this.selected;
374
- })
375
- .pluck('value');
376
- else if (dom.type === 'checkbox' && $.isDom(value)) {
377
- const el = value;
378
- const name = this.attr('name');
379
- const ns = $(`input[name=${name}]:checked`, el);
380
- R = ns.pluck('value');
381
- } else if (dom.type === 'radio' && $.isDom(value)) {
382
- const el = value;
383
- const name = this.attr('name');
384
- const n = $(`input[name=${name}]:checked`, el);
385
- if (n && n.length) R = n[0].value;
386
- }
387
- }
388
-
389
- return R;
390
- }
391
-
392
- // Transforms
393
- // eslint-disable-next-line
394
- function transform(transform) {
395
- for (let i = 0; i < this.length; i += 1) {
396
- const elStyle = this[i].style;
397
- elStyle.webkitTransform = transform;
398
- elStyle.transform = transform;
399
- }
400
- return this;
401
- }
402
- function transition(duration) {
403
- if (typeof duration !== 'string') {
404
- duration = `${duration}ms`; // eslint-disable-line
405
- }
406
- for (let i = 0; i < this.length; i += 1) {
407
- const elStyle = this[i].style;
408
- elStyle.webkitTransitionDuration = duration;
409
- elStyle.transitionDuration = duration;
410
- }
411
- return this;
412
- }
413
-
414
- /**
415
- * 事件响应,第一个参数为event,
416
- * 第二个参数为this,解决类事件函数this绑定到对象无法获得事件this问题。
417
- * targetSelector 目标选择器,常用于容器中的click、change事件,
418
- * 根据触发源target动态向上查找指定元素
419
- * 事件响应,dom事件中的 event作为第一个参数,其他为扩展参数
420
- * trigger触发时,可带扩展参数,扩展参数通过el的 wiaDomEventData 传递
421
- * 触摸屏,click 300ms 有延迟,改用 touch 实现立即触发
422
- * 避免click穿透,touch触发click事件后,禁止300ms后的click事件
423
- * swipe 滑动事件上下左右四个方向,滑动距离超过10px,则触发回调函数
424
- * 触发回调函数,参数为 (ev, {x, y}),x y互斥,只有一个有值
425
- * press 按压事件,超过 1秒,移动距离小于 5px,为 press 事件
426
- */
427
- function on(...args) {
428
- let [eventType, targetSelector, listener, capture] = args;
429
-
430
- if (typeof args[1] === 'function') {
431
- [eventType, listener, capture] = args;
432
- targetSelector = undefined;
433
- }
434
-
435
- // 封装需动态查找目标元素的事件回调函数
436
- function liveHandler(ev, sender, ...evs) {
437
- const n = ev.target; // 事件源,不能用this
438
- if (!n) return;
439
-
440
- const {eventType: evType, selector, liveProxy: fn} = liveHandler;
441
-
442
- // 向上查找符合选择器元素,找到一个即触发,其他符合选择器不触发
443
- // f7是查找所有符合选择器父元素,全部触发,实际使用中,只需最近的元素触发,无需全部触发!
444
- const el = $(n).closest(selector)?.dom; // live事件函数,目标选择器对象,替换真正的this
445
- // console.log('liveHandler ', {listener: this, selector, event: ev, target: n, upper: $n?.dom});
446
- // debugger;
447
- if (el && (evType !== 'click' || canClick(el, fn))) {
448
- const param = [ev, el, ...evs]; // 符合元素作为事件函数第二个参数
449
- fn.apply(n, param); // this 指向符合选择器元素
450
- }
451
- }
452
-
453
- // 带有目标选择器,回调函数转换为 liveHandler
454
- if (targetSelector) {
455
- liveHandler.selector = targetSelector;
456
- liveHandler.liveProxy = listener;
457
- liveHandler.eventType = eventType;
458
- return this.on(eventType, liveHandler, capture);
459
- }
460
-
461
- if (!capture) capture = false;
462
-
463
- // 事件响应,dom事件中的 event作为第一个参数
464
- // trigger通过el的 wiaDomEventData 带额外参数,
465
- function handleEvent(ev, ...vs) {
466
- const ds = ev?.target?.wiaDomEventData ?? [];
467
- const param = [ev, this, ...vs, ...ds];
468
-
469
- // console.log('handleEvent ', {listener: this, event: ev, target: ev?.target});
470
- listener.apply(this, param);
471
- }
472
-
473
- /**
474
- * 同一节点、同一事件函数,过500毫秒才能重复触发click事件,避免连击时连续触发同一函数
475
- * @param {*} el 元素节点
476
- * @param {*} fn 事件函数
477
- * @returns
478
- */
479
- function canClick(el, fn) {
480
- let R = true;
481
-
482
- if (!el || !fn) return false;
483
-
484
- // 排除live、once封装代理函数,排除 document等非元素节点,主要针对 button、link、div
485
- if (fn.liveProxy || fn.onceProxy || el.nodeType !== 1) return true;
486
-
487
- try {
488
- // disabled not trigger event
489
- if (el.clickDisabled?.has?.(fn)) {
490
- // ev.stopPropagation(); // 阻止事件冒泡,会阻止live和对同一节点的多侦听事件
491
- console.log('duplicate click disabled.');
492
- R = false;
493
- } else {
494
- // 阻止连击 Prevent duplicate clicks
495
- if (!el.clickDisabled) el.clickDisabled = new Set();
496
- el.clickDisabled.add(fn);
497
- setTimeout(() => el.clickDisabled.delete(fn), 200); // wait 500 ms, can click again
498
- }
499
- } catch (ex) {
500
- console.log('canClick exp:', ex.message);
501
- }
502
-
503
- return R;
504
- }
505
-
506
- // Prevent duplicate clicks
507
- // click事件响应,dom事件中的 event作为第一个参数,其他为扩展参数
508
- function clickEvent(ev) {
509
- // console.log('clickEvent ', {listener: this, event: ev, target: ev?.target});
510
- const el = this;
511
-
512
- if (!canClick(el, listener)) return false;
513
-
514
- const ds = ev?.target?.wiaDomEventData || [];
515
- const param = [ev, this, ...ds];
516
- listener.apply(this, param);
517
- }
518
-
519
- // on 函数内共享闭包变量
520
- const touch = {};
521
- function touchStart(ev) {
522
- // console.log('touchStart');
523
-
524
- // ev.preventDefault(); // 默认行为为滚动屏幕,调用则禁止屏幕滚动,比如屏幕上画画,就需要禁止屏幕滚动
525
- // touch.x = e.targetTouches[0].pageX; // pageX 相对文档的位置
526
- touch.x = ev.targetTouches[0].pageX; // targetTouches clientX 可见视口位置,pageX 文档位置
527
- touch.y = ev.targetTouches[0].pageY;
528
- touch.el = $(ev.target);
529
- touch.top = touch.el.rect()?.top ?? 0;
530
- touch.left = touch.el.rect()?.left ?? 0;
531
- touch.time = new Date().getTime();
532
- touch.trigger = false;
533
- touch.scrollY = false;
534
- const pg = touch.el.closest('.page-content').dom;
535
- if (pg) {
536
- touch.scrollY = true;
537
- if (pg.scrollTop === 0 || pg.scrollTop + pg.clientHeight === pg.scrollHeight)
538
- touch.scrollY = false;
539
- }
540
- }
541
-
542
- // swipe 滑动事件
543
- function touchMove(ev) {
544
- // console.log('touchMove');
545
- if (eventType !== 'swipe' || touch.trigger) return;
546
-
547
- const x = Math.round(ev.targetTouches[0].pageX - touch.x);
548
- const y = Math.round(ev.targetTouches[0].pageY - touch.y);
549
- const top = Math.round((touch.el.rect()?.top ?? 0) - touch.top);
550
- const left = Math.round((touch.el.rect()?.left ?? 0) - touch.left);
551
-
552
- // 计算手指在屏幕上的滑动距离,减掉页面跟随手指滚动的距离
553
- const mx = Math.abs(x - left);
554
- const my = Math.abs(y - top);
555
-
556
- // 页面不滚动,滑动超过12px,触发滑动事件,页面滚动则不触发
557
- if (my > 15 && mx < 8 && top === 0 && !touch.scrollY) {
558
- // e.preventDefault(); // 滑动不会产生onclick事件! 不阻止后续的 onclick 事件,否则后续onclick 不会触发
559
- touch.trigger = true; // move 会反复触发,事件只触发一次
560
- return handleEvent.call(this, ev, {x: 0, y});
561
- }
562
-
563
- if (mx > 12 && my < 8 && left === 0 && top === 0) {
564
- // e.preventDefault(); // 滑动不会产生onclick事件! 不阻止后续的 onclick 事件,否则后续onclick 不会触发
565
- touch.trigger = true; // move 会反复触发,事件只触发一次
566
- return handleEvent.call(this, ev, {x, y: 0});
567
- }
568
- }
569
-
570
- // 同时具备 press click,需分开两个函数侦听,触发两次,否则只能触发一次
571
- function clickEnd(ev) {
572
- return touchEnd.call(this, ev);
573
- }
574
-
575
- function pressEnd(ev) {
576
- return touchEnd.call(this, ev);
577
- }
578
-
579
- // touch click 和 press 事件,与onclick事件需二选一,使用 touch click,不会抑制后续的onclick事件。
580
- // 如果上层有click事件,客户端需调用e.preventDefault()来阻止穿透。
581
- function touchEnd(ev) {
582
- // console.log('touchEnd', {eventType});
583
- if (eventType !== 'click' && eventType !== 'press') return;
584
- touch.trigger = false;
585
- const x = Math.abs(ev.changedTouches[0].pageX - touch.x);
586
- const y = Math.abs(ev.changedTouches[0].pageY - touch.y);
587
- const tm = new Date().getTime() - touch.time;
588
- // console.log('touchEnd', {x, y, tm});
589
- if (x <= 5 && y <= 5) {
590
- // 由于在层中使用click,禁止缺省行为后,层中的输入框、下拉框等均失效
591
- // 阻止后续的 onclick 事件,可在按钮中实现,否则页面变动后,后续onclick 事件会触发在其他节点上,导致点击穿透错误!
592
- // ev.preventDefault();
593
- if (tm < 500 && eventType === 'click') return clickEvent.call(this, ev);
594
- if (tm > 500 && eventType === 'press') return handleEvent.call(this, ev);
595
- }
596
- }
597
-
598
- const events = eventType.split(' ');
599
- let j;
600
- for (let i = 0; i < this.length; i += 1) {
601
- const el = this[i];
602
- // 未设置目标选择器
603
- for (j = 0; j < events.length; j += 1) {
604
- const event = events[j];
605
- // 侦听事件和函数,保存到el属性中,方便off
606
- if (!el.domListeners) el.domListeners = {};
607
- // 事件对应的函数数组,每个函数都要addEventListener,才能接收事件回调
608
- if (!el.domListeners[event]) el.domListeners[event] = [];
609
-
610
- // 触摸屏,touch 代替 click,proxyListener 事件处理代理,domListeners 保存在el上
611
- if ($.support.touch && (event === 'click' || event === 'swipe' || event === 'press')) {
612
- const lis = {
613
- capture,
614
- listener,
615
- proxyListener: [touchStart],
616
- };
617
-
618
- let passive = capture;
619
- if (event === 'swipe') {
620
- if ($.support.passiveListener) passive = {passive: true, capture};
621
- lis.proxyListener.push(touchMove);
622
- } else if (event === 'click') lis.proxyListener.push(clickEnd);
623
- else if (event === 'press') lis.proxyListener.push(pressEnd);
624
-
625
- el.domListeners[event].push(lis);
626
- lis.proxyListener.forEach(fn => {
627
- let type = '';
628
- // fn.name 会被优化,不可使用
629
- switch (fn) {
630
- case touchStart:
631
- type = 'touchstart';
632
- break;
633
- case touchMove:
634
- type = 'touchmove';
635
- break;
636
- case clickEnd:
637
- type = 'touchend';
638
- break;
639
- case pressEnd:
640
- type = 'touchend';
641
- break;
642
- }
643
- // console.log('touch', {type, fn: fn.name, passive});
644
- el.addEventListener(type, fn, passive);
645
- });
646
- } else if (event === 'click') {
647
- el.domListeners[event].push({
648
- capture,
649
- listener,
650
- proxyListener: clickEvent,
651
- });
652
- el.addEventListener(event, clickEvent, capture);
653
- } else {
654
- // 其他事件
655
- el.domListeners[event].push({
656
- capture,
657
- listener,
658
- proxyListener: handleEvent,
659
- });
660
- el.addEventListener(event, handleEvent, capture);
661
- }
662
- }
663
- }
664
-
665
- return this;
666
- }
667
-
668
- /**
669
- * 解除事件侦听
670
- * @param {...any} args
671
- * @param {String} event 事件,必选
672
- * listener 侦听函数,不传,则解除所有侦听
673
- * capture:不传默认为false,如果on时为true,off时需传true
674
- * targetSelector:多余参数,兼容f7
675
- * @returns
676
- */
677
- function off(...args) {
678
- let [eventType, targetSelector, listener, capture] = args;
679
- if (typeof args[1] === 'function') {
680
- [eventType, listener, capture] = args;
681
- targetSelector = undefined;
682
- }
683
- if (!capture) capture = false;
684
-
685
- const events = eventType.split(' ');
686
- for (let i = 0; i < events.length; i += 1) {
687
- const event = events[i];
688
- for (let j = 0; j < this.length; j += 1) {
689
- const el = this[j];
690
- const handlers = el?.domListeners[event];
691
- if (handlers?.length) {
692
- for (let k = handlers.length - 1; k >= 0; k -= 1) {
693
- const handler = handlers[k]; // 事件响应对象数组
694
- // 未封装,直接匹配,解除指定的侦听
695
- if (handler?.listener === listener && handler?.capture === capture) {
696
- // 解除额外添加的侦听
697
- if ((event === 'click' || event === 'swipe' || event === 'press') && $.support.touch) {
698
- el.removeEventListener('touchstart', handler.proxyListener[0], handler.capture);
699
-
700
- if (event === 'swipe')
701
- el.removeEventListener('touchmove', handler.proxyListener[1], handler.capture);
702
- else el.removeEventListener('touchend', handler.proxyListener[1], handler.capture);
703
- } else el.removeEventListener(event, handler.proxyListener, handler.capture);
704
- handlers.splice(k, 1);
705
- } else if (
706
- listener &&
707
- handler?.listener?.onceProxy === listener &&
708
- handler?.capture === capture
709
- ) {
710
- // once
711
- el.removeEventListener(event, handler.proxyListener, handler.capture);
712
- handlers.splice(k, 1);
713
- } else if (
714
- listener &&
715
- targetSelector &&
716
- handler?.listener?.liveProxy === listener &&
717
- handler?.listener?.selector === targetSelector &&
718
- handler?.capture === capture
719
- ) {
720
- // 指定选择器 live
721
- el.removeEventListener(event, handler.proxyListener, handler.capture);
722
- handlers.splice(k, 1);
723
- } else if (
724
- listener &&
725
- !targetSelector &&
726
- handler?.listener?.liveProxy === listener &&
727
- handler?.capture === capture
728
- ) {
729
- // 不指定选择器,所有 live
730
- el.removeEventListener(event, handler.proxyListener, handler.capture);
731
- handlers.splice(k, 1);
732
- } else if (!listener) {
733
- // 不指定函数,解除该元素所有侦听
734
- el.removeEventListener(event, handler.proxyListener, handler.capture);
735
- handlers.splice(k, 1);
736
- }
737
- }
738
- }
739
- }
740
- }
741
- return this;
742
- }
743
-
744
- function once(...args) {
745
- const self = this;
746
- let [eventName, targetSelector, listener, capture] = args;
747
- if (typeof args[1] === 'function') {
748
- [eventName, listener, capture] = args;
749
- targetSelector = undefined;
750
- }
751
- // 封装 回调函数,执行一次后自动 off
752
- function onceHandler(...eventArgs) {
753
- self.off(eventName, targetSelector, onceHandler, capture);
754
- if (onceHandler.onceProxy) {
755
- onceHandler.onceProxy.apply(this, eventArgs);
756
- delete onceHandler.onceProxy;
757
- }
758
- }
759
- onceHandler.onceProxy = listener;
760
- return self.on(eventName, targetSelector, onceHandler, capture);
761
- }
762
-
763
- /**
764
- * 触发事件函数
765
- * 第一个数据参数放入回调函数第一个参数event事件的 detail 属性中!
766
- * 扩展参数放入el的wiaDomEventData属性传递,触发时带入事件回调函数参数中!
767
- * @param {...any} args
768
- * @returns
769
- */
770
- function trigger(...args) {
771
- const events = args[0].split(' ');
772
- const eventData = args[1];
773
- for (let i = 0; i < events.length; i += 1) {
774
- const event = events[i];
775
- for (let j = 0; j < this.length; j += 1) {
776
- const el = this[j];
777
- let evt;
778
- try {
779
- evt = new window.CustomEvent(event, {
780
- detail: eventData,
781
- bubbles: true,
782
- cancelable: true,
783
- });
784
- } catch (e) {
785
- evt = document.createEvent('Event');
786
- evt.initEvent(event, true, true);
787
- evt.detail = eventData;
788
- }
789
- // eslint-disable-next-line
790
- el.wiaDomEventData = args.filter((data, dataIndex) => dataIndex > 0);
791
- el.dispatchEvent(evt); // el === event.target
792
- el.wiaDomEventData = [];
793
- delete el.wiaDomEventData;
794
- }
795
- }
796
- return this;
797
- }
798
-
799
- function transitionEnd(callback) {
800
- const events = ['webkitTransitionEnd', 'transitionend'];
801
- const dom = this;
802
- let i;
803
- function fireCallBack(e) {
804
- /* jshint validthis:true */
805
- if (e.target !== this) return;
806
- callback.call(this, e);
807
- for (i = 0; i < events.length; i += 1) {
808
- dom.off(events[i], fireCallBack);
809
- }
810
- }
811
- if (callback) {
812
- for (i = 0; i < events.length; i += 1) {
813
- dom.on(events[i], fireCallBack);
814
- }
815
- }
816
- return this;
817
- }
818
-
819
- function animationEnd(callback) {
820
- const events = ['webkitAnimationEnd', 'animationend'];
821
- const dom = this;
822
- let i;
823
- function fireCallBack(e) {
824
- if (e.target !== this) return;
825
- callback.call(this, e);
826
- for (i = 0; i < events.length; i += 1) {
827
- dom.off(events[i], fireCallBack);
828
- }
829
- }
830
- if (callback) {
831
- for (i = 0; i < events.length; i += 1) {
832
- dom.on(events[i], fireCallBack);
833
- }
834
- }
835
- return this;
836
- }
837
-
838
- // Sizing/Styles
839
- function width() {
840
- if (this[0] === window) {
841
- return window.innerWidth;
842
- }
843
-
844
- if (this.length > 0) {
845
- return parseFloat(this.css('width'));
846
- }
847
-
848
- return null;
849
- }
850
- function outerWidth(includeMargins) {
851
- if (this.length > 0) {
852
- if (includeMargins) {
853
- // eslint-disable-next-line
854
- const styles = this.styles();
855
- return (
856
- this[0].offsetWidth +
857
- parseFloat(styles.getPropertyValue('margin-right')) +
858
- parseFloat(styles.getPropertyValue('margin-left'))
859
- );
860
- }
861
- return this[0].offsetWidth;
862
- }
863
- return null;
864
- }
865
- function height() {
866
- if (this[0] === window) {
867
- return window.innerHeight;
868
- }
869
-
870
- if (this.length > 0) {
871
- return parseFloat(this.css('height'));
872
- }
873
-
874
- return null;
875
- }
876
- function outerHeight(includeMargins) {
877
- if (this.length > 0) {
878
- if (includeMargins) {
879
- // eslint-disable-next-line
880
- const styles = this.styles();
881
- return (
882
- this[0].offsetHeight +
883
- parseFloat(styles.getPropertyValue('margin-top')) +
884
- parseFloat(styles.getPropertyValue('margin-bottom'))
885
- );
886
- }
887
- return this[0].offsetHeight;
888
- }
889
- return null;
890
- }
891
-
892
- /**
893
- * 兼容 jQuery,dom7 是错误的
894
- * wia 中,window 滚动被 .page-content 页面层替代
895
- */
896
- function offset(coordinates) {
897
- if (coordinates)
898
- return this.each(function (idx) {
899
- var $this = $(this),
900
- coords = $.funcArg(this, coordinates, idx, $this.offset()),
901
- parentOffset = $this.offsetParent().offset(),
902
- props = {
903
- top: coords.top - parentOffset.top,
904
- left: coords.left - parentOffset.left,
905
- };
906
-
907
- if ($this.css('position') === 'static') props.position = 'relative';
908
- $this.css(props);
909
- });
910
- if (!this.length) return null;
911
- if (document.documentElement !== this[0] && !$.contains(document.documentElement, this[0]))
912
- return {top: 0, left: 0};
913
- const obj = this[0].getBoundingClientRect();
914
- const pg = this.closest('.page-content');
915
- const scrollX = pg.length ? pg.dom.scrollLeft : window.pageXOffset;
916
- const scrollY = pg.length ? pg.dom.scrollTop : window.pageYOffset;
917
- return {
918
- left: obj.left + scrollX,
919
- top: obj.top + scrollY,
920
- width: Math.round(obj.width),
921
- height: Math.round(obj.height),
922
- };
923
- }
924
-
925
- function rect() {
926
- if (!this.length) return null;
927
- if (document.documentElement !== this[0] && !$.contains(document.documentElement, this[0]))
928
- return {top: 0, left: 0};
929
- const obj = this[0].getBoundingClientRect();
930
- return {
931
- left: obj.left,
932
- top: obj.top,
933
- width: Math.round(obj.width),
934
- height: Math.round(obj.height),
935
- };
936
- }
937
-
938
- function position() {
939
- if (!this.length) return;
940
-
941
- var elem = this[0],
942
- // Get *real* offsetParent
943
- offsetParent = this.offsetParent(),
944
- // Get correct offsets
945
- offset = this.offset(),
946
- parentOffset = rootNodeRE.test(offsetParent[0].nodeName)
947
- ? {top: 0, left: 0}
948
- : offsetParent.offset();
949
-
950
- // Subtract element margins
951
- // note: when an element has margin: auto the offsetLeft and marginLeft
952
- // are the same in Safari causing offset.left to incorrectly be 0
953
- offset.top -= parseFloat($(elem).css('margin-top')) || 0;
954
- offset.left -= parseFloat($(elem).css('margin-left')) || 0;
955
-
956
- // Add offsetParent borders
957
- parentOffset.top += parseFloat($(offsetParent[0]).css('border-top-width')) || 0;
958
- parentOffset.left += parseFloat($(offsetParent[0]).css('border-left-width')) || 0;
959
-
960
- // Subtract the two offsets
961
- return {
962
- top: offset.top - parentOffset.top,
963
- left: offset.left - parentOffset.left,
964
- };
965
- }
966
-
967
- function offsetParent() {
968
- return this.map(function () {
969
- let pt = this.offsetParent || document.body;
970
- while (pt && !rootNodeRE.test(pt.nodeName) && $(pt).css('position') == 'static')
971
- pt = pt.offsetParent;
972
- return pt;
973
- });
974
- }
975
-
976
- function hide() {
977
- return this.each(function () {
978
- if (this.style.display !== 'none') this.style.display = 'none';
979
- });
980
- }
981
-
982
- function defaultDisplay(nodeName) {
983
- if (!elementDisplay[nodeName]) {
984
- const el = document.createElement(nodeName);
985
- document.body.appendChild(el);
986
- let display = getComputedStyle(el, '').getPropertyValue('display');
987
- el.parentNode.removeChild(el);
988
- display === 'none' && (display = 'block');
989
- elementDisplay[nodeName] = display;
990
- }
991
- return elementDisplay[nodeName];
992
- }
993
-
994
- function show() {
995
- return this.each(function () {
996
- this.style.display === 'none' && (this.style.display = '');
997
- // Still not visible
998
- if (getComputedStyle(this, '').getPropertyValue('display') === 'none')
999
- this.style.display = defaultDisplay(this.nodeName); // block
1000
- });
1001
-
1002
- /*
1003
- for (let i = 0; i < this.length; i += 1) {
1004
- const el = this[i];
1005
- if (el.style.display === 'none') {
1006
- el.style.display = '';
1007
- }
1008
- if (window.getComputedStyle(el, null).getPropertyValue('display') === 'none') {
1009
- // Still not visible
1010
- el.style.display = 'block';
1011
- }
1012
- }
1013
- return this;
1014
- */
1015
- }
1016
-
1017
- function replaceWith(newContent) {
1018
- return this.before(newContent).remove();
1019
- }
1020
-
1021
- function styles() {
1022
- if (this[0]) return window.getComputedStyle(this[0], null);
1023
- return {};
1024
- }
1025
-
1026
- function css(props, value) {
1027
- const REGEXP_SUFFIX = /^width|height|left|top|marginLeft|marginTop|paddingLeft|paddingTop$/;
1028
-
1029
- let i;
1030
- if (arguments.length === 1) {
1031
- if (typeof props === 'string') {
1032
- if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
1033
- } else {
1034
- for (i = 0; i < this.length; i += 1) {
1035
- // eslint-disable-next-line
1036
- for (let prop in props) {
1037
- let v = props[prop];
1038
- if (REGEXP_SUFFIX.test(prop) && $.isNumber(v)) v = `${v}px`;
1039
-
1040
- this[i].style[prop] = v;
1041
- }
1042
- }
1043
- return this;
1044
- }
1045
- }
1046
- if (arguments.length === 2 && typeof props === 'string') {
1047
- for (i = 0; i < this.length; i += 1) {
1048
- let v = value;
1049
- if (REGEXP_SUFFIX.test(props) && $.isNumber(v)) v = `${v}px`;
1050
-
1051
- this[i].style[props] = v;
1052
- }
1053
- return this;
1054
- }
1055
- return this;
1056
- }
1057
-
1058
- function each(callback) {
1059
- emptyArray.some.call(this, function (el, idx) {
1060
- return callback.call(el, idx, el) === false; // 退出
1061
- });
1062
- return this;
1063
- }
1064
-
1065
- function forEach(callback) {
1066
- emptyArray.some.call(this, function (el, idx) {
1067
- return callback.call(el, el, idx) === false;
1068
- });
1069
- return this;
1070
- }
1071
-
1072
- function some(callback) {
1073
- return emptyArray.some.call(this, function (el, idx) {
1074
- return callback.call(el, el, idx);
1075
- });
1076
- }
1077
-
1078
- function every(callback) {
1079
- return emptyArray.every.call(this, function (el, idx) {
1080
- return callback.call(el, el, idx);
1081
- });
1082
- }
1083
-
1084
- /*
1085
- // Iterate over the collection passing elements to `callback`
1086
- function each(callback) {
1087
- // Don't bother continuing without a callback
1088
- if (!callback) return this;
1089
- // Iterate over the current collection
1090
- for (let i = 0; i < this.length; i += 1) {
1091
- // If the callback returns false
1092
- if (callback.call(this[i], i, this[i]) === false) {
1093
- // End the loop early
1094
- return this;
1095
- }
1096
- }
1097
- // Return `this` to allow chained DOM operations
1098
- return this;
1099
- }
1100
- function forEach(callback) {
1101
- // Don't bother continuing without a callback
1102
- if (!callback) return this;
1103
- // Iterate over the current collection
1104
- for (let i = 0; i < this.length; i += 1) {
1105
- // If the callback returns false
1106
- if (callback.call(this[i], this[i], i) === false) {
1107
- // End the loop early
1108
- return this;
1109
- }
1110
- }
1111
- // Return `this` to allow chained DOM operations
1112
- return this;
1113
- }
1114
- */
1115
-
1116
- /**
1117
- * 排除 dom 节点
1118
- * @param {*} sel 函数、nodeList、选择器
1119
- * @returns Dom对象
1120
- */
1121
- function not(sel) {
1122
- const R = [];
1123
- if ($.isFunction(sel) && sel.call)
1124
- this.each(function (id) {
1125
- if (!sel.call(this, id)) R.push(this);
1126
- });
1127
- else {
1128
- var excludes =
1129
- typeof sel == 'string'
1130
- ? this.filter(sel)
1131
- : likeArray(sel) && isFunction(sel.item)
1132
- ? emptyArray.slice.call(sel)
1133
- : $(sel);
1134
- this.forEach(function (el) {
1135
- if (excludes.indexOf(el) < 0) R.push(el);
1136
- });
1137
- }
1138
- return $(R);
1139
- }
1140
-
1141
- /**
1142
- * 过滤符合要求的dom节点的Dom对象
1143
- * @param {*} sel
1144
- * @returns
1145
- */
1146
- function filter(sel) {
1147
- let R = [];
1148
- try {
1149
- // 回调函数
1150
- if ($.isFunction(sel) && sel.call) {
1151
- this.each(function (id, it) {
1152
- if (sel.call(this, id, it)) R.push(this);
1153
- });
1154
- } else
1155
- R = emptyArray.filter.call(this, function (el) {
1156
- return $.matches(el, sel);
1157
- });
1158
- } catch (e) {}
1159
-
1160
- return $(R);
1161
- }
1162
-
1163
- function map(cb) {
1164
- return $(
1165
- $.map(this, function (el, i) {
1166
- return cb.call(el, i, el);
1167
- })
1168
- );
1169
- }
1170
-
1171
- function clone() {
1172
- return this.map(function () {
1173
- return this.cloneNode(true);
1174
- });
1175
- }
1176
-
1177
- function html(v) {
1178
- return 0 in arguments
1179
- ? this.each(function (idx) {
1180
- var originHtml = this.innerHTML;
1181
- $(this).empty().append($.funcArg(this, v, idx, originHtml));
1182
- })
1183
- : 0 in this
1184
- ? this[0].innerHTML
1185
- : undefined;
1186
- }
1187
-
1188
- /**
1189
- * 返回数组节点指定属性数组
1190
- * @param {*} p
1191
- * @returns
1192
- */
1193
- function pluck(p) {
1194
- return $.map(this, function (el) {
1195
- return el[p];
1196
- });
1197
- }
1198
-
1199
- function text(tx) {
1200
- return 0 in arguments
1201
- ? this.each(function (idx) {
1202
- var newText = $.funcArg(this, tx, idx, this.textContent);
1203
- this.textContent = newText == null ? '' : '' + newText;
1204
- })
1205
- : 0 in this
1206
- ? this.pluck('textContent').join('')
1207
- : undefined;
1208
- }
1209
-
1210
- function is(sel) {
1211
- return this.length > 0 && $.matches(this[0], sel);
1212
- }
1213
-
1214
- function indexOf(el) {
1215
- for (let i = 0; i < this.length; i += 1) {
1216
- if (this[i] === el) return i;
1217
- }
1218
- return -1;
1219
- }
1220
- function index() {
1221
- let chd = this[0];
1222
- let i;
1223
- if (chd) {
1224
- i = 0;
1225
- // eslint-disable-next-line
1226
- while ((chd = chd.previousSibling) !== null) {
1227
- if (chd.nodeType === 1) i += 1;
1228
- }
1229
- return i;
1230
- }
1231
- return undefined;
1232
- }
1233
-
1234
- function slice(...args) {
1235
- return $(emptyArray.slice.apply(this, args));
1236
- }
1237
-
1238
- /**
1239
- * 返回指定索引dom元素的Dom对象
1240
- * @param {*} idx
1241
- */
1242
- function eq(idx) {
1243
- if (typeof idx === 'undefined') return this;
1244
- const {length} = this;
1245
- if (idx > length - 1 || length + idx < 0) {
1246
- return $();
1247
- }
1248
- return idx === -1 ? this.slice(idx) : this.slice(idx, +idx + 1);
1249
- }
1250
-
1251
- function first() {
1252
- const el = this[0];
1253
- return el && !$.isObject(el) ? el : $(el);
1254
- }
1255
-
1256
- function last() {
1257
- const el = this[this.length - 1];
1258
- return el && !$.isObject(el) ? el : $(el);
1259
- }
1260
-
1261
- /**
1262
- * 同级后节点,如果符合条件返回节点,不符合条件,返回空节点,不含文本节点
1263
- */
1264
- function next(selector) {
1265
- if (this.length > 0) {
1266
- if (selector) {
1267
- if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) {
1268
- return $([this[0].nextElementSibling]);
1269
- }
1270
- return $();
1271
- }
1272
-
1273
- if (this[0].nextElementSibling) return $([this[0].nextElementSibling]);
1274
- return $();
1275
- }
1276
- return $();
1277
- }
1278
-
1279
- /**
1280
- * 同级向后查找符合条件的第一个元素节点,不含文本节点
1281
- */
1282
- function nextNode(selector) {
1283
- const nextEls = [];
1284
- const el = this[0];
1285
- if (!el) return $();
1286
-
1287
- let next = el.nextElementSibling; // eslint-disable-line
1288
- while (next) {
1289
- if (selector) {
1290
- if ($(next).is(selector)) {
1291
- nextEls.push(next);
1292
- break;
1293
- }
1294
- } else {
1295
- nextEls.push(next);
1296
- break;
1297
- }
1298
- next = next.nextElementSibling;
1299
- }
1300
- return $(nextEls);
1301
- }
1302
-
1303
- /**
1304
- * 同级向后查找所有符合条件的元素节点,不含文本节点
1305
- */
1306
- function nextAll(selector) {
1307
- const nextEls = [];
1308
- let el = this[0];
1309
- if (!el) return $();
1310
- while (el.nextElementSibling) {
1311
- const next = el.nextElementSibling; // eslint-disable-line
1312
- if (selector) {
1313
- if ($(next).is(selector)) nextEls.push(next);
1314
- } else nextEls.push(next);
1315
- el = next;
1316
- }
1317
- return $(nextEls);
1318
- }
1319
-
1320
- /**
1321
- * 同级前节点,如果符合条件返回节点,不符合条件,返回空节点,不含文本节点
1322
- */
1323
- function prev(selector) {
1324
- if (this.length > 0) {
1325
- const el = this[0];
1326
- if (selector) {
1327
- if (el.previousElementSibling && $(el.previousElementSibling).is(selector)) {
1328
- return $([el.previousElementSibling]);
1329
- }
1330
- return $();
1331
- }
1332
-
1333
- if (el.previousElementSibling) return $([el.previousElementSibling]);
1334
- return $();
1335
- }
1336
- return $();
1337
- }
1338
-
1339
- /**
1340
- * 同级向前查找符合条件的第一个元素节点,不含文本节点
1341
- */
1342
- function prevNode(selector) {
1343
- const prevEls = [];
1344
- const el = this[0];
1345
- if (!el) return $();
1346
-
1347
- let prev = el.previousElementSibling; // eslint-disable-line
1348
- while (prev) {
1349
- if (selector) {
1350
- if ($(prev).is(selector)) {
1351
- prevEls.push(prev);
1352
- break;
1353
- }
1354
- } else {
1355
- prevEls.push(prev);
1356
- break;
1357
- }
1358
- prev = prev.previousElementSibling;
1359
- }
1360
- return $(prevEls);
1361
- }
1362
-
1363
- /**
1364
- * 同级向前查找所有符合条件的元素节点,不含文本节点
1365
- */
1366
- function prevAll(selector) {
1367
- const prevEls = [];
1368
- let el = this[0];
1369
- if (!el) return $();
1370
- while (el.previousElementSibling) {
1371
- const prev = el.previousElementSibling; // eslint-disable-line
1372
- if (selector) {
1373
- if ($(prev).is(selector)) prevEls.push(prev);
1374
- } else prevEls.push(prev);
1375
- el = prev;
1376
- }
1377
- return $(prevEls);
1378
- }
1379
-
1380
- /**
1381
- * 同级前后所有兄弟元素节点,不含文本节点
1382
- */
1383
- function siblings(selector) {
1384
- return this.nextAll(selector).add(this.prevAll(selector));
1385
- }
1386
-
1387
- /**
1388
- * 所有dom节点符合条件的父元素
1389
- */
1390
- function parent(selector) {
1391
- const parents = []; // eslint-disable-line
1392
- for (let i = 0; i < this.length; i += 1) {
1393
- if (this[i].parentNode !== null) {
1394
- if (selector) {
1395
- if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
1396
- } else {
1397
- parents.push(this[i].parentNode);
1398
- }
1399
- }
1400
- }
1401
- return $($.uniq(parents));
1402
- }
1403
-
1404
- /**
1405
- * 从当前元素的父元素开始沿 DOM 树向上,获得匹配选择器的所有祖先元素。
1406
- */
1407
- function parents(selector) {
1408
- const parents = []; // eslint-disable-line
1409
- for (let i = 0; i < this.length; i += 1) {
1410
- let parent = this[i].parentNode; // eslint-disable-line
1411
- while (parent) {
1412
- if (selector) {
1413
- if ($(parent).is(selector)) parents.push(parent);
1414
- } else parents.push(parent);
1415
-
1416
- parent = parent.parentNode;
1417
- }
1418
- }
1419
- return $($.uniq(parents));
1420
- }
1421
-
1422
- /**
1423
- * 从当前元素的父元素开始沿 DOM 树向上,获得匹配选择器的第一个祖先元素。
1424
- * 选择器为空,则返回 空
1425
- */
1426
- function parentNode(sel) {
1427
- const R = [];
1428
-
1429
- for (let i = 0; i < this.length; i += 1) {
1430
- let pn = this[i].parentNode;
1431
- while (pn) {
1432
- if (sel) {
1433
- if ($(pn).is(sel)) {
1434
- R.push(pn);
1435
- return $(R, sel);
1436
- }
1437
- } else {
1438
- R.push(pn);
1439
- return $(R, sel);
1440
- }
1441
-
1442
- pn = pn.parentNode;
1443
- }
1444
- }
1445
- return $(R, sel);
1446
- }
1447
-
1448
- /**
1449
- * 从当前元素开始沿 DOM 树向上,获得匹配选择器的第一个祖先元素。
1450
- * 当前节点符合,则返回当前节点
1451
- * 选择器为空,则返回 空
1452
- */
1453
- function closest(sel) {
1454
- let self = this; // eslint-disable-line
1455
- if (typeof sel === 'undefined') return $();
1456
-
1457
- // ~开头,按 name 属性查找
1458
- if (sel[0] === '~') sel = `[name=${sel.substr(1)}]`;
1459
-
1460
- if (!self.is(sel)) {
1461
-
1462
- for (let i = 0; i < this.length; i += 1) {
1463
- let parent = this[i].parentNode; // eslint-disable-line
1464
- while (parent) {
1465
- const d = $(parent);
1466
- if (d.is(sel)) return d;
1467
-
1468
- parent = parent.parentNode;
1469
- }
1470
- }
1471
-
1472
- return $();
1473
- }
1474
-
1475
- return self;
1476
- }
1477
-
1478
- function upper(sel) {
1479
- return closest.bind(this)(sel);
1480
- }
1481
-
1482
- /**
1483
- * 后代中所有适合选择器的元素
1484
- * @param {*} sel
1485
- */
1486
- function find(sel) {
1487
- let R = null;
1488
- if (!sel) return $();
1489
-
1490
- // ~开头,按 name 属性查找
1491
- if (sel[0] === '~') sel = `[name=${sel.substr(1)}]`;
1492
-
1493
- const self = this;
1494
- // 选择器为对象
1495
- if (typeof sel === 'object')
1496
- R = $(sel).filter(function () {
1497
- const node = this;
1498
- return emptyArray.some.call(self, function (pn) {
1499
- return $.contains(pn, node);
1500
- });
1501
- });
1502
- else if (this.length === 1) R = $($.qsa(sel, this[0]));
1503
- else
1504
- R = this.map(function () {
1505
- return $.qsa(sel, this);
1506
- });
1507
-
1508
- return R || $();
1509
- }
1510
-
1511
- /**
1512
- * 后代中单个适合选择器的元素,效率高于find
1513
- * 不支持对象参数
1514
- * @param {*} sel
1515
- */
1516
- function findNode(sel) {
1517
- let R = null;
1518
- if (!sel) return $();
1519
-
1520
- // ~开头,按 name 属性查找
1521
- if (sel[0] === '~') sel = `[name=${sel.substr(1)}]`;
1522
-
1523
- if (this.length === 1) R = $($.qu(sel, this[0]));
1524
- else
1525
- R = this.map(function () {
1526
- return $.qu(sel, this);
1527
- });
1528
-
1529
- return R || $();
1530
- }
1531
-
1532
- /**
1533
- * 返回所有dom的所有符合条件的直接子元素,不包括文本节点
1534
- * @param {*} sel
1535
- */
1536
- function children(sel) {
1537
- const cs = []; // eslint-disable-line
1538
- for (let i = 0; i < this.length; i += 1) {
1539
- const childs = this[i].children;
1540
-
1541
- for (let j = 0; j < childs.length; j += 1) {
1542
- if (!sel) {
1543
- cs.push(childs[j]);
1544
- } else if ($(childs[j]).is(sel)) cs.push(childs[j]);
1545
- }
1546
- }
1547
- return $($.uniq(cs));
1548
- }
1549
-
1550
- /**
1551
- * 返回被选元素的第一个符合条件直接子元素,不包括文本节点
1552
- * @param {*} sel
1553
- */
1554
- function childNode(sel) {
1555
- return child.bind(this)(sel);
1556
- }
1557
-
1558
- /**
1559
- * 返回被选元素的第一个符合条件直接单个子元素,不包括文本节点
1560
- * 或者 替换节点的所有子元素
1561
- * @param {*} sel
1562
- */
1563
- function child(sel) {
1564
- if ($.isDom(sel)) {
1565
- this.empty().append(sel);
1566
- return this;
1567
- }
1568
-
1569
- const cs = []; // eslint-disable-line
1570
- for (let i = 0; i < this.length; i += 1) {
1571
- const childs = this[i].children;
1572
-
1573
- for (let j = 0; j < childs.length; j += 1) {
1574
- if (!sel) {
1575
- cs.push(childs[j]);
1576
- break;
1577
- } else if ($(childs[j]).is(sel)) {
1578
- cs.push(childs[j]);
1579
- break;
1580
- }
1581
- }
1582
- }
1583
- return $(cs, sel);
1584
- }
1585
-
1586
- function remove() {
1587
- return this.each(function () {
1588
- if (this.parentNode != null) this.parentNode.removeChild(this);
1589
- });
1590
- }
1591
-
1592
- function detach() {
1593
- return this.remove();
1594
- }
1595
-
1596
- function add(...args) {
1597
- const dom = this;
1598
- let i;
1599
- let j;
1600
- for (i = 0; i < args.length; i += 1) {
1601
- const toAdd = $(args[i]);
1602
- for (j = 0; j < toAdd.length; j += 1) {
1603
- dom[dom.length] = toAdd[j];
1604
- dom.length += 1;
1605
- }
1606
- }
1607
- return dom;
1608
- }
1609
-
1610
- function empty() {
1611
- return this.each(function () {
1612
- this.innerHTML = '';
1613
- });
1614
- }
1615
-
1616
- /**
1617
- * 是否包含子元素,不含文本节点
1618
- */
1619
- function hasChild() {
1620
- if (!this.dom) return false;
1621
- return this.dom.children.length > 0;
1622
- }
1623
-
1624
- /**
1625
- * 第一个子元素节点,不含文本节点
1626
- */
1627
- function firstChild() {
1628
- if (!this.dom || this.dom.children.length === 0) return null;
1629
- return $([this.dom.children[0]]);
1630
- }
1631
-
1632
- /**
1633
- * 最后一个子元素节点,不含文本节点
1634
- */
1635
- function lastChild() {
1636
- if (!this.dom || this.dom.children.length === 0) return null;
1637
- return $([this.dom.children[this.dom.children.length - 1]]);
1638
- }
1639
-
1640
- /**
1641
- * 元素子节点数量,不含文本节点
1642
- */
1643
- function childCount() {
1644
- if (!this.dom) return 0;
1645
- return this.dom.children.length;
1646
- }
1647
-
1648
- /**
1649
- * 光标放入尾部
1650
- * @param el
1651
- */
1652
- function cursorEnd() {
1653
- if (!this.dom) return null;
1654
-
1655
- const el = this.dom;
1656
- el.focus();
1657
-
1658
- if (typeof window.getSelection !== 'undefined' && typeof document.createRange !== 'undefined') {
1659
- const rg = document.createRange();
1660
- rg.selectNodeContents(el);
1661
- // 合并光标
1662
- rg.collapse(false);
1663
- const sel = window.getSelection();
1664
- sel.removeAllRanges();
1665
- sel.addRange(rg);
1666
- } else if (typeof document.body.createTextRangrge !== 'undefined') {
1667
- const rg = document.body.createTextRange();
1668
- rg.moveToElementText(el);
1669
- // 合并光标
1670
- rg.collapse(false);
1671
- // textRange.moveStart('character', 3);
1672
- rg.select();
1673
- }
1674
- }
1675
-
1676
- /**
1677
- * 获取光标位置
1678
- * @returns {number}
1679
- */
1680
- function getCursorPos() {
1681
- let R = 0;
1682
-
1683
- if (!this.dom) return 0;
1684
-
1685
- const el = this.dom;
1686
-
1687
- // obj.focus();
1688
- if (el.selectionStart) {
1689
- // IE以外
1690
- R = el.selectionStart;
1691
- } else {
1692
- // IE
1693
- let rg = null;
1694
- if (el.tagName.toLowerCase() === 'textarea') {
1695
- // TEXTAREA
1696
- rg = event.srcElement.createTextRange();
1697
- rg.moveToPoint(event.x, event.y);
1698
- } else {
1699
- // Text
1700
- rg = document.selection.createRange();
1701
- }
1702
- rg.moveStart('character', -event.srcElement.value.length);
1703
- // rg.setEndPoint("StartToStart", obj.createTextRange())
1704
- R = rg.text.length;
1705
- }
1706
- return R;
1707
- }
1708
-
1709
- /**
1710
- * 得到光标的位置
1711
- */
1712
- function getCursorPosition() {
1713
- if (!this.dom) return 0;
1714
-
1715
- const el = this.dom;
1716
-
1717
- const qswh = '@#%#^&#*$';
1718
- // obj.focus();
1719
- const rng = document.selection.createRange();
1720
- rng.text = qswh;
1721
- const nPosition = el.value.indexOf(qswh);
1722
- rng.moveStart('character', -qswh.length);
1723
- rng.text = '';
1724
- return nPosition;
1725
- }
1726
-
1727
- /**
1728
- * 设置光标位置
1729
- */
1730
- function setCursorPos(pos) {
1731
- if (!this.dom) return;
1732
-
1733
- const rg = this.dom.createTextRange();
1734
- rg.collapse(true);
1735
- rg.moveStart('character', pos);
1736
- rg.select();
1737
- }
1738
-
1739
- /**
1740
- * 移到第一行
1741
- */
1742
- function moveFirst() {
1743
- this.rowindex = 0;
1744
- }
1745
-
1746
- /**
1747
- * querySelector
1748
- * return only first
1749
- */
1750
- function qu(sel) {
1751
- let n = [];
1752
- try {
1753
- n = this.dom?.querySelector(sel);
1754
- } catch (e) {}
1755
-
1756
- return $(n || []);
1757
- }
1758
-
1759
- function qus(sel) {
1760
- return $(sel, this.dom);
1761
- }
1762
-
1763
- /**
1764
- * querySelector attribute
1765
- * return only first
1766
- */
1767
- function att(n, v) {
1768
- let R = [];
1769
- try {
1770
- if (this.attr(n) === v) return this; // 自己符合,返回自身
1771
- R = this.dom?.querySelector(`[${n}=${v}]`);
1772
- } catch (e) {}
1773
- return $(R || []);
1774
- }
1775
-
1776
- function atts(n, v) {
1777
- let R = [];
1778
- try {
1779
- R = $(`[${n}=${v}]`, this.dom);
1780
- if (this.attr(n) === v) R.push(this.dom); // 自己符合,添加自身
1781
- } catch (e) {}
1782
- return $(R || []);
1783
- }
1784
-
1785
- /**
1786
- * querySelector name
1787
- * return only first
1788
- */
1789
- function name(v) {
1790
- return this.att('name', v);
1791
- }
1792
-
1793
- function fastLink() {
1794
- $.fastLink(this);
1795
- return this;
1796
- }
1797
-
1798
- /**
1799
- * name 属性组件直接绑定到当前Dom实例,方便调用
1800
- * 只挂载一个,多个同名name,最后一个起作用,因此一个页面内,name不要重复
1801
- * 同节点多次调用不覆盖,同名不同dom节点,覆盖
1802
- * 覆盖后,原直接节点属性的 bind 会失效,需使用新的$dom重新bind
1803
- * 动态内容一般在 ready 中创建,创建后name会自动挂载
1804
- * show/back 中创建的动态内容,未自动挂载,需调用 bindName 挂载!
1805
- */
1806
- function bindName() {
1807
- const ns = this.qus('[name]');
1808
- ns?.forEach(n => {
1809
- const $n = $(n);
1810
- const nm = $n.attr('name');
1811
- if (!this.n) this.n = {};
1812
- if (!this.n[nm] || this.n[nm].dom !== n) this.n[nm] = $n;
1813
- });
1814
-
1815
- return this;
1816
- }
1817
-
1818
- function names(v) {
1819
- return this.atts('name', v);
1820
- }
1821
-
1822
- /**
1823
- * querySelector ClassName
1824
- * cls: 'aaa, bbb' => '.aaa, .bbb'
1825
- * return only first node
1826
- */
1827
- function clas(cls) {
1828
- let R = [];
1829
-
1830
- if (!cls) return $();
1831
-
1832
- try {
1833
- const rs = [];
1834
- const cs = cls.split(',');
1835
- cs.forEach(c => {
1836
- if (c) {
1837
- if (c.includes('.')) rs.push(c.trim());
1838
- else rs.push(`.${c.trim()}`);
1839
- }
1840
- });
1841
-
1842
- R = this.dom?.querySelector(rs.join(','));
1843
- } catch (e) {}
1844
-
1845
- return $(R || []);
1846
- }
1847
-
1848
- /**
1849
- * querySelectorAll ClassName
1850
- * cls: 'aaa, bbb' => '.aaa, .bbb'
1851
- * return all node
1852
- */
1853
- function classes(cls) {
1854
- let R = [];
1855
-
1856
- if (!cls) return $();
1857
-
1858
- try {
1859
- const rs = [];
1860
- const cs = cls.split(',');
1861
- cs.forEach(c => {
1862
- if (c.includes('.')) rs.push(c.trim());
1863
- else rs.push(`.${c.trim()}`);
1864
- });
1865
-
1866
- const ns = this.dom?.querySelectorAll(rs.join(','));
1867
- // if (ns && ns.length > 0) R = slice.call(ns);
1868
- if (ns && ns.length > 0) R = Array.from(ns);
1869
- } catch (e) {}
1870
-
1871
- return $(R || []);
1872
- }
1873
-
1874
- /**
1875
- * querySelector TagName
1876
- * tag: 'div'
1877
- * return only first
1878
- */
1879
- function tag(t) {
1880
- let R = this.dom?.getElementsByTagName(t);
1881
- if (R) R = R[0];
1882
-
1883
- return $(R);
1884
- }
1885
-
1886
- function tags(t) {
1887
- let R = this.dom?.getElementsByTagName(t);
1888
- if (R && R.length > 0) R = [].slice.call(R);
1889
- else R = [];
1890
-
1891
- return $(R);
1892
- }
1893
-
1894
- const Methods = /*#__PURE__*/Object.freeze({
1895
- __proto__: null,
1896
- add: add,
1897
- animationEnd: animationEnd,
1898
- att: att,
1899
- attr: attr,
1900
- atts: atts,
1901
- bindName: bindName,
1902
- child: child,
1903
- childCount: childCount,
1904
- childNode: childNode,
1905
- children: children,
1906
- class: clas,
1907
- classes: classes,
1908
- clone: clone,
1909
- closest: closest,
1910
- concat: concat,
1911
- css: css,
1912
- cursorEnd: cursorEnd,
1913
- data: data,
1914
- dataset: dataset,
1915
- detach: detach,
1916
- each: each,
1917
- empty: empty,
1918
- eq: eq,
1919
- every: every,
1920
- fastLink: fastLink,
1921
- filter: filter,
1922
- find: find,
1923
- findNode: findNode,
1924
- first: first,
1925
- firstChild: firstChild,
1926
- forEach: forEach,
1927
- get: get,
1928
- getCursorPos: getCursorPos,
1929
- getCursorPosition: getCursorPosition,
1930
- hasAttr: hasAttr,
1931
- hasChild: hasChild,
1932
- height: height,
1933
- hide: hide,
1934
- html: html,
1935
- index: index,
1936
- indexOf: indexOf,
1937
- is: is,
1938
- last: last,
1939
- lastChild: lastChild,
1940
- map: map,
1941
- moveFirst: moveFirst,
1942
- name: name,
1943
- names: names,
1944
- next: next,
1945
- nextAll: nextAll,
1946
- nextNode: nextNode,
1947
- not: not,
1948
- off: off,
1949
- offset: offset,
1950
- offsetParent: offsetParent,
1951
- on: on,
1952
- once: once,
1953
- outerHeight: outerHeight,
1954
- outerWidth: outerWidth,
1955
- parent: parent,
1956
- parentNode: parentNode,
1957
- parents: parents,
1958
- pluck: pluck,
1959
- position: position,
1960
- prev: prev,
1961
- prevAll: prevAll,
1962
- prevNode: prevNode,
1963
- prop: prop,
1964
- qu: qu,
1965
- qus: qus,
1966
- ready: ready,
1967
- rect: rect,
1968
- remove: remove,
1969
- removeAttr: removeAttr,
1970
- removeData: removeData,
1971
- removeProp: removeProp,
1972
- replaceWith: replaceWith,
1973
- setCursorPos: setCursorPos,
1974
- show: show,
1975
- siblings: siblings,
1976
- size: size,
1977
- slice: slice,
1978
- some: some,
1979
- styles: styles,
1980
- tag: tag,
1981
- tags: tags,
1982
- text: text,
1983
- toArray: toArray,
1984
- transform: transform,
1985
- transition: transition,
1986
- transitionEnd: transitionEnd,
1987
- trigger: trigger,
1988
- upper: upper,
1989
- val: val,
1990
- width: width
1991
- });
1992
-
1993
- /**
1994
- * 支持按动画滚动窗口
1995
- * @param {...any} args
1996
- * left, top, duration, easing, callback
1997
- * @returns
1998
- */
1999
- function scrollTo(...args) {
2000
- let [left, top, duration, easing, callback] = args;
2001
- if (args.length === 4 && typeof easing === 'function') {
2002
- callback = easing;
2003
- [left, top, duration, callback, easing] = args;
2004
- }
2005
- if (typeof easing === 'undefined') easing = 'swing';
2006
-
2007
- return this.each(function animate() {
2008
- const el = this; // dom
2009
-
2010
- let currentTop;
2011
- let currentLeft;
2012
- let maxTop;
2013
- let maxLeft;
2014
- let newTop;
2015
- let newLeft;
2016
- let scrollTop; // eslint-disable-line
2017
- let scrollLeft; // eslint-disable-line
2018
-
2019
- if (typeof easing === 'undefined') easing = 'swing';
2020
- const hasScrollTop = 'scrollTop' in el;
2021
- const hasScrollLeft = 'scrollLeft' in el;
2022
-
2023
- let animateTop = top > 0 || top === 0;
2024
- let animateLeft = left > 0 || left === 0;
2025
-
2026
- if (animateTop) {
2027
- currentTop = el.scrollTop;
2028
- if (!duration) {
2029
- if (hasScrollTop) el.scrollTop = top;
2030
- else el.scrollTo(el.scrollX, top);
2031
- }
2032
- }
2033
-
2034
- if (animateLeft) {
2035
- currentLeft = el.scrollLeft;
2036
- if (!duration) {
2037
- if (hasScrollLeft) el.scrollLeft = left;
2038
- else el.scrollTo(left, el.scrollY);
2039
- }
2040
- }
2041
-
2042
- // 不需要动画
2043
- if (!duration) return;
2044
-
2045
- // 延时动画
2046
- if (animateTop) {
2047
- maxTop = el.scrollHeight - el.offsetHeight;
2048
- newTop = Math.max(Math.min(top, maxTop), 0);
2049
- }
2050
-
2051
- if (animateLeft) {
2052
- maxLeft = el.scrollWidth - el.offsetWidth;
2053
- newLeft = Math.max(Math.min(left, maxLeft), 0);
2054
- }
2055
-
2056
- let startTime = null;
2057
- if (animateTop && newTop === currentTop) animateTop = false;
2058
- if (animateLeft && newLeft === currentLeft) animateLeft = false;
2059
-
2060
- function render(time = new Date().getTime()) {
2061
- if (startTime === null) {
2062
- startTime = time;
2063
- }
2064
- const progress = Math.max(Math.min((time - startTime) / duration, 1), 0);
2065
- const easeProgress =
2066
- easing === 'linear' ? progress : 0.5 - Math.cos(progress * Math.PI) / 2;
2067
-
2068
- let done;
2069
- if (animateTop)
2070
- scrollTop = currentTop + easeProgress * (newTop - currentTop);
2071
- if (animateLeft)
2072
- scrollLeft = currentLeft + easeProgress * (newLeft - currentLeft);
2073
- if (animateTop && newTop > currentTop && scrollTop >= newTop) {
2074
- el.scrollTop = newTop;
2075
- done = true;
2076
- }
2077
- if (animateTop && newTop < currentTop && scrollTop <= newTop) {
2078
- el.scrollTop = newTop;
2079
- done = true;
2080
- }
2081
- if (animateLeft && newLeft > currentLeft && scrollLeft >= newLeft) {
2082
- el.scrollLeft = newLeft;
2083
- done = true;
2084
- }
2085
- if (animateLeft && newLeft < currentLeft && scrollLeft <= newLeft) {
2086
- el.scrollLeft = newLeft;
2087
- done = true;
2088
- }
2089
-
2090
- if (done) {
2091
- if (callback) callback();
2092
- return;
2093
- }
2094
-
2095
- if (animateTop) el.scrollTop = scrollTop;
2096
- if (animateLeft) el.scrollLeft = scrollLeft;
2097
- $.requestAnimationFrame(render);
2098
- }
2099
- $.requestAnimationFrame(render);
2100
- });
2101
- }
2102
-
2103
- /**
2104
- * 垂直滚动
2105
- * @param {...any} args
2106
- * top 滚动距离
2107
- * duration 动画时长
2108
- * easing 动画
2109
- * callback 滚动完成后的回调
2110
- * @returns
2111
- */
2112
- function scrollTop(...args) {
2113
- if (!this.length) return;
2114
-
2115
- let [top, duration, easing, callback] = args;
2116
- if (args.length === 3 && typeof easing === 'function') {
2117
- [top, duration, callback, easing] = args;
2118
- }
2119
- const hasScrollTop = 'scrollTop' in this[0];
2120
-
2121
- // 没有传值,则取回当前dom节点的scrollTop
2122
- if (top === undefined)
2123
- return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset;
2124
-
2125
- return this.scrollTo(undefined, top, duration, easing, callback);
2126
- }
2127
-
2128
- /**
2129
- * 水平滚动
2130
- * @param {...any} args
2131
- * left 滚动距离
2132
- * duration 动画时长
2133
- * easing 动画
2134
- * callback 滚动完成后的回调
2135
- * @returns
2136
- */
2137
- function scrollLeft(...args) {
2138
- if (!this.length) return;
2139
-
2140
- let [left, duration, easing, callback] = args;
2141
- if (args.length === 3 && typeof easing === 'function') {
2142
- [left, duration, callback, easing] = args;
2143
- }
2144
-
2145
- const hasScrollLeft = 'scrollLeft' in this[0];
2146
- if (left === undefined)
2147
- return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset;
2148
-
2149
- return this.scrollTo(left, undefined, duration, easing, callback);
2150
- }
2151
-
2152
- function scrollHeight() {
2153
- return this[0].scrollHeight;
2154
- }
2155
-
2156
- function scrollWidth() {
2157
- return this[0].scrollWidth;
2158
- }
2159
-
2160
- const Scroll = /*#__PURE__*/Object.freeze({
2161
- __proto__: null,
2162
- scrollHeight: scrollHeight,
2163
- scrollLeft: scrollLeft,
2164
- scrollTo: scrollTo,
2165
- scrollTop: scrollTop,
2166
- scrollWidth: scrollWidth
2167
- });
2168
-
2169
- function animate(initialProps, initialParams) {
2170
- const els = this;
2171
- const a = {
2172
- props: Object.assign({}, initialProps),
2173
- params: Object.assign(
2174
- {
2175
- duration: 300,
2176
- easing: 'swing', // or 'linear'
2177
- /* Callbacks
2178
- begin(elements)
2179
- complete(elements)
2180
- progress(elements, complete, remaining, start, tweenValue)
2181
- */
2182
- },
2183
- initialParams
2184
- ),
2185
-
2186
- elements: els,
2187
- animating: false,
2188
- que: [],
2189
-
2190
- easingProgress(easing, progress) {
2191
- if (easing === 'swing') {
2192
- return 0.5 - Math.cos(progress * Math.PI) / 2;
2193
- }
2194
- if (typeof easing === 'function') {
2195
- return easing(progress);
2196
- }
2197
- return progress;
2198
- },
2199
- stop() {
2200
- if (a.frameId) {
2201
- $.cancelAnimationFrame(a.frameId);
2202
- }
2203
- a.animating = false;
2204
- a.elements.each((index, el) => {
2205
- const element = el;
2206
- delete element.dom7AnimateInstance;
2207
- });
2208
- a.que = [];
2209
- },
2210
- done(complete) {
2211
- a.animating = false;
2212
- a.elements.each((index, el) => {
2213
- const element = el;
2214
- delete element.domAnimateInstance;
2215
- });
2216
- if (complete) complete(els);
2217
- if (a.que.length > 0) {
2218
- const que = a.que.shift();
2219
- a.animate(que[0], que[1]);
2220
- }
2221
- },
2222
- animate(props, params) {
2223
- if (a.animating) {
2224
- a.que.push([props, params]);
2225
- return a;
2226
- }
2227
- const elements = [];
2228
-
2229
- // Define & Cache Initials & Units
2230
- a.elements.each((index, el) => {
2231
- let initialFullValue;
2232
- let initialValue;
2233
- let unit;
2234
- let finalValue;
2235
- let finalFullValue;
2236
-
2237
- if (!el.dom7AnimateInstance) a.elements[index].domAnimateInstance = a;
2238
-
2239
- elements[index] = {
2240
- container: el,
2241
- };
2242
- Object.keys(props).forEach(prop => {
2243
- initialFullValue = window
2244
- .getComputedStyle(el, null)
2245
- .getPropertyValue(prop)
2246
- .replace(',', '.');
2247
- initialValue = parseFloat(initialFullValue);
2248
- unit = initialFullValue.replace(initialValue, '');
2249
- finalValue = parseFloat(props[prop]);
2250
- finalFullValue = props[prop] + unit;
2251
- elements[index][prop] = {
2252
- initialFullValue,
2253
- initialValue,
2254
- unit,
2255
- finalValue,
2256
- finalFullValue,
2257
- currentValue: initialValue,
2258
- };
2259
- });
2260
- });
2261
-
2262
- let startTime = null;
2263
- let time;
2264
- let elementsDone = 0;
2265
- let propsDone = 0;
2266
- let done;
2267
- let began = false;
2268
-
2269
- a.animating = true;
2270
-
2271
- function render() {
2272
- time = new Date().getTime();
2273
- let progress;
2274
- let easeProgress;
2275
- // let el;
2276
- if (!began) {
2277
- began = true;
2278
- if (params.begin) params.begin(els);
2279
- }
2280
- if (startTime === null) {
2281
- startTime = time;
2282
- }
2283
- if (params.progress) {
2284
- // eslint-disable-next-line
2285
- params.progress(
2286
- els,
2287
- Math.max(Math.min((time - startTime) / params.duration, 1), 0),
2288
- startTime + params.duration - time < 0
2289
- ? 0
2290
- : startTime + params.duration - time,
2291
- startTime
2292
- );
2293
- }
2294
-
2295
- elements.forEach(element => {
2296
- const el = element;
2297
- if (done || el.done) return;
2298
- Object.keys(props).forEach(prop => {
2299
- if (done || el.done) return;
2300
- progress = Math.max(
2301
- Math.min((time - startTime) / params.duration, 1),
2302
- 0
2303
- );
2304
- easeProgress = a.easingProgress(params.easing, progress);
2305
- const {initialValue, finalValue, unit} = el[prop];
2306
- el[prop].currentValue =
2307
- initialValue + easeProgress * (finalValue - initialValue);
2308
- const currentValue = el[prop].currentValue;
2309
-
2310
- if (
2311
- (finalValue > initialValue && currentValue >= finalValue) ||
2312
- (finalValue < initialValue && currentValue <= finalValue)
2313
- ) {
2314
- el.container.style[prop] = finalValue + unit;
2315
- propsDone += 1;
2316
- if (propsDone === Object.keys(props).length) {
2317
- el.done = true;
2318
- elementsDone += 1;
2319
- }
2320
- if (elementsDone === elements.length) {
2321
- done = true;
2322
- }
2323
- }
2324
- if (done) {
2325
- a.done(params.complete);
2326
- return;
2327
- }
2328
- el.container.style[prop] = currentValue + unit;
2329
- });
2330
- });
2331
- if (done) return;
2332
- // Then call
2333
- a.frameId = $.requestAnimationFrame(render);
2334
- }
2335
- a.frameId = $.requestAnimationFrame(render);
2336
- return a;
2337
- },
2338
- };
2339
-
2340
- if (a.elements.length === 0) {
2341
- return els;
2342
- }
2343
-
2344
- let animateInstance;
2345
- for (let i = 0; i < a.elements.length; i += 1) {
2346
- if (a.elements[i].domAnimateInstance) {
2347
- animateInstance = a.elements[i].domAnimateInstance;
2348
- } else a.elements[i].domAnimateInstance = a;
2349
- }
2350
- if (!animateInstance) {
2351
- animateInstance = a;
2352
- }
2353
-
2354
- if (initialProps === 'stop') {
2355
- animateInstance.stop();
2356
- } else {
2357
- animateInstance.animate(a.props, a.params);
2358
- }
2359
-
2360
- return els;
2361
- }
2362
-
2363
- function stop() {
2364
- const els = this;
2365
- for (let i = 0; i < els.length; i += 1) {
2366
- if (els[i].domAnimateInstance) {
2367
- els[i].domAnimateInstance.stop();
2368
- }
2369
- }
2370
- }
2371
-
2372
- /**
2373
- * 通过css3 Translate 移动后,获取 x 或 y 坐标
2374
- * @param {*} el
2375
- * @param {*} axis
2376
- */
2377
- function getTranslate(axis = 'x') {
2378
- const els = this;
2379
- if (!els || !els.dom) return 0;
2380
-
2381
- const el = els.dom;
2382
-
2383
- let matrix;
2384
- let curTransform;
2385
- let transformMatrix;
2386
-
2387
- const curStyle = window.getComputedStyle(el, null);
2388
-
2389
- if (window.WebKitCSSMatrix) {
2390
- curTransform = curStyle.transform || curStyle.webkitTransform;
2391
- if (curTransform.split(',').length > 6) {
2392
- curTransform = curTransform
2393
- .split(', ')
2394
- .map(a => a.replace(',', '.'))
2395
- .join(', ');
2396
- }
2397
- // Some old versions of Webkit choke when 'none' is passed; pass
2398
- // empty string instead in this case
2399
- transformMatrix = new window.WebKitCSSMatrix(
2400
- curTransform === 'none' ? '' : curTransform
2401
- );
2402
- } else {
2403
- transformMatrix =
2404
- curStyle.MozTransform ||
2405
- curStyle.OTransform ||
2406
- curStyle.MsTransform ||
2407
- curStyle.msTransform ||
2408
- curStyle.transform ||
2409
- curStyle
2410
- .getPropertyValue('transform')
2411
- .replace('translate(', 'matrix(1, 0, 0, 1,');
2412
- matrix = transformMatrix.toString().split(',');
2413
- }
2414
-
2415
- if (axis === 'x') {
2416
- // Latest Chrome and webkits Fix
2417
- if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
2418
- // Crazy IE10 Matrix
2419
- else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
2420
- // Normal Browsers
2421
- else curTransform = parseFloat(matrix[4]);
2422
- }
2423
- if (axis === 'y') {
2424
- // Latest Chrome and webkits Fix
2425
- if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
2426
- // Crazy IE10 Matrix
2427
- else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
2428
- // Normal Browsers
2429
- else curTransform = parseFloat(matrix[5]);
2430
- }
2431
- return curTransform || 0;
2432
- }
2433
-
2434
- const Animate = /*#__PURE__*/Object.freeze({
2435
- __proto__: null,
2436
- animate: animate,
2437
- getTranslate: getTranslate,
2438
- stop: stop
2439
- });
2440
-
2441
- /**
2442
- * 实现页面视图(不限表单)与数据交互
2443
- *
2444
- * 简介:
2445
- * 数据与视图交互是所有带UI界面都需实现的基本功能,不同开发框架都制定了一套固定机制。
2446
- * 其中web前端与所有其他UI(原生ios、安卓、windows)都不一样,由于其开放、自由、无主,
2447
- * 导致没有一套固定机制,不同人、不同组织提供的开发框架、方式几十上百种。
2448
- *
2449
- * 最原始的方法,是通过jQuery操作页面dom对象完成,工作量大,效率低、容易出错,逐渐被淘汰。
2450
- * 现在主流的vue、react、angular都需要学习一套新的语法、知识、理论,并且不仅仅如此,
2451
- * 一旦采用其中一种,就得整体采用其全家桶,陷入技术陷阱。
2452
- * wia的form通过最自然的es6插值方式,在html页面写入插值即可实现数据展示。
2453
- * 这种方式,理解起来非常自然,一看就会,无需学习任何新的知识。
2454
- *
2455
- * setForm 分解对象属性(key)按名称匹配视图内的dom对象或模板,进行赋值。
2456
- * 属性名称对应的视图,可以是input,也可以是模板,模板则按setView方式赋值。
2457
- * 隐藏域(hidden)一般会带模板,通过模板展示内容(数组、对象),隐藏域收集信息。
2458
- * setForm调用了setView,可以理解为setView的批量调用。
2459
- * 比如页面有三个视图,a、b、c,通过 {a:v1,b:v2,c:v3},setForm等于调用了三次setView。
2460
- * 如果展示页面有input部分,需使用setForm。
2461
- * setForm 一般用于表单,不限于表单,也可以用于层。
2462
- * setView 不分解对象属性,将对象整体直接作为r传入页面模板${r.xxx},
2463
- * 进行字符串替换,支持子对象${r.aaa.bbb}。
2464
- * 如果只是页面模板展示,没有input,直接使用setView。
2465
- * 模板 es6中的插值字符串模式,${r.xxx},r为传入的对象,支持子对象、简单运算。
2466
- * 图片src,模板需使用src-tp="http://${r.url}",渲染时自动改为src。
2467
- * 直接使用src浏览器会下载http://${r.url},这个资源肯定找不到。
2468
- *
2469
- * 1. 简单数据直接填入 input的value。
2470
- * 2. 复杂数据,如对象、数组等,则填入 隐藏域 的data 对象,
2471
- * 并通过页面模板实现复杂数据展示。
2472
- * 3. 页面模板(数据替换展示),隐藏在页面,通过克隆模板替换插值字符串实现展现。
2473
- * 名称:name-tp,一般传入对象数组或对象,用于赋值,模板自身隐藏。
2474
- * 属性tp="kv":key-value键值对,对应模板中的${r.k} ${r.v},用于引用对象属性及值,实现动态列表。
2475
- * 属性tp="kv-3":${r.k1} ${r.v1} ${r.k2} ${r.v2} ${r.k3} ${r.v3} 对应对象中的第一个、第二个、第三个属性,
2476
- * 用于横向多列对象多属性展现,比如 PC版本订单详情,横向3列。
2477
- * 名称:name-val:直接按模板替换,与名称为 name效果等同。
2478
- * 名称:name:如果内部有 ${字符,则视为直接替换模板,类似 name-val。
2479
- * 4. 数据输出到页面,通过以下函数:
2480
- * setForm 对象数据对Form表单或者Div层,进行数据展现,每个字段对应同名dom或者name-tp模板。
2481
- * setView 对单个字段或视图,进行数据展现,如果为空,则清除
2482
- * addView 单个字段或视图,增加数据
2483
- * 5. 读取页面数据
2484
- * getForm 读取整个页面数据,返回 FormData 对象
2485
- * getView 读取指定字段数据,返回 仅仅包含 指定字段的 FormData对象
2486
- * 读取时,自动将所有隐藏域的data对象,转换为json字符串,方便FormData 提交服务器。
2487
- * 6. 对于重复 name 的 input,一般是对象数组,自动转换为对象数组,存入 FormData,
2488
- * 方便服务器处理。
2489
- * 7. 重复数据通过id 和 _id 字段判断,addView时,重复id 或 _id,删除之前的对象,仅保存新增的对象。
2490
- * id 作为服务器返回的字段,_id 作为客户端添加的字段,
2491
- * getForm 或 getView 时,tp模板自动删除,不返回给服务器,避免影响服务器数据。
2492
- * 8. 以上方法 绑定到 $.fn 中,使用时,按 Dom类似方法使用,如:
2493
- * _.name('fmData').setForm(data);
2494
- */
2495
-
2496
- /**
2497
- * 视图数据展现
2498
- * setViews 调用了 setView,为setView的批量操作
2499
- * 用于 tp模板中的form表单场景
2500
- * 数据内的元素,支持数组、对象,一次性实现整个容器的数据展现
2501
- * 根据数据项名称,自动查找页面对应input(按名称) 或 视图层(name 或 name-tp),实现数据展现
2502
- * 调用该方法的容器一般是 Form,也支持非Form,如 div
2503
- * 容器中的节点, 一般是input, 也支持非input,通过对象属性名称对应dom名称实现匹配展现
2504
- * 如果数据为数组,则使用调用者同名模板,生成多节点,
2505
- * field、input隐藏域带模板,会按模板生成字段部分展现
2506
- * 模板名称为 name-tp,根据模板添加后的节点名称为 name-data
2507
- * @param {*} v 数据
2508
- * @param {*} n 模板名称,可选,如果不填,默认调用者的name
2509
- * 注意,setViews的模板与setView中的模板不一样
2510
- * setViews 模板先调用clone克隆模板节点,不赋值,后续再调用 setView 进行赋值。
2511
- * 意味着 setViews 中的模板里面可以再嵌套字段模板。
2512
- * setView中的模板,使用带${r.name}这种插值模板,根据后台r数据,生成带数据值的 html。
2513
- * @param {*} add 新增,可选
2514
- */
2515
- function setForms(v, n, add = false) {
2516
- try {
2517
- const el = this;
2518
- // 清空所有数据,填充新数据
2519
- if (!add) clearForm.bind(el)();
2520
-
2521
- if (!n) n = el.attr('name');
2522
-
2523
- // 使用模板
2524
- if (n) {
2525
- const tp = el.name(`${n}-tp`);
2526
- if (tp.length) {
2527
- tp.hide();
2528
- if ($.isArray(v))
2529
- v.forEach(r => {
2530
- setTpForm.bind(el)(n, r, add);
2531
- });
2532
- else setTpForm.bind(el)(n, v, add);
2533
- }
2534
- }
2535
- } catch (ex) {
2536
- console.error('setForms exp.', {msg: ex.message});
2537
- }
2538
- }
2539
-
2540
- /**
2541
- * 向 view 中添加值
2542
- * @param {*} el 容器
2543
- * @param {*} k 字段名称
2544
- * @param {*} v 新增数据
2545
- */
2546
- function addForms(v, n) {
2547
- const el = this;
2548
- if (!n) n = el.attr('name');
2549
- setForms.bind(el)(v, n, true);
2550
- }
2551
-
2552
- /**
2553
- * 读取整个页面表单数据,返回对象 或对象数组
2554
- * 需要被读取的数据,需使用 input,包括隐藏域,否则无法被读取
2555
- * 读取时,自动将所有隐藏域的data对象,转换为字符串,方便FormData 提交服务器。
2556
- * @param {*} n 模板名称,不填与容器名称相同,可选参数
2557
- */
2558
- function getForm(n) {
2559
- let R = null;
2560
- try {
2561
- const el = this;
2562
- // 将data存入 value,方便FormData读取
2563
- el.find('input[type=hidden]').forEach(d => {
2564
- if (!$.isEmpty(d.data)) d.value = JSON.stringify(d.data);
2565
- });
2566
-
2567
- if (!n) n = el.attr('name');
2568
-
2569
- // 对象列表表单,需删除模板,避免模板数据干扰数据获取
2570
- const tp = el.name(`${n}-tp`);
2571
- let prev = null;
2572
- let hasTp = tp.length;
2573
- if (hasTp) {
2574
- hasTp = true;
2575
- prev = tp.prev();
2576
- tp.remove();
2577
- }
2578
-
2579
- // 读取整个表单输入数据
2580
- const fd = new FormData(el.dom);
2581
- // 还原模板
2582
- if (hasTp) tp.insertAfter(prev);
2583
-
2584
- const rs = [];
2585
- let last = null;
2586
- let r = {};
2587
- // eslint-disable-next-line no-restricted-syntax
2588
- for (const e of fd.entries()) {
2589
- const k = e[0];
2590
- if (!last) last = k;
2591
- else if (last === k) {
2592
- if (!$.isEmpty(r)) rs.push({...r});
2593
- r = {};
2594
- }
2595
- let v = e[1];
2596
- // 还原对象
2597
- try {
2598
- if (/^\s*[{[]/.test(v)) v = JSON.parse(v);
2599
- } catch (ex) {
2600
- console.error('getForm exp.', {msg: ex.message});
2601
- }
2602
- r[k] = v;
2603
- }
2604
-
2605
- if ($.hasVal(r)) rs.push(r);
2606
- if (rs.length === 1) [R] = rs;
2607
- else if (rs.length > 1) R = rs;
2608
- } catch (ex) {
2609
- console.error('getForm exp.', {msg: ex.message});
2610
- }
2611
-
2612
- return R;
2613
- }
2614
-
2615
- /**
2616
- * 清除表单
2617
- */
2618
- function clearForm() {
2619
- try {
2620
- const el = this;
2621
- // 清除input值
2622
- const es = el.find('input,textarea');
2623
- es.forEach(e => {
2624
- if (e.data) {
2625
- e.data = null;
2626
- delete e.data;
2627
- }
2628
- if (e.type !== 'checkbox') e.value = '';
2629
- });
2630
-
2631
- // 清除 模板数据
2632
- el.find('[name$=-data]').remove();
2633
- el.find('[name$=-empty]').show();
2634
- } catch (e) {
2635
- console.error(`clearForm exp:${e.message}`);
2636
- }
2637
- }
2638
-
2639
- /**
2640
- * 根据页面模板,设置视图域数据
2641
- * 模板为同名节点或tp模板
2642
- * 数据支持两维数组、对象、对象数组等
2643
- * 参数选项:opts: {
2644
- * add:是否新增
2645
- * name:指定视图名称,默认为当前Dom对象
2646
- * idx:数组索引
2647
- * form: 是否为表单,默认 false
2648
- * }
2649
- * 在Form表单中,一般用input来存放字符串值,如使用模板,input type 必须为 hidden
2650
- * 在非Form中,没有input,同名dom,或者名称-tp为插值模板,将对象数据与模板匹配展示数据
2651
- * tb.setView(data); // 数据
2652
- * tb.setView(arr, 0); // 数组,第一列为id
2653
- * tb.setView(arr, 0, 模板名称); // 数组,第一列为id
2654
- * tb.setView(obj, 模板名称); //
2655
- * tb.setView(arr, 0, 模板名称, add); // 第一列为id
2656
- * tb.setView(obj, 模板名称, add); // 对象数据,指定模版名称
2657
- * @param {*} v 数据
2658
- * @param {Number} idx 数组id列序号,可选
2659
- * @param {*} n 视图名称,缺省为dom对象name属性,dom容器如无name,参数n不传则不工作。
2660
- * @param {*} add 重置还是新增,重置会清除数据项,默认为重置
2661
- */
2662
- // function setView(v, idx = -1, n = '', add = false) {
2663
- function setView(v, ...args) {
2664
- let R = false;
2665
- try {
2666
- if (v === undefined || v === null) return false;
2667
-
2668
- const el = this;
2669
- let add = false;
2670
- let idx = -1;
2671
- // 表单视图
2672
- let form = false;
2673
- let name = el.attr('name');
2674
-
2675
- // 复合参数,兼容多参数
2676
- if (args.length) {
2677
- // opts
2678
- if ($.isObject(args[0])) {
2679
- const def = {add, name, idx, form};
2680
- const opt = {...def, ...args[0]};
2681
- ({add, name, idx, form} = opt);
2682
- } else if ($.isArray(v) && $.isNumber(args[0])) {
2683
- // eslint-disable-next-line
2684
- if (args.length >= 1) idx = args[0];
2685
- // eslint-disable-next-line
2686
- if (args.length >= 2 && $.isString(args[1])) name = args[1];
2687
- // eslint-disable-next-line
2688
- if (args.length >= 3 && $.isBool(args[2])) add = args[2];
2689
- } else {
2690
- // if ($.isObject(v) && $.isBool(args[0])) add = args[0];
2691
- // eslint-disable-next-line
2692
- if (args.length >= 1 && $.isString(args[0])) name = args[0];
2693
- else if (args.length >= 1 && $.isBool(args[0])) add = args[0];
2694
- // eslint-disable-next-line
2695
- else if (args.length >= 2 && $.isBool(args[1])) add = args[1];
2696
- }
2697
- }
2698
-
2699
- // 查找是否包含 input
2700
- // if (el.nodeName.toLowerCase() === 'form' || el.find('input,textarea').length) from = true;
2701
-
2702
- // 清除视图数据
2703
- if (!add) {
2704
- if (form) clearForm.bind(el)();
2705
- clearView.bind(el)(name);
2706
- }
2707
-
2708
- // 表单,需将对象拆开,按字段名称逐项赋值
2709
- if (form && $.isObject(v)) {
2710
- Object.keys(v).forEach(k => setData.bind(el)(k, v[k]));
2711
- } else if (name) R = setData.bind(el)(name, v, idx); // 没有指定name的dom,可通过name-tp、name-val等模板赋值
2712
- } catch (ex) {
2713
- console.error('setView exp.', {msg: ex.message});
2714
- }
2715
- return R;
2716
- }
2717
-
2718
- /**
2719
- * 表单赋值
2720
- * @param {*} v
2721
- * @param {*} opts
2722
- */
2723
- function setForm(v, opts) {
2724
- const opt = opts || {};
2725
- opt.form = true;
2726
- setView.bind(this)(v, opt);
2727
- }
2728
-
2729
- /**
2730
- * 向 field 中添加值
2731
- * tb.setView(d);
2732
- * tb.setView(arr, 0); // 第一列为id
2733
- * tb.setView(arr, 0, 模板名称); // 第一列为id
2734
- * tb.setView(obj, 模板名称); // 第一列为id
2735
- * tb.setView(arr, 0, 模板名称); // 第一列为id
2736
- * tb.setView(obj, 模板名称); // 第一列为id
2737
- * @param {*} v 数据
2738
- * @param {*} n 视图名称,缺省为调用者name
2739
- */
2740
- function addView(v, ...args) {
2741
- const el = this;
2742
- setView.bind(el)(v, ...args, true);
2743
- }
2744
-
2745
- /**
2746
- * 清除视图
2747
- * @param {*} k 视图名称
2748
- */
2749
- function clearView(n) {
2750
- try {
2751
- const el = this;
2752
- if (!n) n = el.attr('name');
2753
-
2754
- // 清除input值
2755
- const es = el.names(n);
2756
- es.forEach(e => {
2757
- if (e.tagName.toLowerCase() === 'input' || e.tagName.toLowerCase() === 'textarea') {
2758
- if (e.data) {
2759
- e.data = null;
2760
- delete e.data;
2761
- }
2762
- if (e.type !== 'checkbox') e.value = '';
2763
- }
2764
- });
2765
-
2766
- // 清除 模板数据
2767
- el.names(`${n}-data`).remove();
2768
- el.name(`${n}-empty`).show();
2769
- } catch (e) {
2770
- console.error(`clearView exp:${e.message}`);
2771
- }
2772
- }
2773
-
2774
- /**
2775
- * 读取指定视图数据,返回 仅仅包含 指定视图的值,如果有data,则返回 对象
2776
- * 读取时,自动将隐藏域的data对象,转换为字符串,方便FormData 提交服务器。
2777
- * @param {*} n 视图名称
2778
- */
2779
- function getView(n) {
2780
- let R = null;
2781
- try {
2782
- const el = this;
2783
- if (!n) n = el.attr('name');
2784
- const d = el.name(n);
2785
- if (d.length) {
2786
- if ($.hasVal(d.data)) R = d.data;
2787
- else R = d.val();
2788
- }
2789
- } catch (ex) {
2790
- console.error('getView exp.', {msg: ex.message});
2791
- }
2792
-
2793
- return R;
2794
- }
2795
-
2796
- /**
2797
- *
2798
- * @param {*} e
2799
- */
2800
- function removeChip(e) {
2801
- console.log('removeChip', {e});
2802
-
2803
- const el = $(e.target).closest('.chip');
2804
- if (el && el.length > 0) {
2805
- let id = el.data('id');
2806
- const n = el.prevNode('input[type=hidden]');
2807
- el.remove();
2808
- if (n && n.length > 0) {
2809
- id = n
2810
- .val()
2811
- .replace(new RegExp(`${id}\\s*,?\\s*`), '')
2812
- .replace(/\s*,\s*$/, '');
2813
- n.val(id);
2814
- }
2815
- }
2816
- }
2817
-
2818
- /**
2819
- * 根据模板添加 form 数据集
2820
- * 内部函数,被setViews调用
2821
- * @param {*} n 模板名称
2822
- * @param {*} v 数据对象
2823
- */
2824
- function setTpForm(n, v, add = false) {
2825
- try {
2826
- const el = this;
2827
- const tp = el.name(`${n}-tp`);
2828
- if (tp.length) {
2829
- tp.hide();
2830
- const p = tp.clone();
2831
- p.insertBefore(tp);
2832
- setView.bind(p)(v, {form: true, add});
2833
- p.attr('name', tp.attr('name').replace('-tp', '-data')).show();
2834
- }
2835
- } catch (ex) {
2836
- console.error('setForm exp.', {msg: ex.message});
2837
- }
2838
- }
2839
-
2840
- /**
2841
- * 渲染模板字符串,使用 r 参数,替换模板代参,生成展示html视图
2842
- * 替代 eval,减少安全漏洞,eval 会带入了所有内存上下文变量,导致数据泄露!
2843
- * @param {*} tp 模板
2844
- * @param {*} r 数据
2845
- * @returns 返回html
2846
- */
2847
- function render(tp, r) {
2848
- const code = `function(r){return \`${tp}\`}`;
2849
- // eslint-disable-next-line no-new-func
2850
- return Function(`"use strict";return (${code})`)()(r);
2851
- }
2852
-
2853
- /**
2854
- * 根据模板,添加数据节点
2855
- * 添加前,根据id 或 _id,删除相同已加载数据节点,避免重复添加
2856
- * 内部函数,被 setData 调用
2857
- * @param {*} tp 模板
2858
- * @param {*} n 字段名称
2859
- * @param {*} r 数据,对象 或 值
2860
- * @param {*} ns 已经存在的数据节点,避免重复添加
2861
- * @param {Number} idx 数组中作为id的序号,从0开始,-1表示没有
2862
- */
2863
- function addData(tp, n, r, ns, idx = -1) {
2864
- try {
2865
- if (!tp) return;
2866
-
2867
- // 对象、数组可能存在id、_id
2868
- const isObj = $.isObject(r);
2869
- const isArr = $.isArray(r);
2870
-
2871
- let id;
2872
- let _id;
2873
- if (isObj) {
2874
- id = r.id;
2875
- _id = r._id;
2876
- } else if (isArr) {
2877
- if (idx > -1) id = r[idx];
2878
- } // 普通值直接作为_id
2879
- else _id = r;
2880
-
2881
- // 通过id、_id删除重复节点
2882
- if ((id !== undefined || _id !== undefined) && ns?.length) {
2883
- const ds = ns.filter((i, n) => {
2884
- const $n = $(n);
2885
- return (id && $n.data('id') == id) || (_id && $n.data('_id') == _id);
2886
- });
2887
-
2888
- if (ds.length) ds.remove();
2889
- }
2890
-
2891
- // 通过模板与r结合,生成页面html
2892
- const $n = $(
2893
- render(tp.dom.outerHTML, r)
2894
- .replaceAll('undefined:', '')
2895
- .replaceAll('undefined:', '')
2896
- .replaceAll('undefined', '')
2897
- );
2898
- if (id !== undefined) $n.data('id', id);
2899
- else if (_id !== undefined) $n.data('_id', _id);
2900
- $n.attr('name', `${n}-data`).insertBefore(tp).show();
2901
- } catch (ex) {
2902
- console.error('addData exp.', {msg: ex.message});
2903
- }
2904
- }
2905
-
2906
- /**
2907
- * 视图赋值
2908
- * 优先节点名称表单value赋值:input、hidden、select、checkbox、radio、textarea
2909
- * 然后继续对模板继续赋值:-tp、-val 和内部包含 ${ 模板特殊字符串的视图赋值!
2910
- * 使用-tp模板或name的html作为模版,xxx-val 不判断 ${直接覆盖,
2911
- * xxx 判断内部是否有 ${,如果有,则视为模板,进行模板替换。
2912
- * 加载数据到页面,模板请使用 ${r} 或 ${r.xx}
2913
- * img 的 $src 改为 src
2914
- * 内部函数,被 setField 调用,只管模板,不管input 和 form
2915
- * 在非 form 和 input环境可用
2916
- * @param {*} n 模板名称,组件name="n-tp",n为模板名称
2917
- * @param {*} v 数据,对象或者对象数组
2918
- * @param {Numver} idx 指定数组id列序号,v 为数组时有效
2919
- */
2920
- function setData(n, v, idx = -1) {
2921
- try {
2922
- if (!n) return false;
2923
-
2924
- const el = this; // 容器
2925
-
2926
- // 查找名称节点
2927
- const $d = el.name(n); // 包含容器自身
2928
-
2929
- // 名称节点赋值优先!
2930
- // 容器内查找字段名称对应组件进行赋值,支持select、radio、checkbox,Dom的val已经支持,这里可直接调用val即可!
2931
- if ($d.length > 0) {
2932
- const d = $d.dom;
2933
- // console.log('setView', {type: d.type});
2934
- // null undfined 转换为空
2935
- v = v ?? '';
2936
- if (v === 'null' || v === 'undefined') v = '';
2937
-
2938
- if (d.tagName.toLowerCase() === 'textarea') $d.val(v);
2939
- // input 赋值
2940
- else if (d.tagName.toLowerCase() === 'input') {
2941
- if (d.type === 'text') setInput.bind(el)(n, v);
2942
- else if (
2943
- [
2944
- 'date',
2945
- 'time',
2946
- 'month',
2947
- 'week',
2948
- 'datetime',
2949
- 'datetime-local',
2950
- 'email',
2951
- 'number',
2952
- 'search',
2953
- 'url',
2954
- ].includes(d.type)
2955
- )
2956
- $d.val(v);
2957
- // 隐藏域,一般带同名模板,数据为数组或对象,不使用隐藏域也可以展示对象数据,使用隐藏域便于收集数据提交
2958
- else if (d.type === 'hidden') {
2959
- setInput.bind(el)(n, v);
2960
- // setData.bind(el)(n, v); // 后续继续执行模板部分!
2961
- // 触发 input的 onchange 事件,hidden 组件数据变化,不会触发onchange
2962
- // 这里发起change事件,方便其他组件接收事件后,实现UI等处理
2963
- // 其他接受change事件的组件,不能再次触发change,否则导致死循环
2964
- $d.change();
2965
- } else if (
2966
- d.type === 'select-one' ||
2967
- d.type === 'select-multiple' ||
2968
- d.type === 'checkbox' ||
2969
- d.type === 'radio'
2970
- ) {
2971
- $d.val(v, el);
2972
- }
2973
- }
2974
- }
2975
-
2976
- // 继续${} 模板字符串替换赋值:-tp、-val、和内部包含${特征字符串的内容赋值
2977
- if ($.isEmpty(v)) return false;
2978
-
2979
- // 查找数据模板,按模板增加数据,模板优先 name
2980
- const tp = el.name(`${n}-tp`);
2981
- // 有模板,使用模板添加数据,通过id或_id避免重复添加
2982
- if (tp.length) {
2983
- tp.hide();
2984
- let kv = false; // key value
2985
- const tpa = tp.attr('tp');
2986
- if (tpa === 'kv' || /kv-\d+/.test(tpa)) kv = true;
2987
- let empty = el.names(`${n}-data`).length === 0;
2988
- // chip
2989
- const d = el.name(n).dom;
2990
- // 如果 input存在,优先获取 input 中的 data
2991
- if (d && d.type === 'hidden') {
2992
- const val = d.value;
2993
- if (!$.isEmpty(d.data)) v = d.data;
2994
- else if (val) {
2995
- v = val;
2996
- if (val.indexOf(',') > -1) v = val.split(',');
2997
- }
2998
- }
2999
-
3000
- // 已经存在的数据视图,新增时,需删除后新增,避免重复
3001
- const ns = el.names(`${n}-data`);
3002
-
3003
- // 数组,两维数组,对象数组
3004
- if ($.isArray(v))
3005
- v.forEach((r, x) => {
3006
- if (r) {
3007
- empty = false;
3008
- addData.bind(el)(tp, n, r, ns, idx); // 二维数组,模板中通过 r[0] r[1] 引用数据
3009
- }
3010
- });
3011
- else if ($.isObject(v) && kv) {
3012
- const ks = Object.keys(v);
3013
- if (ks.length) {
3014
- empty = false;
3015
- const ms = /kv-(\d+)/.exec(tpa);
3016
- if (!ms) {
3017
- ks.forEach(vk => {
3018
- if (v[vk]) {
3019
- addData.bind(el)(tp, n, {k: vk, v: v[vk]}, ns, idx);
3020
- }
3021
- });
3022
- } else {
3023
- const kn = ms[1];
3024
- let ik = 0;
3025
- // 取模存值
3026
- const mks = [];
3027
- const mvs = [];
3028
- let m = 0;
3029
- ks.forEach(vk => {
3030
- ik++;
3031
- mks.push(vk);
3032
- mvs.push(v[vk] ?? '');
3033
-
3034
- // 取模
3035
- m = ik % kn;
3036
- // id >= kn
3037
- if (m === 0) {
3038
- const md = {};
3039
- mks.forEach((mk, mi) => {
3040
- md[`k${mi + 1}`] = mks[mi];
3041
- md[`v${mi + 1}`] = mvs[mi];
3042
- });
3043
- console.log('setData', {md});
3044
- addData.bind(el)(tp, n, md, ns, idx);
3045
- mks.length = 0;
3046
- mvs.length = 0;
3047
- }
3048
- });
3049
-
3050
- if (m > 0) {
3051
- const md = {};
3052
- mks.forEach((mk, mi) => {
3053
- md[`k${mi + 1}`] = mks[mi];
3054
- md[`v${mi + 1}`] = mvs[mi];
3055
- });
3056
- console.log('setData', {md});
3057
- addData.bind(el)(tp, n, md, ns, idx);
3058
- mks.length = 0;
3059
- mvs.length = 0;
3060
- }
3061
- }
3062
- }
3063
- } else if (v) {
3064
- empty = false;
3065
- addData.bind(el)(tp, n, v, ns, idx);
3066
- }
3067
-
3068
- // 支持点击删除
3069
- if (tp.hasClass('chip')) tp.parentNode().click(removeChip);
3070
-
3071
- // img src-tp replace src
3072
- const imgs = tp.find('img[src-tp]');
3073
- el.find('img[src-tp]').forEach(img => {
3074
- if (imgs.length === 0 || imgs.indexOf(img) === -1) {
3075
- const $img = $(img);
3076
- $img.attr('src', $img.attr('src-tp'));
3077
- $img.removeAttr('src-tp');
3078
- }
3079
- });
3080
-
3081
- // 如果数据节点为空,则显示空节点(存在则显示)
3082
- if (empty) el.name(`${n}-empty`).show();
3083
- else el.name(`${n}-empty`).hide();
3084
- } else {
3085
- // 没有-tp模板,查找-val,直接覆盖
3086
- const r = v;
3087
- const vp = el.name(`${n}-val`);
3088
- if (vp.length) {
3089
- const tx = vp.html();
3090
- if (r && tx.indexOf('${') > -1) {
3091
- vp.html(
3092
- render(tx, r)
3093
- .replaceAll('undefined:', '')
3094
- .replaceAll('undefined:', '')
3095
- .replaceAll('undefined', '')
3096
- );
3097
- // img $src replace src
3098
- vp.find('img[src-tp]').forEach(n => {
3099
- const $n = $(n);
3100
- $n.attr('src', $n.attr('src-tp'));
3101
- });
3102
- } else if (r) vp.html(r);
3103
- } else {
3104
- // 没有-tp和-val,获取name为k的视图,如果内部有${,按模板覆盖内容
3105
- // const $d = el.name(`${n}`);
3106
- if ($d.length && $d.dom.type !== 'text') {
3107
- const tx = $d.html();
3108
- if (r && tx && tx.indexOf('${') > -1) {
3109
- $d.html(
3110
- render(tx, r)
3111
- .replaceAll('undefined:', '')
3112
- .replaceAll('undefined:', '')
3113
- .replaceAll('undefined', '')
3114
- );
3115
- // img $src replace src
3116
- $d.find('img[src-tp]').forEach(img => {
3117
- const $img = $(img);
3118
- $img.attr('src', $img.attr('src-tp'));
3119
- });
3120
- }
3121
- }
3122
- }
3123
- }
3124
- } catch (ex) {
3125
- console.error('setData exp.', {msg: ex.message});
3126
- }
3127
- }
3128
-
3129
- /**
3130
- * input 赋值时设置数据,自动去重
3131
- * 内部函数,被 setInput调用
3132
- * @param {*} n input Dom 实例
3133
- * @param {*} v 值
3134
- * @param {*} org 原来的值
3135
- */
3136
- function getValue(n, v, org) {
3137
- let R = v;
3138
-
3139
- try {
3140
- // 对象需判断是否重复
3141
- if ($.isObject(v)) {
3142
- if ($.isObject(org)) {
3143
- if ((org.id && org.id == v.id) || (org._id && org._id == v._id)) R = v;
3144
- else R = [org, v];
3145
- } else if ($.isArray(org)) {
3146
- const rs = org.filter(
3147
- o => (!o.id && !o._id) || (o.id && o.id != v.id) || (o._id && o._id != v._id)
3148
- );
3149
- if (rs.length) {
3150
- rs.push(v);
3151
- R = rs;
3152
- }
3153
- }
3154
- } else {
3155
- // 值变量,直接使用 value 字符串方式存储
3156
- let val = `${org},${v}`;
3157
- // 去重
3158
- if (val.indexOf(',') > -1) val = Array.from(new Set(val.split(','))).join(',');
3159
- R = val;
3160
- }
3161
- } catch (e) {
3162
- console.error('getValue exp.', {msg: e.message});
3163
- }
3164
- return R;
3165
- }
3166
-
3167
- /**
3168
- * 设置 input 的值
3169
- * 如果带id,则检查是否已存在,避免重复添加
3170
- * @param {*} n 字段名称
3171
- * @param {*} v 值,接受字符串、对象 和 对象数组
3172
- * 对象、对象数组 赋值到 data,值,值数组,赋值到 value
3173
- */
3174
- function setInput(n, v) {
3175
- try {
3176
- const el = this;
3177
- const d = el.name(n);
3178
- if (!d.length) return;
3179
-
3180
- if ($.isEmpty(v)) return;
3181
-
3182
- // 没有id 和 _id,自动添加 _id,避免重复添加
3183
- if ($.isObject(v) && v.id === undefined && v._id === undefined) v._id = $.num();
3184
- else if ($.isArray(v)) {
3185
- v.forEach(r => {
3186
- if ($.isObject(r) && r.id === undefined && r._id === undefined) r._id = $.num();
3187
- });
3188
- }
3189
-
3190
- let org = d.dom.data;
3191
- if (!org) {
3192
- org = d.val();
3193
- // 隐藏域,从字符串还原对象,保存到 dom.data
3194
- if (d.dom.type === 'hidden' && /\s*[{[]/g.test(org)) {
3195
- try {
3196
- org = JSON.parse(org);
3197
- d.dom.data = org;
3198
- d.val('');
3199
- } catch (e) {
3200
- console.error('setInput exp.', {msg: e.message});
3201
- }
3202
- }
3203
- }
3204
-
3205
- if ($.isEmpty(org)) {
3206
- if ($.isVal(v)) d.val(v);
3207
- else if ($.isArray(v) && $.isVal(v[0])) d.val(v.join(','));
3208
- else d.dom.data = v;
3209
- } else {
3210
- if ($.isArray(v)) {
3211
- v = v.reduce((pre, cur) => getValue(d, cur, pre), org);
3212
- if ($.hasVal(v) && $.isArray(v)) {
3213
- v = Array.from(new Set(v));
3214
- }
3215
- } else v = getValue(d, v, org);
3216
-
3217
- if ($.hasVal(v)) {
3218
- if ($.isVal(v)) d.val(v);
3219
- // 值 数组
3220
- else if ($.isArray(v) && $.isVal(v[0])) d.val(v.join(','));
3221
- else d.dom.data = v;
3222
- }
3223
- }
3224
- } catch (ex) {
3225
- console.error('setInput exp.', {msg: ex.message});
3226
- }
3227
- }
3228
-
3229
- // test
3230
- // Object.keys(fn).forEach(k => ($.fn[k] = fn[k]));
3231
-
3232
- const View = /*#__PURE__*/Object.freeze({
3233
- __proto__: null,
3234
- addForms: addForms,
3235
- addView: addView,
3236
- clearForm: clearForm,
3237
- clearView: clearView,
3238
- getForm: getForm,
3239
- getView: getView,
3240
- setForm: setForm,
3241
- setForms: setForms,
3242
- setView: setView
3243
- });
3244
-
3245
- /**
3246
- * 输出方法到 $.fn,用户对 $(dom) 对象操作
3247
- * 相关方法与用法与 zepto、jQuery兼容。
3248
- * 替代zepto、jQuery,不可同时使用zepto、jQuery
3249
- */
3250
-
3251
-
3252
- // 获取当前全局$变量,$.fn 上增加操作函数!
3253
- const $$1 = window.$ ?? {};
3254
- [Methods, Scroll, Animate, View].forEach(group => {
3255
- // , eventShortcuts
3256
- Object.keys(group).forEach(methodName => {
3257
- $$1.fn[methodName] = group[methodName];
3258
- });
3259
- });
3260
-
3261
- // shortcut methods for `.on(event, fn)` for each event type
3262
- const noTrigger = 'resize scroll'.split(' ');
3263
- (
3264
- 'load,unload,dblclick,select,error,click,blur,focus,focusin,' +
3265
- 'focusout,keyup,keydown,keypress,submit,change,mousedown,mousemove,mouseup,' +
3266
- 'mouseenter,mouseleave,mouseout,mouseover,touchstart,touchend,touchmove,resize,' +
3267
- 'scroll,swipe,press'
3268
- )
3269
- .split(',')
3270
- .forEach(function (event) {
3271
- $$1.fn[event] = function (...args) {
3272
- if (typeof args[0] === 'undefined') {
3273
- for (let i = 0; i < this.length; i += 1) {
3274
- try {
3275
- if (noTrigger.indexOf(event) < 0) {
3276
- if (event in this[i]) this[i][event]();
3277
- else {
3278
- $$1(this[i]).trigger(event);
3279
- }
3280
- }
3281
- } catch (ex) {}
3282
- }
3283
- return this;
3284
- }
3285
- return this.on(event, ...args);
3286
- };
3287
- });
3288
-
3289
- function traverseNode(node, fun) {
3290
- fun(node);
3291
- for (var i = 0, len = node.childNodes.length; i < len; i++) traverseNode(node.childNodes[i], fun);
3292
- }
3293
-
3294
- // Generate the `after`, `prepend`, `before`, `append`,
3295
- // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods.
3296
- const operators = ['after', 'prepend', 'before', 'append'];
3297
- operators.forEach(function (op, idx) {
3298
- var inside = idx % 2; //=> prepend, append
3299
- $$1.fn[op] = function () {
3300
- // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
3301
- let argType;
3302
- // map 每个参数,支持添加多个节点
3303
- const nodes = $$1.map(arguments, function (arg) {
3304
- var arr = [];
3305
- argType = $$1.type(arg);
3306
- if (argType == 'array') {
3307
- arg.forEach(function (el) {
3308
- if (el.nodeType !== undefined) return arr.push(el);
3309
- else if ($$1.isDom(el)) return (arr = arr.concat(el.get()));
3310
- arr = arr.concat($$1.fragment(el));
3311
- });
3312
- return arr;
3313
- }
3314
- return argType == 'object' || arg == null ? arg : $$1.fragment(arg);
3315
- });
3316
-
3317
- if (nodes.length < 1) return this;
3318
-
3319
- let parent;
3320
- // 多目标节点增加新节点时,需克隆,否则只有最后一个目标节点增加了新节点
3321
- let copyByClone = this.length > 1;
3322
-
3323
- // 针对每个节点进行节点添加操作
3324
- return this.each(function (_, target) {
3325
- parent = inside ? target : target.parentNode;
3326
-
3327
- // convert all methods to a "before" operation
3328
- target =
3329
- idx == 0
3330
- ? target.nextSibling // after
3331
- : idx == 1
3332
- ? target.firstChild // prepend
3333
- : idx == 2
3334
- ? target // before
3335
- : null; // append
3336
-
3337
- var parentInDoc = $$1.contains(document.documentElement, parent);
3338
-
3339
- nodes.forEach(function (node) {
3340
- if (copyByClone) node = node.cloneNode(true);
3341
- else if (!parent) return $$1(node).remove();
3342
-
3343
- parent.insertBefore(node, target);
3344
-
3345
- // 防止空链接,刷新页面
3346
- const ns = $$1.qus('a[href=""]', parent);
3347
- if (ns && ns.length > 0) ns.forEach(n => n.setAttribute('href', 'javascript:;'));
3348
-
3349
- if (parentInDoc)
3350
- // 执行 节点中包含的脚本代码
3351
- traverseNode(node, function (el) {
3352
- if (
3353
- el.nodeName != null &&
3354
- el.nodeName.toUpperCase() === 'SCRIPT' &&
3355
- (!el.type || el.type === 'text/javascript') &&
3356
- !el.src
3357
- ) {
3358
- var target = el.ownerDocument ? el.ownerDocument.defaultView : window;
3359
- target['eval'].call(target, el.innerHTML);
3360
- }
3361
- });
3362
- });
3363
- });
3364
- };
3365
-
3366
- // 参数调换,参数作为目标节点,this作为新增节点
3367
- // after => insertAfter
3368
- // prepend => prependTo
3369
- // before => insertBefore
3370
- // append => appendTo
3371
- const op2 = inside ? op + 'To' : 'insert' + (idx ? 'Before' : 'After');
3372
- $$1.fn[op2] = function (html) {
3373
- $$1(html)[op](this);
3374
- return this;
3375
- };
3376
- });
3377
-
3378
- $$1.default = $$1;
3379
- // export {$};
3380
-
3381
- dom_cmn = $$1;
3382
- return dom_cmn;
3383
- }
3384
-
3385
- {
3386
- dom.exports = requireDom_cmn();
3387
- }
3388
-
3389
- var domExports = dom.exports;
3390
- const $$1 = /*@__PURE__*/getDefaultExportFromCjs(domExports);
3391
-
3392
93
  /* eslint-disable */
3393
94
  function signum(num) {
3394
95
  return num < 0 ? -1 : 0 === num ? 0 : 1;
@@ -5646,9 +2347,13 @@ const SW$1 = {
5646
2347
  * Wia App 基类,从 Module 和 Event 继承。
5647
2348
  */
5648
2349
  // 使用 rollup打包注意
2350
+ // dom 独立,不打入 core!!!
2351
+ // import $ from '@wiajs/dom'; // dom操作库,这种引用,导致 dom的压缩、非压缩 common包都会打入 core
2352
+ // const $ = require('@wiajs/dom'); // dom操作库,这种引用,导致 dom的压缩、非压缩 common包都不会打入 core,保留了 require
2353
+
5649
2354
 
5650
2355
  const {extend, nextFrame, colorThemeCSSStyles} = Utils;
5651
- const {support, device} = $$1;
2356
+ const {support, device} = $;
5652
2357
 
5653
2358
  // Default
5654
2359
  const def = {
@@ -5704,7 +2409,7 @@ class App extends Module {
5704
2409
  const passedParams = extend({}, opts);
5705
2410
 
5706
2411
  const app = this;
5707
- $$1.App = App;
2412
+ $.App = App;
5708
2413
  App.instance = app; // 控制单例
5709
2414
  app.device = device;
5710
2415
  app.support = support;
@@ -5721,8 +2426,8 @@ class App extends Module {
5721
2426
  }
5722
2427
 
5723
2428
  // 判断Page、App实例
5724
- $$1.isPage = p => p instanceof Page;
5725
- $$1.isApp = p => p instanceof App;
2429
+ $.isPage = p => p instanceof Page;
2430
+ $.isApp = p => p instanceof App;
5726
2431
 
5727
2432
  // 参数内容赋值给app 实例
5728
2433
  extend(app, {
@@ -5774,7 +2479,7 @@ class App extends Module {
5774
2479
  // 应用初始化,路由跳转时不执行初始化
5775
2480
  if (app.params.init) {
5776
2481
  if (device.cordova && app.params.initOnDeviceReady) {
5777
- $$1(document).on('deviceready', () => {
2482
+ $(document).on('deviceready', () => {
5778
2483
  app.init();
5779
2484
  });
5780
2485
  } else {
@@ -5832,7 +2537,7 @@ class App extends Module {
5832
2537
  mount(rootEl) {
5833
2538
  const app = this;
5834
2539
 
5835
- const $rootEl = $$1(rootEl || app.params.el).eq(0);
2540
+ const $rootEl = $(rootEl || app.params.el).eq(0);
5836
2541
  extend(app, {
5837
2542
  // Root
5838
2543
  root: $rootEl,
@@ -5888,9 +2593,9 @@ class App extends Module {
5888
2593
  // Data
5889
2594
  app.data = {};
5890
2595
  if (app.params.data && typeof app.params.data === 'function') {
5891
- $$1.extend(app.data, app.params.data.bind(app)());
2596
+ $.extend(app.data, app.params.data.bind(app)());
5892
2597
  } else if (app.params.data) {
5893
- $$1.extend(app.data, app.params.data);
2598
+ $.extend(app.data, app.params.data);
5894
2599
  }
5895
2600
  // Methods
5896
2601
  app.methods = {};
@@ -5939,7 +2644,7 @@ class App extends Module {
5939
2644
  app.enableAutoDarkMode();
5940
2645
  } else {
5941
2646
  app.disableAutoDarkMode();
5942
- $$1('html')[mode ? 'addClass' : 'removeClass']('dark');
2647
+ $('html')[mode ? 'addClass' : 'removeClass']('dark');
5943
2648
  app.darkMode = mode;
5944
2649
  }
5945
2650
  }
@@ -5951,7 +2656,7 @@ class App extends Module {
5951
2656
  app.params.componentUrl,
5952
2657
  {componentOptions: {el: app.$el[0]}},
5953
2658
  el => {
5954
- app.$el = $$1(el);
2659
+ app.$el = $(el);
5955
2660
  app.$el[0].wia = app;
5956
2661
  app.$elComponent = el.f7Component;
5957
2662
  app.el = app.$el[0];
@@ -5974,12 +2679,12 @@ class App extends Module {
5974
2679
 
5975
2680
  // RTL attr
5976
2681
  if (app.rtl) {
5977
- $$1('html').attr('dir', 'rtl');
2682
+ $('html').attr('dir', 'rtl');
5978
2683
  }
5979
2684
 
5980
2685
  // Auto Dark Mode
5981
2686
  if (typeof app.params.darkMode === 'undefined') {
5982
- app.darkMode = $$1('html').hasClass('dark');
2687
+ app.darkMode = $('html').hasClass('dark');
5983
2688
  } else {
5984
2689
  app.setDarkMode(app.params.darkMode);
5985
2690
  }
@@ -6001,14 +2706,14 @@ class App extends Module {
6001
2706
  app.$el.addClass('framework7-root');
6002
2707
 
6003
2708
  // Theme class
6004
- $$1('html').removeClass('ios md pc').addClass(app.theme);
2709
+ $('html').removeClass('ios md pc').addClass(app.theme);
6005
2710
 
6006
2711
  // iOS Translucent
6007
2712
  if (app.params.iosTranslucentBars && app.theme === 'ios') {
6008
- $$1('html').addClass('ios-translucent-bars');
2713
+ $('html').addClass('ios-translucent-bars');
6009
2714
  }
6010
2715
  if (app.params.iosTranslucentModals && app.theme === 'ios') {
6011
- $$1('html').addClass('ios-translucent-modals');
2716
+ $('html').addClass('ios-translucent-modals');
6012
2717
  }
6013
2718
 
6014
2719
  // Init class
@@ -6057,15 +2762,15 @@ class App extends Module {
6057
2762
 
6058
2763
  // eslint-disable-next-line
6059
2764
  get $() {
6060
- return $$1;
2765
+ return $;
6061
2766
  }
6062
2767
 
6063
2768
  static get Dom() {
6064
- return $$1;
2769
+ return $;
6065
2770
  }
6066
2771
 
6067
2772
  static get $() {
6068
- return $$1;
2773
+ return $;
6069
2774
  }
6070
2775
 
6071
2776
  static get Module() {