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