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