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