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