@whitesev/pops 1.8.9 → 1.9.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.amd.js CHANGED
@@ -1666,6 +1666,8 @@ define((function () { 'use strict';
1666
1666
  /**
1667
1667
  * 获取页面中最大的z-index的元素信息
1668
1668
  * @param deviation 获取最大的z-index值的偏移,默认是+1
1669
+ * @param node 进行判断的元素,默认是document
1670
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
1669
1671
  * @example
1670
1672
  * Utils.getMaxZIndexNodeInfo();
1671
1673
  * > {
@@ -1673,11 +1675,11 @@ define((function () { 'use strict';
1673
1675
  * zIndex: 1001
1674
1676
  * }
1675
1677
  **/
1676
- getMaxZIndexNodeInfo(deviation = 1) {
1678
+ getMaxZIndexNodeInfo(deviation = 1, target = PopsCore.document, ignoreCallBack) {
1677
1679
  deviation = Number.isNaN(deviation) ? 1 : deviation;
1678
- // 最大值2147483647
1679
- const maxZIndex = Math.pow(2, 31) - 1;
1680
- // 比较值2000000000
1680
+ // 最大值 2147483647
1681
+ // const maxZIndex = Math.pow(2, 31) - 1;
1682
+ // 比较值 2000000000
1681
1683
  const maxZIndexCompare = 2 * Math.pow(10, 9);
1682
1684
  // 当前页面最大的z-index
1683
1685
  let zIndex = 0;
@@ -1697,6 +1699,12 @@ define((function () { 'use strict';
1697
1699
  * @param $ele
1698
1700
  */
1699
1701
  function queryMaxZIndex($ele) {
1702
+ if (typeof ignoreCallBack === "function") {
1703
+ let ignoreResult = ignoreCallBack($ele);
1704
+ if (typeof ignoreResult === "boolean" && !ignoreResult) {
1705
+ return;
1706
+ }
1707
+ }
1700
1708
  /** 元素的样式 */
1701
1709
  const nodeStyle = PopsCore.window.getComputedStyle($ele);
1702
1710
  /* 不对position为static和display为none的元素进行获取它们的z-index */
@@ -1717,48 +1725,48 @@ define((function () { 'use strict';
1717
1725
  }
1718
1726
  }
1719
1727
  }
1720
- PopsCore.document.querySelectorAll("*").forEach(($ele, index) => {
1728
+ target.querySelectorAll("*").forEach(($ele, index) => {
1721
1729
  queryMaxZIndex($ele);
1722
1730
  });
1723
1731
  zIndex += deviation;
1724
1732
  if (zIndex >= maxZIndexCompare) {
1725
1733
  // 最好不要超过最大值
1726
- zIndex = maxZIndex;
1734
+ zIndex = maxZIndexCompare;
1727
1735
  }
1728
1736
  return {
1729
1737
  node: maxZIndexNode,
1730
1738
  zIndex: zIndex,
1731
1739
  };
1732
1740
  },
1733
- /**
1734
- * 获取页面中最大的z-index
1735
- * @param deviation 获取最大的z-index值的偏移,默认是+1
1736
- * @example
1737
- * Utils.getMaxZIndex();
1738
- * > 1001
1739
- **/
1740
- getMaxZIndex(deviation = 1) {
1741
- return this.getMaxZIndexNodeInfo(deviation).zIndex;
1742
- },
1743
1741
  /**
1744
1742
  * 获取pops所有弹窗中的最大的z-index
1745
1743
  * @param deviation
1746
1744
  */
1747
1745
  getPopsMaxZIndex(deviation = 1) {
1748
1746
  deviation = Number.isNaN(deviation) ? 1 : deviation;
1749
- // 最大值2147483647
1750
- let maxZIndex = Math.pow(2, 31) - 1;
1747
+ // 最大值 2147483647
1748
+ // 最大值 2147483647
1749
+ // const maxZIndex = Math.pow(2, 31) - 1;
1750
+ // 比较值 2000000000
1751
+ const maxZIndexCompare = 2 * Math.pow(10, 9);
1751
1752
  // 当前页面最大的z-index
1752
1753
  let zIndex = 0;
1753
1754
  // 当前的最大z-index的元素,调试使用
1754
1755
  let maxZIndexNode = null;
1756
+ /**
1757
+ * 元素是否可见
1758
+ * @param $css
1759
+ */
1760
+ function isVisibleNode($css) {
1761
+ return $css.position !== "static" && $css.display !== "none";
1762
+ }
1755
1763
  Object.keys(pops.config.layer).forEach((layerName) => {
1756
1764
  let layerList = pops.config.layer[layerName];
1757
1765
  for (let index = 0; index < layerList.length; index++) {
1758
1766
  const layer = layerList[index];
1759
1767
  let nodeStyle = window.getComputedStyle(layer.animElement);
1760
1768
  /* 不对position为static和display为none的元素进行获取它们的z-index */
1761
- if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
1769
+ if (isVisibleNode(nodeStyle)) {
1762
1770
  let nodeZIndex = parseInt(nodeStyle.zIndex);
1763
1771
  if (!isNaN(nodeZIndex)) {
1764
1772
  if (nodeZIndex > zIndex) {
@@ -1770,14 +1778,22 @@ define((function () { 'use strict';
1770
1778
  }
1771
1779
  });
1772
1780
  zIndex += deviation;
1773
- // 用于比较的值2000000000,大于该值就取该值
1774
- let maxZIndexCompare = 2 * Math.pow(10, 9);
1775
1781
  if (zIndex >= maxZIndexCompare) {
1776
1782
  // 最好不要超过最大值
1777
- zIndex = maxZIndex;
1783
+ zIndex = maxZIndexCompare;
1778
1784
  }
1779
1785
  return { zIndex: zIndex, animElement: maxZIndexNode };
1780
1786
  },
1787
+ /**
1788
+ * 获取页面中最大的z-index
1789
+ * @param deviation 获取最大的z-index值的偏移,默认是+1
1790
+ * @example
1791
+ * Utils.getMaxZIndex();
1792
+ * > 1001
1793
+ **/
1794
+ getMaxZIndex(deviation = 1) {
1795
+ return this.getMaxZIndexNodeInfo(deviation).zIndex;
1796
+ },
1781
1797
  /**
1782
1798
  * 获取CSS Rule
1783
1799
  * @param sheet
@@ -2761,6 +2777,8 @@ define((function () { 'use strict';
2761
2777
  },
2762
2778
  /**
2763
2779
  * 处理遮罩层
2780
+ *
2781
+ * + 设置遮罩层的点击事件
2764
2782
  * @param details 传递的配置
2765
2783
  */
2766
2784
  handleMask(details = {}) {
@@ -2794,22 +2812,29 @@ define((function () { 'use strict';
2794
2812
  }
2795
2813
  return false;
2796
2814
  }
2797
- function isAnimElement(element) {
2798
- return Boolean(element?.localName?.toLowerCase() === "div" &&
2799
- element.className &&
2800
- element.className === "pops-anim" &&
2801
- element.hasAttribute("anim"));
2802
- }
2815
+ // 判断是否启用了遮罩层点击动作
2803
2816
  if (details.config.mask.clickEvent.toClose ||
2804
2817
  details.config.mask.clickEvent.toHide) {
2818
+ /**
2819
+ * 判断点击的元素是否是动画层的元素
2820
+ * @param element
2821
+ * @returns
2822
+ */
2823
+ function isAnimElement(element) {
2824
+ return Boolean(element?.localName?.toLowerCase() === "div" &&
2825
+ element.className &&
2826
+ element.className === "pops-anim" &&
2827
+ element.hasAttribute("anim"));
2828
+ }
2805
2829
  /* 判断按下的元素是否是pops-anim */
2806
2830
  popsDOMUtils.on(details.animElement, ["touchstart", "mousedown"], void 0, (event) => {
2807
- isMaskClick = isAnimElement(event.composedPath()[0]);
2831
+ let $click = event.composedPath()[0];
2832
+ isMaskClick = isAnimElement($click);
2808
2833
  });
2809
2834
  /* 如果有动画层,在动画层上监听点击事件 */
2810
2835
  popsDOMUtils.on(details.animElement, "click", void 0, (event) => {
2811
- if (isAnimElement(event.composedPath()[0]) &&
2812
- isMaskClick) {
2836
+ let $click = event.composedPath()[0];
2837
+ if (isAnimElement($click) && isMaskClick) {
2813
2838
  return clickEvent(event);
2814
2839
  }
2815
2840
  });
@@ -2824,7 +2849,7 @@ define((function () { 'use strict';
2824
2849
  },
2825
2850
  /**
2826
2851
  * 处理获取元素
2827
- * @param {HTMLDivElement} animElement
2852
+ * @param animElement
2828
2853
  * @param type
2829
2854
  */
2830
2855
  handleQueryElement(animElement, type) {
@@ -8223,25 +8248,25 @@ define((function () { 'use strict';
8223
8248
  /**
8224
8249
  * 已创建的元素列表
8225
8250
  */
8226
- let elementList = [$anim];
8251
+ let isCreatedElementList = [$anim];
8227
8252
  /* 遮罩层元素 */
8228
8253
  if (config.mask.enable) {
8229
- let _handleMask_ = PopsHandler.handleMask({
8254
+ let { maskElement } = PopsHandler.handleMask({
8230
8255
  type: PopsType,
8231
8256
  guid: guid,
8232
8257
  config: config,
8233
8258
  animElement: $anim,
8234
8259
  maskHTML: maskHTML,
8235
8260
  });
8236
- $mask = _handleMask_.maskElement;
8237
- elementList.push($mask);
8261
+ $mask = maskElement;
8262
+ isCreatedElementList.push($mask);
8238
8263
  }
8239
8264
  /* 处理返回的配置 */
8240
8265
  let eventDetails = PopsHandler.handleEventDetails(guid, $shadowContainer, $shadowRoot, PopsType, $anim, $pops, $mask, config);
8241
8266
  /* 为顶部右边的关闭按钮添加点击事件 */
8242
8267
  PopsHandler.handleClickEvent("close", $headerCloseBtn, eventDetails, config.btn.close.callback);
8243
8268
  /* 创建到页面中 */
8244
- popsDOMUtils.append($shadowRoot, elementList);
8269
+ popsDOMUtils.append($shadowRoot, isCreatedElementList);
8245
8270
  if (typeof config.beforeAppendToPageCallBack === "function") {
8246
8271
  config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
8247
8272
  }