@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 CHANGED
@@ -28,10 +28,10 @@ nnpm add @whitesev/domutils
28
28
  - focus `绑定或触发元素的focus事件`
29
29
  - height `获取元素的高度`
30
30
  - hide `隐藏元素`
31
- - hover `当鼠标移入或移出元素时触发事件`
31
+ - onHover `当鼠标移入或移出元素时触发事件`
32
32
  - html `获取或设置元素的HTML内容`
33
- - keydown `当按键按下时触发事件`
34
- - keyup `当按键松开时触发事件`
33
+ - onKeydown `当按键按下时触发事件`
34
+ - onKeyup `当按键松开时触发事件`
35
35
  - next `获取当前元素的后一个兄弟元素`
36
36
  - off `取消绑定事件`
37
37
  - offset `设置或返回被选元素相对于文档的偏移坐标`
@@ -50,7 +50,7 @@ nnpm add @whitesev/domutils
50
50
  - siblings `获取当前元素的所有兄弟元素`
51
51
  - text `获取或设置元素的文本内容`
52
52
  - toggle `切换元素的显示和隐藏状态`
53
- - trigger `主动触发事件`
53
+ - emit `主动触发事件`
54
54
  - val `获取或设置元素的value属性值`
55
55
  - width `获取元素的宽度`
56
56
  - wrap `将一个元素包裹在指定的HTML元素中`
