@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.umd.js CHANGED
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DOMUtils = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
- const version = "2.0.5";
7
+ const version = "2.0.7";
8
8
 
9
9
  class WindowApi {
10
10
  /** 默认的配置 */
@@ -111,15 +111,15 @@
111
111
  * @param $el
112
112
  */
113
113
  forceShow($el) {
114
- const dupNode = $el.cloneNode(true);
115
- dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
116
- this.windowApi.document.documentElement.appendChild(dupNode);
114
+ const $clone = $el.cloneNode(true);
115
+ $clone.setAttribute("style", "visibility: hidden !important;display:block !important;");
116
+ this.windowApi.document.documentElement.appendChild($clone);
117
117
  return {
118
118
  /**
119
119
  * 恢复修改的style
120
120
  */
121
121
  recovery() {
122
- dupNode.remove();
122
+ $clone.remove();
123
123
  },
124
124
  };
125
125
  },
@@ -152,37 +152,37 @@
152
152
  },
153
153
  /**
154
154
  * 判断是否是window,例如window、self、globalThis
155
- * @param target
155
+ * @param obj
156
156
  */
157
- isWin(target) {
158
- if (typeof target !== "object") {
157
+ isWin(obj) {
158
+ if (typeof obj !== "object") {
159
159
  return false;
160
160
  }
161
- if (target instanceof Node) {
161
+ if (obj instanceof Node) {
162
162
  return false;
163
163
  }
164
- if (target === globalThis) {
164
+ if (obj === globalThis) {
165
165
  return true;
166
166
  }
167
- if (target === window) {
167
+ if (obj === window) {
168
168
  return true;
169
169
  }
170
- if (target === self) {
170
+ if (obj === self) {
171
171
  return true;
172
172
  }
173
- if (target === globalThis) {
173
+ if (obj === globalThis) {
174
174
  return true;
175
175
  }
176
- if (target === window) {
176
+ if (obj === window) {
177
177
  return true;
178
178
  }
179
- if (target === self) {
179
+ if (obj === self) {
180
180
  return true;
181
181
  }
182
- if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
182
+ if (typeof unsafeWindow !== "undefined" && obj === unsafeWindow) {
183
183
  return true;
184
184
  }
185
- if (target?.Math?.toString() !== "[object Math]") {
185
+ if (obj?.Math?.toString() !== "[object Math]") {
186
186
  return false;
187
187
  }
188
188
  return true;
@@ -202,23 +202,23 @@
202
202
  },
203
203
  /**
204
204
  * 删除对象上的属性
205
- * @param target
205
+ * @param obj
206
206
  * @param propName
207
207
  */
208
- delete(target, propName) {
208
+ delete(obj, propName) {
209
209
  if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
210
- return Reflect.deleteProperty(target, propName);
210
+ return Reflect.deleteProperty(obj, propName);
211
211
  }
212
212
  else {
213
- delete target[propName];
213
+ delete obj[propName];
214
214
  }
215
215
  },
216
216
  /**
217
217
  * 判断是否是元素列表
218
- * @param $ele
218
+ * @param $el
219
219
  */
220
- isNodeList($ele) {
221
- return Array.isArray($ele) || $ele instanceof NodeList;
220
+ isNodeList($el) {
221
+ return Array.isArray($el) || $el instanceof NodeList;
222
222
  },
223
223
  /** 获取 animationend 在各个浏览器的兼容名 */
224
224
  getAnimationEndNameList() {
@@ -1713,7 +1713,7 @@
1713
1713
  /**
1714
1714
  * 取消绑定所有的事件
1715
1715
  * @param element 需要取消绑定的元素|元素数组
1716
- * @param eventType (可选)需要取消监听的事件
1716
+ * @param eventType (可选)需要取消监听的事件,不传入该参数则遍历所有监听的事件
1717
1717
  */
1718
1718
  offAll(element, eventType) {
1719
1719
  const that = this;
@@ -3317,7 +3317,7 @@
3317
3317
  handler($el, $fragment);
3318
3318
  }
3319
3319
  /**
3320
- * 移除元素
3320
+ * 移除元素(包括它和内部使用.on添加的监听事件)
3321
3321
  * @param $el 目标元素,可以是数组、单个元素、NodeList、元素选择器
3322
3322
  * @example
3323
3323
  * DOMUtils.remove(document.querySelector("a.xx"))
@@ -3326,19 +3326,25 @@
3326
3326
  * DOMUtils.remove([a.xxx, div.xxx, span.xxx])
3327
3327
  * */
3328
3328
  remove($el) {
3329
- const that = this;
3330
3329
  if (typeof $el === "string") {
3331
- $el = that.selectorAll($el);
3330
+ $el = this.selectorAll($el);
3332
3331
  }
3333
3332
  if ($el == null) {
3334
3333
  return;
3335
3334
  }
3336
3335
  if (CommonUtils.isNodeList($el)) {
3337
3336
  $el.forEach(($elItem) => {
3338
- that.remove($elItem);
3337
+ this.remove($elItem);
3339
3338
  });
3340
3339
  return;
3341
3340
  }
3341
+ // 移除事件
3342
+ $el.querySelectorAll("*").forEach(($elItem) => {
3343
+ if (!($elItem instanceof Element))
3344
+ return;
3345
+ this.offAll($elItem);
3346
+ });
3347
+ this.offAll($el);
3342
3348
  if (typeof $el.remove === "function") {
3343
3349
  $el.remove();
3344
3350
  }
@@ -3373,7 +3379,7 @@
3373
3379
  return;
3374
3380
  }
3375
3381
  if ($el.innerHTML) {
3376
- $el.innerHTML = "";
3382
+ CommonUtils.setSafeHTML($el, "");
3377
3383
  }
3378
3384
  else if ($el.textContent) {
3379
3385
  $el.textContent = "";
@@ -3571,7 +3577,7 @@
3571
3577
  }
3572
3578
  else {
3573
3579
  that.after($el, $newEl);
3574
- $el.remove();
3580
+ this.remove($el);
3575
3581
  }
3576
3582
  }
3577
3583
  /**