@whitesev/domutils 1.7.2 → 1.7.4
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 +40 -28
- 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 +40 -28
- 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 +40 -28
- 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 +40 -28
- 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 +40 -28
- 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 +40 -28
- 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/ElementEvent.d.ts +8 -2
- package/dist/types/src/index.d.ts +2 -2
- package/package.json +5 -5
- package/src/ElementEvent.ts +44 -18
- package/src/index.ts +2 -2
package/dist/index.amd.js
CHANGED
|
@@ -523,7 +523,7 @@ define((function () { 'use strict';
|
|
|
523
523
|
},
|
|
524
524
|
};
|
|
525
525
|
|
|
526
|
-
const version = "1.7.
|
|
526
|
+
const version = "1.7.4";
|
|
527
527
|
|
|
528
528
|
/* 数据 */
|
|
529
529
|
const GlobalData = {
|
|
@@ -1992,18 +1992,10 @@ define((function () { 'use strict';
|
|
|
1992
1992
|
});
|
|
1993
1993
|
});
|
|
1994
1994
|
}
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
* DOMUtils.ready(function(){
|
|
2000
|
-
* console.log("文档加载完毕")
|
|
2001
|
-
* })
|
|
2002
|
-
*/
|
|
2003
|
-
ready(callback) {
|
|
2004
|
-
if (typeof callback !== "function") {
|
|
2005
|
-
return;
|
|
2006
|
-
}
|
|
1995
|
+
ready(...args) {
|
|
1996
|
+
const callback = args[0];
|
|
1997
|
+
// 异步回调
|
|
1998
|
+
let resolve = void 0;
|
|
2007
1999
|
const that = this;
|
|
2008
2000
|
/**
|
|
2009
2001
|
* 检测文档是否加载完毕
|
|
@@ -2028,9 +2020,17 @@ define((function () { 'use strict';
|
|
|
2028
2020
|
*/
|
|
2029
2021
|
function completed() {
|
|
2030
2022
|
removeDomReadyListener();
|
|
2031
|
-
callback
|
|
2023
|
+
if (typeof callback === "function") {
|
|
2024
|
+
callback();
|
|
2025
|
+
}
|
|
2026
|
+
if (typeof resolve === "function") {
|
|
2027
|
+
resolve();
|
|
2028
|
+
}
|
|
2032
2029
|
}
|
|
2033
|
-
|
|
2030
|
+
/**
|
|
2031
|
+
* 监听目标
|
|
2032
|
+
*/
|
|
2033
|
+
const listenTargetList = [
|
|
2034
2034
|
{
|
|
2035
2035
|
target: that.windowApi.document,
|
|
2036
2036
|
eventType: "DOMContentLoaded",
|
|
@@ -2046,27 +2046,39 @@ define((function () { 'use strict';
|
|
|
2046
2046
|
* 添加监听
|
|
2047
2047
|
*/
|
|
2048
2048
|
function addDomReadyListener() {
|
|
2049
|
-
for (
|
|
2050
|
-
|
|
2051
|
-
item.target.addEventListener(item.eventType, item.callback);
|
|
2049
|
+
for (const item of listenTargetList) {
|
|
2050
|
+
that.on(item.target, item.eventType, item.callback);
|
|
2052
2051
|
}
|
|
2053
2052
|
}
|
|
2054
2053
|
/**
|
|
2055
2054
|
* 移除监听
|
|
2056
2055
|
*/
|
|
2057
2056
|
function removeDomReadyListener() {
|
|
2058
|
-
for (
|
|
2059
|
-
|
|
2060
|
-
|
|
2057
|
+
for (const item of listenTargetList) {
|
|
2058
|
+
that.off(item.target, item.eventType, item.callback);
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
/**
|
|
2062
|
+
* 执行检查
|
|
2063
|
+
*/
|
|
2064
|
+
function check() {
|
|
2065
|
+
if (checkDOMReadyState()) {
|
|
2066
|
+
/* 检查document状态 */
|
|
2067
|
+
CommonUtils.setTimeout(completed, 0);
|
|
2068
|
+
}
|
|
2069
|
+
else {
|
|
2070
|
+
/* 添加监听 */
|
|
2071
|
+
addDomReadyListener();
|
|
2061
2072
|
}
|
|
2062
2073
|
}
|
|
2063
|
-
if (
|
|
2064
|
-
|
|
2065
|
-
|
|
2074
|
+
if (args.length === 0) {
|
|
2075
|
+
return new Promise((__resolve__) => {
|
|
2076
|
+
resolve = __resolve__;
|
|
2077
|
+
check();
|
|
2078
|
+
});
|
|
2066
2079
|
}
|
|
2067
2080
|
else {
|
|
2068
|
-
|
|
2069
|
-
addDomReadyListener();
|
|
2081
|
+
check();
|
|
2070
2082
|
}
|
|
2071
2083
|
}
|
|
2072
2084
|
/**
|
|
@@ -3272,12 +3284,12 @@ define((function () { 'use strict';
|
|
|
3272
3284
|
}
|
|
3273
3285
|
/**
|
|
3274
3286
|
* 移除元素
|
|
3275
|
-
* @param $el
|
|
3287
|
+
* @param $el 目标元素,可以是数组、单个元素、NodeList、元素选择器
|
|
3276
3288
|
* @example
|
|
3277
|
-
* // 元素a.xx前面添加一个元素
|
|
3278
3289
|
* DOMUtils.remove(document.querySelector("a.xx"))
|
|
3279
3290
|
* DOMUtils.remove(document.querySelectorAll("a.xx"))
|
|
3280
3291
|
* DOMUtils.remove("a.xx")
|
|
3292
|
+
* DOMUtils.remove([a.xxx, div.xxx, span.xxx])
|
|
3281
3293
|
* */
|
|
3282
3294
|
remove($el) {
|
|
3283
3295
|
const that = this;
|