package/dist/index.amd.js CHANGED
@@ -523,13 +523,7 @@ define((function () { 'use strict';
523
523
  },
524
524
  };
525
525
 
526
- const version = "1.7.5";
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 @@ define((function () { 'use strict';
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 @@ define((function () { 'use strict';
1681
1681
  if (element == null) {
1682
1682
  return {
1683
1683
  off() { },
1684
- trigger() { },
1684
+ emit() { },
1685
1685
  };
1686
1686
  }
1687
1687
  let $elList = [];
@@ -1816,10 +1816,10 @@ define((function () { 'use strict';
1816
1816
  /**
1817
1817
  * 主动触发事件
1818
1818
  * @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
1819
- * @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
1819
+ * @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
1820
1820
  */
1821
- trigger: (details, useDispatchToTriggerEvent) => {
1822
- that.trigger($elList, eventTypeList, details, useDispatchToTriggerEvent);
1821
+ emit: (details, useDispatchToEmit) => {
1822
+ that.emit($elList, eventTypeList, details, useDispatchToEmit);
1823
1823
  },
1824
1824
  };
1825
1825
  }
@@ -1998,7 +1998,7 @@ define((function () { 'use strict';
1998
1998
  });
1999
1999
  });
2000
2000
  }
2001
- ready(...args) {
2001
+ onReady(...args) {
2002
2002
  const callback = args[0];
2003
2003
  // 异步回调
2004
2004
  let resolve = void 0;
@@ -2092,16 +2092,16 @@ define((function () { 'use strict';
2092
2092
  * @param element 需要触发的元素|元素数组|window
2093
2093
  * @param eventType 需要触发的事件
2094
2094
  * @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
2095
- * @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
2095
+ * @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
2096
2096
  * @example
2097
2097
  * // 触发元素a.xx的click事件
2098
- * DOMUtils.trigger(document.querySelector("a.xx"),"click")
2099
- * DOMUtils.trigger("a.xx","click")
2098
+ * DOMUtils.emit(document.querySelector("a.xx"),"click")
2099
+ * DOMUtils.emit("a.xx","click")
2100
2100
  * // 触发元素a.xx的click、tap、hover事件
2101
- * DOMUtils.trigger(document.querySelector("a.xx"),"click tap hover")
2102
- * DOMUtils.trigger("a.xx",["click","tap","hover"])
2101
+ * DOMUtils.emit(document.querySelector("a.xx"),"click tap hover")
2102
+ * DOMUtils.emit("a.xx",["click","tap","hover"])
2103
2103
  */
2104
- trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
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 @@ define((function () { 'use strict';
2143
2143
  });
2144
2144
  }
2145
2145
  }
2146
- if (useDispatchToTriggerEvent == false && eventTypeItem in elementEvents) {
2146
+ if (useDispatchToEmit == false && eventTypeItem in elementEvents) {
2147
2147
  // 直接调用监听的事件
2148
2148
  elementEvents[eventTypeItem].forEach((eventsItem) => {
2149
2149
  eventsItem.callback(event);
@@ -2156,11 +2156,11 @@ define((function () { 'use strict';
2156
2156
  });
2157
2157
  }
2158
2158
  /**
2159
- * 绑定或触发元素的click事件
2159
+ * 监听或触发元素的click事件
2160
2160
  * @param element 目标元素
2161
2161
  * @param handler (可选)事件处理函数
2162
2162
  * @param details (可选)赋予触发的Event的额外属性
2163
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
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 @@ define((function () { 'use strict';
2169
2169
  * console.log("触发click事件成功")
2170
2170
  * })
2171
2171
  * */
2172
- click(element, handler, details, useDispatchToTriggerEvent) {
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 @@ define((function () { 'use strict';
2180
2180
  if (CommonUtils.isNodeList(element)) {
2181
2181
  // 设置
2182
2182
  element.forEach(($ele) => {
2183
- that.click($ele, handler, details, useDispatchToTriggerEvent);
2183
+ that.click($ele, handler, details, useDispatchToEmit);
2184
2184
  });
2185
2185
  return;
2186
2186
  }
2187
2187
  if (handler == null) {
2188
- that.trigger(element, "click", details, useDispatchToTriggerEvent);
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
- * 绑定或触发元素的blur事件
2195
+ * 监听或触发元素的blur事件
2196
2196
  * @param element 目标元素
2197
2197
  * @param handler (可选)事件处理函数
2198
2198
  * @param details (可选)赋予触发的Event的额外属性
2199
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
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 @@ define((function () { 'use strict';
2205
2205
  * console.log("触发blur事件成功")
2206
2206
  * })
2207
2207
  * */
2208
- blur(element, handler, details, useDispatchToTriggerEvent) {
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 @@ define((function () { 'use strict';
2216
2216
  if (CommonUtils.isNodeList(element)) {
2217
2217
  // 设置
2218
2218
  element.forEach(($ele) => {
2219
- that.focus($ele, handler, details, useDispatchToTriggerEvent);
2219
+ that.focus($ele, handler, details, useDispatchToEmit);
2220
2220
  });
2221
2221
  return;
2222
2222
  }
2223
2223
  if (handler === null) {
2224
- that.trigger(element, "blur", details, useDispatchToTriggerEvent);
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
- * 绑定或触发元素的focus事件
2231
+ * 监听或触发元素的focus事件
2232
2232
  * @param element 目标元素
2233
2233
  * @param handler (可选)事件处理函数
2234
2234
  * @param details (可选)赋予触发的Event的额外属性
2235
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
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 @@ define((function () { 'use strict';
2241
2241
  * console.log("触发focus事件成功")
2242
2242
  * })
2243
2243
  * */
2244
- focus(element, handler, details, useDispatchToTriggerEvent) {
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 @@ define((function () { 'use strict';
2252
2252
  if (CommonUtils.isNodeList(element)) {
2253
2253
  // 设置
2254
2254
  element.forEach(($ele) => {
2255
- that.focus($ele, handler, details, useDispatchToTriggerEvent);
2255
+ that.focus($ele, handler, details, useDispatchToEmit);
2256
2256
  });
2257
2257
  return;
2258
2258
  }
2259
2259
  if (handler == null) {
2260
- that.trigger(element, "focus", details, useDispatchToTriggerEvent);
2260
+ that.emit(element, "focus", details, useDispatchToEmit);
2261
2261
  }
2262
2262
  else {
2263
2263
  that.on(element, "focus", null, handler);
@@ -2270,14 +2270,14 @@ define((function () { 'use strict';
2270
2270
  * @param option 配置
2271
2271
  * @example
2272
2272
  * // 监听a.xx元素的移入或移出
2273
- * DOMUtils.hover(document.querySelector("a.xx"),()=>{
2273
+ * DOMUtils.onHover(document.querySelector("a.xx"),()=>{
2274
2274
  * console.log("移入/移除");
2275
2275
  * })
2276
- * DOMUtils.hover("a.xx",()=>{
2276
+ * DOMUtils.onHover("a.xx",()=>{
2277
2277
  * console.log("移入/移除");
2278
2278
  * })
2279
2279
  */
2280
- hover(element, handler, option) {
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 @@ define((function () { 'use strict';
2288
2288
  if (CommonUtils.isNodeList(element)) {
2289
2289
  // 设置
2290
2290
  element.forEach(($ele) => {
2291
- that.hover($ele, handler, option);
2291
+ that.onHover($ele, handler, option);
2292
2292
  });
2293
2293
  return;
2294
2294
  }
@@ -2296,12 +2296,12 @@ define((function () { 'use strict';
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
- animationend(element, handler, option) {
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 @@ define((function () { 'use strict';
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
- transitionend(element, handler, option) {
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 @@ define((function () { 'use strict';
2366
2366
  * console.log("按键松开");
2367
2367
  * })
2368
2368
  */
2369
- keyup(element, handler, option) {
2369
+ onKeyup(element, handler, option) {
2370
2370
  const that = this;
2371
2371
  if (element == null) {
2372
2372
  return;
@@ -2377,7 +2377,7 @@ define((function () { 'use strict';
2377
2377
  if (CommonUtils.isNodeList(element)) {
2378
2378
  // 设置
2379
2379
  element.forEach(($ele) => {
2380
- that.keyup($ele, handler, option);
2380
+ that.onKeyup($ele, handler, option);
2381
2381
  });
2382
2382
  return;
2383
2383
  }
@@ -2398,7 +2398,7 @@ define((function () { 'use strict';
2398
2398
  * console.log("按键按下");
2399
2399
  * })
2400
2400
  */
2401
- keydown(element, handler, option) {
2401
+ onKeydown(element, handler, option) {
2402
2402
  const that = this;
2403
2403
  if (element == null) {
2404
2404
  return;
@@ -2409,7 +2409,7 @@ define((function () { 'use strict';
2409
2409
  if (CommonUtils.isNodeList(element)) {
2410
2410
  // 设置
2411
2411
  element.forEach(($ele) => {
2412
- that.keydown($ele, handler, option);
2412
+ that.onKeydown($ele, handler, option);
2413
2413
  });
2414
2414
  return;
2415
2415
  }
@@ -2430,7 +2430,7 @@ define((function () { 'use strict';
2430
2430
  * console.log("按键按下");
2431
2431
  * })
2432
2432
  */
2433
- keypress(element, handler, option) {
2433
+ onKeypress(element, handler, option) {
2434
2434
  const that = this;
2435
2435
  if (element == null) {
2436
2436
  return;
@@ -2441,76 +2441,76 @@ define((function () { 'use strict';
2441
2441
  if (CommonUtils.isNodeList(element)) {
2442
2442
  // 设置
2443
2443
  element.forEach(($ele) => {
2444
- that.keypress($ele, handler, option);
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
- * 监听某个元素键盘按键事件或window全局按键事件
2452
- * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
2453
- * @param element 需要监听的对象,可以是全局Window或者某个元素
2454
- * @param eventName 事件名,默认keypress
2455
- * @param callback 自己定义的回调事件,参数1为当前的key,参数2为组合按键,数组类型,包含ctrl、shift、alt和meta(win键或mac的cmd键)
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
- * @example
2458
- Utils.listenKeyboard(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
- listenKeyboard(element, eventName = "keypress", callback, options) {
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 @@ define((function () { 'use strict';
2534
2534
  if (event.shiftKey) {
2535
2535
  otherCodeList.push("shift");
2536
2536
  }
2537
- if (typeof callback === "function") {
2538
- callback(keyName, keyValue, otherCodeList, event);
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 @@ define((function () { 'use strict';
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
  * 阻止事件的默认行为发生,并阻止事件传播