@whitesev/domutils 1.7.4 → 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.cjs.js CHANGED
@@ -523,13 +523,7 @@ const CommonUtils = {
523
523
  },
524
524
  };
525
525
 
526
- const version = "1.7.4";
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;
@@ -901,35 +895,41 @@ class Utils {
901
895
  if (target == null) {
902
896
  target = {};
903
897
  }
898
+ // 当前遍历的目标对象
899
+ let iteratorTarget;
904
900
  if (isAdd) {
905
- for (const sourceKeyName in source) {
906
- const targetKeyName = sourceKeyName;
907
- const targetValue = Reflect.get(target, targetKeyName);
908
- const sourceValue = Reflect.get(source, sourceKeyName);
909
- if (typeof sourceValue === "object" && sourceValue != null && sourceKeyName in target && !isDOM(sourceValue)) {
910
- /* 源端的值是object类型,且不是元素节点 */
911
- Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
912
- continue;
913
- }
914
- Reflect.set(target, sourceKeyName, sourceValue);
915
- }
901
+ // 追加并覆盖是以source为准
902
+ iteratorTarget = source;
916
903
  }
917
904
  else {
918
- for (const targetKeyName in target) {
919
- if (targetKeyName in source) {
920
- const targetValue = Reflect.get(target, targetKeyName);
921
- const sourceValue = Reflect.get(source, targetKeyName);
922
- if (typeof sourceValue === "object" &&
923
- sourceValue != null &&
924
- !isDOM(sourceValue) &&
925
- Object.keys(sourceValue).length) {
926
- /* 源端的值是object类型,且不是元素节点 */
927
- Reflect.set(target, targetKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
928
- continue;
905
+ // 覆盖以target为准
906
+ iteratorTarget = target;
907
+ }
908
+ for (const keyName in iteratorTarget) {
909
+ if (!isAdd && !(keyName in source)) {
910
+ // 仅替换 但是源端没有此键
911
+ continue;
912
+ }
913
+ const targetValue = Reflect.get(target, keyName);
914
+ const sourceValue = Reflect.get(source, keyName);
915
+ if (typeof sourceValue === "object" && sourceValue != null && keyName in target && !isDOM(sourceValue)) {
916
+ // 源端的值是object类型,且不是元素节点
917
+ // 如果是数组,那此数组中有值,清空旧的数组再赋值
918
+ let childObjectValue;
919
+ if (Array.isArray(sourceValue)) {
920
+ if (Array.isArray(targetValue)) {
921
+ targetValue.length = 0;
929
922
  }
930
- /* 直接赋值 */
931
- Reflect.set(target, targetKeyName, sourceValue);
923
+ childObjectValue = sourceValue;
924
+ }
925
+ else {
926
+ childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
932
927
  }
928
+ Reflect.set(target, keyName, childObjectValue);
929
+ }
930
+ else {
931
+ /* 直接赋值 */
932
+ Reflect.set(target, keyName, sourceValue);
933
933
  }
934
934
  }
935
935
  return target;
@@ -1616,6 +1616,12 @@ class ElementAnimate extends ElementWait {
1616
1616
  }
1617
1617
  new ElementAnimate();
1618
1618
 
1619
+ /* 数据 */
1620
+ const GlobalData = {
1621
+ /** .on添加在元素存储的事件 */
1622
+ domEventSymbol: Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)),
1623
+ };
1624
+
1619
1625
  const OriginPrototype = {
1620
1626
  Object: {
1621
1627
  defineProperty: Object.defineProperty,
@@ -1675,7 +1681,7 @@ class ElementEvent extends ElementAnimate {
1675
1681
  if (element == null) {
1676
1682
  return {
1677
1683
  off() { },
1678
- trigger() { },
1684
+ emit() { },
1679
1685
  };
1680
1686
  }
1681
1687
  let $elList = [];
@@ -1810,10 +1816,10 @@ class ElementEvent extends ElementAnimate {
1810
1816
  /**
1811
1817
  * 主动触发事件
1812
1818
  * @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
1813
- * @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
1819
+ * @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
1814
1820
  */
1815
- trigger: (details, useDispatchToTriggerEvent) => {
1816
- that.trigger($elList, eventTypeList, details, useDispatchToTriggerEvent);
1821
+ emit: (details, useDispatchToEmit) => {
1822
+ that.emit($elList, eventTypeList, details, useDispatchToEmit);
1817
1823
  },
1818
1824
  };
1819
1825
  }
@@ -1992,7 +1998,7 @@ class ElementEvent extends ElementAnimate {
1992
1998
  });
1993
1999
  });
1994
2000
  }
1995
- ready(...args) {
2001
+ onReady(...args) {
1996
2002
  const callback = args[0];
1997
2003
  // 异步回调
1998
2004
  let resolve = void 0;
@@ -2086,16 +2092,16 @@ class ElementEvent extends ElementAnimate {
2086
2092
  * @param element 需要触发的元素|元素数组|window
2087
2093
  * @param eventType 需要触发的事件
2088
2094
  * @param details 赋予触发的Event的额外属性,如果是Event类型,那么将自动代替默认new的Event对象
2089
- * @param useDispatchToTriggerEvent 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
2095
+ * @param useDispatchToEmit 是否使用dispatchEvent来触发事件,默认true,如果为false,则直接调用callback,但是这种会让使用了selectorTarget的没有值
2090
2096
  * @example
2091
2097
  * // 触发元素a.xx的click事件
2092
- * DOMUtils.trigger(document.querySelector("a.xx"),"click")
2093
- * DOMUtils.trigger("a.xx","click")
2098
+ * DOMUtils.emit(document.querySelector("a.xx"),"click")
2099
+ * DOMUtils.emit("a.xx","click")
2094
2100
  * // 触发元素a.xx的click、tap、hover事件
2095
- * DOMUtils.trigger(document.querySelector("a.xx"),"click tap hover")
2096
- * 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"])
2097
2103
  */
2098
- trigger(element, eventType, details, useDispatchToTriggerEvent = true) {
2104
+ emit(element, eventType, details, useDispatchToEmit = true) {
2099
2105
  const that = this;
2100
2106
  if (typeof element === "string") {
2101
2107
  element = that.selectorAll(element);
@@ -2137,7 +2143,7 @@ class ElementEvent extends ElementAnimate {
2137
2143
  });
2138
2144
  }
2139
2145
  }
2140
- if (useDispatchToTriggerEvent == false && eventTypeItem in elementEvents) {
2146
+ if (useDispatchToEmit == false && eventTypeItem in elementEvents) {
2141
2147
  // 直接调用监听的事件
2142
2148
  elementEvents[eventTypeItem].forEach((eventsItem) => {
2143
2149
  eventsItem.callback(event);
@@ -2150,11 +2156,11 @@ class ElementEvent extends ElementAnimate {
2150
2156
  });
2151
2157
  }
2152
2158
  /**
2153
- * 绑定或触发元素的click事件
2159
+ * 监听或触发元素的click事件
2154
2160
  * @param element 目标元素
2155
2161
  * @param handler (可选)事件处理函数
2156
2162
  * @param details (可选)赋予触发的Event的额外属性
2157
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
2163
+ * @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
2158
2164
  * @example
2159
2165
  * // 触发元素a.xx的click事件
2160
2166
  * DOMUtils.click(document.querySelector("a.xx"))
@@ -2163,7 +2169,7 @@ class ElementEvent extends ElementAnimate {
2163
2169
  * console.log("触发click事件成功")
2164
2170
  * })
2165
2171
  * */
2166
- click(element, handler, details, useDispatchToTriggerEvent) {
2172
+ click(element, handler, details, useDispatchToEmit) {
2167
2173
  const that = this;
2168
2174
  if (typeof element === "string") {
2169
2175
  element = that.selectorAll(element);
@@ -2174,23 +2180,23 @@ class ElementEvent extends ElementAnimate {
2174
2180
  if (CommonUtils.isNodeList(element)) {
2175
2181
  // 设置
2176
2182
  element.forEach(($ele) => {
2177
- that.click($ele, handler, details, useDispatchToTriggerEvent);
2183
+ that.click($ele, handler, details, useDispatchToEmit);
2178
2184
  });
2179
2185
  return;
2180
2186
  }
2181
2187
  if (handler == null) {
2182
- that.trigger(element, "click", details, useDispatchToTriggerEvent);
2188
+ that.emit(element, "click", details, useDispatchToEmit);
2183
2189
  }
2184
2190
  else {
2185
2191
  that.on(element, "click", null, handler);
2186
2192
  }
2187
2193
  }
2188
2194
  /**
2189
- * 绑定或触发元素的blur事件
2195
+ * 监听或触发元素的blur事件
2190
2196
  * @param element 目标元素
2191
2197
  * @param handler (可选)事件处理函数
2192
2198
  * @param details (可选)赋予触发的Event的额外属性
2193
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
2199
+ * @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
2194
2200
  * @example
2195
2201
  * // 触发元素a.xx的blur事件
2196
2202
  * DOMUtils.blur(document.querySelector("a.xx"))
@@ -2199,7 +2205,7 @@ class ElementEvent extends ElementAnimate {
2199
2205
  * console.log("触发blur事件成功")
2200
2206
  * })
2201
2207
  * */
2202
- blur(element, handler, details, useDispatchToTriggerEvent) {
2208
+ blur(element, handler, details, useDispatchToEmit) {
2203
2209
  const that = this;
2204
2210
  if (typeof element === "string") {
2205
2211
  element = that.selectorAll(element);
@@ -2210,23 +2216,23 @@ class ElementEvent extends ElementAnimate {
2210
2216
  if (CommonUtils.isNodeList(element)) {
2211
2217
  // 设置
2212
2218
  element.forEach(($ele) => {
2213
- that.focus($ele, handler, details, useDispatchToTriggerEvent);
2219
+ that.focus($ele, handler, details, useDispatchToEmit);
2214
2220
  });
2215
2221
  return;
2216
2222
  }
2217
2223
  if (handler === null) {
2218
- that.trigger(element, "blur", details, useDispatchToTriggerEvent);
2224
+ that.emit(element, "blur", details, useDispatchToEmit);
2219
2225
  }
2220
2226
  else {
2221
2227
  that.on(element, "blur", null, handler);
2222
2228
  }
2223
2229
  }
2224
2230
  /**
2225
- * 绑定或触发元素的focus事件
2231
+ * 监听或触发元素的focus事件
2226
2232
  * @param element 目标元素
2227
2233
  * @param handler (可选)事件处理函数
2228
2234
  * @param details (可选)赋予触发的Event的额外属性
2229
- * @param useDispatchToTriggerEvent (可选)是否使用dispatchEvent来触发事件,默认true
2235
+ * @param useDispatchToEmit (可选)是否使用dispatchEvent来触发事件,默认true
2230
2236
  * @example
2231
2237
  * // 触发元素a.xx的focus事件
2232
2238
  * DOMUtils.focus(document.querySelector("a.xx"))
@@ -2235,7 +2241,7 @@ class ElementEvent extends ElementAnimate {
2235
2241
  * console.log("触发focus事件成功")
2236
2242
  * })
2237
2243
  * */
2238
- focus(element, handler, details, useDispatchToTriggerEvent) {
2244
+ focus(element, handler, details, useDispatchToEmit) {
2239
2245
  const that = this;
2240
2246
  if (typeof element === "string") {
2241
2247
  element = that.selectorAll(element);
@@ -2246,12 +2252,12 @@ class ElementEvent extends ElementAnimate {
2246
2252
  if (CommonUtils.isNodeList(element)) {
2247
2253
  // 设置
2248
2254
  element.forEach(($ele) => {
2249
- that.focus($ele, handler, details, useDispatchToTriggerEvent);
2255
+ that.focus($ele, handler, details, useDispatchToEmit);
2250
2256
  });
2251
2257
  return;
2252
2258
  }
2253
2259
  if (handler == null) {
2254
- that.trigger(element, "focus", details, useDispatchToTriggerEvent);
2260
+ that.emit(element, "focus", details, useDispatchToEmit);
2255
2261
  }
2256
2262
  else {
2257
2263
  that.on(element, "focus", null, handler);
@@ -2264,14 +2270,14 @@ class ElementEvent extends ElementAnimate {
2264
2270
  * @param option 配置
2265
2271
  * @example
2266
2272
  * // 监听a.xx元素的移入或移出
2267
- * DOMUtils.hover(document.querySelector("a.xx"),()=>{
2273
+ * DOMUtils.onHover(document.querySelector("a.xx"),()=>{
2268
2274
  * console.log("移入/移除");
2269
2275
  * })
2270
- * DOMUtils.hover("a.xx",()=>{
2276
+ * DOMUtils.onHover("a.xx",()=>{
2271
2277
  * console.log("移入/移除");
2272
2278
  * })
2273
2279
  */
2274
- hover(element, handler, option) {
2280
+ onHover(element, handler, option) {
2275
2281
  const that = this;
2276
2282
  if (typeof element === "string") {
2277
2283
  element = that.selectorAll(element);
@@ -2282,7 +2288,7 @@ class ElementEvent extends ElementAnimate {
2282
2288
  if (CommonUtils.isNodeList(element)) {
2283
2289
  // 设置
2284
2290
  element.forEach(($ele) => {
2285
- that.hover($ele, handler, option);
2291
+ that.onHover($ele, handler, option);
2286
2292
  });
2287
2293
  return;
2288
2294
  }
@@ -2290,12 +2296,12 @@ class ElementEvent extends ElementAnimate {
2290
2296
  that.on(element, "mouseleave", null, handler, option);
2291
2297
  }
2292
2298
  /**
2293
- * 当动画结束时触发事件
2299
+ * 监听动画结束
2294
2300
  * @param element 监听的元素
2295
2301
  * @param handler 触发的回调函数
2296
2302
  * @param option 配置项,这里默认配置once为true
2297
2303
  */
2298
- animationend(element, handler, option) {
2304
+ onAnimationend(element, handler, option) {
2299
2305
  const that = this;
2300
2306
  if (typeof element === "string") {
2301
2307
  element = that.selector(element);
@@ -2318,12 +2324,12 @@ class ElementEvent extends ElementAnimate {
2318
2324
  }
2319
2325
  }
2320
2326
  /**
2321
- * 当过渡结束时触发事件
2327
+ * 监听过渡结束
2322
2328
  * @param element 监听的元素
2323
2329
  * @param handler 触发的回调函数
2324
2330
  * @param option 配置项,这里默认配置once为true
2325
2331
  */
2326
- transitionend(element, handler, option) {
2332
+ onTransitionend(element, handler, option) {
2327
2333
  const that = this;
2328
2334
  if (typeof element === "string") {
2329
2335
  element = that.selector(element);
@@ -2360,7 +2366,7 @@ class ElementEvent extends ElementAnimate {
2360
2366
  * console.log("按键松开");
2361
2367
  * })
2362
2368
  */
2363
- keyup(element, handler, option) {
2369
+ onKeyup(element, handler, option) {
2364
2370
  const that = this;
2365
2371
  if (element == null) {
2366
2372
  return;
@@ -2371,7 +2377,7 @@ class ElementEvent extends ElementAnimate {
2371
2377
  if (CommonUtils.isNodeList(element)) {
2372
2378
  // 设置
2373
2379
  element.forEach(($ele) => {
2374
- that.keyup($ele, handler, option);
2380
+ that.onKeyup($ele, handler, option);
2375
2381
  });
2376
2382
  return;
2377
2383
  }
@@ -2392,7 +2398,7 @@ class ElementEvent extends ElementAnimate {
2392
2398
  * console.log("按键按下");
2393
2399
  * })
2394
2400
  */
2395
- keydown(element, handler, option) {
2401
+ onKeydown(element, handler, option) {
2396
2402
  const that = this;
2397
2403
  if (element == null) {
2398
2404
  return;
@@ -2403,7 +2409,7 @@ class ElementEvent extends ElementAnimate {
2403
2409
  if (CommonUtils.isNodeList(element)) {
2404
2410
  // 设置
2405
2411
  element.forEach(($ele) => {
2406
- that.keydown($ele, handler, option);
2412
+ that.onKeydown($ele, handler, option);
2407
2413
  });
2408
2414
  return;
2409
2415
  }
@@ -2424,7 +2430,7 @@ class ElementEvent extends ElementAnimate {
2424
2430
  * console.log("按键按下");
2425
2431
  * })
2426
2432
  */
2427
- keypress(element, handler, option) {
2433
+ onKeypress(element, handler, option) {
2428
2434
  const that = this;
2429
2435
  if (element == null) {
2430
2436
  return;
@@ -2435,76 +2441,76 @@ class ElementEvent extends ElementAnimate {
2435
2441
  if (CommonUtils.isNodeList(element)) {
2436
2442
  // 设置
2437
2443
  element.forEach(($ele) => {
2438
- that.keypress($ele, handler, option);
2444
+ that.onKeypress($ele, handler, option);
2439
2445
  });
2440
2446
  return;
2441
2447
  }
2442
2448
  that.on(element, "keypress", null, handler, option);
2443
2449
  }
2444
2450
  /**
2445
- * 监听某个元素键盘按键事件或window全局按键事件
2446
- * 按下有值的键时触发,按下Ctrl\Alt\Shift\Meta是无值键。按下先触发keydown事件,再触发keypress事件。
2447
- * @param element 需要监听的对象,可以是全局Window或者某个元素
2448
- * @param eventName 事件名,默认keypress
2449
- * @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键)
2450
2456
  * @param options 监听事件的配置
2451
- * @example
2452
- Utils.listenKeyboard(window,(keyName,keyValue,otherKey,event)=>{
2453
- if(keyName === "Enter"){
2454
- console.log("回车按键的值是:"+keyValue)
2455
- }
2456
- if(otherKey.indexOf("ctrl") && keyName === "Enter" ){
2457
- console.log("Ctrl和回车键");
2458
- }
2459
- })
2460
- * @example
2461
- 字母和数字键的键码值(keyCode)
2462
- 按键 键码 按键 键码 按键 键码 按键 键码
2463
- A 65 J 74 S 83 1 49
2464
- B 66 K 75 T 84 2 50
2465
- C 67 L 76 U 85 3 51
2466
- D 68 M 77 V 86 4 52
2467
- E 69 N 78 W 87 5 53
2468
- F 70 O 79 X 88 6 54
2469
- G 71 P 80 Y 89 7 55
2470
- H 72 Q 81 Z 90 8 56
2471
- I 73 R 82 0 48 9 57
2472
-
2473
- 数字键盘上的键的键码值(keyCode)
2474
- 功能键键码值(keyCode)
2475
- 按键 键码 按键 键码 按键 键码 按键 键码
2476
- 0 96 8 104 F1 112 F7 118
2477
- 1 97 9 105 F2 113 F8 119
2478
- 2 98 * 106 F3 114 F9 120
2479
- 3 99 + 107 F4 115 F10 121
2480
- 4 100 Enter 108 F5 116 F11 122
2481
- 5 101 - 109 F6 117 F12 123
2482
- 6 102 . 110
2483
- 7 103 / 111
2484
-
2485
- 控制键键码值(keyCode)
2486
- 按键 键码 按键 键码 按键 键码 按键 键码
2487
- BackSpace 8 Esc 27 → 39 -_ 189
2488
- Tab 9 Spacebar 32 ↓ 40 .> 190
2489
- Clear 12 Page Up 33 Insert 45 /? 191
2490
- Enter 13 Page Down 34 Delete 46 `~ 192
2491
- Shift 16 End 35 Num Lock 144 [{ 219
2492
- Control 17 Home 36 ;: 186 \| 220
2493
- Alt 18 ← 37 =+ 187 ]} 221
2494
- Cape Lock 20 ↑ 38 ,< 188 '" 222
2495
-
2496
- 多媒体键码值(keyCode)
2497
- 按键 键码
2498
- 音量加 175
2499
- 音量减 174
2500
- 停止 179
2501
- 静音 173
2502
- 浏览器 172
2503
- 邮件 180
2504
- 搜索 170
2505
- 收藏 171
2506
- **/
2507
- 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) {
2508
2514
  const that = this;
2509
2515
  if (typeof element === "string") {
2510
2516
  element = that.selectorAll(element);
@@ -2528,8 +2534,8 @@ class ElementEvent extends ElementAnimate {
2528
2534
  if (event.shiftKey) {
2529
2535
  otherCodeList.push("shift");
2530
2536
  }
2531
- if (typeof callback === "function") {
2532
- callback(keyName, keyValue, otherCodeList, event);
2537
+ if (typeof handler === "function") {
2538
+ handler(keyName, keyValue, otherCodeList, event);
2533
2539
  }
2534
2540
  };
2535
2541
  that.on(element, eventName, keyboardEventCallBack, options);
@@ -2539,6 +2545,113 @@ class ElementEvent extends ElementAnimate {
2539
2545
  },
2540
2546
  };
2541
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
+ }
2542
2655
  preventEvent(...args) {
2543
2656
  /**
2544
2657
  * 阻止事件的默认行为发生,并阻止事件传播