@inappstory/slide-api 0.0.24 → 0.0.26

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.d.cts CHANGED
@@ -58,11 +58,14 @@ declare class WidgetRangeSlider extends WidgetBase<WidgetRangeSliderOptions> {
58
58
  * @param options
59
59
  */
60
60
  constructor(element: HTMLElement, options: Partial<WidgetRangeSliderOptions>);
61
+ private isTouchListenersInit;
62
+ private initTouchListeners;
61
63
  /**
62
64
  * Start or restart widget
63
65
  * @param localData
64
66
  */
65
67
  onRefreshUserData(localData: Record<string, any>): void;
68
+ onStart(): void;
66
69
  onStop(): void;
67
70
  private _statEventInputSave;
68
71
  click(): boolean;
@@ -792,13 +795,15 @@ declare class WidgetTest extends WidgetBase<WidgetTestOptions> {
792
795
  private startTimerAt;
793
796
  private timeLeft;
794
797
  private timeLeftDefault;
795
- private timeline;
798
+ private readonly timeline;
799
+ private isWidgetTimerInit;
796
800
  constructor(element: HTMLElement, options: Partial<WidgetTestOptions>);
797
801
  /**
798
802
  * Start or restart widget
799
803
  * @param localData
800
804
  */
801
805
  onRefreshUserData(localData: Record<string, any>): void;
806
+ private initWidgetTimer;
802
807
  onStart(): void;
803
808
  onStop(): void;
804
809
  private _statEventVoteAnswer;
package/dist/index.d.ts CHANGED
@@ -58,11 +58,14 @@ declare class WidgetRangeSlider extends WidgetBase<WidgetRangeSliderOptions> {
58
58
  * @param options
59
59
  */
60
60
  constructor(element: HTMLElement, options: Partial<WidgetRangeSliderOptions>);
61
+ private isTouchListenersInit;
62
+ private initTouchListeners;
61
63
  /**
62
64
  * Start or restart widget
63
65
  * @param localData
64
66
  */
65
67
  onRefreshUserData(localData: Record<string, any>): void;
68
+ onStart(): void;
66
69
  onStop(): void;
67
70
  private _statEventInputSave;
68
71
  click(): boolean;
@@ -792,13 +795,15 @@ declare class WidgetTest extends WidgetBase<WidgetTestOptions> {
792
795
  private startTimerAt;
793
796
  private timeLeft;
794
797
  private timeLeftDefault;
795
- private timeline;
798
+ private readonly timeline;
799
+ private isWidgetTimerInit;
796
800
  constructor(element: HTMLElement, options: Partial<WidgetTestOptions>);
797
801
  /**
798
802
  * Start or restart widget
799
803
  * @param localData
800
804
  */
801
805
  onRefreshUserData(localData: Record<string, any>): void;
806
+ private initWidgetTimer;
802
807
  onStart(): void;
803
808
  onStop(): void;
804
809
  private _statEventVoteAnswer;
package/dist/index.js CHANGED
@@ -3157,8 +3157,8 @@ class WidgetQuest extends WidgetBase {
3157
3157
  init() {
3158
3158
  if (this.localData) {
3159
3159
  if (this.localData["_qt_g_" + this.elementId + "_sa"] !== undefined) ;
3160
- if (this.localData["_qt_fo_at"] === undefined) {
3161
- this.localData["_qt_fo_at"] = Math.round(new Date().getTime() / 1000);
3160
+ if (this.localData["_qt_g_" + this.elementId + "fo_at"] === undefined) {
3161
+ this.localData["_qt_g_" + this.elementId + "fo_at"] = Math.round(new Date().getTime() / 1000);
3162
3162
  this.setLocalData(this.localData, false);
3163
3163
  }
3164
3164
  let lastSlideIdx = this.localData["_qt_last_slide_idx"];
@@ -3476,8 +3476,8 @@ class WidgetQuiz extends WidgetBase {
3476
3476
  else {
3477
3477
  this._clearAnswerSelection();
3478
3478
  }
3479
- if (this.localData["_q_fo_at"] === undefined) {
3480
- this.localData["_q_fo_at"] = Math.round(new Date().getTime() / 1000);
3479
+ if (this.localData["_q_g_" + this.elementId + "fo_at"] === undefined) {
3480
+ this.localData["_q_g_" + this.elementId + "fo_at"] = Math.round(new Date().getTime() / 1000);
3481
3481
  this.setLocalData(this.localData, false);
3482
3482
  }
3483
3483
  }
@@ -3683,8 +3683,8 @@ class WidgetQuizGrouped extends WidgetBase {
3683
3683
  else {
3684
3684
  this._clearAnswerSelection();
3685
3685
  }
3686
- if (this.localData["_qg_fo_at"] === undefined) {
3687
- this.localData["_qg_fo_at"] = Math.round(new Date().getTime() / 1000);
3686
+ if (this.localData["_qg_g_" + this.elementId + "fo_at"] === undefined) {
3687
+ this.localData["_qg_g_" + this.elementId + "fo_at"] = Math.round(new Date().getTime() / 1000);
3688
3688
  this.setLocalData(this.localData, false);
3689
3689
  }
3690
3690
  }
@@ -4066,8 +4066,14 @@ class WidgetRangeSlider extends WidgetBase {
4066
4066
  // _this.update(false, false);
4067
4067
  // }, 300);
4068
4068
  // }, 20));
4069
- this.env.document.addEventListener("touchstart", this.handleDown);
4070
- this.env.document.addEventListener("mousedown", this.handleDown);
4069
+ }
4070
+ isTouchListenersInit = false;
4071
+ initTouchListeners() {
4072
+ if (!this.isTouchListenersInit) {
4073
+ this.env.document.addEventListener("touchstart", this.handleDown);
4074
+ this.env.document.addEventListener("mousedown", this.handleDown);
4075
+ this.isTouchListenersInit = true;
4076
+ }
4071
4077
  }
4072
4078
  /**
4073
4079
  * Start or restart widget
@@ -4092,6 +4098,10 @@ class WidgetRangeSlider extends WidgetBase {
4092
4098
  }
4093
4099
  this.init();
4094
4100
  }
4101
+ onStart() {
4102
+ super.onStart();
4103
+ this.initTouchListeners();
4104
+ }
4095
4105
  onStop() {
4096
4106
  super.onStop();
4097
4107
  this.destroy();
@@ -4433,6 +4443,11 @@ class WidgetRangeSlider extends WidgetBase {
4433
4443
  destroy() {
4434
4444
  this.env.document.removeEventListener("touchstart", this.handleDown);
4435
4445
  this.env.document.removeEventListener("mousedown", this.handleDown);
4446
+ this.env.document.removeEventListener("touchmove", this.handleMove);
4447
+ this.env.document.removeEventListener("touchend", this.handleEnd);
4448
+ this.env.document.removeEventListener("mousemove", this.handleMove);
4449
+ this.env.document.removeEventListener("mouseup", this.handleEnd);
4450
+ this.isTouchListenersInit = false;
4436
4451
  // off resize event
4437
4452
  // this.$window.off('.' + this.identifier);
4438
4453
  // this.$element
@@ -4447,11 +4462,11 @@ class WidgetRangeSlider extends WidgetBase {
4447
4462
  onRefreshUserData: WidgetRangeSlider.onRefreshUserData,
4448
4463
  init: function (element, localData) {
4449
4464
  WidgetRangeSlider.initWidget(element, localData, (element, options) => new WidgetRangeSlider(element, options));
4450
- WidgetRangeSlider.getInstance(element)?.onStart();
4451
4465
  },
4452
4466
  /** @deprecated */
4453
4467
  initWidget: function (element, localData) {
4454
4468
  WidgetRangeSlider.initWidgets((element, options) => new WidgetRangeSlider(element, options), [element], localData);
4469
+ WidgetRangeSlider.getInstance(element)?.onStart();
4455
4470
  },
4456
4471
  onStart: function (element) {
4457
4472
  WidgetRangeSlider.getInstance(element)?.onStart();
@@ -4922,6 +4937,7 @@ class WidgetTest extends WidgetBase {
4922
4937
  timeLeft;
4923
4938
  timeLeftDefault;
4924
4939
  timeline;
4940
+ isWidgetTimerInit = false;
4925
4941
  constructor(element, options) {
4926
4942
  super(element, options);
4927
4943
  this.label = this.element.querySelector(".label-view .label");
@@ -4929,6 +4945,7 @@ class WidgetTest extends WidgetBase {
4929
4945
  this.testCount = getValueOrException(getTagDataAsNumber(this.slide, "testCount"), "Empty testCount");
4930
4946
  this.withTimeToAnswer = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "withTimeToAnswer"), 0));
4931
4947
  this.answerTimeout = getValueOrDefault(getTagDataAsNumber(this.element, "answerTimeout"), 0);
4948
+ this.timeline = this.element.querySelector(".timeline");
4932
4949
  this.tick = () => {
4933
4950
  this.animationFrameId = this.env.requestAnimationFrame(() => {
4934
4951
  this.tick();
@@ -4936,12 +4953,8 @@ class WidgetTest extends WidgetBase {
4936
4953
  // update timer
4937
4954
  // update timeline position
4938
4955
  if (this.startTimerAt) {
4939
- // if (this.state.timeLeft - this.timeLeft >= 950) {
4940
- // this.setState({timeLeft: this.timeLeft});
4941
- // }
4942
4956
  const timeNow = new Date().getTime();
4943
- this.timeLeft -= timeNow - this.startTimerAt;
4944
- this.startTimerAt = timeNow;
4957
+ this.timeLeft = this.startTimerAt + this.timeLeftDefault - timeNow;
4945
4958
  if (this.timeLeft <= 0) {
4946
4959
  this.timeLeft = 0;
4947
4960
  this.cancelTick();
@@ -4970,15 +4983,19 @@ class WidgetTest extends WidgetBase {
4970
4983
  this._selectAnswer(this.localData["_t_g_" + this.elementId + "_sa"]);
4971
4984
  this.setLocalData(this.localData, false);
4972
4985
  }
4973
- if (this.localData["_t_fo_at"] === undefined) {
4974
- this.localData["_t_fo_at"] = Math.round(new Date().getTime() / 1000);
4986
+ if (this.localData["_t_g_" + this.elementId + "fo_at"] === undefined) {
4987
+ this.localData["_t_g_" + this.elementId + "fo_at"] = Math.round(new Date().getTime() / 1000);
4975
4988
  this.setLocalData(this.localData, false);
4976
4989
  }
4977
4990
  }
4978
4991
  this.firstOpenTime = new Date().getTime();
4979
4992
  if (this.slideTestWithTimer()) {
4980
4993
  this.cancelTick();
4981
- this.timeline = this.element.querySelector(".timeline");
4994
+ this.initWidgetTimer();
4995
+ }
4996
+ }
4997
+ initWidgetTimer() {
4998
+ if (!this.isWidgetTimerInit) {
4982
4999
  if (this.selectedAnswer === undefined) {
4983
5000
  // find timer element
4984
5001
  // start raf
@@ -4986,13 +5003,18 @@ class WidgetTest extends WidgetBase {
4986
5003
  this.timeLeftDefault = (this.answerTimeout ? this.answerTimeout : 0) * 1000;
4987
5004
  this.timeLeft = this.timeLeftDefault;
4988
5005
  this.animationFrameId = null;
4989
- this.startTimerAt = new Date().getTime();
4990
5006
  this.startReadyPromise.then(() => {
5007
+ if (this.localData["_t_g_" + this.elementId + "st_at"] != null) {
5008
+ this.startTimerAt = this.localData["_t_g_" + this.elementId + "st_at"];
5009
+ this.startTimerAt *= 1000;
5010
+ }
5011
+ if (this.startTimerAt == null) {
5012
+ this.startTimerAt = new Date().getTime();
5013
+ this.localData["_t_g_" + this.elementId + "st_at"] = Math.round(this.startTimerAt / 1000);
5014
+ this.setLocalData(this.localData, false);
5015
+ }
4991
5016
  this.tick();
4992
5017
  });
4993
- // set answer - unanswered (for close and run again)
4994
- this.localData["_t_g_" + this.elementId + "_sa"] = -1;
4995
- this.setLocalData(this.localData, true);
4996
5018
  }
4997
5019
  else {
4998
5020
  // animate 100%
@@ -5007,16 +5029,21 @@ class WidgetTest extends WidgetBase {
5007
5029
  }
5008
5030
  }
5009
5031
  }
5032
+ this.isWidgetTimerInit = true;
5010
5033
  }
5011
5034
  }
5012
5035
  onStart() {
5013
5036
  super.onStart();
5037
+ if (this.slideTestWithTimer()) {
5038
+ this.initWidgetTimer();
5039
+ }
5014
5040
  }
5015
5041
  onStop() {
5016
5042
  super.onStop();
5017
5043
  if (this.slideTestWithTimer()) {
5018
5044
  this.cancelTick();
5019
5045
  }
5046
+ this.isWidgetTimerInit = false;
5020
5047
  }
5021
5048
  _statEventVoteAnswer(answerScore) {
5022
5049
  try {
@@ -5233,7 +5260,7 @@ class WidgetVote extends WidgetBase {
5233
5260
  if (Array.isArray(value)) {
5234
5261
  index = value[0];
5235
5262
  }
5236
- this._checkVariant(index);
5263
+ this.variants[index]?.classList.add("checked");
5237
5264
  this._selectVariant(index, true);
5238
5265
  if (!this.hideClientTotalResult) {
5239
5266
  this.displayPercents([index], true);
@@ -5250,7 +5277,7 @@ class WidgetVote extends WidgetBase {
5250
5277
  }
5251
5278
  for (let i = 0; i < values.length; ++i) {
5252
5279
  const index = values[i];
5253
- this._checkVariant(index);
5280
+ this.variants[index]?.classList.add("checked");
5254
5281
  this._selectVariant(index, true);
5255
5282
  }
5256
5283
  if (!this.hideClientTotalResult) {
@@ -16005,7 +16032,7 @@ class WidgetProducts extends WidgetBase {
16005
16032
  ...this.statisticEventBaseFieldsShortForm,
16006
16033
  wi: this.elementId,
16007
16034
  wl: captionViewText,
16008
- wv: this.linkTarget,
16035
+ wv: JSON.stringify(this.linkTarget),
16009
16036
  }, {
16010
16037
  ...this.statisticEventBaseFieldsShortForm,
16011
16038
  widget_id: this.elementId,
@@ -16026,8 +16053,8 @@ class WidgetProducts extends WidgetBase {
16026
16053
  ...this.statisticEventBaseFieldsShortForm,
16027
16054
  wi: this.elementId,
16028
16055
  wl: captionViewText,
16029
- wv: this.linkTarget,
16030
- wit: offers.map(item => item.offerId),
16056
+ wv: JSON.stringify(this.linkTarget),
16057
+ wit: JSON.stringify(offers.map(item => item.offerId)),
16031
16058
  }, {
16032
16059
  ...this.statisticEventBaseFieldsShortForm,
16033
16060
  widget_id: this.elementId,
@@ -16244,14 +16271,15 @@ class WidgetProducts extends WidgetBase {
16244
16271
  const figure = document.createElement("div");
16245
16272
  figure.classList.add("ias-products-card-figure");
16246
16273
  if (offer.coverUrl) {
16247
- // todo preload coverImage by fetch, save to offer.coverUrl via createUrl (add revoke)
16248
- // if cannot fetch - skip caching
16249
16274
  const image = document.createElement("img");
16250
16275
  image.classList.add("ias-products-card-figure-image");
16251
16276
  image.alt = offer.name ?? "";
16252
16277
  image.src = offer.coverUrl;
16253
16278
  figure.appendChild(image);
16254
16279
  }
16280
+ const imageMask = document.createElement("div");
16281
+ imageMask.classList.add("ias-products-card-figure-image-mask");
16282
+ figure.appendChild(imageMask);
16255
16283
  // const subTitle = document.createElement("div");
16256
16284
  // subTitle.classList.add("ias-products-card-subtitle");
16257
16285
  // subTitle.innerText = offer.description ?? "";
@@ -16362,8 +16390,10 @@ class WidgetProducts extends WidgetBase {
16362
16390
  e.stopPropagation();
16363
16391
  onClose();
16364
16392
  };
16393
+ const divider = document.createElement("div");
16365
16394
  backgroundView.appendChild(scrollView);
16366
16395
  backgroundView.appendChild(closeButton);
16396
+ backgroundView.appendChild(divider);
16367
16397
  containerView.appendChild(backdropView);
16368
16398
  containerView.appendChild(backgroundView);
16369
16399
  return containerView;