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