@inappstory/slide-api 0.0.20 → 0.0.21

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.cjs CHANGED
@@ -1254,6 +1254,10 @@ class WidgetBase {
1254
1254
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
1255
1255
  ++WidgetBase.widgetIndex;
1256
1256
  }
1257
+ /**
1258
+ * Start or restart widget
1259
+ * @param localData
1260
+ */
1257
1261
  onRefreshUserData(localData) { }
1258
1262
  static widgetCacheKey = "ias.story-element";
1259
1263
  static widgetClassName = "";
@@ -1284,19 +1288,23 @@ class WidgetBase {
1284
1288
  }
1285
1289
  static initWidget(htmlElement, localData, instantiate) {
1286
1290
  if (localData != null) {
1287
- this.createInstance(instantiate, htmlElement, {
1291
+ const widget = this.createInstance(instantiate, htmlElement, {
1288
1292
  slide: null,
1289
1293
  localData,
1290
1294
  });
1295
+ // start widget (just created or cached instance)
1296
+ widget.onRefreshUserData(localData);
1291
1297
  return Promise.resolve(localData);
1292
1298
  }
1293
1299
  else {
1294
1300
  return new Promise(resolve => {
1295
1301
  this.getLocalData().then(localData => {
1296
- this.createInstance(instantiate, htmlElement, {
1302
+ const widget = this.createInstance(instantiate, htmlElement, {
1297
1303
  slide: null,
1298
1304
  localData,
1299
1305
  });
1306
+ // start widget (just created or cached instance)
1307
+ widget.onRefreshUserData(localData);
1300
1308
  resolve(localData);
1301
1309
  });
1302
1310
  });
@@ -1306,10 +1314,12 @@ class WidgetBase {
1306
1314
  static initWidgets(instantiate, elements, localData) {
1307
1315
  if (localData != null) {
1308
1316
  forEach(elements, element => {
1309
- this.createInstance(instantiate, element, {
1317
+ const widget = this.createInstance(instantiate, element, {
1310
1318
  slide: null,
1311
1319
  localData,
1312
1320
  });
1321
+ // start widget (just created or cached instance)
1322
+ widget.onRefreshUserData(localData);
1313
1323
  });
1314
1324
  return Promise.resolve(localData);
1315
1325
  }
@@ -1317,10 +1327,12 @@ class WidgetBase {
1317
1327
  return new Promise(resolve => {
1318
1328
  this.getLocalData().then(localData => {
1319
1329
  forEach(elements, element => {
1320
- this.createInstance(instantiate, element, {
1330
+ const widget = this.createInstance(instantiate, element, {
1321
1331
  slide: null,
1322
1332
  localData,
1323
1333
  });
1334
+ // start widget (just created or cached instance)
1335
+ widget.onRefreshUserData(localData);
1324
1336
  });
1325
1337
  resolve(localData);
1326
1338
  });
@@ -1509,7 +1521,6 @@ class WidgetCopy extends WidgetBase {
1509
1521
  this.button = this.element.querySelector(".narrative-element-text-lines");
1510
1522
  this.clipboardTarget = getTagData(element, "clipboardTarget");
1511
1523
  this.isPromotionalCode = getTagData(element, "clipboardType") === "promocode";
1512
- this.state = null;
1513
1524
  this.msgNetworkError = getTagData(this.element, "msgNetworkError");
1514
1525
  this.msgServiceError = getTagData(this.element, "msgServiceError");
1515
1526
  this.msgNoMoreCodes = getTagData(this.element, "msgNoMoreCodes");
@@ -1538,12 +1549,19 @@ class WidgetCopy extends WidgetBase {
1538
1549
  this.resultLayerGeometry.style.setProperty("left", newResultLayerGeometryLeft + "px");
1539
1550
  }
1540
1551
  }
1552
+ }
1553
+ /**
1554
+ * Start or restart widget
1555
+ * @param localData
1556
+ */
1557
+ onRefreshUserData(localData) {
1558
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
1559
+ this.localData = extend({}, this.savedData ?? {}, localData);
1560
+ this.state = null;
1541
1561
  if (this.isPromotionalCode) {
1542
1562
  this.fetchPromoCode();
1543
1563
  }
1544
- // this.onRefreshUserData(this.options.localData);
1545
1564
  }
1546
- onRefreshUserData(localData) { }
1547
1565
  isTransparentElement() {
1548
1566
  if (this.element) {
1549
1567
  try {
@@ -1748,8 +1766,11 @@ class WidgetDataInput extends WidgetBase {
1748
1766
  this.inputElement = getValueOrException(this.element.querySelector(".input-view .input"), "Empty .input-view .input");
1749
1767
  this.textElement = getValueOrException(this.inputElement.querySelector(".narrative-element-text-lines"), "Empty .narrative-element-text-lines");
1750
1768
  this.inputPlaceholderValue = this.textElement.innerHTML;
1751
- this.onRefreshUserData(this.options.localData);
1752
1769
  }
1770
+ /**
1771
+ * Start or restart widget
1772
+ * @param localData
1773
+ */
1753
1774
  onRefreshUserData(localData) {
1754
1775
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
1755
1776
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -1922,7 +1943,7 @@ class WidgetDateCountdown extends WidgetBase {
1922
1943
  messages;
1923
1944
  timestampSeconds;
1924
1945
  diff;
1925
- timerInited;
1946
+ timerInit;
1926
1947
  pendingUpdate;
1927
1948
  firstGroup1;
1928
1949
  firstGroup2;
@@ -1944,7 +1965,7 @@ class WidgetDateCountdown extends WidgetBase {
1944
1965
  };
1945
1966
  this.timestampSeconds = getValueOrException(getTagDataAsNumber(this.element, "timestampSeconds"), "Empty timestampSeconds");
1946
1967
  this.diff = 0;
1947
- this.timerInited = false;
1968
+ this.timerInit = false;
1948
1969
  this.pendingUpdate = true;
1949
1970
  this.layers = this.options.layers;
1950
1971
  // if (false) {
@@ -1973,16 +1994,22 @@ class WidgetDateCountdown extends WidgetBase {
1973
1994
  // } else {
1974
1995
  this.initTimer();
1975
1996
  // }
1976
- // this.onRefreshUserData(this.options.localData);
1977
1997
  }
1978
- onRefreshUserData(localData) { }
1998
+ /**
1999
+ * Start or restart widget
2000
+ * @param localData
2001
+ */
2002
+ onRefreshUserData(localData) {
2003
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
2004
+ this.localData = extend({}, this.savedData ?? {}, localData);
2005
+ }
1979
2006
  pause() {
1980
- if (this.timerInited) {
2007
+ if (this.timerInit) {
1981
2008
  this.pendingUpdate = false;
1982
2009
  }
1983
2010
  }
1984
2011
  resume() {
1985
- if (this.timerInited) {
2012
+ if (this.timerInit) {
1986
2013
  this.pendingUpdate = true;
1987
2014
  this.updateTimer();
1988
2015
  }
@@ -1999,7 +2026,7 @@ class WidgetDateCountdown extends WidgetBase {
1999
2026
  this.thirdGroup2 = getValueOrException(this.element.querySelector(".date-item-view-group-3 .date-output-label-2"), "Empty thirdGroup2");
2000
2027
  this.thirdGroupCaption = getValueOrException(this.element.querySelector(".date-item-view-group-3 .date-item-caption"), "Empty thirdGroupCaption");
2001
2028
  this.timestampSeconds *= 1000;
2002
- this.timerInited = true;
2029
+ this.timerInit = true;
2003
2030
  const value = this.timestampSeconds - (new Date().getTime() - this.diff);
2004
2031
  if (value > 0) {
2005
2032
  this._showLayout(this.layers, 0);
@@ -2312,8 +2339,11 @@ class WidgetPoll extends WidgetBase {
2312
2339
  this.getUseResponseOnFirstButton = Boolean(getTagDataAsNumber(this.element, "getUserResponseOnFirstButton"));
2313
2340
  this.getUseResponseOnSecondButton = Boolean(getTagDataAsNumber(this.element, "getUserResponseOnSecondButton"));
2314
2341
  this.showClientTotalResult = Boolean(getTagDataAsNumber(this.element, "showClientTotalResult"));
2315
- this.onRefreshUserData(this.options.localData);
2316
2342
  }
2343
+ /**
2344
+ * Start or restart widget
2345
+ * @param localData
2346
+ */
2317
2347
  onRefreshUserData(localData) {
2318
2348
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
2319
2349
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -2821,6 +2851,14 @@ class WidgetPollLayers extends WidgetBase {
2821
2851
  this.variantsTexts.push(label.textContent ?? "");
2822
2852
  }
2823
2853
  });
2854
+ }
2855
+ /**
2856
+ * Start or restart widget
2857
+ * @param localData
2858
+ */
2859
+ onRefreshUserData(localData) {
2860
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
2861
+ this.localData = extend({}, this.savedData ?? {}, localData);
2824
2862
  this.selectedVariant = undefined;
2825
2863
  if (this.slidePollIsDone()) {
2826
2864
  this._selectVariant(this.localData["_pl_g_" + this.elementId + "_sa"]);
@@ -2829,9 +2867,7 @@ class WidgetPollLayers extends WidgetBase {
2829
2867
  this._showLayout(this.layers, 0);
2830
2868
  }
2831
2869
  this.firstOpenTime = new Date().getTime();
2832
- this.onRefreshUserData(this.options.localData);
2833
2870
  }
2834
- onRefreshUserData(localData) { }
2835
2871
  _statEventPollVariant() {
2836
2872
  try {
2837
2873
  if (this.selectedVariant != null) {
@@ -2981,9 +3017,15 @@ class WidgetQuest extends WidgetBase {
2981
3017
  this.label = this.element.querySelector(".label-view .label");
2982
3018
  this.variants = slice.call(this.element.querySelectorAll(".variants-box .variant-view"));
2983
3019
  this.selectedAnswer = undefined;
2984
- // this.onRefreshUserData(this.options.localData);
2985
3020
  }
2986
- onRefreshUserData(localData) { }
3021
+ /**
3022
+ * Start or restart widget
3023
+ * @param localData
3024
+ */
3025
+ onRefreshUserData(localData) {
3026
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
3027
+ this.localData = extend({}, this.savedData ?? {}, localData);
3028
+ }
2987
3029
  setCardSessionValue(name, value) {
2988
3030
  this.sdkApi.setCardSessionValue(this.element, name, value);
2989
3031
  }
@@ -3223,6 +3265,7 @@ class WidgetQuest extends WidgetBase {
3223
3265
  });
3224
3266
  });
3225
3267
  },
3268
+ /** @deprecated */
3226
3269
  initWidget: function (element, localData) {
3227
3270
  return new Promise(function (resolve, reject) {
3228
3271
  WidgetQuest.initWidgets((element, options) => new WidgetQuest(element, options), [element], localData).then(localData => {
@@ -3280,8 +3323,11 @@ class WidgetQuiz extends WidgetBase {
3280
3323
  this.question = this.element.querySelector(".label-view .label");
3281
3324
  this.answers = slice.call(this.element.querySelectorAll(".variants-box .variant-view-group"));
3282
3325
  this.questionCount = getValueOrException(getTagDataAsNumber(this.slide, "quizCount"), "Empty quizCount");
3283
- this.onRefreshUserData(this.options.localData);
3284
3326
  }
3327
+ /**
3328
+ * Start or restart widget
3329
+ * @param localData
3330
+ */
3285
3331
  onRefreshUserData(localData) {
3286
3332
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
3287
3333
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -3475,8 +3521,11 @@ class WidgetQuizGrouped extends WidgetBase {
3475
3521
  this.question = this.element.querySelector(".label-view .label");
3476
3522
  this.answers = slice.call(this.element.querySelectorAll(".variants-box .variant-view-group"));
3477
3523
  this.questionCount = getValueOrException(getTagDataAsNumber(this.slide, "quizCount"), "Empty quizCount");
3478
- this.onRefreshUserData(this.options.localData);
3479
3524
  }
3525
+ /**
3526
+ * Start or restart widget
3527
+ * @param localData
3528
+ */
3480
3529
  onRefreshUserData(localData) {
3481
3530
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
3482
3531
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -3857,7 +3906,6 @@ class WidgetRangeSlider extends WidgetBase {
3857
3906
  this.handleDown = proxy(this.handleDown, this);
3858
3907
  this.handleMove = proxy(this.handleMove, this);
3859
3908
  this.handleEnd = proxy(this.handleEnd, this);
3860
- this.onRefreshUserData(this.options.localData);
3861
3909
  // Attach Events
3862
3910
  // window.addEventListener('resize.' + this.identifier, debounce(function() {
3863
3911
  // // Simulate resizeEnd event.
@@ -3868,6 +3916,10 @@ class WidgetRangeSlider extends WidgetBase {
3868
3916
  this.env.document.addEventListener("touchstart", this.handleDown);
3869
3917
  this.env.document.addEventListener("mousedown", this.handleDown);
3870
3918
  }
3919
+ /**
3920
+ * Start or restart widget
3921
+ * @param localData
3922
+ */
3871
3923
  onRefreshUserData(localData) {
3872
3924
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
3873
3925
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -4296,8 +4348,11 @@ class WidgetRate extends WidgetBase {
4296
4348
  this.showDialogOnLowRate = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "showDialogOnLowRate"), 0));
4297
4349
  this.showDialogueMin = getValueOrDefault(getTagDataAsNumber(this.element, "showDialogueMin"), 1);
4298
4350
  this.showDialogueMax = getValueOrDefault(getTagDataAsNumber(this.element, "showDialogueMax"), 3);
4299
- this.onRefreshUserData(this.options.localData);
4300
4351
  }
4352
+ /**
4353
+ * Start or restart widget
4354
+ * @param localData
4355
+ */
4301
4356
  onRefreshUserData(localData) {
4302
4357
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
4303
4358
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -4539,6 +4594,14 @@ class WidgetShare extends WidgetBase {
4539
4594
  this.shareTarget = getTagData(this.element, "shareTarget");
4540
4595
  this.layers = this.options.layers;
4541
4596
  this.withLayer = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "withLayer"), 0));
4597
+ }
4598
+ /**
4599
+ * Start or restart widget
4600
+ * @param localData
4601
+ */
4602
+ onRefreshUserData(localData) {
4603
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
4604
+ this.localData = extend({}, this.savedData ?? {}, localData);
4542
4605
  if (this.withLayer) {
4543
4606
  if (this.isDone()) {
4544
4607
  this._showLayout(this.layers, 1);
@@ -4551,9 +4614,7 @@ class WidgetShare extends WidgetBase {
4551
4614
  this.startDisabledTimeline();
4552
4615
  }
4553
4616
  this.btnDisabled = false;
4554
- // this.onRefreshUserData(this.options.localData);
4555
4617
  }
4556
- onRefreshUserData(localData) { }
4557
4618
  _statEventShare(result, via) {
4558
4619
  try {
4559
4620
  const buttonText = this.element.textContent ?? "";
@@ -4682,18 +4743,6 @@ class WidgetTest extends WidgetBase {
4682
4743
  this.testCount = getValueOrException(getTagDataAsNumber(this.slide, "testCount"), "Empty testCount");
4683
4744
  this.withTimeToAnswer = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "withTimeToAnswer"), 0));
4684
4745
  this.answerTimeout = getValueOrDefault(getTagDataAsNumber(this.element, "answerTimeout"), 0);
4685
- this.selectedAnswer = undefined;
4686
- if (this.localData) {
4687
- if (this.localData["_t_g_" + this.elementId + "_sa"] !== undefined) {
4688
- this._selectAnswer(this.localData["_t_g_" + this.elementId + "_sa"]);
4689
- this.setLocalData(this.localData, false);
4690
- }
4691
- if (this.localData["_t_fo_at"] === undefined) {
4692
- this.localData["_t_fo_at"] = Math.round(new Date().getTime() / 1000);
4693
- this.setLocalData(this.localData, false);
4694
- }
4695
- }
4696
- this.firstOpenTime = new Date().getTime();
4697
4746
  this.tick = () => {
4698
4747
  this.animationFrameId = this.env.requestAnimationFrame(() => {
4699
4748
  this.tick();
@@ -4722,7 +4771,28 @@ class WidgetTest extends WidgetBase {
4722
4771
  this.env.cancelAnimationFrame(this.animationFrameId);
4723
4772
  }
4724
4773
  };
4774
+ }
4775
+ /**
4776
+ * Start or restart widget
4777
+ * @param localData
4778
+ */
4779
+ onRefreshUserData(localData) {
4780
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
4781
+ this.localData = extend({}, this.savedData ?? {}, localData);
4782
+ this.selectedAnswer = undefined;
4783
+ if (this.localData) {
4784
+ if (this.localData["_t_g_" + this.elementId + "_sa"] !== undefined) {
4785
+ this._selectAnswer(this.localData["_t_g_" + this.elementId + "_sa"]);
4786
+ this.setLocalData(this.localData, false);
4787
+ }
4788
+ if (this.localData["_t_fo_at"] === undefined) {
4789
+ this.localData["_t_fo_at"] = Math.round(new Date().getTime() / 1000);
4790
+ this.setLocalData(this.localData, false);
4791
+ }
4792
+ }
4793
+ this.firstOpenTime = new Date().getTime();
4725
4794
  if (this.slideTestWithTimer()) {
4795
+ this.cancelTick();
4726
4796
  this.timeline = this.element.querySelector(".timeline");
4727
4797
  if (this.selectedAnswer === undefined) {
4728
4798
  // find timer element
@@ -4751,9 +4821,7 @@ class WidgetTest extends WidgetBase {
4751
4821
  }
4752
4822
  }
4753
4823
  }
4754
- // this.onRefreshUserData(this.options.localData);
4755
4824
  }
4756
- onRefreshUserData(localData) { }
4757
4825
  _statEventVoteAnswer(answerScore) {
4758
4826
  try {
4759
4827
  if (this.selectedAnswer != null) {
@@ -4952,7 +5020,6 @@ class WidgetVote extends WidgetBase {
4952
5020
  });
4953
5021
  this.hideClientTotalResult = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "hideClientTotalResult")), false);
4954
5022
  this.multipleChoice = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "multipleChoice")), false);
4955
- this.onRefreshUserData(this.options.localData);
4956
5023
  }
4957
5024
  _initFromLocalData() {
4958
5025
  const value = this.localData["_v_g_" + this.elementId + "_sa"];
@@ -4987,6 +5054,10 @@ class WidgetVote extends WidgetBase {
4987
5054
  this._fillWidget(true);
4988
5055
  }
4989
5056
  }
5057
+ /**
5058
+ * Start or restart widget
5059
+ * @param localData
5060
+ */
4990
5061
  onRefreshUserData(localData) {
4991
5062
  this.savedData = this.sdkApi.getCardServerData(this.cardId);
4992
5063
  this.localData = extend({}, this.savedData ?? {}, localData);
@@ -14769,12 +14840,20 @@ class WidgetBarcode extends WidgetBase {
14769
14840
  this.formatterType = getTagData(element, "formatterType");
14770
14841
  this.copiedText = getTagData(element, "copiedText");
14771
14842
  this.svgView = this.element.querySelector(".barcode-view-inner");
14772
- this.state = null;
14773
14843
  this.msgNetworkError = getTagData(this.element, "msgNetworkError");
14774
14844
  this.msgServiceError = getTagData(this.element, "msgServiceError");
14775
14845
  this.msgNoMoreCodes = getTagData(this.element, "msgNoMoreCodes");
14776
14846
  this.msgTryAgain = getTagData(this.element, "msgTryAgain");
14777
14847
  this.msgBarcodeRenderError = getTagData(this.element, "msgBarcodeRenderError");
14848
+ }
14849
+ /**
14850
+ * Start or restart widget
14851
+ * @param localData
14852
+ */
14853
+ onRefreshUserData(localData) {
14854
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
14855
+ this.localData = extend({}, this.savedData ?? {}, localData);
14856
+ this.state = null;
14778
14857
  if (this.isPromotionalCode) {
14779
14858
  this.fetchPromoCode();
14780
14859
  }
@@ -14782,9 +14861,7 @@ class WidgetBarcode extends WidgetBase {
14782
14861
  this.renderCodeView();
14783
14862
  this.renderCaptionView();
14784
14863
  }
14785
- // this.onRefreshUserData(this.options.localData);
14786
14864
  }
14787
- onRefreshUserData(localData) { }
14788
14865
  isTransparentElement() {
14789
14866
  if (this.element) {
14790
14867
  try {