@wiajs/core 1.0.5 → 1.0.7

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