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