@whitesev/pops 3.3.1 → 3.3.3

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.umd.js CHANGED
@@ -297,6 +297,13 @@
297
297
  isDOM(target) {
298
298
  return target instanceof Node;
299
299
  }
300
+ /**
301
+ * 判断是否是元素列表
302
+ * @param $ele
303
+ */
304
+ isNodeList($ele) {
305
+ return Array.isArray($ele) || $ele instanceof NodeList;
306
+ }
300
307
  /**
301
308
  * 删除对象上的属性
302
309
  * @param target
@@ -481,9 +488,18 @@
481
488
  result = addType ? result + resultType.toString() : parseFloat(result.toString());
482
489
  return result;
483
490
  }
491
+ /**
492
+ * https://github.com/any86/any-touch/blob/master/README.CN.md
493
+ */
484
494
  AnyTouch = () => {
485
495
  return i;
486
496
  };
497
+ /**
498
+ * `any-touch`的`doubletap`事件插件
499
+ */
500
+ AnyTouchDoubleTapPlugin = () => {
501
+ return e;
502
+ };
487
503
  /**
488
504
  * 通过navigator.userAgent判断是否是手机访问
489
505
  * @param userAgent
@@ -1020,7 +1036,7 @@
1020
1036
  */
1021
1037
  emit(element, eventType, details, useDispatchToEmitEvent = true) {
1022
1038
  if (typeof element === "string") {
1023
- element = PopsCore.document.querySelector(element);
1039
+ element = this.selector(element);
1024
1040
  }
1025
1041
  if (element == null) {
1026
1042
  return;
@@ -1082,18 +1098,18 @@
1082
1098
  * })
1083
1099
  * */
1084
1100
  click(element, handler, details, useDispatchToEmitEvent) {
1085
- const DOMUtilsContext = this;
1086
1101
  if (typeof element === "string") {
1087
- element = PopsCore.document.querySelector(element);
1102
+ element = this.selector(element);
1088
1103
  }
1089
1104
  if (element == null) {
1090
1105
  return;
1091
1106
  }
1092
1107
  if (handler == null) {
1093
- DOMUtilsContext.emit(element, "click", details, useDispatchToEmitEvent);
1108
+ this.emit(element, "click", details, useDispatchToEmitEvent);
1094
1109
  }
1095
1110
  else {
1096
- DOMUtilsContext.on(element, "click", null, handler);
1111
+ const listener = this.on(element, "click", handler);
1112
+ return listener;
1097
1113
  }
1098
1114
  }
1099
1115
  /**
@@ -1111,18 +1127,18 @@
1111
1127
  * })
1112
1128
  * */
1113
1129
  blur(element, handler, details, useDispatchToEmitEvent) {
1114
- const DOMUtilsContext = this;
1115
1130
  if (typeof element === "string") {
1116
- element = PopsCore.document.querySelector(element);
1131
+ element = this.selector(element);
1117
1132
  }
1118
1133
  if (element == null) {
1119
1134
  return;
1120
1135
  }
1121
1136
  if (handler === null) {
1122
- DOMUtilsContext.emit(element, "blur", details, useDispatchToEmitEvent);
1137
+ this.emit(element, "blur", details, useDispatchToEmitEvent);
1123
1138
  }
1124
1139
  else {
1125
- DOMUtilsContext.on(element, "blur", null, handler);
1140
+ const listener = this.on(element, "blur", handler);
1141
+ return listener;
1126
1142
  }
1127
1143
  }
1128
1144
  /**
@@ -1140,18 +1156,18 @@
1140
1156
  * })
1141
1157
  * */
1142
1158
  focus(element, handler, details, useDispatchToEmitEvent) {
1143
- const DOMUtilsContext = this;
1144
1159
  if (typeof element === "string") {
1145
- element = PopsCore.document.querySelector(element);
1160
+ element = this.selector(element);
1146
1161
  }
1147
1162
  if (element == null) {
1148
1163
  return;
1149
1164
  }
1150
1165
  if (handler == null) {
1151
- DOMUtilsContext.emit(element, "focus", details, useDispatchToEmitEvent);
1166
+ this.emit(element, "focus", details, useDispatchToEmitEvent);
1152
1167
  }
1153
1168
  else {
1154
- DOMUtilsContext.on(element, "focus", null, handler);
1169
+ const listener = this.on(element, "focus", handler);
1170
+ return listener;
1155
1171
  }
1156
1172
  }
