@whitesev/pops 1.8.6 → 1.8.8

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
@@ -9464,8 +9464,8 @@
9464
9464
  $data = {
9465
9465
  config: null,
9466
9466
  guid: null,
9467
- timeId_show: [],
9468
- timeId_close: [],
9467
+ timeId_close_TouchEvent: [],
9468
+ timeId_close_MouseEvent: [],
9469
9469
  };
9470
9470
  constructor(config, guid, ShadowInfo) {
9471
9471
  this.$data.config = config;
@@ -9483,6 +9483,7 @@
9483
9483
  this.changeZIndex();
9484
9484
  this.changePosition();
9485
9485
  if (!this.$data.config.alwaysShow) {
9486
+ this.offEvent();
9486
9487
  this.onEvent();
9487
9488
  }
9488
9489
  }
@@ -9637,23 +9638,60 @@
9637
9638
  this.offAnimationFinishEvent();
9638
9639
  this.offShowEvent();
9639
9640
  this.offCloseEvent();
9641
+ this.offMouseEnterEvent();
9642
+ this.offMouseLeaveEvent();
9643
+ }
9644
+ /**
9645
+ * 添加关闭的timeId
9646
+ * @param type
9647
+ * @param timeId
9648
+ */
9649
+ addCloseTimeoutId(type, timeId) {
9650
+ if (type === "MouseEvent") {
9651
+ this.$data.timeId_close_MouseEvent.push(timeId);
9652
+ }
9653
+ else {
9654
+ this.$data.timeId_close_TouchEvent.push(timeId);
9655
+ }
9656
+ }
9657
+ /**
9658
+ * 清除延迟的timeId
9659
+ * @param type 事件类型
9660
+ */
9661
+ clearCloseTimeoutId(type, timeId) {
9662
+ let timeIdList = type === "MouseEvent"
9663
+ ? this.$data.timeId_close_MouseEvent
9664
+ : this.$data.timeId_close_TouchEvent;
9665
+ for (let index = 0; index < timeIdList.length; index++) {
9666
+ const currentTimeId = timeIdList[index];
9667
+ if (typeof timeId === "number") {
9668
+ // 只清除一个
9669
+ if (timeId == currentTimeId) {
9670
+ clearTimeout(timeId);
9671
+ timeIdList.splice(index, 1);
9672
+ break;
9673
+ }
9674
+ }
9675
+ else {
9676
+ clearTimeout(currentTimeId);
9677
+ timeIdList.splice(index, 1);
9678
+ index--;
9679
+ }
9680
+ }
9640
9681
  }
9641
9682
  /**
9642
9683
  * 显示提示框
9643
9684
  */
