@whitesev/pops 3.3.2 → 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
@@ -1028,7 +1035,7 @@ System.register('pops', [], (function (exports) {
1028
1035
  */
1029
1036
  emit(element, eventType, details, useDispatchToEmitEvent = true) {
1030
1037
  if (typeof element === "string") {
1031
- element = PopsCore.document.querySelector(element);
1038
+ element = this.selector(element);
1032
1039
  }
1033
1040
  if (element == null) {
1034
1041
  return;
@@ -1090,18 +1097,18 @@ System.register('pops', [], (function (exports) {
1090
1097
  * })
1091
1098
  * */
1092
1099
  click(element, handler, details, useDispatchToEmitEvent) {
1093
- const DOMUtilsContext = this;
1094
1100
  if (typeof element === "string") {
1095
- element = PopsCore.document.querySelector(element);
1101
+ element = this.selector(element);
1096
1102
  }
1097
1103
  if (element == null) {
1098
1104
  return;
1099
1105
  }
1100
1106
  if (handler == null) {
1101
- DOMUtilsContext.emit(element, "click", details, useDispatchToEmitEvent);
1107
+ this.emit(element, "click", details, useDispatchToEmitEvent);
1102
1108
  }
1103
1109
  else {
1104
- DOMUtilsContext.on(element, "click", null, handler);
1110
+ const listener = this.on(element, "click", handler);
1111
+ return listener;
1105
1112
  }
1106
1113
  }
1107
1114
  /**
@@ -1119,18 +1126,18 @@ System.register('pops', [], (function (exports) {
1119
1126
  * })
1120
1127
  * */
1121
1128
  blur(element, handler, details, useDispatchToEmitEvent) {
1122
- const DOMUtilsContext = this;
1123
1129
  if (typeof element === "string") {
1124
- element = PopsCore.document.querySelector(element);
1130
+ element = this.selector(element);
1125
1131
  }
1126
1132
  if (element == null) {
1127
1133
  return;
1128
1134
  }
1129
1135
  if (handler === null) {
1130
- DOMUtilsContext.emit(element, "blur", details, useDispatchToEmitEvent);
1136
+ this.emit(element, "blur", details, useDispatchToEmitEvent);
1131
1137
  }
1132
1138
  else {
1133
- DOMUtilsContext.on(element, "blur", null, handler);
1139
+ const listener = this.on(element, "blur", handler);
1140
+ return listener;
1134
1141
  }
1135
1142
  }
1136
1143
  /**
@@ -1148,18 +1155,18 @@ System.register('pops', [], (function (exports) {
1148
1155
  * })
1149
1156
  * */
1150
1157
  focus(element, handler, details, useDispatchToEmitEvent) {
1151
- const DOMUtilsContext = this;
1152
1158
  if (typeof element === "string") {
1153
- element = PopsCore.document.querySelector(element);
1159
+ element = this.selector(element);
1154
1160
  }
1155
1161
  if (element == null) {
1156
1162
  return;
1157
1163
  }
1158
1164
  if (handler == null) {
1159
- DOMUtilsContext.emit(element, "focus", details, useDispatchToEmitEvent);
1165
+ this.emit(element, "focus", details, useDispatchToEmitEvent);
1160
1166
  }
1161
1167
  else {
1162
- DOMUtilsContext.on(element, "focus", null, handler);
1168
+ const listener = this.on(element, "focus", handler);
1169
+ return listener;
1163
1170
  }
1164
1171
  }
1165
1172
  /**
@@ -1177,15 +1184,39 @@ System.register('pops', [], (function (exports) {
1177
1184
  * })
1178
1185
  */
1179
1186
  onHover(element, handler, option) {
1180
- const DOMUtilsContext = this;
1187
+ const that = this;
1181
1188
  if (typeof element === "string") {
1182
- element = PopsCore.document.querySelector(element);
1189
+ element = that.selectorAll(element);
1183
1190
  }
1184
1191
  if (element == null) {
1185
1192
  return;
1186
1193
  }
1187
- DOMUtilsContext.on(element, "mouseenter", null, handler, option);
1188
- 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
+ };
1189
1220
  }
1190
1221
  /**
1191
1222
  * 当按键松开时触发事件
@@ -1203,14 +1234,14 @@ System.register('pops', [], (function (exports) {
1203
1234
  * })
1204
1235
  */
1205
1236
  onKeyup(target, handler, option) {
1206
- const DOMUtilsContext = this;
1207
1237
  if (target == null) {
1208
1238
  return;
1209
1239
  }
1210
1240
  if (typeof target === "string") {
1211
- target = PopsCore.document.querySelector(target);
1241
+ target = this.selector(target);
1212
1242
  }
1213
- DOMUtilsContext.on(target, "keyup", null, handler, option);
1243
+ const listener = this.on(target, "keyup", handler, option);
1244
+ return listener;
1214
1245
  }
1215
1246
  /**
1216
1247
  * 当按键按下时触发事件
@@ -1228,14 +1259,14 @@ System.register('pops', [], (function (exports) {
1228
1259
  * })
1229
1260
  */
1230
1261
  onKeydown(target, handler, option) {
1231
- const DOMUtilsContext = this;
1232
1262
  if (target == null) {
1233
1263
  return;
1234
1264
  }
1235
1265
  if (typeof target === "string") {
1236
- target = PopsCore.document.querySelector(target);
1266
+ target = this.selector(target);
1237
1267
  }
1238
- DOMUtilsContext.on(target, "keydown", null, handler, option);
1268
+ const listener = this.on(target, "keydown", handler, option);
1269
+ return listener;
1239
1270
  }
1240
1271
  /**
1241
1272
  * 当按键按下时触发事件
@@ -1253,38 +1284,69 @@ System.register('pops', [], (function (exports) {
1253
1284
  * })
1254
1285
  */
1255
1286
  onKeypress(target, handler, option) {
1256
- const DOMUtilsContext = this;
1257
1287
  if (target == null) {
1258
1288
  return;
1259
1289
  }
1260
1290
  if (typeof target === "string") {
1261
- target = PopsCore.document.querySelector(target);
1291
+ target = this.selector(target);
1262
1292
  }
1263
- DOMUtilsContext.on(target, "keypress", null, handler, option);
1293
+ const listener = this.on(target, "keypress", handler, option);
1294
+ return listener;
1264
1295
  }
1265
- preventEvent(element, eventNameList = [], capture) {
1266
- function stopEvent(event) {
1267
- // 阻止事件的默认行为发生。例如,当点击一个链接时,浏览器会默认打开链接的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,或者在输入框内输入文字
1268
1309
  event?.preventDefault();
1269
- // 停止事件的传播,阻止它继续向更上层的元素冒泡,事件将不会再传播给其他的元素
1270
- event?.stopPropagation();
1271
- // 阻止事件传播,并且还能阻止元素上的其他事件处理程序被触发
1272
- event?.stopImmediatePropagation();
1273
1310
  return false;
1274
- }
1275
- if (arguments.length === 1) {
1311
+ };
1312
+ if (args[0] instanceof Event) {
1276
1313
  // 直接阻止事件
1277
- // eslint-disable-next-line prefer-rest-params
1278
- return stopEvent(arguments[0]);
1314
+ const onlyStopPropagation = args[1];
1315
+ return stopEvent(args[0], onlyStopPropagation);
1279
1316
  }
1280
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;
1281
1323
  // 添加对应的事件来阻止触发
1282
1324
  if (typeof eventNameList === "string") {
1283
1325
  eventNameList = [eventNameList];
1284
1326
  }
1285
- eventNameList.forEach((eventName) => {
1286
- this.on(element, eventName, stopEvent, { capture: Boolean(capture) });
1287
- });
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;
1288
1350
  }
1289
1351
  }
1290
1352
  selector(selector) {
@@ -1470,7 +1532,7 @@ System.register('pops', [], (function (exports) {
1470
1532
  width(element, isShow = false, parent) {
1471
1533
  const DOMUtilsContext = this;
1472
1534
  if (typeof element === "string") {
1473
- element = PopsCore.document.querySelector(element);
1535
+ element = this.selector(element);
1474
1536
  }
1475
1537
  if (element == null) {
1476
1538
  return;
@@ -1521,7 +1583,7 @@ System.register('pops', [], (function (exports) {
1521
1583
  return PopsCore.window.document.documentElement.clientHeight;
1522
1584
  }
1523
1585
  if (typeof element === "string") {
1524
- element = PopsCore.document.querySelector(element);
1586
+ element = this.selector(element);
1525
1587
  }
1526
1588
  if (element == null) {
1527
1589
  return;
@@ -1569,7 +1631,7 @@ System.register('pops', [], (function (exports) {
1569
1631
  return PopsCore.window.innerWidth;
1570
1632
  }
1571
1633
  if (typeof element === "string") {
1572
- element = PopsCore.document.querySelector(element);
1634
+ element = this.selector(element);
1573
1635
  }
1574
1636
  if (element == null) {
1575
1637
  return;
@@ -1594,7 +1656,7 @@ System.register('pops', [], (function (exports) {
1594
1656
  return PopsCore.window.innerHeight;
1595
1657
  }
1596
1658
  if (typeof element === "string") {
1597
- element = PopsCore.document.querySelector(element);
1659
+ element = this.selector(element);
1598
1660
  }
1599
1661
  element = element;
1600
1662
  if (isShow || (!isShow && popsDOMUtils.isShow(element))) {
@@ -2016,12 +2078,12 @@ System.register('pops', [], (function (exports) {
2016
2078
  * @param content 子元素或HTML字符串
2017
2079
  * @example
2018
2080
  * // 元素a.xx的内部末尾添加一个元素
2019
- * DOMUtils.append(document.querySelector("a.xx"),document.querySelector("b.xx"))
2081
+ * DOMUtils.append(document.querySelector("a.xx"), document.querySelector("b.xx"))
2020
2082
  * DOMUtils.append("a.xx","'<b class="xx"></b>")
2021
2083
  * */
2022
2084
  append(element, content) {
2023
2085
  if (typeof element === "string") {
2024
- element = PopsCore.document.querySelector(element);
2086
+ element = this.selector(element);
2025
2087
  }
2026
2088
  if (element == null) {
2027
2089
  return;
@@ -2157,7 +2219,7 @@ System.register('pops', [], (function (exports) {
2157
2219
  * */
2158
2220
  before(element, content) {
2159
2221
  if (typeof element === "string") {
2160
- element = PopsCore.document.querySelector(element);
2222
+ element = this.selector(element);
2161
2223
  }
2162
2224
  if (element == null) {
2163
2225
  return;
@@ -2180,7 +2242,7 @@ System.register('pops', [], (function (exports) {
2180
2242
  * */
2181
2243
  after(element, content) {
2182
2244
  if (typeof element === "string") {
2183
- element = PopsCore.document.querySelector(element);
2245
+ element = this.selector(element);
2184
2246
  }
2185
2247
  if (element == null) {
2186
2248
  return;
@@ -5831,7 +5893,7 @@ System.register('pops', [], (function (exports) {
5831
5893
  */
5832
5894
  const $anim = PopsElementHandler.parseElement(animHTML);
5833
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);
5834
- let $iframeContainer = PopsCore.document.querySelector(".pops-iframe-container");
5896
+ let $iframeContainer = popsDOMUtils.selector(".pops-iframe-container");
5835
5897
  if (!$iframeContainer) {
5836
5898
  $iframeContainer = popsDOMUtils.createElement("div", {
5837
5899
  className: "pops-iframe-container",
@@ -13309,7 +13371,7 @@ System.register('pops', [], (function (exports) {
13309
13371
  },
13310
13372
  };
13311
13373
 
13312
- const version = "3.3.2";
13374
+ const version = "3.3.3";
13313
13375
 
13314
13376
  class Pops {
13315
13377
  /** 配置 */