@whitesev/domutils 1.7.5 → 1.8.0
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/README.md +4 -4
- package/dist/index.amd.js +219 -112
- 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 +219 -112
- 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 +219 -112
- 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 +219 -112
- 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 +219 -112
- 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 +219 -112
- 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 +123 -105
- package/dist/types/src/types/DOMUtilsEvent.d.ts +2 -2
- package/package.json +9 -9
- package/src/ElementEvent.ts +270 -135
- package/src/types/DOMUtilsEvent.d.ts +2 -2
package/dist/index.system.js
CHANGED
|
@@ -526,13 +526,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
526
526
|
},
|
|
527
527
|
};
|
|
528
528
|
|
|
529
|
-
const version = "1.
|
|
530
|
-
|
|
531
|
-
/* 数据 */
|
|
532
|
-
const GlobalData = {
|
|
533
|
-
/** .on添加在元素存储的事件 */
|
|
534
|
-
domEventSymbol: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
|
|
535
|
-
};
|
|
529
|
+
const version = "1.8.0";
|
|
536
530
|
|
|
537
531
|
class ElementSelector {
|
|
538
532
|
windowApi;
|
|
@@ -1625,6 +1619,12 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1625
1619
|
}
|
|
1626
1620
|
new ElementAnimate();
|
|
1627
1621
|
|
|
1622
|
+
/* 数据 */
|
|
1623
|
+
const GlobalData = {
|
|
1624
|
+
/** .on添加在元素存储的事件 */
|
|
1625
|
+
domEventSymbol: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
1628
|
const OriginPrototype = {
|
|
1629
1629
|
Object: {
|
|
1630
1630
|
defineProperty: Object.defineProperty,
|
|
@@ -1684,7 +1684,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1684
1684
|
if (element == null) {
|
|
1685
1685
|
return {
|
|
1686
1686
|
off() { },
|
|
1687
|
-
|
|
1687
|
+
emit() { },
|
|
1688
1688
|
};
|
|
1689
1689
|
}
|
|
1690
1690
|
let $elList = [];
|
|
@@ -1819,10 +1819,10 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
1819
1819
|
/**
|
|
1820
1820
|
* 主动触发事件
|
|
1821
1821
|
* @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
|
|
1822
|
-
* @param
|
|
1822
|
+
* @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
|
|
1823
1823
|
*/
|
|
1824
|
-
|
|
1825
|
-
that.
|
|
1824
|
+
emit: (details, useDispatchToEmit) => {
|
|
1825
|
+
that.emit($elList, eventTypeList, details, useDispatchToEmit);
|
|
1826
1826
|
},
|
|
1827
1827
|
};
|
|
1828
1828
|
}
|
|
@@ -2001,7 +2001,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2001
2001
|
});
|
|
2002
2002
|
});
|
|
2003
2003
|
}
|
|
2004
|
-
|
|
2004
|
+
onReady(...args) {
|
|
2005
2005
|
const callback = args[0];
|
|
2006
2006
|
// 异步回调
|
|
2007
2007
|
let resolve = void 0;
|
|
@@ -2095,16 +2095,16 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2095
2095
|
* @param element 需要触发的元素|元素数组|window
|
|
2096
2096
|
* @param eventType 需要触发的事件
|
|
2097
2097
|
* @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
|
|
2098
|
-
* @param
|
|
2098
|
+
* @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
|
|
2099
2099
|
* @example
|
|
2100
2100
|
* // 触发元素a.xx的click事件
|
|
2101
|
-
* DOMUtils.
|
|
2102
|
-
* DOMUtils.
|
|
2101
|
+
* DOMUtils.emit(document.querySelector("a.xx"),"click")
|
|
2102
|
+
* DOMUtils.emit("a.xx","click")
|
|
2103
2103
|
* // 触发元素a.xx的click、tap、hover事件
|
|
2104
|
-
* DOMUtils.
|
|
2105
|
-
* DOMUtils.
|
|
2104
|
+
* DOMUtils.emit(document.querySelector("a.xx"),"click tap hover")
|
|
2105
|
+
* DOMUtils.emit("a.xx",["click","tap","hover"])
|
|
2106
2106
|
*/
|
|
2107
|
-
|
|
2107
|
+
emit(element, eventType, details, useDispatchToEmit = true) {
|
|
2108
2108
|
const that = this;
|
|
2109
2109
|
if (typeof element === "string") {
|
|
2110
2110
|
element = that.selectorAll(element);
|
|
@@ -2146,7 +2146,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2146
2146
|
});
|
|
2147
2147
|
}
|
|
2148
2148
|
}
|
|
2149
|
-
if (
|
|
2149
|
+
if (useDispatchToEmit == false && eventTypeItem in elementEvents) {
|
|
2150
2150
|
// 直接调用监听的事件
|
|
2151
2151
|
elementEvents[eventTypeItem].forEach((eventsItem) => {
|
|
2152
2152
|
eventsItem.callback(event);
|
|
@@ -2159,11 +2159,11 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2159
2159
|
});
|
|
2160
2160
|
}
|
|
2161
2161
|
/**
|
|
2162
|
-
*
|
|
2162
|
+
* 监听或触发元素的click事件
|
|
2163
2163
|
* @param element 目标元素
|
|
2164
2164
|
* @param handler (可选)事件处理函数
|
|
2165
2165
|
* @param details (可选)赋予触发的Event的额外属性
|
|
2166
|
-
* @param
|
|
2166
|
+
* @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
|
|
2167
2167
|
* @example
|
|
2168
2168
|
* // 触发元素a.xx的click事件
|
|
2169
2169
|
* DOMUtils.click(document.querySelector("a.xx"))
|
|
@@ -2172,7 +2172,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2172
2172
|
* console.log("触发click事件成功")
|
|
2173
2173
|
* })
|
|
2174
2174
|
* */
|
|
2175
|
-
click(element, handler, details,
|
|
2175
|
+
click(element, handler, details, useDispatchToEmit) {
|
|
2176
2176
|
const that = this;
|
|
2177
2177
|
if (typeof element === "string") {
|
|
2178
2178
|
element = that.selectorAll(element);
|
|
@@ -2183,23 +2183,23 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2183
2183
|
if (CommonUtils.isNodeList(element)) {
|
|
2184
2184
|
// 设置
|
|
2185
2185
|
element.forEach(($ele) => {
|
|
2186
|
-
that.click($ele, handler, details,
|
|
2186
|
+
that.click($ele, handler, details, useDispatchToEmit);
|
|
2187
2187
|
});
|
|
2188
2188
|
return;
|
|
2189
2189
|
}
|
|
2190
2190
|
if (handler == null) {
|
|
2191
|
-
that.
|
|
2191
|
+
that.emit(element, "click", details, useDispatchToEmit);
|
|
2192
2192
|
}
|
|
2193
2193
|
else {
|
|
2194
2194
|
that.on(element, "click", null, handler);
|
|
2195
2195
|
}
|
|
2196
2196
|
}
|
|
2197
2197
|
/**
|
|
2198
|
-
*
|
|
2198
|
+
* 监听或触发元素的blur事件
|
|
2199
2199
|
* @param element 目标元素
|
|
2200
2200
|
* @param handler (可选)事件处理函数
|
|
2201
2201
|
* @param details (可选)赋予触发的Event的额外属性
|
|
2202
|
-
* @param
|
|
2202
|
+
* @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
|
|
2203
2203
|
* @example
|
|
2204
2204
|
* // 触发元素a.xx的blur事件
|
|
2205
2205
|
* DOMUtils.blur(document.querySelector("a.xx"))
|
|
@@ -2208,7 +2208,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2208
2208
|
* console.log("触发blur事件成功")
|
|
2209
2209
|
* })
|
|
2210
2210
|
* */
|
|
2211
|
-
blur(element, handler, details,
|
|
2211
|
+
blur(element, handler, details, useDispatchToEmit) {
|
|
2212
2212
|
const that = this;
|
|
2213
2213
|
if (typeof element === "string") {
|
|
2214
2214
|
element = that.selectorAll(element);
|
|
@@ -2219,23 +2219,23 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2219
2219
|
if (CommonUtils.isNodeList(element)) {
|
|
2220
2220
|
// 设置
|
|
2221
2221
|
element.forEach(($ele) => {
|
|
2222
|
-
that.focus($ele, handler, details,
|
|
2222
|
+
that.focus($ele, handler, details, useDispatchToEmit);
|
|
2223
2223
|
});
|
|
2224
2224
|
return;
|
|
2225
2225
|
}
|
|
2226
2226
|
if (handler === null) {
|
|
2227
|
-
that.
|
|
2227
|
+
that.emit(element, "blur", details, useDispatchToEmit);
|
|
2228
2228
|
}
|
|
2229
2229
|
else {
|
|
2230
2230
|
that.on(element, "blur", null, handler);
|
|
2231
2231
|
}
|
|
2232
2232
|
}
|
|
2233
2233
|
/**
|
|
2234
|
-
*
|
|
2234
|
+
* 监听或触发元素的focus事件
|
|
2235
2235
|
* @param element 目标元素
|
|
2236
2236
|
* @param handler (可选)事件处理函数
|
|
2237
2237
|
* @param details (可选)赋予触发的Event的额外属性
|
|
2238
|
-
* @param
|
|
2238
|
+
* @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
|
|
2239
2239
|
* @example
|
|
2240
2240
|
* // 触发元素a.xx的focus事件
|
|
2241
2241
|
* DOMUtils.focus(document.querySelector("a.xx"))
|
|
@@ -2244,7 +2244,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2244
2244
|
* console.log("触发focus事件成功")
|
|
2245
2245
|
* })
|
|
2246
2246
|
* */
|
|
2247
|
-
focus(element, handler, details,
|
|
2247
|
+
focus(element, handler, details, useDispatchToEmit) {
|
|
2248
2248
|
const that = this;
|
|
2249
2249
|
if (typeof element === "string") {
|
|
2250
2250
|
element = that.selectorAll(element);
|
|
@@ -2255,12 +2255,12 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2255
2255
|
if (CommonUtils.isNodeList(element)) {
|
|
2256
2256
|
// 设置
|
|
2257
2257
|
element.forEach(($ele) => {
|
|
2258
|
-
that.focus($ele, handler, details,
|
|
2258
|
+
that.focus($ele, handler, details, useDispatchToEmit);
|
|
2259
2259
|
});
|
|
2260
2260
|
return;
|
|
2261
2261
|
}
|
|
2262
2262
|
if (handler == null) {
|
|
2263
|
-
that.
|
|
2263
|
+
that.emit(element, "focus", details, useDispatchToEmit);
|
|
2264
2264
|
}
|
|
2265
2265
|
else {
|
|
2266
2266
|
that.on(element, "focus", null, handler);
|
|
@@ -2273,14 +2273,14 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2273
2273
|
* @param option 配置
|
|
2274
2274
|
* @example
|
|
2275
2275
|
* // 监听a.xx元素的移入或移出
|
|
2276
|
-
* DOMUtils.
|
|
2276
|
+
* DOMUtils.onHover(document.querySelector("a.xx"),()=>{
|
|
2277
2277
|
* console.log("移入/移除");
|
|
2278
2278
|
* })
|
|
2279
|
-
* DOMUtils.
|
|
2279
|
+
* DOMUtils.onHover("a.xx",()=>{
|
|
2280
2280
|
* console.log("移入/移除");
|
|
2281
2281
|
* })
|
|
2282
2282
|
*/
|
|
2283
|
-
|
|
2283
|
+
onHover(element, handler, option) {
|
|
2284
2284
|
const that = this;
|
|
2285
2285
|
if (typeof element === "string") {
|
|
2286
2286
|
element = that.selectorAll(element);
|
|
@@ -2291,7 +2291,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2291
2291
|
if (CommonUtils.isNodeList(element)) {
|
|
2292
2292
|
// 设置
|
|
2293
2293
|
element.forEach(($ele) => {
|
|
2294
|
-
that.
|
|
2294
|
+
that.onHover($ele, handler, option);
|
|
2295
2295
|
});
|
|
2296
2296
|
return;
|
|
2297
2297
|
}
|
|
@@ -2299,12 +2299,12 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2299
2299
|
that.on(element, "mouseleave", null, handler, option);
|
|
2300
2300
|
}
|
|
2301
2301
|
/**
|
|
2302
|
-
*
|
|
2302
|
+
* 监听动画结束
|
|
2303
2303
|
* @param element 监听的元素
|
|
2304
2304
|
* @param handler 触发的回调函数
|
|
2305
2305
|
* @param option 配置项,这里默认配置once为true
|
|
2306
2306
|
*/
|
|
2307
|
-
|
|
2307
|
+
onAnimationend(element, handler, option) {
|
|
2308
2308
|
const that = this;
|
|
2309
2309
|
if (typeof element === "string") {
|
|
2310
2310
|
element = that.selector(element);
|
|
@@ -2327,12 +2327,12 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2327
2327
|
}
|
|
2328
2328
|
}
|
|
2329
2329
|
/**
|
|
2330
|
-
*
|
|
2330
|
+
* 监听过渡结束
|
|
2331
2331
|
* @param element 监听的元素
|
|
2332
2332
|
* @param handler 触发的回调函数
|
|
2333
2333
|
* @param option 配置项,这里默认配置once为true
|
|
2334
2334
|
*/
|
|
2335
|
-
|
|
2335
|
+
onTransitionend(element, handler, option) {
|
|
2336
2336
|
const that = this;
|
|
2337
2337
|
if (typeof element === "string") {
|
|
2338
2338
|
element = that.selector(element);
|
|
@@ -2369,7 +2369,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2369
2369
|
* console.log("按键松开");
|
|
2370
2370
|
* })
|
|
2371
2371
|
*/
|
|
2372
|
-
|
|
2372
|
+
onKeyup(element, handler, option) {
|
|
2373
2373
|
const that = this;
|
|
2374
2374
|
if (element == null) {
|
|
2375
2375
|
return;
|
|
@@ -2380,7 +2380,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2380
2380
|
if (CommonUtils.isNodeList(element)) {
|
|
2381
2381
|
// 设置
|
|
2382
2382
|
element.forEach(($ele) => {
|
|
2383
|
-
that.
|
|
2383
|
+
that.onKeyup($ele, handler, option);
|
|
2384
2384
|
});
|
|
2385
2385
|
return;
|
|
2386
2386
|
}
|
|
@@ -2401,7 +2401,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2401
2401
|
* console.log("按键按下");
|
|
2402
2402
|
* })
|
|
2403
2403
|
*/
|
|
2404
|
-
|
|
2404
|
+
onKeydown(element, handler, option) {
|
|
2405
2405
|
const that = this;
|
|
2406
2406
|
if (element == null) {
|
|
2407
2407
|
return;
|
|
@@ -2412,7 +2412,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2412
2412
|
if (CommonUtils.isNodeList(element)) {
|
|
2413
2413
|
// 设置
|
|
2414
2414
|
element.forEach(($ele) => {
|
|
2415
|
-
that.
|
|
2415
|
+
that.onKeydown($ele, handler, option);
|
|
2416
2416
|
});
|
|
2417
2417
|
return;
|
|
2418
2418
|
}
|
|
@@ -2433,7 +2433,7 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2433
2433
|
* console.log("按键按下");
|
|
2434
2434
|
* })
|
|
2435
2435
|
*/
|
|
2436
|
-
|
|
2436
|
+
onKeypress(element, handler, option) {
|
|
2437
2437
|
const that = this;
|
|
2438
2438
|
if (element == null) {
|
|
2439
2439
|
return;
|
|
@@ -2444,76 +2444,76 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2444
2444
|
if (CommonUtils.isNodeList(element)) {
|
|
2445
2445
|
// 设置
|
|
2446
2446
|
element.forEach(($ele) => {
|
|
2447
|
-
that.
|
|
2447
|
+
that.onKeypress($ele, handler, option);
|
|
2448
2448
|
});
|
|
2449
2449
|
return;
|
|
2450
2450
|
}
|
|
2451
2451
|
that.on(element, "keypress", null, handler, option);
|
|
2452
2452
|
}
|
|
2453
2453
|
/**
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2454
|
+
* 监听某个元素键盘按键事件或window全局按键事件
|
|
2455
|
+
* 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
|
|
2456
|
+
* @param element 需要监听的对象,可以是全局Window或者某个元素
|
|
2457
|
+
* @param eventName 事件名,默认keypress,keydown - > keypress - > keyup
|
|
2458
|
+
* @param handler 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
|
|
2459
2459
|
* @param options 监听事件的配置
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2460
|
+
* @example
|
|
2461
|
+
Utils.onKeyboard(window,(keyName,keyValue,otherKey,event)=>{
|
|
2462
|
+
if(keyName === "Enter"){
|
|
2463
|
+
console.log("回车按键的值是:"+keyValue)
|
|
2464
|
+
}
|
|
2465
|
+
if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
|
|
2466
|
+
console.log("Ctrl和回车键");
|
|
2467
|
+
}
|
|
2468
|
+
})
|
|
2469
|
+
* @example
|
|
2470
|
+
字母和数字键的键码值(keyCode)
|
|
2471
|
+
按键 键码 按键 键码 按键 键码 按键 键码
|
|
2472
|
+
A 65 J 74 S 83 1 49
|
|
2473
|
+
B 66 K 75 T 84 2 50
|
|
2474
|
+
C 67 L 76 U 85 3 51
|
|
2475
|
+
D 68 M 77 V 86 4 52
|
|
2476
|
+
E 69 N 78 W 87 5 53
|
|
2477
|
+
F 70 O 79 X 88 6 54
|
|
2478
|
+
G 71 P 80 Y 89 7 55
|
|
2479
|
+
H 72 Q 81 Z 90 8 56
|
|
2480
|
+
I 73 R 82 0 48 9 57
|
|
2481
|
+
|
|
2482
|
+
数字键盘上的键的键码值(keyCode)
|
|
2483
|
+
功能键键码值(keyCode)
|
|
2484
|
+
按键 键码 按键 键码 按键 键码 按键 键码
|
|
2485
|
+
0 96 8 104 F1 112 F7 118
|
|
2486
|
+
1 97 9 105 F2 113 F8 119
|
|
2487
|
+
2 98 * 106 F3 114 F9 120
|
|
2488
|
+
3 99 + 107 F4 115 F10 121
|
|
2489
|
+
4 100 Enter 108 F5 116 F11 122
|
|
2490
|
+
5 101 - 109 F6 117 F12 123
|
|
2491
|
+
6 102 . 110
|
|
2492
|
+
7 103 / 111
|
|
2493
|
+
|
|
2494
|
+
控制键键码值(keyCode)
|
|
2495
|
+
按键 键码 按键 键码 按键 键码 按键 键码
|
|
2496
|
+
BackSpace 8 Esc 27 → 39 -_ 189
|
|
2497
|
+
Tab 9 Spacebar 32 ↓ 40 .> 190
|
|
2498
|
+
Clear 12 Page Up 33 Insert 45 /? 191
|
|
2499
|
+
Enter 13 Page Down 34 Delete 46 `~ 192
|
|
2500
|
+
Shift 16 End 35 Num Lock 144 [{ 219
|
|
2501
|
+
Control 17 Home 36 ;: 186 \| 220
|
|
2502
|
+
Alt 18 ← 37 =+ 187 ]} 221
|
|
2503
|
+
Cape Lock 20 ↑ 38 ,< 188 '" 222
|
|
2504
|
+
|
|
2505
|
+
多媒体键码值(keyCode)
|
|
2506
|
+
按键 键码
|
|
2507
|
+
音量加 175
|
|
2508
|
+
音量减 174
|
|
2509
|
+
停止 179
|
|
2510
|
+
静音 173
|
|
2511
|
+
浏览器 172
|
|
2512
|
+
邮件 180
|
|
2513
|
+
搜索 170
|
|
2514
|
+
收藏 171
|
|
2515
|
+
**/
|
|
2516
|
+
onKeyboard(element, eventName = "keypress", handler, options) {
|
|
2517
2517
|
const that = this;
|
|
2518
2518
|
if (typeof element === "string") {
|
|
2519
2519
|
element = that.selectorAll(element);
|
|
@@ -2537,8 +2537,8 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2537
2537
|
if (event.shiftKey) {
|
|
2538
2538
|
otherCodeList.push("shift");
|
|
2539
2539
|
}
|
|
2540
|
-
if (typeof
|
|
2541
|
-
|
|
2540
|
+
if (typeof handler === "function") {
|
|
2541
|
+
handler(keyName, keyValue, otherCodeList, event);
|
|
2542
2542
|
}
|
|
2543
2543
|
};
|
|
2544
2544
|
that.on(element, eventName, keyboardEventCallBack, options);
|
|
@@ -2548,6 +2548,113 @@ System.register('DOMUtils', [], (function (exports) {
|
|
|
2548
2548
|
},
|
|
2549
2549
|
};
|
|
2550
2550
|
}
|
|
2551
|
+
/**
|
|
2552
|
+
* 监input、textarea的输入框值改变的事件(当输入法输入时,不会触发该监听)
|
|
2553
|
+
* @param $el 输入框元素
|
|
2554
|
+
* @param handler 回调函数
|
|
2555
|
+
* @param option 配置
|
|
2556
|
+
*/
|
|
2557
|
+
onInput($el, handler, option) {
|
|
2558
|
+
/**
|
|
2559
|
+
* 是否正在输入中
|
|
2560
|
+
*/
|
|
2561
|
+
let isComposite = false;
|
|
2562
|
+
const __callback = async (event) => {
|
|
2563
|
+
if (isComposite)
|
|
2564
|
+
return;
|
|
2565
|
+
await handler(event);
|
|
2566
|
+
};
|
|
2567
|
+
const __composition_start_callback = () => {
|
|
2568
|
+
isComposite = true;
|
|
2569
|
+
};
|
|
2570
|
+
const __composition_end_callback = () => {
|
|
2571
|
+
isComposite = false;
|
|
2572
|
+
this.emit($el, "input", {
|
|
2573
|
+
isComposite,
|
|
2574
|
+
});
|
|
2575
|
+
};
|
|
2576
|
+
const inputListener = this.on($el, "input", __callback, option);
|
|
2577
|
+
const compositionStartListener = this.on($el, "compositionstart", __composition_start_callback, option);
|
|
2578
|
+
const compositionEndListener = this.on($el, "compositionend", __composition_end_callback, option);
|
|
2579
|
+
return {
|
|
2580
|
+
off: () => {
|
|
2581
|
+
inputListener.off();
|
|
2582
|
+
compositionStartListener.off();
|
|
2583
|
+
compositionEndListener.off();
|
|
2584
|
+
},
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
onDoubleClick(...args) {
|
|
2588
|
+
const $el = args[0];
|
|
2589
|
+
let selector = void 0;
|
|
2590
|
+
let handler;
|
|
2591
|
+
let options;
|
|
2592
|
+
if (args.length === 2) {
|
|
2593
|
+
if (typeof args[1] === "function") {
|
|
2594
|
+
handler = args[1];
|
|
2595
|
+
}
|
|
2596
|
+
else {
|
|
2597
|
+
throw new TypeError("handler is not a function");
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
else if (args.length === 3) {
|
|
2601
|
+
if (typeof args[1] === "function") {
|
|
2602
|
+
handler = args[1];
|
|
2603
|
+
options = args[2];
|
|
2604
|
+
}
|
|
2605
|
+
else {
|
|
2606
|
+
selector = args[1];
|
|
2607
|
+
handler = args[2];
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
else if (args.length === 4) {
|
|
2611
|
+
selector = args[1];
|
|
2612
|
+
handler = args[2];
|
|
2613
|
+
options = args[3];
|
|
2614
|
+
}
|
|
2615
|
+
else {
|
|
2616
|
+
throw new Error("args length error");
|
|
2617
|
+
}
|
|
2618
|
+
let $click = null;
|
|
2619
|
+
let isDoubleClick = false;
|
|
2620
|
+
let timer = void 0;
|
|
2621
|
+
/** 是否是移动端点击 */
|
|
2622
|
+
let isMobileTouch = false;
|
|
2623
|
+
const dblclick_handler = async (evt) => {
|
|
2624
|
+
if (evt.type === "dblclick" && isMobileTouch) {
|
|
2625
|
+
// 禁止在移动端触发dblclick事件
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
await handler(evt);
|
|
2629
|
+
};
|
|
2630
|
+
const dblClickListener = this.on($el, "dblclick", dblclick_handler, options);
|
|
2631
|
+
const touchEndListener = this.on($el, "touchend", selector, (evt, selectorTarget) => {
|
|
2632
|
+
isMobileTouch = true;
|
|
2633
|
+
CommonUtils.clearTimeout(timer);
|
|
2634
|
+
timer = void 0;
|
|
2635
|
+
if (isDoubleClick && $click === selectorTarget) {
|
|
2636
|
+
isDoubleClick = false;
|
|
2637
|
+
$click = null;
|
|
2638
|
+
/* 判定为双击 */
|
|
2639
|
+
dblclick_handler(evt);
|
|
2640
|
+
}
|
|
2641
|
+
else {
|
|
2642
|
+
timer = CommonUtils.setTimeout(() => {
|
|
2643
|
+
isDoubleClick = false;
|
|
2644
|
+
// 判断为单击
|
|
2645
|
+
}, 200);
|
|
2646
|
+
isDoubleClick = true;
|
|
2647
|
+
$click = selectorTarget;
|
|
2648
|
+
}
|
|
2649
|
+
}, options);
|
|
2650
|
+
return {
|
|
2651
|
+
off() {
|
|
2652
|
+
$click = null;
|
|
2653
|
+
dblClickListener.off();
|
|
2654
|
+
touchEndListener.off();
|
|
2655
|
+
},
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2551
2658
|
preventEvent(...args) {
|
|
2552
2659
|
/**
|
|
2553
2660
|
* 阻止事件的默认行为发生,并阻止事件传播
|