9644
- show() {
9685
+ show(...args) {
9686
+ let event = args[0];
9687
+ let eventType = event instanceof MouseEvent ? "MouseEvent" : "TouchEvent";
9688
+ this.clearCloseTimeoutId(eventType);
9645
9689
  if (typeof this.$data.config.showBeforeCallBack === "function") {
9646
9690
  let result = this.$data.config.showBeforeCallBack(this.$el.$toolTip);
9647
9691
  if (typeof result === "boolean" && !result) {
9648
9692
  return;
9649
9693
  }
9650
9694
  }
9651
- for (let index = 0; index < this.$data.timeId_close.length; index++) {
9652
- let timeId = this.$data.timeId_close[index];
9653
- clearTimeout(timeId);
9654
- this.$data.timeId_close.splice(index, 1);
9655
- index--;
9656
- }
9657
9695
  if (!popsUtils.contains(this.$el.$shadowRoot, this.$el.$toolTip)) {
9658
9696
  // 不在容器中,添加
9659
9697
  this.init();
@@ -9693,7 +9731,10 @@
9693
9731
  */
9694
9732
  close(...args) {
9695
9733
  let event = args[0];
9696
- if (event) {
9734
+ let eventType = event instanceof MouseEvent ? "MouseEvent" : "TouchEvent";
9735
+ // 只判断鼠标事件
9736
+ // 其它的如Touch事件不做处理
9737
+ if (event && event instanceof MouseEvent) {
9697
9738
  let $target = event.composedPath()[0];
9698
9739
  // 如果是子元素触发的话,忽视
9699
9740
  if ($target != this.$data.config.target) {
@@ -9712,11 +9753,13 @@
9712
9753
  this.$data.config.delayCloseTime = 100;
9713
9754
  }
9714
9755
  let timeId = setTimeout(() => {
9756
+ // 设置属性触发关闭动画
9757
+ this.clearCloseTimeoutId(eventType, timeId);
9715
9758
  this.$el.$toolTip.setAttribute("data-motion", this.$el.$toolTip
9716
9759
  .getAttribute("data-motion")
9717
9760
  .replace("fadeIn", "fadeOut"));
9718
9761
  }, this.$data.config.delayCloseTime);
9719
- this.$data.timeId_close.push(timeId);
9762
+ this.addCloseTimeoutId(eventType, timeId);
9720
9763
  if (typeof this.$data.config.closeAfterCallBack === "function") {
9721
9764
  this.$data.config.closeAfterCallBack(this.$el.$toolTip);
9722
9765
  }
@@ -9774,29 +9817,45 @@
9774
9817
  popsDOMUtils.off(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.animationFinishEvent.bind(this));
9775
9818
  }
9776
9819
  /**
9777
- * 当鼠标|手触摸
9820
+ * 鼠标|触摸进入事件
9821
+ */
9822
+ mouseEnterEvent() {
9823
+ this.$el.$toolTip.style.animationPlayState = "paused";
9824
+ // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
9825
+ // toolTipElement.style.animationPlayState = "paused";
9826
+ // }
9827
+ }
9828
+ /**
9829
+ * 监听鼠标|触摸事件
9778
9830
  */
9779
9831
  onMouseEnterEvent() {
9780
- for (let index = 0; index < this.$data.timeId_close.length; index++) {
9781
- let timeId = this.$data.timeId_close[index];
9782
- clearTimeout(timeId);
9783
- this.$data.timeId_close.splice(index, 1);
9784
- index--;
9785
- }
9786
- popsDOMUtils.on(this.$el.$toolTip, "mouseenter touchstart", () => {
9787
- this.$el.$toolTip.style.animationPlayState = "paused";
9788
- // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
9789
- // toolTipElement.style.animationPlayState = "paused";
9790
- // }
9791
- }, this.$data.config.eventOption);
9832
+ this.clearCloseTimeoutId("MouseEvent");
9833
+ this.clearCloseTimeoutId("TouchEvent");
9834
+ popsDOMUtils.on(this.$el.$toolTip, "mouseenter touchstart", this.mouseEnterEvent.bind(this), this.$data.config.eventOption);
9835
+ }
9836
+ /**
9837
+ * 取消监听鼠标|触摸事件
9838
+ */
9839
+ offMouseEnterEvent() {
9840
+ popsDOMUtils.off(this.$el.$toolTip, "mouseenter touchstart", this.mouseEnterEvent.bind(this), this.$data.config.eventOption);
9841
+ }
9842
+ /**
9843
+ * 鼠标|触摸离开事件
9844
+ */
9845
+ mouseLeaveEvent() {
9846
+ this.$el.$toolTip.style.animationPlayState = "running";
9792
9847
  }
9793
9848
  /**
9794
- * 当鼠标|手离开,开始当前动画
9849
+ * 监听鼠标|触摸离开事件
9795
9850
  */
9796
9851
  onMouseLeaveEvent() {
9797
- popsDOMUtils.on(this.$el.$toolTip, "mouseleave touchend", () => {
9798
- this.$el.$toolTip.style.animationPlayState = "running";
9799
- }, this.$data.config.eventOption);
9852
+ popsDOMUtils.on(this.$el.$toolTip, "mouseleave touchend", this.mouseLeaveEvent.bind(this), this.$data.config.eventOption);
9853
+ }
9854
+ /**
9855
+ * 取消监听鼠标|触摸离开事件
9856
+ */
9857
+ offMouseLeaveEvent() {
9858
+ popsDOMUtils.off(this.$el.$toolTip, "mouseleave touchend", this.mouseLeaveEvent.bind(this), this.$data.config.eventOption);
9800
9859
  }
9801
9860
  }
9802
9861
  class PopsTooltip {