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