1157
1173
  /**
@@ -1169,15 +1185,39 @@
1169
1185
  * })
1170
1186
  */
1171
1187
  onHover(element, handler, option) {
1172
- const DOMUtilsContext = this;
1188
+ const that = this;
1173
1189
  if (typeof element === "string") {
1174
- element = PopsCore.document.querySelector(element);
1190
+ element = that.selectorAll(element);
1175
1191
  }
1176
1192
  if (element == null) {
1177
1193
  return;
1178
1194
  }
1179
- DOMUtilsContext.on(element, "mouseenter", null, handler, option);
1180
- DOMUtilsContext.on(element, "mouseleave", null, handler, option);
1195
+ if (popsUtils.isNodeList(element)) {
1196
+ // 设置
1197
+ const listenerList = [];
1198
+ element.forEach(($ele) => {
1199
+ const listener = that.onHover($ele, handler, option);
1200
+ listenerList.push(listener);
1201
+ });
1202
+ return {
1203
+ off() {
1204
+ listenerList.forEach((listener) => {
1205
+ if (!listener) {
1206
+ return;
1207
+ }
1208
+ listener.off();
1209
+ });
1210
+ },
1211
+ };
1212
+ }
1213
+ const mouseenter_listener = that.on(element, "mouseenter", null, handler, option);
1214
+ const mouseleave_listener = that.on(element, "mouseleave", null, handler, option);
1215
+ return {
1216
+ off() {
1217
+ mouseenter_listener.off();
1218
+ mouseleave_listener.off();
1219
+ },
1220
+ };
1181
1221
  }
1182
1222
  /**
1183
1223
  * 当按键松开时触发事件
@@ -1195,14 +1235,14 @@
1195
1235
  * })
1196
1236
  */
1197
1237
  onKeyup(target, handler, option) {
1198
- const DOMUtilsContext = this;
1199
1238
  if (target == null) {
1200
1239
  return;
1201
1240
  }
1202
1241
  if (typeof target === "string") {
1203
- target = PopsCore.document.querySelector(target);
1242
+ target = this.selector(target);
1204
1243
  }
1205
- DOMUtilsContext.on(target, "keyup", null, handler, option);
1244
+ const listener = this.on(target, "keyup", handler, option);
1245
+ return listener;
1206
1246
  }
1207
1247
  /**
1208
1248
  * 当按键按下时触发事件
@@ -1220,14 +1260,14 @@
1220
1260
  * })
1221
1261
  */
1222
1262
  onKeydown(target, handler, option) {
1223
- const DOMUtilsContext = this;
1224
1263
  if (target == null) {
1225
1264
  return;
1226
1265
  }
1227
1266
  if (typeof target === "string") {
1228
- target = PopsCore.document.querySelector(target);
1267
+ target = this.selector(target);
1229
1268
  }
1230
- DOMUtilsContext.on(target, "keydown", null, handler, option);
1269
+ const listener = this.on(target, "keydown", handler, option);
1270
+ return listener;
1231
1271
  }
1232
1272
  /**
1233
1273
  * 当按键按下时触发事件
@@ -1245,38 +1285,69 @@
1245
1285
  * })
1246
1286
  */
1247
1287
  onKeypress(target, handler, option) {
1248
- const DOMUtilsContext = this;
1249
1288
  if (target == null) {
1250
1289
  return;
1251
1290
  }
1252
1291
  if (typeof target === "string") {
1253
- target = PopsCore.document.querySelector(target);
1292
+ target = this.selector(target);
1254
1293
  }
1255
- DOMUtilsContext.on(target, "keypress", null, handler, option);
1294
+ const listener = this.on(target, "keypress", handler, option);
1295
+ return listener;
1256
1296
  }
