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