@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.
@@ -1,7 +1,7 @@
1
1
  var DOMUtils = (function () {
2
2
  'use strict';
3
3
 
4
- const version = "2.0.5";
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 dupNode = $el.cloneNode(true);
112
- dupNode.setAttribute("style", "visibility: hidden !important;display:block !important;");
113
- this.windowApi.document.documentElement.appendChild(dupNode);
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
- dupNode.remove();
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 target
152
+ * @param obj
153
153
  */
154
- isWin(target) {
155
- if (typeof target !== "object") {
154
+ isWin(obj) {
155
+ if (typeof obj !== "object") {
156
156
  return false;
157
157
  }
158
- if (target instanceof Node) {
158
+ if (obj instanceof Node) {
159
159
  return false;
160
160
  }
161
- if (target === globalThis) {
161
+ if (obj === globalThis) {
162
162
  return true;
163
163
  }
164
- if (target === window) {
164
+ if (obj === window) {
165
165
  return true;
166
166
  }
167
- if (target === self) {
167
+ if (obj === self) {
168
168
  return true;
169
169
  }
170
- if (target === globalThis) {
170
+ if (obj === globalThis) {
171
171
  return true;
172
172
  }
173
- if (target === window) {
173
+ if (obj === window) {
174
174
  return true;
175
175
  }
176
- if (target === self) {
176
+ if (obj === self) {
177
177
  return true;
178
178
  }
179
- if (typeof unsafeWindow !== "undefined" && target === unsafeWindow) {
179
+ if (typeof unsafeWindow !== "undefined" && obj === unsafeWindow) {
180
180
  return true;
181
181
  }
182
- if (target?.Math?.toString() !== "[object Math]") {
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 target
202
+ * @param obj
203
203
  * @param propName
204
204
  */
205
- delete(target, propName) {
205
+ delete(obj, propName) {
206
206
  if (typeof Reflect === "object" && Reflect != null && Reflect.deleteProperty) {
207
- return Reflect.deleteProperty(target, propName);
207
+ return Reflect.deleteProperty(obj, propName);
208
208
  }
209
209
  else {
210
- delete target[propName];
210
+ delete obj[propName];
211
211
  }
212
212
  },
213
213
  /**
214
214
  * 判断是否是元素列表
215
- * @param $ele
215
+ * @param $el
216
216
  */
217
- isNodeList($ele) {
218
- return Array.isArray($ele) || $ele instanceof NodeList;
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 = that.selectorAll($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
- that.remove($elItem);
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.innerHTML = "";
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
- $el.remove();
3577
+ this.remove($el);
3572
3578
  }
3573
3579
  }
3574
3580
  /**