@whitesev/domutils 1.0.0 → 1.0.3
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/README.md +46 -0
- package/dist/index.cjs.js +109 -63
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +109 -63
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +109 -63
- package/dist/index.umd.js.map +1 -1
- package/dist/src/DOMUtils.d.ts +7 -0
- package/dist/src/DOMUtilsCore.d.ts +8 -0
- package/package.json +1 -1
- package/src/CommonDOMUtils.ts +3 -1
- package/src/DOMUtils.ts +80 -62
- package/src/DOMUtilsCore.ts +34 -0
- package/src/{Core.ts → types/Event.d.ts} +0 -6
- package/src/types/index.d.ts +12 -0
- package/tsconfig.json +1 -1
- /package/{global.d.ts → src/types/global.d.ts} +0 -0
package/dist/index.umd.js
CHANGED
|
@@ -4,6 +4,39 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DOMUtils = factory());
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
|
+
const DOMUtilsCoreDefaultEnv = {
|
|
8
|
+
document: document,
|
|
9
|
+
window: window,
|
|
10
|
+
globalThis: globalThis,
|
|
11
|
+
self: self,
|
|
12
|
+
};
|
|
13
|
+
const DOMUtilsCoreEnv = {
|
|
14
|
+
document: document,
|
|
15
|
+
window: window,
|
|
16
|
+
globalThis: globalThis,
|
|
17
|
+
self: self,
|
|
18
|
+
};
|
|
19
|
+
const DOMUtilsCore = {
|
|
20
|
+
init(option) {
|
|
21
|
+
if (!option) {
|
|
22
|
+
option = Object.assign({}, DOMUtilsCoreDefaultEnv);
|
|
23
|
+
}
|
|
24
|
+
Object.assign(DOMUtilsCoreEnv, option);
|
|
25
|
+
},
|
|
26
|
+
get document() {
|
|
27
|
+
return DOMUtilsCoreEnv.document;
|
|
28
|
+
},
|
|
29
|
+
get window() {
|
|
30
|
+
return DOMUtilsCoreEnv.window;
|
|
31
|
+
},
|
|
32
|
+
get globalThis() {
|
|
33
|
+
return DOMUtilsCoreEnv.globalThis;
|
|
34
|
+
},
|
|
35
|
+
get self() {
|
|
36
|
+
return DOMUtilsCoreEnv.self;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
7
40
|
/** 通用工具类 */
|
|
8
41
|
const CommonDOMUtils = {
|
|
9
42
|
/**
|
|
@@ -20,7 +53,7 @@
|
|
|
20
53
|
showElement(element) {
|
|
21
54
|
let dupNode = element.cloneNode(true);
|
|
22
55
|
dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
|
|
23
|
-
document.documentElement.appendChild(dupNode);
|
|
56
|
+
DOMUtilsCore.document.documentElement.appendChild(dupNode);
|
|
24
57
|
return {
|
|
25
58
|
/**
|
|
26
59
|
* 恢复修改的style
|
|
@@ -113,11 +146,14 @@
|
|
|
113
146
|
};
|
|
114
147
|
|
|
115
148
|
class DOMUtils {
|
|
149
|
+
constructor(option) {
|
|
150
|
+
DOMUtilsCore.init(option);
|
|
151
|
+
}
|
|
116
152
|
/** 版本号 */
|
|
117
153
|
version = "2024.5.24";
|
|
118
154
|
attr(element, attrName, attrValue) {
|
|
119
155
|
if (typeof element === "string") {
|
|
120
|
-
element = document.querySelector(element);
|
|
156
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
121
157
|
}
|
|
122
158
|
if (element == null) {
|
|
123
159
|
return;
|
|
@@ -154,7 +190,7 @@
|
|
|
154
190
|
property,
|
|
155
191
|
/** 自定义属性 */
|
|
156
192
|
attributes) {
|
|
157
|
-
let tempElement = document.createElement(tagName);
|
|
193
|
+
let tempElement = DOMUtilsCore.document.createElement(tagName);
|
|
158
194
|
if (typeof property === "string") {
|
|
159
195
|
tempElement.innerHTML = property;
|
|
160
196
|
return tempElement;
|
|
@@ -208,7 +244,7 @@
|
|
|
208
244
|
return propertyValue;
|
|
209
245
|
}
|
|
210
246
|
if (typeof element === "string") {
|
|
211
|
-
element = document.querySelector(element);
|
|
247
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
212
248
|
}
|
|
213
249
|
if (element == null) {
|
|
214
250
|
return;
|
|
@@ -242,7 +278,7 @@
|
|
|
242
278
|
}
|
|
243
279
|
text(element, text) {
|
|
244
280
|
if (typeof element === "string") {
|
|
245
|
-
element = document.querySelector(element);
|
|
281
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
246
282
|
}
|
|
247
283
|
if (element == null) {
|
|
248
284
|
return;
|
|
@@ -264,7 +300,7 @@
|
|
|
264
300
|
}
|
|
265
301
|
html(element, html) {
|
|
266
302
|
if (typeof element === "string") {
|
|
267
|
-
element = document.querySelector(element);
|
|
303
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
268
304
|
}
|
|
269
305
|
if (element == null) {
|
|
270
306
|
return;
|
|
@@ -298,7 +334,7 @@
|
|
|
298
334
|
click(element, handler, details, useDispatchToTriggerEvent) {
|
|
299
335
|
let DOMUtilsContext = this;
|
|
300
336
|
if (typeof element === "string") {
|
|
301
|
-
element = document.querySelector(element);
|
|
337
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
302
338
|
}
|
|
303
339
|
if (element == null) {
|
|
304
340
|
return;
|
|
@@ -327,7 +363,7 @@
|
|
|
327
363
|
blur(element, handler, details, useDispatchToTriggerEvent) {
|
|
328
364
|
let DOMUtilsContext = this;
|
|
329
365
|
if (typeof element === "string") {
|
|
330
|
-
element = document.querySelector(element);
|
|
366
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
331
367
|
}
|
|
332
368
|
if (element == null) {
|
|
333
369
|
return;
|
|
@@ -356,7 +392,7 @@
|
|
|
356
392
|
focus(element, handler, details, useDispatchToTriggerEvent) {
|
|
357
393
|
let DOMUtilsContext = this;
|
|
358
394
|
if (typeof element === "string") {
|
|
359
|
-
element = document.querySelector(element);
|
|
395
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
360
396
|
}
|
|
361
397
|
if (element == null) {
|
|
362
398
|
return;
|
|
@@ -405,7 +441,7 @@
|
|
|
405
441
|
}
|
|
406
442
|
val(element, value) {
|
|
407
443
|
if (typeof element === "string") {
|
|
408
|
-
element = document.querySelector(element);
|
|
444
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
409
445
|
}
|
|
410
446
|
if (element == null) {
|
|
411
447
|
return;
|
|
@@ -434,7 +470,7 @@
|
|
|
434
470
|
return;
|
|
435
471
|
}
|
|
436
472
|
if (typeof element === "string") {
|
|
437
|
-
element = document.querySelector(element);
|
|
473
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
438
474
|
}
|
|
439
475
|
if (propValue == null) {
|
|
440
476
|
return element[propName];
|
|
@@ -454,7 +490,7 @@
|
|
|
454
490
|
* */
|
|
455
491
|
removeAttr(element, attrName) {
|
|
456
492
|
if (typeof element === "string") {
|
|
457
|
-
element = document.querySelector(element);
|
|
493
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
458
494
|
}
|
|
459
495
|
if (element == null) {
|
|
460
496
|
return;
|
|
@@ -472,7 +508,7 @@
|
|
|
472
508
|
*/
|
|
473
509
|
removeClass(element, className) {
|
|
474
510
|
if (typeof element === "string") {
|
|
475
|
-
element = document.querySelector(element);
|
|
511
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
476
512
|
}
|
|
477
513
|
if (element == null) {
|
|
478
514
|
return;
|
|
@@ -493,7 +529,7 @@
|
|
|
493
529
|
* */
|
|
494
530
|
removeProp(element, propName) {
|
|
495
531
|
if (typeof element === "string") {
|
|
496
|
-
element = document.querySelector(element);
|
|
532
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
497
533
|
}
|
|
498
534
|
if (element == null) {
|
|
499
535
|
return;
|
|
@@ -512,7 +548,7 @@
|
|
|
512
548
|
replaceWith(element, newElement) {
|
|
513
549
|
let DOMUtilsContext = this;
|
|
514
550
|
if (typeof element === "string") {
|
|
515
|
-
element = document.querySelector(element);
|
|
551
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
516
552
|
}
|
|
517
553
|
if (element == null) {
|
|
518
554
|
return;
|
|
@@ -540,7 +576,7 @@
|
|
|
540
576
|
* */
|
|
541
577
|
addClass(element, className) {
|
|
542
578
|
if (typeof element === "string") {
|
|
543
|
-
element = document.querySelector(element);
|
|
579
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
544
580
|
}
|
|
545
581
|
if (element == null) {
|
|
546
582
|
return;
|
|
@@ -558,7 +594,7 @@
|
|
|
558
594
|
* */
|
|
559
595
|
append(element, content) {
|
|
560
596
|
if (typeof element === "string") {
|
|
561
|
-
element = document.querySelector(element);
|
|
597
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
562
598
|
}
|
|
563
599
|
if (element == null) {
|
|
564
600
|
return;
|
|
@@ -581,7 +617,7 @@
|
|
|
581
617
|
* */
|
|
582
618
|
prepend(element, content) {
|
|
583
619
|
if (typeof element === "string") {
|
|
584
|
-
element = document.querySelector(element);
|
|
620
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
585
621
|
}
|
|
586
622
|
if (element == null) {
|
|
587
623
|
return;
|
|
@@ -604,7 +640,7 @@
|
|
|
604
640
|
* */
|
|
605
641
|
after(element, content) {
|
|
606
642
|
if (typeof element === "string") {
|
|
607
|
-
element = document.querySelector(element);
|
|
643
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
608
644
|
}
|
|
609
645
|
if (element == null) {
|
|
610
646
|
return;
|
|
@@ -627,7 +663,7 @@
|
|
|
627
663
|
* */
|
|
628
664
|
before(element, content) {
|
|
629
665
|
if (typeof element === "string") {
|
|
630
|
-
element = document.querySelector(element);
|
|
666
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
631
667
|
}
|
|
632
668
|
if (element == null) {
|
|
633
669
|
return;
|
|
@@ -651,7 +687,7 @@
|
|
|
651
687
|
remove(target) {
|
|
652
688
|
let DOMUtilsContext = this;
|
|
653
689
|
if (typeof target === "string") {
|
|
654
|
-
target = document.querySelectorAll(target);
|
|
690
|
+
target = DOMUtilsCore.document.querySelectorAll(target);
|
|
655
691
|
}
|
|
656
692
|
if (target == null) {
|
|
657
693
|
return;
|
|
@@ -676,7 +712,7 @@
|
|
|
676
712
|
* */
|
|
677
713
|
empty(element) {
|
|
678
714
|
if (typeof element === "string") {
|
|
679
|
-
element = document.querySelector(element);
|
|
715
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
680
716
|
}
|
|
681
717
|
if (element == null) {
|
|
682
718
|
return;
|
|
@@ -713,7 +749,7 @@
|
|
|
713
749
|
let DOMUtilsContext = this;
|
|
714
750
|
let args = arguments;
|
|
715
751
|
if (typeof element === "string") {
|
|
716
|
-
element = document.querySelectorAll(element);
|
|
752
|
+
element = DOMUtilsCore.document.querySelectorAll(element);
|
|
717
753
|
}
|
|
718
754
|
if (element == null) {
|
|
719
755
|
return;
|
|
@@ -764,7 +800,7 @@
|
|
|
764
800
|
if (_selector_) {
|
|
765
801
|
/* 存在自定义子元素选择器 */
|
|
766
802
|
let totalParent = CommonDOMUtils.isWin(elementItem)
|
|
767
|
-
? document.documentElement
|
|
803
|
+
? DOMUtilsCore.document.documentElement
|
|
768
804
|
: elementItem;
|
|
769
805
|
if (target.matches(_selector_)) {
|
|
770
806
|
/* 当前目标可以被selector所匹配到 */
|
|
@@ -830,7 +866,7 @@
|
|
|
830
866
|
}
|
|
831
867
|
let args = arguments;
|
|
832
868
|
if (typeof element === "string") {
|
|
833
|
-
element = document.querySelectorAll(element);
|
|
869
|
+
element = DOMUtilsCore.document.querySelectorAll(element);
|
|
834
870
|
}
|
|
835
871
|
if (element == null) {
|
|
836
872
|
return;
|
|
@@ -914,7 +950,7 @@
|
|
|
914
950
|
*/
|
|
915
951
|
offAll(element, eventType) {
|
|
916
952
|
if (typeof element === "string") {
|
|
917
|
-
element = document.querySelectorAll(element);
|
|
953
|
+
element = DOMUtilsCore.document.querySelectorAll(element);
|
|
918
954
|
}
|
|
919
955
|
if (element == null) {
|
|
920
956
|
return;
|
|
@@ -974,7 +1010,7 @@
|
|
|
974
1010
|
*/
|
|
975
1011
|
trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
|
|
976
1012
|
if (typeof element === "string") {
|
|
977
|
-
element = document.querySelector(element);
|
|
1013
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
978
1014
|
}
|
|
979
1015
|
if (element == null) {
|
|
980
1016
|
return;
|
|
@@ -1032,7 +1068,7 @@
|
|
|
1032
1068
|
*/
|
|
1033
1069
|
offset(element) {
|
|
1034
1070
|
if (typeof element === "string") {
|
|
1035
|
-
element = document.querySelector(element);
|
|
1071
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1036
1072
|
}
|
|
1037
1073
|
if (element == null) {
|
|
1038
1074
|
return;
|
|
@@ -1040,21 +1076,21 @@
|
|
|
1040
1076
|
let rect = element.getBoundingClientRect();
|
|
1041
1077
|
return {
|
|
1042
1078
|
/** y轴偏移 */
|
|
1043
|
-
top: rect.top + globalThis.scrollY,
|
|
1079
|
+
top: rect.top + DOMUtilsCore.globalThis.scrollY,
|
|
1044
1080
|
/** x轴偏移 */
|
|
1045
|
-
left: rect.left + globalThis.scrollX,
|
|
1081
|
+
left: rect.left + DOMUtilsCore.globalThis.scrollX,
|
|
1046
1082
|
};
|
|
1047
1083
|
}
|
|
1048
1084
|
width(element, isShow = false) {
|
|
1049
1085
|
let DOMUtilsContext = this;
|
|
1050
1086
|
if (typeof element === "string") {
|
|
1051
|
-
element = document.querySelector(element);
|
|
1087
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1052
1088
|
}
|
|
1053
1089
|
if (element == null) {
|
|
1054
1090
|
return;
|
|
1055
1091
|
}
|
|
1056
1092
|
if (CommonDOMUtils.isWin(element)) {
|
|
1057
|
-
return window.document.documentElement.clientWidth;
|
|
1093
|
+
return DOMUtilsCore.window.document.documentElement.clientWidth;
|
|
1058
1094
|
}
|
|
1059
1095
|
if (element.nodeType === 9) {
|
|
1060
1096
|
/* Document文档节点 */
|
|
@@ -1097,10 +1133,10 @@
|
|
|
1097
1133
|
height(element, isShow = false) {
|
|
1098
1134
|
let DOMUtilsContext = this;
|
|
1099
1135
|
if (CommonDOMUtils.isWin(element)) {
|
|
1100
|
-
return window.document.documentElement.clientHeight;
|
|
1136
|
+
return DOMUtilsCore.window.document.documentElement.clientHeight;
|
|
1101
1137
|
}
|
|
1102
1138
|
if (typeof element === "string") {
|
|
1103
|
-
element = document.querySelector(element);
|
|
1139
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1104
1140
|
}
|
|
1105
1141
|
if (element == null) {
|
|
1106
1142
|
// @ts-ignore
|
|
@@ -1147,10 +1183,10 @@
|
|
|
1147
1183
|
outerWidth(element, isShow = false) {
|
|
1148
1184
|
let DOMUtilsContext = this;
|
|
1149
1185
|
if (CommonDOMUtils.isWin(element)) {
|
|
1150
|
-
return window.innerWidth;
|
|
1186
|
+
return DOMUtilsCore.window.innerWidth;
|
|
1151
1187
|
}
|
|
1152
1188
|
if (typeof element === "string") {
|
|
1153
|
-
element = document.querySelector(element);
|
|
1189
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1154
1190
|
}
|
|
1155
1191
|
if (element == null) {
|
|
1156
1192
|
// @ts-ignore
|
|
@@ -1173,10 +1209,10 @@
|
|
|
1173
1209
|
outerHeight(element, isShow = false) {
|
|
1174
1210
|
let DOMUtilsContext = this;
|
|
1175
1211
|
if (CommonDOMUtils.isWin(element)) {
|
|
1176
|
-
return window.innerHeight;
|
|
1212
|
+
return DOMUtilsCore.window.innerHeight;
|
|
1177
1213
|
}
|
|
1178
1214
|
if (typeof element === "string") {
|
|
1179
|
-
element = document.querySelector(element);
|
|
1215
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1180
1216
|
}
|
|
1181
1217
|
if (element == null) {
|
|
1182
1218
|
// @ts-ignore
|
|
@@ -1237,7 +1273,7 @@
|
|
|
1237
1273
|
*/
|
|
1238
1274
|
animate(element, styles, duration = 1000, callback = null) {
|
|
1239
1275
|
if (typeof element === "string") {
|
|
1240
|
-
element = document.querySelector(element);
|
|
1276
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1241
1277
|
}
|
|
1242
1278
|
if (element == null) {
|
|
1243
1279
|
return;
|
|
@@ -1289,14 +1325,14 @@
|
|
|
1289
1325
|
*/
|
|
1290
1326
|
wrap(element, wrapperHTML) {
|
|
1291
1327
|
if (typeof element === "string") {
|
|
1292
|
-
element = document.querySelector(element);
|
|
1328
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1293
1329
|
}
|
|
1294
1330
|
if (element == null) {
|
|
1295
1331
|
return;
|
|
1296
1332
|
}
|
|
1297
1333
|
element = element;
|
|
1298
1334
|
// 创建一个新的div元素,并将wrapperHTML作为其innerHTML
|
|
1299
|
-
let wrapper = document.createElement("div");
|
|
1335
|
+
let wrapper = DOMUtilsCore.document.createElement("div");
|
|
1300
1336
|
wrapper.innerHTML = wrapperHTML;
|
|
1301
1337
|
let wrapperFirstChild = wrapper.firstChild;
|
|
1302
1338
|
// 将要包裹的元素插入目标元素前面
|
|
@@ -1306,7 +1342,7 @@
|
|
|
1306
1342
|
}
|
|
1307
1343
|
prev(element) {
|
|
1308
1344
|
if (typeof element === "string") {
|
|
1309
|
-
element = document.querySelector(element);
|
|
1345
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1310
1346
|
}
|
|
1311
1347
|
if (element == null) {
|
|
1312
1348
|
return;
|
|
@@ -1315,7 +1351,7 @@
|
|
|
1315
1351
|
}
|
|
1316
1352
|
next(element) {
|
|
1317
1353
|
if (typeof element === "string") {
|
|
1318
|
-
element = document.querySelector(element);
|
|
1354
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1319
1355
|
}
|
|
1320
1356
|
if (element == null) {
|
|
1321
1357
|
return;
|
|
@@ -1328,15 +1364,15 @@
|
|
|
1328
1364
|
* let DOMUtils = window.DOMUtils.noConflict()
|
|
1329
1365
|
*/
|
|
1330
1366
|
noConflict() {
|
|
1331
|
-
if (window.DOMUtils) {
|
|
1367
|
+
if (DOMUtilsCore.window.DOMUtils) {
|
|
1332
1368
|
CommonDOMUtils.delete(window, "DOMUtils");
|
|
1333
1369
|
}
|
|
1334
|
-
window.DOMUtils = this;
|
|
1370
|
+
DOMUtilsCore.window.DOMUtils = this;
|
|
1335
1371
|
return this;
|
|
1336
1372
|
}
|
|
1337
1373
|
siblings(element) {
|
|
1338
1374
|
if (typeof element === "string") {
|
|
1339
|
-
element = document.querySelector(element);
|
|
1375
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1340
1376
|
}
|
|
1341
1377
|
if (element == null) {
|
|
1342
1378
|
return;
|
|
@@ -1357,7 +1393,7 @@
|
|
|
1357
1393
|
parent(element) {
|
|
1358
1394
|
let DOMUtilsContext = this;
|
|
1359
1395
|
if (typeof element === "string") {
|
|
1360
|
-
element = document.querySelector(element);
|
|
1396
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1361
1397
|
}
|
|
1362
1398
|
if (element == null) {
|
|
1363
1399
|
return;
|
|
@@ -1385,7 +1421,7 @@
|
|
|
1385
1421
|
}
|
|
1386
1422
|
}
|
|
1387
1423
|
function parseHTMLByCreateDom() {
|
|
1388
|
-
let tempDIV = document.createElement("div");
|
|
1424
|
+
let tempDIV = DOMUtilsCore.document.createElement("div");
|
|
1389
1425
|
tempDIV.innerHTML = html;
|
|
1390
1426
|
if (isComplete) {
|
|
1391
1427
|
return tempDIV;
|
|
@@ -1418,7 +1454,7 @@
|
|
|
1418
1454
|
hover(element, handler, option) {
|
|
1419
1455
|
let DOMUtilsContext = this;
|
|
1420
1456
|
if (typeof element === "string") {
|
|
1421
|
-
element = document.querySelector(element);
|
|
1457
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1422
1458
|
}
|
|
1423
1459
|
if (element == null) {
|
|
1424
1460
|
return;
|
|
@@ -1441,7 +1477,7 @@
|
|
|
1441
1477
|
return;
|
|
1442
1478
|
}
|
|
1443
1479
|
if (typeof target === "string") {
|
|
1444
|
-
target = document.querySelectorAll(target);
|
|
1480
|
+
target = DOMUtilsCore.document.querySelectorAll(target);
|
|
1445
1481
|
}
|
|
1446
1482
|
if (target instanceof NodeList || target instanceof Array) {
|
|
1447
1483
|
target = target;
|
|
@@ -1450,6 +1486,7 @@
|
|
|
1450
1486
|
}
|
|
1451
1487
|
}
|
|
1452
1488
|
else {
|
|
1489
|
+
target = target;
|
|
1453
1490
|
target.style.display = "";
|
|
1454
1491
|
if (!CommonDOMUtils.isShow(target)) {
|
|
1455
1492
|
/* 仍然是不显示,尝试使用强覆盖 */
|
|
@@ -1472,7 +1509,7 @@
|
|
|
1472
1509
|
return;
|
|
1473
1510
|
}
|
|
1474
1511
|
if (typeof target === "string") {
|
|
1475
|
-
target = document.querySelectorAll(target);
|
|
1512
|
+
target = DOMUtilsCore.document.querySelectorAll(target);
|
|
1476
1513
|
}
|
|
1477
1514
|
if (target instanceof NodeList || target instanceof Array) {
|
|
1478
1515
|
target = target;
|
|
@@ -1481,6 +1518,7 @@
|
|
|
1481
1518
|
}
|
|
1482
1519
|
}
|
|
1483
1520
|
else {
|
|
1521
|
+
target = target;
|
|
1484
1522
|
target.style.display = "none";
|
|
1485
1523
|
if (CommonDOMUtils.isShow(target)) {
|
|
1486
1524
|
/* 仍然是显示,尝试使用强覆盖 */
|
|
@@ -1509,7 +1547,7 @@
|
|
|
1509
1547
|
return;
|
|
1510
1548
|
}
|
|
1511
1549
|
if (typeof target === "string") {
|
|
1512
|
-
target = document.querySelector(target);
|
|
1550
|
+
target = DOMUtilsCore.document.querySelector(target);
|
|
1513
1551
|
}
|
|
1514
1552
|
DOMUtilsContext.on(target, "keyup", null, handler, option);
|
|
1515
1553
|
}
|
|
@@ -1534,7 +1572,7 @@
|
|
|
1534
1572
|
return;
|
|
1535
1573
|
}
|
|
1536
1574
|
if (typeof target === "string") {
|
|
1537
|
-
target = document.querySelector(target);
|
|
1575
|
+
target = DOMUtilsCore.document.querySelector(target);
|
|
1538
1576
|
}
|
|
1539
1577
|
DOMUtilsContext.on(target, "keydown", null, handler, option);
|
|
1540
1578
|
}
|
|
@@ -1559,7 +1597,7 @@
|
|
|
1559
1597
|
return;
|
|
1560
1598
|
}
|
|
1561
1599
|
if (typeof target === "string") {
|
|
1562
|
-
target = document.querySelector(target);
|
|
1600
|
+
target = DOMUtilsCore.document.querySelector(target);
|
|
1563
1601
|
}
|
|
1564
1602
|
DOMUtilsContext.on(target, "keypress", null, handler, option);
|
|
1565
1603
|
}
|
|
@@ -1582,7 +1620,7 @@
|
|
|
1582
1620
|
return;
|
|
1583
1621
|
}
|
|
1584
1622
|
if (typeof element === "string") {
|
|
1585
|
-
element = document.querySelector(element);
|
|
1623
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1586
1624
|
}
|
|
1587
1625
|
element = element;
|
|
1588
1626
|
element.style.opacity = "0";
|
|
@@ -1596,16 +1634,16 @@
|
|
|
1596
1634
|
element = element;
|
|
1597
1635
|
element.style.opacity = Math.min(progress / duration, 1).toString();
|
|
1598
1636
|
if (progress < duration) {
|
|
1599
|
-
window.requestAnimationFrame(step);
|
|
1637
|
+
DOMUtilsCore.window.requestAnimationFrame(step);
|
|
1600
1638
|
}
|
|
1601
1639
|
else {
|
|
1602
1640
|
if (callback && typeof callback === "function") {
|
|
1603
1641
|
callback();
|
|
1604
1642
|
}
|
|
1605
|
-
window.cancelAnimationFrame(timer);
|
|
1643
|
+
DOMUtilsCore.window.cancelAnimationFrame(timer);
|
|
1606
1644
|
}
|
|
1607
1645
|
}
|
|
1608
|
-
timer = window.requestAnimationFrame(step);
|
|
1646
|
+
timer = DOMUtilsCore.window.requestAnimationFrame(step);
|
|
1609
1647
|
}
|
|
1610
1648
|
/**
|
|
1611
1649
|
* 淡出元素
|
|
@@ -1626,7 +1664,7 @@
|
|
|
1626
1664
|
return;
|
|
1627
1665
|
}
|
|
1628
1666
|
if (typeof element === "string") {
|
|
1629
|
-
element = document.querySelector(element);
|
|
1667
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1630
1668
|
}
|
|
1631
1669
|
element = element;
|
|
1632
1670
|
element.style.opacity = "1";
|
|
@@ -1639,17 +1677,17 @@
|
|
|
1639
1677
|
element = element;
|
|
1640
1678
|
element.style.opacity = Math.max(1 - progress / duration, 0).toString();
|
|
1641
1679
|
if (progress < duration) {
|
|
1642
|
-
window.requestAnimationFrame(step);
|
|
1680
|
+
DOMUtilsCore.window.requestAnimationFrame(step);
|
|
1643
1681
|
}
|
|
1644
1682
|
else {
|
|
1645
1683
|
element.style.display = "none";
|
|
1646
1684
|
if (typeof callback === "function") {
|
|
1647
1685
|
callback();
|
|
1648
1686
|
}
|
|
1649
|
-
window.cancelAnimationFrame(timer);
|
|
1687
|
+
DOMUtilsCore.window.cancelAnimationFrame(timer);
|
|
1650
1688
|
}
|
|
1651
1689
|
}
|
|
1652
|
-
timer = window.requestAnimationFrame(step);
|
|
1690
|
+
timer = DOMUtilsCore.window.requestAnimationFrame(step);
|
|
1653
1691
|
}
|
|
1654
1692
|
/**
|
|
1655
1693
|
* 切换元素的显示和隐藏状态
|
|
@@ -1662,7 +1700,7 @@
|
|
|
1662
1700
|
toggle(element) {
|
|
1663
1701
|
let DOMUtilsContext = this;
|
|
1664
1702
|
if (typeof element === "string") {
|
|
1665
|
-
element = document.querySelector(element);
|
|
1703
|
+
element = DOMUtilsCore.document.querySelector(element);
|
|
1666
1704
|
}
|
|
1667
1705
|
if (element == null) {
|
|
1668
1706
|
return;
|
|
@@ -1674,6 +1712,14 @@
|
|
|
1674
1712
|
DOMUtilsContext.hide(element);
|
|
1675
1713
|
}
|
|
1676
1714
|
}
|
|
1715
|
+
/**
|
|
1716
|
+
* 创建一个新的DOMUtils实例
|
|
1717
|
+
* @param option
|
|
1718
|
+
* @returns
|
|
1719
|
+
*/
|
|
1720
|
+
createDOMUtils(option) {
|
|
1721
|
+
return new DOMUtils(option);
|
|
1722
|
+
}
|
|
1677
1723
|
}
|
|
1678
1724
|
let domUtils = new DOMUtils();
|
|
1679
1725
|
|