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