1257
- preventEvent(element, eventNameList = [], capture) {
1258
- function stopEvent(event) {
1259
- // 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL
1297
+ preventEvent(...args) {
1298
+ /**
1299
+ * 阻止事件的默认行为发生,并阻止事件传播
1300
+ */
1301
+ const stopEvent = (event, onlyStopPropagation) => {
1302
+ if (typeof onlyStopPropagation === "boolean" && onlyStopPropagation) {
1303
+ // 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
1304
+ event?.stopPropagation();
1305
+ // 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
1306
+ event?.stopImmediatePropagation();
1307
+ return;
1308
+ }
1309
+ // 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的URL,或者在输入框内输入文字
1260
1310
  event?.preventDefault();
1261
- // 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
1262
- event?.stopPropagation();
1263
- // 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
1264
- event?.stopImmediatePropagation();
1265
1311
  return false;
1266
- }
1267
- if (arguments.length === 1) {
1312
+ };
1313
+ if (args[0] instanceof Event) {
1268
1314
  // 直接阻止事件
1269
- // eslint-disable-next-line prefer-rest-params
1270
- return stopEvent(arguments[0]);
1315
+ const onlyStopPropagation = args[1];
1316
+ return stopEvent(args[0], onlyStopPropagation);
1271
1317
  }
1272
1318
  else {
1319
+ const $el = args[0];
1320
+ let eventNameList = args[1];
1321
+ let selector = void 0;
1322
+ let capture = false;
1323
+ let onlyStopPropagation = false;
1273
1324
  // 添加对应的事件来阻止触发
1274
1325
  if (typeof eventNameList === "string") {
1275
1326
  eventNameList = [eventNameList];
1276
1327
  }
1277
- eventNameList.forEach((eventName) => {
1278
- this.on(element, eventName, stopEvent, { capture: Boolean(capture) });
1279
- });
1328
+ let option = void 0;
1329
+ if (typeof args[2] === "string" || Array.isArray(args[2])) {
1330
+ // selector
1331
+ selector = args[2];
1332
+ if (typeof args[3] === "object" && args[3] != null) {
1333
+ option = args[3];
1334
+ }
1335
+ }
1336
+ else if (typeof args[2] === "object" && args[2] != null && !Array.isArray(args[2])) {
1337
+ // option
1338
+ option = args[2];
1339
+ }
1340
+ else {
1341
+ throw new TypeError("Invalid argument");
1342
+ }
1343
+ if (option) {
1344
+ capture = Boolean(option.capture);
1345
+ onlyStopPropagation = Boolean(option.onlyStopPropagation);
1346
+ }
1347
+ const listener = this.on($el, eventNameList, selector, (evt) => {
1348
+ return stopEvent(evt, onlyStopPropagation);
1349
+ }, { capture: capture });
1350
+ return listener;
1280
1351
  }
1281
1352
  }
1282
1353
  selector(selector) {
@@ -1462,7 +1533,7 @@
1462
1533
  width(element, isShow = false, parent) {
1463
1534
  const DOMUtilsContext = this;
1464
1535
  if (typeof element === "string") {
1465
- element = PopsCore.document.querySelector(element);
1536
+ element = this.selector(element);
1466
1537
  }
1467
1538
  if (element == null) {
1468
1539
  return;
@@ -1513,7 +1584,7 @@
1513
1584
  return PopsCore.window.document.documentElement.clientHeight;
1514
1585
  }
1515
1586
  if (typeof element === "string") {
1516
- element = PopsCore.document.querySelector(element);
1587
+ element = this.selector(element);
1517
1588
  }
1518
1589
  if (element == null) {
1519
1590
  return;
@@ -1561,7 +1632,7 @@
1561
1632
  return PopsCore.window.innerWidth;
1562
1633
  }
1563
1634
  if (typeof element === "string") {
1564
- element = PopsCore.document.querySelector(element);
1635
+ element = this.selector(element);
1565
1636
  }
1566
1637
  if (element == null) {
1567
1638
  return;
@@ -1586,7 +1657,7 @@
1586
1657
  return PopsCore.window.innerHeight;
1587
1658
  }
1588
1659
  if (typeof element === "string") {
1589
- element = PopsCore.document.querySelector(element);
1660
+ element = this.selector(element);
1590
1661
  }
1591
1662
  element = element;
1592
1663
  if (isShow || (!isShow && popsDOMUtils.isShow(element))) {
@@ -2008,12 +2079,12 @@
2008
2079
  * @param content 子元素或HTML字符串
2009
2080
  * @example
2010
2081
  * // 元素a.xx的内部末尾添加一个元素
2011
- * DOMUtils.append(document.querySelector("a.xx"),document.querySelector("b.xx"))
2082
+ * DOMUtils.append(document.querySelector("a.xx"), document.querySelector("b.xx"))
2012
2083
  * DOMUtils.append("a.xx","'<b class="xx"></b>")
2013
2084
  * */
2014
2085
  append(element, content) {
2015
2086
  if (typeof element === "string") {
2016
- element = PopsCore.document.querySelector(element);
2087
+ element = this.selector(element);
2017
2088
  }
2018
2089
  if (element == null) {
2019
2090
  return;
@@ -2149,7 +2220,7 @@
2149
2220
  * */
2150
2221
  before(element, content) {
2151
2222
  if (typeof element === "string") {
2152
- element = PopsCore.document.querySelector(element);
2223
+ element = this.selector(element);
2153
2224
  }
2154
2225
  if (element == null) {
2155
2226
  return;
@@ -2172,7 +2243,7 @@
2172
2243
  * */
2173
2244
  after(element, content) {
2174
2245
  if (typeof element === "string") {
2175
- element = PopsCore.document.querySelector(element);
2246
+ element = this.selector(element);
2176
2247
  }
2177
2248
  if (element == null) {
2178
2249
  return;
@@ -3537,14 +3608,14 @@
3537
3608
  element.hasAttribute("anim"));
3538
3609
  }
3539
3610
  // 判断按下的元素是否是pops-anim
3540
- popsDOMUtils.on(config.animElement, ["touchstart", "mousedown"], (event) => {
3611
+ popsDOMUtils.on(config.animElement, "pointerup", (event) => {
3541
3612
  const $click = event.composedPath()[0];
3542
3613
  isMaskClick = isAnimElement($click);
3543
3614
  });
3544
3615
  // 如果有动画层,在动画层上监听点击事件
3545
3616
  popsDOMUtils.on(config.animElement, "click", (event) => {
3546
3617
  const $click = event.composedPath()[0];
3547
- if (isAnimElement($click) && isMaskClick) {
3618
+ if (isMaskClick && isAnimElement($click)) {
3548
3619
  return clickEvent(event);
3549
3620
  }
3550
3621
  });
@@ -5823,7 +5894,7 @@
5823
5894
  */
5824
5895
  const $anim = PopsElementHandler.parseElement(animHTML);
5825
5896
  const { $pops: $pops, $headerBtnClose: headerCloseBtnElement, $headerControls: headerControlsElement, $title: $title, $iframe: $iframe, $loading: loadingElement, $contentLoading: $contentLoading, $headerBtnMin: headerMinBtnElement, $headerBtnMax: headerMaxBtnElement, $headerBtnMise: headerMiseBtnElement, } = PopsHandler.handleQueryElement($anim, popsType);
5826
- let $iframeContainer = PopsCore.document.querySelector(".pops-iframe-container");
5897
+ let $iframeContainer = popsDOMUtils.selector(".pops-iframe-container");
5827
5898
  if (!$iframeContainer) {
5828
5899
  $iframeContainer = popsDOMUtils.createElement("div", {
5829
5900
  className: "pops-iframe-container",
@@ -13301,7 +13372,7 @@
13301
13372
  },
13302
13373
  };
13303
13374
 
13304
- const version = "3.3.1";
13375
+ const version = "3.3.3";
13305
13376
 
13306
13377
  class Pops {
13307
13378
  /** 配置 */