@whitesev/domutils 2.0.5 → 2.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/index.amd.js +37 -31
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +37 -31
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +37 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +37 -31
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +37 -31
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +37 -31
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/CommonUtils.d.ts +10 -10
- package/dist/types/src/ElementEvent.d.ts +2 -2
- package/dist/types/src/index.d.ts +2 -2
- package/package.json +1 -1
- package/src/CommonUtils.ts +27 -27
- package/src/ElementEvent.ts +3 -3
- package/src/index.ts +12 -7
package/dist/index.iife.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var DOMUtils = (function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const version = "2.0.
|
|
4
|
+
const version = "2.0.7";
|
|
5
5
|
|
|
6
6
|
class WindowApi {
|
|
7
7
|
/** 默认的配置 */
|
|
@@ -108,15 +108,15 @@ var DOMUtils = (function () {
|
|
|
108
108
|
* @param $el
|
|
109
109
|
*/
|
|
110
110
|
forceShow($el) {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
this.windowApi.document.documentElement.appendChild(
|
|
111
|
+
const $clone = $el.cloneNode(true);
|
|
112
|
+
$clone.setAttribute("style", "visibility: hidden !important;display:block !important;");
|
|
113
|
+
this.windowApi.document.documentElement.appendChild($clone);
|
|
114
114
|
return {
|
|
115
115
|
/**
|
|
116
116
|
* 恢复修改的style
|
|
117
117
|
*/
|
|
118
118
|
recovery() {
|
|
119
|
-
|
|
119
|
+
$clone.remove();
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
},
|
|
@@ -149,37 +149,37 @@ var DOMUtils = (function () {
|
|
|
149
149
|
},
|
|
150
150
|
/**
|
|
151
151
|
* 判断是否是window,例如window、self、globalThis
|
|
152
|
-
* @param
|
|
152
|
+
* @param obj
|
|
153
153
|
*/
|
|
154
|
-
isWin(
|
|
155
|
-
if (typeof
|
|
154
|
+
isWin(obj) {
|
|
155
|
+
if (typeof obj !== "object") {
|
|
156
156
|
return false;
|
|
157
157
|
}
|
|
158
|
-
if (
|
|
158
|
+
if (obj instanceof Node) {
|
|
159
159
|
return false;
|
|
160
160
|
}
|
|
161
|
-
if (
|
|
161
|
+
if (obj === globalThis) {
|
|
162
162
|
return true;
|
|
163
163
|
}
|
|
164
|
-
if (
|
|
164
|
+
if (obj === window) {
|
|
165
165
|
return true;
|
|
166
166
|
}
|
|
167
|
-
if (
|
|
167
|
+
if (obj === self) {
|
|
168
168
|
return true;
|
|
169
169
|
}
|
|
170
|
-
if (
|
|
170
|
+
if (obj === globalThis) {
|
|
171
171
|
return true;
|
|
172
172
|
}
|
|
173
|
-
if (
|
|
173
|
+
if (obj === window) {
|
|
174
174
|
return true;
|
|
175
175
|
}
|
|
176
|
-
if (
|
|
176
|
+
if (obj === self) {
|
|
177
177
|
return true;
|
|
178
178
|
}
|
|
179
|
-
if (typeof unsafeWindow !== "undefined" &&
|
|
179
|
+
if (typeof unsafeWindow !== "undefined" && obj === unsafeWindow) {
|
|
180
180
|
return true;
|
|
181
181
|
}
|
|
182
|
-
if (
|
|
182
|
+
if (obj?.Math?.toString() !== "[object Math]") {
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
185
|
return true;
|
|
@@ -199,23 +199,23 @@ var DOMUtils = (function () {
|
|
|
199
199
|
},
|
|
200
200
|
/**
|
|
201
201
|
* 删除对象上的属性
|
|
202
|
-
* @param
|
|
202
|
+
* @param obj
|
|
203
203
|
* @param propName
|
|
204
204
|
*/
|
|
205
|
-
delete(
|
|
205
|
+
delete(obj, propName) {
|
|
206
206
|
if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
|
|
207
|
-
return Reflect.deleteProperty(
|
|
207
|
+
return Reflect.deleteProperty(obj, propName);
|
|
208
208
|
}
|
|
209
209
|
else {
|
|
210
|
-
delete
|
|
210
|
+
delete obj[propName];
|
|
211
211
|
}
|
|
212
212
|
},
|
|
213
213
|
/**
|
|
214
214
|
* 判断是否是元素列表
|
|
215
|
-
* @param $
|
|
215
|
+
* @param $el
|
|
216
216
|
*/
|
|
217
|
-
isNodeList($
|
|
218
|
-
return Array.isArray($
|
|
217
|
+
isNodeList($el) {
|
|
218
|
+
return Array.isArray($el) || $el instanceof NodeList;
|
|
219
219
|
},
|
|
220
220
|
/** 获取 animationend 在各个浏览器的兼容名 */
|
|
221
221
|
getAnimationEndNameList() {
|
|
@@ -1710,7 +1710,7 @@ var DOMUtils = (function () {
|
|
|
1710
1710
|
/**
|
|
1711
1711
|
* 取消绑定所有的事件
|
|
1712
1712
|
* @param element 需要取消绑定的元素|元素数组
|
|
1713
|
-
* @param eventType
|
|
1713
|
+
* @param eventType (可选)需要取消监听的事件,不传入该参数则遍历所有监听的事件
|
|
1714
1714
|
*/
|
|
1715
1715
|
offAll(element, eventType) {
|
|
1716
1716
|
const that = this;
|
|
@@ -3314,7 +3314,7 @@ var DOMUtils = (function () {
|
|
|
3314
3314
|
handler($el, $fragment);
|
|
3315
3315
|
}
|
|
3316
3316
|
/**
|
|
3317
|
-
*
|
|
3317
|
+
* 移除元素(包括它和内部使用.on添加的监听事件)
|
|
3318
3318
|
* @param $el 目标元素,可以是数组、单个元素、NodeList、元素选择器
|
|
3319
3319
|
* @example
|
|
3320
3320
|
* DOMUtils.remove(document.querySelector("a.xx"))
|
|
@@ -3323,19 +3323,25 @@ var DOMUtils = (function () {
|
|
|
3323
3323
|
* DOMUtils.remove([a.xxx, div.xxx, span.xxx])
|
|
3324
3324
|
* */
|
|
3325
3325
|
remove($el) {
|
|
3326
|
-
const that = this;
|
|
3327
3326
|
if (typeof $el === "string") {
|
|
3328
|
-
$el =
|
|
3327
|
+
$el = this.selectorAll($el);
|
|
3329
3328
|
}
|
|
3330
3329
|
if ($el == null) {
|
|
3331
3330
|
return;
|
|
3332
3331
|
}
|
|
3333
3332
|
if (CommonUtils.isNodeList($el)) {
|
|
3334
3333
|
$el.forEach(($elItem) => {
|
|
3335
|
-
|
|
3334
|
+
this.remove($elItem);
|
|
3336
3335
|
});
|
|
3337
3336
|
return;
|
|
3338
3337
|
}
|
|
3338
|
+
// 移除事件
|
|
3339
|
+
$el.querySelectorAll("*").forEach(($elItem) => {
|
|
3340
|
+
if (!($elItem instanceof Element))
|
|
3341
|
+
return;
|
|
3342
|
+
this.offAll($elItem);
|
|
3343
|
+
});
|
|
3344
|
+
this.offAll($el);
|
|
3339
3345
|
if (typeof $el.remove === "function") {
|
|
3340
3346
|
$el.remove();
|
|
3341
3347
|
}
|
|
@@ -3370,7 +3376,7 @@ var DOMUtils = (function () {
|
|
|
3370
3376
|
return;
|
|
3371
3377
|
}
|
|
3372
3378
|
if ($el.innerHTML) {
|
|
3373
|
-
$el
|
|
3379
|
+
CommonUtils.setSafeHTML($el, "");
|
|
3374
3380
|
}
|
|
3375
3381
|
else if ($el.textContent) {
|
|
3376
3382
|
$el.textContent = "";
|
|
@@ -3568,7 +3574,7 @@ var DOMUtils = (function () {
|
|
|
3568
3574
|
}
|
|
3569
3575
|
else {
|
|
3570
3576
|
that.after($el, $newEl);
|
|
3571
|
-
|
|
3577
|
+
this.remove($el);
|
|
3572
3578
|
}
|
|
3573
3579
|
}
|
|
3574
3580
|
/**
|