@inappstory/slide-api 0.0.20 → 0.0.22

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.js CHANGED
@@ -1200,6 +1200,8 @@ class WidgetBase {
1200
1200
  localData = null;
1201
1201
  firstOpenTime = 0;
1202
1202
  id;
1203
+ startReadyPromise = null;
1204
+ startReadyResolve = null;
1203
1205
  constructor(element, options, elementIdGetter, slideGetter) {
1204
1206
  this.options = extend({}, this.constructor.DEFAULTS, options);
1205
1207
  this.element = element;
@@ -1251,8 +1253,32 @@ class WidgetBase {
1251
1253
  this.localData = extend({}, this.savedData ?? {}, this.options.localData ?? {});
1252
1254
  this.id = `w_${this.elementId}_${WidgetBase.widgetIndex}`;
1253
1255
  ++WidgetBase.widgetIndex;
1256
+ this.resetStartReadyPromise();
1254
1257
  }
1255
- onRefreshUserData(localData) { }
1258
+ resetStartReadyPromise() {
1259
+ this.startReadyPromise = new Promise(resolve => {
1260
+ this.startReadyResolve = resolve;
1261
+ });
1262
+ }
1263
+ /**
1264
+ * Start or restart widget
1265
+ * @param localData
1266
+ */
1267
+ onRefreshUserData(localData) {
1268
+ this.savedData = this.sdkApi.getCardServerData(this.cardId);
1269
+ this.localData = extend({}, this.savedData ?? {}, localData);
1270
+ }
1271
+ onStart() {
1272
+ // add active class for enable animation
1273
+ this.element.classList.add("active");
1274
+ this.startReadyResolve();
1275
+ }
1276
+ onStop() {
1277
+ this.element.classList.remove("active");
1278
+ this.resetStartReadyPromise();
1279
+ }
1280
+ onPause() { }
1281
+ onResume() { }
1256
1282
  static widgetCacheKey = "ias.story-element";
1257
1283
  static widgetClassName = "";
1258
1284
  static getInstance(element) {
@@ -1282,19 +1308,23 @@ class WidgetBase {
1282
1308
  }
1283
1309
  static initWidget(htmlElement, localData, instantiate) {
1284
1310
  if (localData != null) {
1285
- this.createInstance(instantiate, htmlElement, {
1311
+ const widget = this.createInstance(instantiate, htmlElement, {
1286
1312
  slide: null,
1287
1313
  localData,
1288
1314
  });
1315
+ // start widget (just created or cached instance)
1316
+ widget.onRefreshUserData(localData);
1289
1317
  return Promise.resolve(localData);
1290
1318
  }
1291
1319
  else {
1292
1320
  return new Promise(resolve => {
1293
1321
  this.getLocalData().then(localData => {
1294
- this.createInstance(instantiate, htmlElement, {
1322
+ const widget = this.createInstance(instantiate, htmlElement, {
1295
1323
  slide: null,
1296
1324
  localData,
1297
1325
  });
1326
+ // start widget (just created or cached instance)
1327
+ widget.onRefreshUserData(localData);
1298
1328
  resolve(localData);
1299
1329
  });
1300
1330
  });
@@ -1304,10 +1334,12 @@ class WidgetBase {
1304
1334
  static initWidgets(instantiate, elements, localData) {
1305
1335
  if (localData != null) {
1306
1336
  forEach(elements, element => {
1307
- this.createInstance(instantiate, element, {
1337
+ const widget = this.createInstance(instantiate, element, {
1308
1338
  slide: null,
1309
1339
  localData,
1310
1340
  });
1341
+ // start widget (just created or cached instance)
1342
+ widget.onRefreshUserData(localData);
1311
1343
  });
1312
1344
  return Promise.resolve(localData);
1313
1345
  }
@@ -1315,10 +1347,12 @@ class WidgetBase {
1315
1347
  return new Promise(resolve => {
1316
1348
  this.getLocalData().then(localData => {
1317
1349
  forEach(elements, element => {
1318
- this.createInstance(instantiate, element, {
1350
+ const widget = this.createInstance(instantiate, element, {
1319
1351
  slide: null,
1320
1352
  localData,
1321
1353
  });
1354
+ // start widget (just created or cached instance)
1355
+ widget.onRefreshUserData(localData);
1322
1356
  });
1323
1357
  resolve(localData);
1324
1358
  });
@@ -1398,7 +1432,7 @@ class WidgetBase {
1398
1432
  startDisabledTimeline() {
1399
1433
  this.sdkApi.startDisabledTimeline(this.cardId, this.slideIndex);
1400
1434
  }
1401
- _showLayout(layers, selectIndex, withStatEvent = false) {
1435
+ _showLayer(layers, selectIndex, withStatEvent = false) {
1402
1436
  if (this.sdkApi.isExistsShowLayer()) {
1403
1437
  this.sdkApi.showLayer(selectIndex);
1404
1438
  }
@@ -1507,7 +1541,6 @@ class WidgetCopy extends WidgetBase {
1507
1541
  this.button = this.element.querySelector(".narrative-element-text-lines");
1508
1542
  this.clipboardTarget = getTagData(element, "clipboardTarget");
1509
1543
  this.isPromotionalCode = getTagData(element, "clipboardType") === "promocode";
1510
- this.state = null;
1511
1544
  this.msgNetworkError = getTagData(this.element, "msgNetworkError");
1512
1545
  this.msgServiceError = getTagData(this.element, "msgServiceError");
1513
1546
  this.msgNoMoreCodes = getTagData(this.element, "msgNoMoreCodes");
@@ -1536,12 +1569,31 @@ class WidgetCopy extends WidgetBase {
1536
1569
  this.resultLayerGeometry.style.setProperty("left", newResultLayerGeometryLeft + "px");
1537
1570
  }
1538
1571
  }
1572
+ }
1573
+ /**
1574
+ * Start or restart widget
1575
+ * @param localData
1576
+ */
1577
+ onRefreshUserData(localData) {
1578
+ super.onRefreshUserData(localData);
1579
+ // return DOM to init state (ready to copy)
1580
+ this.element.classList.remove("done");
1581
+ if (this.resultLayer) {
1582
+ this.resultLayer.classList.remove("done");
1583
+ }
1584
+ this.state = null;
1585
+ if (this.isPromotionalCode) {
1586
+ this.initPromotionalCodeFromLocalData();
1587
+ }
1588
+ }
1589
+ onStart() {
1590
+ super.onStart();
1591
+ // add active class for enable animation
1592
+ this.resultLayer?.classList.add("active");
1539
1593
  if (this.isPromotionalCode) {
1540
1594
  this.fetchPromoCode();
1541
1595
  }
1542
- // this.onRefreshUserData(this.options.localData);
1543
1596
  }
1544
- onRefreshUserData(localData) { }
1545
1597
  isTransparentElement() {
1546
1598
  if (this.element) {
1547
1599
  try {
@@ -1561,16 +1613,22 @@ class WidgetCopy extends WidgetBase {
1561
1613
  this.button.textContent = newText;
1562
1614
  }
1563
1615
  }
1564
- fetchPromoCode() {
1565
- this.state = 0;
1566
- if (this.localData["_cp_g_" + this.elementId + "_pc"] !== undefined) {
1616
+ getPromotionalCodeFromLocalData() {
1617
+ return this.localData["_cp_g_" + this.elementId + "_pc"];
1618
+ }
1619
+ initPromotionalCodeFromLocalData() {
1620
+ if (this.getPromotionalCodeFromLocalData() !== undefined) {
1567
1621
  this.state = 1;
1568
- this.clipboardTarget = this.localData["_cp_g_" + this.elementId + "_pc"];
1622
+ this.clipboardTarget = this.getPromotionalCodeFromLocalData();
1569
1623
  if (this.clipboardTarget != null) {
1570
1624
  this.changeText(this.clipboardTarget);
1571
1625
  }
1572
1626
  removeClass(this.element, "loader");
1573
1627
  }
1628
+ }
1629
+ fetchPromoCode() {
1630
+ this.state = 0;
1631
+ this.initPromotionalCodeFromLocalData();
1574
1632
  if (this.state === 0) {
1575
1633
  if (!this.isTransparentElement()) {
1576
1634
  // for transparent element
@@ -1658,12 +1716,14 @@ class WidgetCopy extends WidgetBase {
1658
1716
  if (this.resultLayer) {
1659
1717
  this.resultLayer.classList.add("done");
1660
1718
  }
1661
- if (this.disableTimer) {
1662
- // флаг - что таймер уже стартанул (в layout или добавить объект sharedMemory)
1663
- // смотрим что прозрачный текст - тогда и лоадер прозрачный
1664
- // _log("_showNarrativeNextSlide: " + getSlideDuration(this.narrativeId, this.slideIndex), true);
1665
- this.startDisabledTimeline();
1666
- }
1719
+ this.startReadyPromise.then(() => {
1720
+ if (this.disableTimer) {
1721
+ // флаг - что таймер уже стартанул layout или добавить объект sharedMemory)
1722
+ // смотрим что прозрачный текст - тогда и лоадер прозрачный
1723
+ // _log("_showNarrativeNextSlide: " + getSlideDuration(this.narrativeId, this.slideIndex), true);
1724
+ this.startDisabledTimeline();
1725
+ }
1726
+ });
1667
1727
  }
1668
1728
  copyToClipboard(element) {
1669
1729
  this._select();
@@ -1697,6 +1757,13 @@ class WidgetCopy extends WidgetBase {
1697
1757
  // prevent initWidget for result layer
1698
1758
  const elements = slice.call(nodeList).filter(element => !element.classList.contains("narrative-element-copy-result-variant"));
1699
1759
  WidgetCopy.initWidgets((element, options) => new WidgetCopy(element, options), elements, localData);
1760
+ elements.forEach(element => WidgetCopy.getInstance(element)?.onStart());
1761
+ },
1762
+ onStart: function (element) {
1763
+ WidgetCopy.getInstance(element)?.onStart();
1764
+ },
1765
+ onStop: function (element) {
1766
+ WidgetCopy.getInstance(element)?.onStop();
1700
1767
  },
1701
1768
  click: function (element) {
1702
1769
  const widgetElement = element.closest(`.${WidgetCopy.widgetClassName}`);
@@ -1746,20 +1813,27 @@ class WidgetDataInput extends WidgetBase {
1746
1813
  this.inputElement = getValueOrException(this.element.querySelector(".input-view .input"), "Empty .input-view .input");
1747
1814
  this.textElement = getValueOrException(this.inputElement.querySelector(".narrative-element-text-lines"), "Empty .narrative-element-text-lines");
1748
1815
  this.inputPlaceholderValue = this.textElement.innerHTML;
1749
- this.onRefreshUserData(this.options.localData);
1750
1816
  }
1817
+ /**
1818
+ * Start or restart widget
1819
+ * @param localData
1820
+ */
1751
1821
  onRefreshUserData(localData) {
1752
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
1753
- this.localData = extend({}, this.savedData ?? {}, localData);
1754
- const text = this.localData["_di_g_" + this.elementId + "_t"];
1822
+ super.onRefreshUserData(localData);
1823
+ const text = this.getTextFromLocalData();
1755
1824
  this._fillUserText(text);
1756
- if (text) {
1825
+ if (text != null) {
1757
1826
  this.element.classList.add("done");
1758
- if (this.disableTimer) {
1759
- this.startDisabledTimeline();
1760
- }
1827
+ this.startReadyPromise.then(() => {
1828
+ if (this.disableTimer) {
1829
+ this.startDisabledTimeline();
1830
+ }
1831
+ });
1761
1832
  }
1762
1833
  }
1834
+ getTextFromLocalData() {
1835
+ return this.localData["_di_g_" + this.elementId + "_t"];
1836
+ }
1763
1837
  _statEventFocusIn() {
1764
1838
  try {
1765
1839
  const labelText = this.label ? this.label.textContent ?? "" : "";
@@ -1837,7 +1911,7 @@ class WidgetDataInput extends WidgetBase {
1837
1911
  }
1838
1912
  _fillUserText(text) {
1839
1913
  if (this.inputElement && this.textElement) {
1840
- if (text) {
1914
+ if (text != null) {
1841
1915
  this.inputElement.classList.remove("_is-placeholder");
1842
1916
  text = text.replace(new RegExp("\r?\n", "g"), "<br />");
1843
1917
  this.textElement.innerHTML = text;
@@ -1887,7 +1961,15 @@ class WidgetDataInput extends WidgetBase {
1887
1961
  },
1888
1962
  /** @deprecated */
1889
1963
  initWidget: function (nodeList, localData) {
1964
+ const elements = slice.call(nodeList);
1890
1965
  WidgetDataInput.initWidgets((element, options) => new WidgetDataInput(element, options), slice.call(nodeList), localData);
1966
+ elements.forEach(element => WidgetDataInput.getInstance(element)?.onStart());
1967
+ },
1968
+ onStart: function (element) {
1969
+ WidgetDataInput.getInstance(element)?.onStart();
1970
+ },
1971
+ onStop: function (element) {
1972
+ WidgetDataInput.getInstance(element)?.onStop();
1891
1973
  },
1892
1974
  click: function (element) {
1893
1975
  const widgetElement = element.closest(`.${WidgetDataInput.widgetClassName}`);
@@ -1918,9 +2000,9 @@ class WidgetDateCountdown extends WidgetBase {
1918
2000
  label;
1919
2001
  layers;
1920
2002
  messages;
1921
- timestampSeconds;
2003
+ timestampMs;
1922
2004
  diff;
1923
- timerInited;
2005
+ timerInit;
1924
2006
  pendingUpdate;
1925
2007
  firstGroup1;
1926
2008
  firstGroup2;
@@ -1940,52 +2022,56 @@ class WidgetDateCountdown extends WidgetBase {
1940
2022
  minutes: getTagData(this.element, "tMinutes") ?? "",
1941
2023
  seconds: getTagData(this.element, "tSeconds") ?? "",
1942
2024
  };
1943
- this.timestampSeconds = getValueOrException(getTagDataAsNumber(this.element, "timestampSeconds"), "Empty timestampSeconds");
2025
+ this.timestampMs = getValueOrException(getTagDataAsNumber(this.element, "timestampSeconds"), "Empty timestampSeconds") * 1000;
1944
2026
  this.diff = 0;
1945
- this.timerInited = false;
2027
+ this.timerInit = false;
1946
2028
  this.pendingUpdate = true;
1947
2029
  this.layers = this.options.layers;
1948
- // if (false) {
1949
- // // if (sendApiRequestSupported()) {
1950
- // // fetch project time
1951
- // var path = "story/" + this.storyId + "/widget/" + this.elementId + "/timestamp";
1952
- // var profileKey = "fetch-story-timestamp";
1953
- // this.sdkApi
1954
- // .sendApiRequest<{ timestamp: number }>(path, "GET", null, null, null, profileKey)
1955
- // .then(response => {
1956
- // var status = response.status;
1957
- // var timestamp = null;
1958
- // if (status === 200) {
1959
- // if (response.data) timestamp = response.data.timestamp;
1960
- // if (timestamp) {
1961
- // this.diff = new Date().getTime() - timestamp * 1000;
1962
- // }
1963
- // }
1964
- //
1965
- // this.initTimer();
1966
- // })
1967
- // .catch( (reason)=> {
1968
- // console.error(reason);
1969
- // this.initTimer();
1970
- // });
1971
- // } else {
1972
- this.initTimer();
1973
- // }
1974
- // this.onRefreshUserData(this.options.localData);
1975
2030
  }
1976
- onRefreshUserData(localData) { }
1977
- pause() {
1978
- if (this.timerInited) {
2031
+ /**
2032
+ * Start or restart widget
2033
+ * @param localData
2034
+ */
2035
+ onRefreshUserData(localData) {
2036
+ super.onRefreshUserData(localData);
2037
+ const value = this.timestampMs - (new Date().getTime() - this.diff);
2038
+ if (value > 0) {
2039
+ this._showLayer(this.layers, 0);
2040
+ }
2041
+ else {
2042
+ this._showLayer(this.layers, 1);
2043
+ }
2044
+ }
2045
+ onPause() {
2046
+ super.onPause();
2047
+ if (this.timerInit) {
1979
2048
  this.pendingUpdate = false;
1980
2049
  }
1981
2050
  }
1982
- resume() {
1983
- if (this.timerInited) {
2051
+ onResume() {
2052
+ super.onResume();
2053
+ if (this.timerInit && !this.pendingUpdate) {
1984
2054
  this.pendingUpdate = true;
1985
2055
  this.updateTimer();
1986
2056
  }
1987
2057
  }
2058
+ onStart() {
2059
+ super.onStart();
2060
+ if (!this.timerInit) {
2061
+ this.initTimer();
2062
+ }
2063
+ }
2064
+ onStop() {
2065
+ super.onStop();
2066
+ if (this.timerInit) {
2067
+ this.pendingUpdate = false;
2068
+ this.timerInit = false;
2069
+ }
2070
+ }
1988
2071
  initTimer() {
2072
+ if (this.timerInit) {
2073
+ return;
2074
+ }
1989
2075
  // find groups
1990
2076
  this.firstGroup1 = getValueOrException(this.element.querySelector(".date-item-view-group-1 .date-output-label-1"), "Empty firstGroup1");
1991
2077
  this.firstGroup2 = getValueOrException(this.element.querySelector(".date-item-view-group-1 .date-output-label-2"), "Empty firstGroup2");
@@ -1996,16 +2082,18 @@ class WidgetDateCountdown extends WidgetBase {
1996
2082
  this.thirdGroup1 = getValueOrException(this.element.querySelector(".date-item-view-group-3 .date-output-label-1"), "Empty thirdGroup1");
1997
2083
  this.thirdGroup2 = getValueOrException(this.element.querySelector(".date-item-view-group-3 .date-output-label-2"), "Empty thirdGroup2");
1998
2084
  this.thirdGroupCaption = getValueOrException(this.element.querySelector(".date-item-view-group-3 .date-item-caption"), "Empty thirdGroupCaption");
1999
- this.timestampSeconds *= 1000;
2000
- this.timerInited = true;
2001
- const value = this.timestampSeconds - (new Date().getTime() - this.diff);
2085
+ this.timerInit = true;
2086
+ const value = this.timestampMs - (new Date().getTime() - this.diff);
2002
2087
  if (value > 0) {
2003
- this._showLayout(this.layers, 0);
2088
+ this._showLayer(this.layers, 0);
2004
2089
  }
2005
2090
  this.updateTimer();
2006
2091
  }
2007
2092
  updateTimer() {
2008
- const value = this.timestampSeconds - (new Date().getTime() - this.diff);
2093
+ if (!this.timerInit) {
2094
+ return;
2095
+ }
2096
+ const value = this.timestampMs - (new Date().getTime() - this.diff);
2009
2097
  if (value > 0) {
2010
2098
  const result = this._asDuration(Math.round(value / 1000));
2011
2099
  if (result.days) {
@@ -2034,7 +2122,7 @@ class WidgetDateCountdown extends WidgetBase {
2034
2122
  }
2035
2123
  else {
2036
2124
  this.pendingUpdate = false;
2037
- this._showLayout(this.layers, 1);
2125
+ this._showLayer(this.layers, 1);
2038
2126
  }
2039
2127
  if (this.pendingUpdate) {
2040
2128
  this.env.requestAnimationFrame(() => this.updateTimer());
@@ -2107,24 +2195,32 @@ class WidgetDateCountdown extends WidgetBase {
2107
2195
  },
2108
2196
  /** @deprecated */
2109
2197
  initWidget: function (nodeList, layers, localData) {
2110
- WidgetDateCountdown.initWidgets((element, options) => new WidgetDateCountdown(element, { ...options, layers }), slice.call(nodeList), localData);
2198
+ const elements = slice.call(nodeList);
2199
+ WidgetDateCountdown.initWidgets((element, options) => new WidgetDateCountdown(element, { ...options, layers }), elements, localData);
2200
+ elements.forEach(element => WidgetDateCountdown.getInstance(element)?.onStart());
2201
+ },
2202
+ onStart: function (element) {
2203
+ WidgetDateCountdown.getInstance(element)?.onStart();
2204
+ },
2205
+ onStop: function (element) {
2206
+ WidgetDateCountdown.getInstance(element)?.onStop();
2111
2207
  },
2112
2208
  onPause: function (element) {
2113
- WidgetDateCountdown.getInstance(element)?.pause();
2209
+ WidgetDateCountdown.getInstance(element)?.onPause();
2114
2210
  },
2115
2211
  onResume: function (element) {
2116
- WidgetDateCountdown.getInstance(element)?.resume();
2212
+ WidgetDateCountdown.getInstance(element)?.onResume();
2117
2213
  },
2118
2214
  /** @deprecated */
2119
2215
  pause: function (nodeList) {
2120
2216
  forEach(slice.call(nodeList), function (el, index) {
2121
- WidgetDateCountdown.getInstance(el)?.pause();
2217
+ WidgetDateCountdown.getInstance(el)?.onPause();
2122
2218
  });
2123
2219
  },
2124
2220
  /** @deprecated */
2125
2221
  resume: function (nodeList) {
2126
2222
  forEach(slice.call(nodeList), function (el, index) {
2127
- WidgetDateCountdown.getInstance(el)?.resume();
2223
+ WidgetDateCountdown.getInstance(el)?.onResume();
2128
2224
  });
2129
2225
  },
2130
2226
  };
@@ -2310,11 +2406,13 @@ class WidgetPoll extends WidgetBase {
2310
2406
  this.getUseResponseOnFirstButton = Boolean(getTagDataAsNumber(this.element, "getUserResponseOnFirstButton"));
2311
2407
  this.getUseResponseOnSecondButton = Boolean(getTagDataAsNumber(this.element, "getUserResponseOnSecondButton"));
2312
2408
  this.showClientTotalResult = Boolean(getTagDataAsNumber(this.element, "showClientTotalResult"));
2313
- this.onRefreshUserData(this.options.localData);
2314
2409
  }
2410
+ /**
2411
+ * Start or restart widget
2412
+ * @param localData
2413
+ */
2315
2414
  onRefreshUserData(localData) {
2316
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
2317
- this.localData = extend({}, this.savedData ?? {}, localData);
2415
+ super.onRefreshUserData(localData);
2318
2416
  this.selectedVariant = undefined;
2319
2417
  if (this.localData) {
2320
2418
  if (this.localData["_p_g_" + this.elementId + "_sa"] !== undefined) {
@@ -2397,14 +2495,11 @@ class WidgetPoll extends WidgetBase {
2397
2495
  this.element.classList.add("with-total-result");
2398
2496
  this.displayPercents(index, filled);
2399
2497
  }
2400
- if (this.disableTimer) {
2401
- this.env.setTimeout(() => {
2402
- // todo poll - если виджет на первом слайде то при повторном заходе автоматически не стартует таймлайн слайда
2403
- // только в web sdk такое
2404
- // если поставить через setTimeout то все ок
2498
+ this.startReadyPromise.then(() => {
2499
+ if (this.disableTimer) {
2405
2500
  this.startDisabledTimeline();
2406
- });
2407
- }
2501
+ }
2502
+ });
2408
2503
  }
2409
2504
  _clearVariantSelection() {
2410
2505
  forEach(this.variants, function (variant) {
@@ -2751,6 +2846,13 @@ class WidgetPoll extends WidgetBase {
2751
2846
  /** @deprecated */
2752
2847
  initWidget: function (element, localData) {
2753
2848
  WidgetPoll.initWidgets((element, options) => new WidgetPoll(element, options), [element], localData);
2849
+ WidgetPoll.getInstance(element)?.onStart();
2850
+ },
2851
+ onStart: function (element) {
2852
+ WidgetPoll.getInstance(element)?.onStart();
2853
+ },
2854
+ onStop: function (element) {
2855
+ WidgetPoll.getInstance(element)?.onStop();
2754
2856
  },
2755
2857
  /**
2756
2858
  * click
@@ -2819,17 +2921,22 @@ class WidgetPollLayers extends WidgetBase {
2819
2921
  this.variantsTexts.push(label.textContent ?? "");
2820
2922
  }
2821
2923
  });
2924
+ }
2925
+ /**
2926
+ * Start or restart widget
2927
+ * @param localData
2928
+ */
2929
+ onRefreshUserData(localData) {
2930
+ super.onRefreshUserData(localData);
2822
2931
  this.selectedVariant = undefined;
2823
2932
  if (this.slidePollIsDone()) {
2824
2933
  this._selectVariant(this.localData["_pl_g_" + this.elementId + "_sa"]);
2825
2934
  }
2826
2935
  else {
2827
- this._showLayout(this.layers, 0);
2936
+ this._showLayer(this.layers, 0);
2828
2937
  }
2829
2938
  this.firstOpenTime = new Date().getTime();
2830
- this.onRefreshUserData(this.options.localData);
2831
2939
  }
2832
- onRefreshUserData(localData) { }
2833
2940
  _statEventPollVariant() {
2834
2941
  try {
2835
2942
  if (this.selectedVariant != null) {
@@ -2872,10 +2979,12 @@ class WidgetPollLayers extends WidgetBase {
2872
2979
  else if (index === 1) {
2873
2980
  layerIndex = 2;
2874
2981
  }
2875
- this._showLayout(this.layers, layerIndex, userAction);
2876
- if (this.disableTimer) {
2877
- this.startDisabledTimeline();
2878
- }
2982
+ this._showLayer(this.layers, layerIndex, userAction);
2983
+ this.startReadyPromise.then(() => {
2984
+ if (this.disableTimer) {
2985
+ this.startDisabledTimeline();
2986
+ }
2987
+ });
2879
2988
  }
2880
2989
  selectVariant(variant) {
2881
2990
  if (this.selectedVariant !== undefined) {
@@ -2932,6 +3041,13 @@ class WidgetPollLayers extends WidgetBase {
2932
3041
  localData = undefined;
2933
3042
  }
2934
3043
  WidgetPollLayers.initWidgets((element, options) => new WidgetPollLayers(element, { ...options, layers }), [element], localData);
3044
+ WidgetPollLayers.getInstance(element)?.onStart();
3045
+ },
3046
+ onStart: function (element) {
3047
+ WidgetPollLayers.getInstance(element)?.onStart();
3048
+ },
3049
+ onStop: function (element) {
3050
+ WidgetPollLayers.getInstance(element)?.onStop();
2935
3051
  },
2936
3052
  /**
2937
3053
  * click on poll variant
@@ -2979,9 +3095,14 @@ class WidgetQuest extends WidgetBase {
2979
3095
  this.label = this.element.querySelector(".label-view .label");
2980
3096
  this.variants = slice.call(this.element.querySelectorAll(".variants-box .variant-view"));
2981
3097
  this.selectedAnswer = undefined;
2982
- // this.onRefreshUserData(this.options.localData);
2983
3098
  }
2984
- onRefreshUserData(localData) { }
3099
+ /**
3100
+ * Start or restart widget
3101
+ * @param localData
3102
+ */
3103
+ onRefreshUserData(localData) {
3104
+ super.onRefreshUserData(localData);
3105
+ }
2985
3106
  setCardSessionValue(name, value) {
2986
3107
  this.sdkApi.setCardSessionValue(this.element, name, value);
2987
3108
  }
@@ -3221,6 +3342,7 @@ class WidgetQuest extends WidgetBase {
3221
3342
  });
3222
3343
  });
3223
3344
  },
3345
+ /** @deprecated */
3224
3346
  initWidget: function (element, localData) {
3225
3347
  return new Promise(function (resolve, reject) {
3226
3348
  WidgetQuest.initWidgets((element, options) => new WidgetQuest(element, options), [element], localData).then(localData => {
@@ -3232,8 +3354,15 @@ class WidgetQuest extends WidgetBase {
3232
3354
  resolve(true);
3233
3355
  }
3234
3356
  });
3357
+ WidgetQuest.getInstance(element)?.onStart();
3235
3358
  });
3236
3359
  },
3360
+ onStart: function (element) {
3361
+ WidgetQuest.getInstance(element)?.onStart();
3362
+ },
3363
+ onStop: function (element) {
3364
+ WidgetQuest.getInstance(element)?.onStop();
3365
+ },
3237
3366
  select: function (element) {
3238
3367
  const widgetElement = element.closest(`.${WidgetQuest.widgetClassName}`);
3239
3368
  if (widgetElement) {
@@ -3278,11 +3407,13 @@ class WidgetQuiz extends WidgetBase {
3278
3407
  this.question = this.element.querySelector(".label-view .label");
3279
3408
  this.answers = slice.call(this.element.querySelectorAll(".variants-box .variant-view-group"));
3280
3409
  this.questionCount = getValueOrException(getTagDataAsNumber(this.slide, "quizCount"), "Empty quizCount");
3281
- this.onRefreshUserData(this.options.localData);
3282
3410
  }
3411
+ /**
3412
+ * Start or restart widget
3413
+ * @param localData
3414
+ */
3283
3415
  onRefreshUserData(localData) {
3284
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
3285
- this.localData = extend({}, this.savedData ?? {}, localData);
3416
+ super.onRefreshUserData(localData);
3286
3417
  this.selectedAnswer = undefined;
3287
3418
  if (this.localData) {
3288
3419
  if (this.localData["_q_g_" + this.elementId + "_sa"] !== undefined) {
@@ -3325,9 +3456,11 @@ class WidgetQuiz extends WidgetBase {
3325
3456
  // })
3326
3457
  // })
3327
3458
  // }
3328
- if (this.disableTimer) {
3329
- this.startDisabledTimeline();
3330
- }
3459
+ this.startReadyPromise.then(() => {
3460
+ if (this.disableTimer) {
3461
+ this.startDisabledTimeline();
3462
+ }
3463
+ });
3331
3464
  }
3332
3465
  _clearAnswerSelection() {
3333
3466
  forEach(this.answers, function (answer) {
@@ -3426,6 +3559,13 @@ class WidgetQuiz extends WidgetBase {
3426
3559
  /** @deprecated */
3427
3560
  initWidget: function (element, localData) {
3428
3561
  WidgetQuiz.initWidgets((element, options) => new WidgetQuiz(element, options), [element], localData);
3562
+ WidgetQuiz.getInstance(element)?.onStart();
3563
+ },
3564
+ onStart: function (element) {
3565
+ WidgetQuiz.getInstance(element)?.onStart();
3566
+ },
3567
+ onStop: function (element) {
3568
+ WidgetQuiz.getInstance(element)?.onStop();
3429
3569
  },
3430
3570
  /**
3431
3571
  * click on quiz answer
@@ -3473,11 +3613,13 @@ class WidgetQuizGrouped extends WidgetBase {
3473
3613
  this.question = this.element.querySelector(".label-view .label");
3474
3614
  this.answers = slice.call(this.element.querySelectorAll(".variants-box .variant-view-group"));
3475
3615
  this.questionCount = getValueOrException(getTagDataAsNumber(this.slide, "quizCount"), "Empty quizCount");
3476
- this.onRefreshUserData(this.options.localData);
3477
3616
  }
3617
+ /**
3618
+ * Start or restart widget
3619
+ * @param localData
3620
+ */
3478
3621
  onRefreshUserData(localData) {
3479
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
3480
- this.localData = extend({}, this.savedData ?? {}, localData);
3622
+ super.onRefreshUserData(localData);
3481
3623
  this.selectedAnswer = undefined;
3482
3624
  if (this.localData) {
3483
3625
  if (this.localData["_q_gg_" + this.elementId + "_sa"] !== undefined) {
@@ -3507,9 +3649,11 @@ class WidgetQuizGrouped extends WidgetBase {
3507
3649
  this.submitButtonAnimatedView.style.maxHeight = this.submitButtonViewHeight + "px";
3508
3650
  }
3509
3651
  });
3510
- if (this.disableTimer) {
3511
- this.startDisabledTimeline();
3512
- }
3652
+ this.startReadyPromise.then(() => {
3653
+ if (this.disableTimer) {
3654
+ this.startDisabledTimeline();
3655
+ }
3656
+ });
3513
3657
  }
3514
3658
  _clearAnswerSelection() {
3515
3659
  forEach(this.answers, function (answer) {
@@ -3625,6 +3769,13 @@ class WidgetQuizGrouped extends WidgetBase {
3625
3769
  /** @deprecated */
3626
3770
  initWidget: function (element, localData) {
3627
3771
  WidgetQuizGrouped.initWidgets((element, options) => new WidgetQuizGrouped(element, options), [element], localData);
3772
+ WidgetQuizGrouped.getInstance(element)?.onStart();
3773
+ },
3774
+ onStart: function (element) {
3775
+ WidgetQuizGrouped.getInstance(element)?.onStart();
3776
+ },
3777
+ onStop: function (element) {
3778
+ WidgetQuizGrouped.getInstance(element)?.onStop();
3628
3779
  },
3629
3780
  /**
3630
3781
  * click on quiz answer
@@ -3855,7 +4006,6 @@ class WidgetRangeSlider extends WidgetBase {
3855
4006
  this.handleDown = proxy(this.handleDown, this);
3856
4007
  this.handleMove = proxy(this.handleMove, this);
3857
4008
  this.handleEnd = proxy(this.handleEnd, this);
3858
- this.onRefreshUserData(this.options.localData);
3859
4009
  // Attach Events
3860
4010
  // window.addEventListener('resize.' + this.identifier, debounce(function() {
3861
4011
  // // Simulate resizeEnd event.
@@ -3866,16 +4016,21 @@ class WidgetRangeSlider extends WidgetBase {
3866
4016
  this.env.document.addEventListener("touchstart", this.handleDown);
3867
4017
  this.env.document.addEventListener("mousedown", this.handleDown);
3868
4018
  }
4019
+ /**
4020
+ * Start or restart widget
4021
+ * @param localData
4022
+ */
3869
4023
  onRefreshUserData(localData) {
3870
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
3871
- this.localData = extend({}, this.savedData ?? {}, localData);
4024
+ super.onRefreshUserData(localData);
3872
4025
  if (this.localData["_rs_g_" + this.elementId + "_v"] !== undefined) {
3873
4026
  this.elementSlider.value = String(tryParseFloat(this.localData["_rs_g_" + this.elementId + "_v"], 0));
3874
4027
  this.element.classList.add("done");
3875
4028
  this.displayAverageAnswer();
3876
- if (this.disableTimer) {
3877
- this.startDisabledTimeline();
3878
- }
4029
+ this.startReadyPromise.then(() => {
4030
+ if (this.disableTimer) {
4031
+ this.startDisabledTimeline();
4032
+ }
4033
+ });
3879
4034
  }
3880
4035
  else {
3881
4036
  this.elementSlider.value = String(this.startValue);
@@ -3884,6 +4039,10 @@ class WidgetRangeSlider extends WidgetBase {
3884
4039
  }
3885
4040
  this.init();
3886
4041
  }
4042
+ onStop() {
4043
+ super.onStop();
4044
+ this.destroy();
4045
+ }
3887
4046
  _statEventInputSave(val) {
3888
4047
  try {
3889
4048
  const labelText = this.label?.textContent ?? "";
@@ -4235,11 +4394,18 @@ class WidgetRangeSlider extends WidgetBase {
4235
4394
  onRefreshUserData: WidgetRangeSlider.onRefreshUserData,
4236
4395
  init: function (element, localData) {
4237
4396
  WidgetRangeSlider.initWidget(element, localData, (element, options) => new WidgetRangeSlider(element, options));
4397
+ WidgetRangeSlider.getInstance(element)?.onStart();
4238
4398
  },
4239
4399
  /** @deprecated */
4240
4400
  initWidget: function (element, localData) {
4241
4401
  WidgetRangeSlider.initWidgets((element, options) => new WidgetRangeSlider(element, options), [element], localData);
4242
4402
  },
4403
+ onStart: function (element) {
4404
+ WidgetRangeSlider.getInstance(element)?.onStart();
4405
+ },
4406
+ onStop: function (element) {
4407
+ WidgetRangeSlider.getInstance(element)?.onStop();
4408
+ },
4243
4409
  click: function (element) {
4244
4410
  const widgetElement = element.closest(`.${WidgetRangeSlider.widgetClassName}`);
4245
4411
  if (widgetElement) {
@@ -4294,11 +4460,13 @@ class WidgetRate extends WidgetBase {
4294
4460
  this.showDialogOnLowRate = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "showDialogOnLowRate"), 0));
4295
4461
  this.showDialogueMin = getValueOrDefault(getTagDataAsNumber(this.element, "showDialogueMin"), 1);
4296
4462
  this.showDialogueMax = getValueOrDefault(getTagDataAsNumber(this.element, "showDialogueMax"), 3);
4297
- this.onRefreshUserData(this.options.localData);
4298
4463
  }
4464
+ /**
4465
+ * Start or restart widget
4466
+ * @param localData
4467
+ */
4299
4468
  onRefreshUserData(localData) {
4300
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
4301
- this.localData = extend({}, this.savedData ?? {}, localData);
4469
+ super.onRefreshUserData(localData);
4302
4470
  this.selectedStar = undefined;
4303
4471
  if (this.localData) {
4304
4472
  if (this.localData["_r_g_" + this.elementId + "_ss"] !== undefined) {
@@ -4356,9 +4524,11 @@ class WidgetRate extends WidgetBase {
4356
4524
  this.selectedStar = value;
4357
4525
  this.localData["_r_g_" + this.elementId + "_ss"] = value;
4358
4526
  this.element.classList.add("done");
4359
- if (this.disableTimer && runTimer) {
4360
- this.startDisabledTimeline();
4361
- }
4527
+ this.startReadyPromise.then(() => {
4528
+ if (this.disableTimer && runTimer) {
4529
+ this.startDisabledTimeline();
4530
+ }
4531
+ });
4362
4532
  }
4363
4533
  _clearSelectedStar() {
4364
4534
  forEach(this.stars, function (element) {
@@ -4491,7 +4661,15 @@ class WidgetRate extends WidgetBase {
4491
4661
  },
4492
4662
  /** @deprecated */
4493
4663
  initWidget: function (nodeList, localData) {
4494
- WidgetRate.initWidgets((element, options) => new WidgetRate(element, options), slice.call(nodeList), localData);
4664
+ const elements = slice.call(nodeList);
4665
+ WidgetRate.initWidgets((element, options) => new WidgetRate(element, options), elements, localData);
4666
+ elements.forEach(element => WidgetRate.getInstance(element)?.onStart());
4667
+ },
4668
+ onStart: function (element) {
4669
+ WidgetRate.getInstance(element)?.onStart();
4670
+ },
4671
+ onStop: function (element) {
4672
+ WidgetRate.getInstance(element)?.onStop();
4495
4673
  },
4496
4674
  select: function (element) {
4497
4675
  const widgetElement = element.closest(`.${WidgetRate.widgetClassName}`);
@@ -4537,21 +4715,28 @@ class WidgetShare extends WidgetBase {
4537
4715
  this.shareTarget = getTagData(this.element, "shareTarget");
4538
4716
  this.layers = this.options.layers;
4539
4717
  this.withLayer = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "withLayer"), 0));
4718
+ }
4719
+ /**
4720
+ * Start or restart widget
4721
+ * @param localData
4722
+ */
4723
+ onRefreshUserData(localData) {
4724
+ super.onRefreshUserData(localData);
4540
4725
  if (this.withLayer) {
4541
4726
  if (this.isDone()) {
4542
- this._showLayout(this.layers, 1);
4727
+ this._showLayer(this.layers, 1);
4543
4728
  }
4544
4729
  else {
4545
- this._showLayout(this.layers, 0);
4730
+ this._showLayer(this.layers, 0);
4546
4731
  }
4547
4732
  }
4548
- if (this.isDone() && this.disableTimer) {
4549
- this.startDisabledTimeline();
4550
- }
4733
+ this.startReadyPromise.then(() => {
4734
+ if (this.isDone() && this.disableTimer) {
4735
+ this.startDisabledTimeline();
4736
+ }
4737
+ });
4551
4738
  this.btnDisabled = false;
4552
- // this.onRefreshUserData(this.options.localData);
4553
4739
  }
4554
- onRefreshUserData(localData) { }
4555
4740
  _statEventShare(result, via) {
4556
4741
  try {
4557
4742
  const buttonText = this.element.textContent ?? "";
@@ -4604,7 +4789,7 @@ class WidgetShare extends WidgetBase {
4604
4789
  }
4605
4790
  this._statEventShare(isSuccess, null);
4606
4791
  if (isSuccess && this.withLayer) {
4607
- this._showLayout(this.layers, 1, true);
4792
+ this._showLayer(this.layers, 1, true);
4608
4793
  }
4609
4794
  if (this.disableTimer) {
4610
4795
  this.startDisabledTimeline();
@@ -4620,7 +4805,10 @@ class WidgetShare extends WidgetBase {
4620
4805
  refreshUserData: WidgetShare.refreshUserData,
4621
4806
  onRefreshUserData: WidgetShare.onRefreshUserData,
4622
4807
  init: function (element, layers, localData) {
4623
- WidgetShare.initWidget(element, localData, (element, options) => new WidgetShare(element, { ...options, layers }));
4808
+ WidgetShare.initWidget(element, localData, (element, options) => new WidgetShare(element, {
4809
+ ...options,
4810
+ layers,
4811
+ }));
4624
4812
  },
4625
4813
  /** @deprecated
4626
4814
  * signature variants
@@ -4634,7 +4822,15 @@ class WidgetShare extends WidgetBase {
4634
4822
  layers = localData;
4635
4823
  localData = undefined;
4636
4824
  }
4637
- WidgetShare.initWidgets((element, options) => new WidgetShare(element, { ...options, layers }), slice.call(nodeList), localData);
4825
+ const elements = slice.call(nodeList);
4826
+ WidgetShare.initWidgets((element, options) => new WidgetShare(element, { ...options, layers }), elements, localData);
4827
+ elements.forEach(element => WidgetShare.getInstance(element)?.onStart());
4828
+ },
4829
+ onStart: function (element) {
4830
+ WidgetShare.getInstance(element)?.onStart();
4831
+ },
4832
+ onStop: function (element) {
4833
+ WidgetShare.getInstance(element)?.onStop();
4638
4834
  },
4639
4835
  click: function (element) {
4640
4836
  const widgetElement = element.closest(`.${WidgetShare.widgetClassName}`);
@@ -4680,18 +4876,6 @@ class WidgetTest extends WidgetBase {
4680
4876
  this.testCount = getValueOrException(getTagDataAsNumber(this.slide, "testCount"), "Empty testCount");
4681
4877
  this.withTimeToAnswer = Boolean(getValueOrDefault(getTagDataAsNumber(this.element, "withTimeToAnswer"), 0));
4682
4878
  this.answerTimeout = getValueOrDefault(getTagDataAsNumber(this.element, "answerTimeout"), 0);
4683
- this.selectedAnswer = undefined;
4684
- if (this.localData) {
4685
- if (this.localData["_t_g_" + this.elementId + "_sa"] !== undefined) {
4686
- this._selectAnswer(this.localData["_t_g_" + this.elementId + "_sa"]);
4687
- this.setLocalData(this.localData, false);
4688
- }
4689
- if (this.localData["_t_fo_at"] === undefined) {
4690
- this.localData["_t_fo_at"] = Math.round(new Date().getTime() / 1000);
4691
- this.setLocalData(this.localData, false);
4692
- }
4693
- }
4694
- this.firstOpenTime = new Date().getTime();
4695
4879
  this.tick = () => {
4696
4880
  this.animationFrameId = this.env.requestAnimationFrame(() => {
4697
4881
  this.tick();
@@ -4720,7 +4904,27 @@ class WidgetTest extends WidgetBase {
4720
4904
  this.env.cancelAnimationFrame(this.animationFrameId);
4721
4905
  }
4722
4906
  };
4907
+ }
4908
+ /**
4909
+ * Start or restart widget
4910
+ * @param localData
4911
+ */
4912
+ onRefreshUserData(localData) {
4913
+ super.onRefreshUserData(localData);
4914
+ this.selectedAnswer = undefined;
4915
+ if (this.localData) {
4916
+ if (this.localData["_t_g_" + this.elementId + "_sa"] !== undefined) {
4917
+ this._selectAnswer(this.localData["_t_g_" + this.elementId + "_sa"]);
4918
+ this.setLocalData(this.localData, false);
4919
+ }
4920
+ if (this.localData["_t_fo_at"] === undefined) {
4921
+ this.localData["_t_fo_at"] = Math.round(new Date().getTime() / 1000);
4922
+ this.setLocalData(this.localData, false);
4923
+ }
4924
+ }
4925
+ this.firstOpenTime = new Date().getTime();
4723
4926
  if (this.slideTestWithTimer()) {
4927
+ this.cancelTick();
4724
4928
  this.timeline = this.element.querySelector(".timeline");
4725
4929
  if (this.selectedAnswer === undefined) {
4726
4930
  // find timer element
@@ -4730,7 +4934,9 @@ class WidgetTest extends WidgetBase {
4730
4934
  this.timeLeft = this.timeLeftDefault;
4731
4935
  this.animationFrameId = null;
4732
4936
  this.startTimerAt = new Date().getTime();
4733
- this.tick();
4937
+ this.startReadyPromise.then(() => {
4938
+ this.tick();
4939
+ });
4734
4940
  // set answer - unanswered (for close and run again)
4735
4941
  this.localData["_t_g_" + this.elementId + "_sa"] = -1;
4736
4942
  this.setLocalData(this.localData, true);
@@ -4749,9 +4955,16 @@ class WidgetTest extends WidgetBase {
4749
4955
  }
4750
4956
  }
4751
4957
  }
4752
- // this.onRefreshUserData(this.options.localData);
4753
4958
  }
4754
- onRefreshUserData(localData) { }
4959
+ onStart() {
4960
+ super.onStart();
4961
+ }
4962
+ onStop() {
4963
+ super.onStop();
4964
+ if (this.slideTestWithTimer()) {
4965
+ this.cancelTick();
4966
+ }
4967
+ }
4755
4968
  _statEventVoteAnswer(answerScore) {
4756
4969
  try {
4757
4970
  if (this.selectedAnswer != null) {
@@ -4799,9 +5012,11 @@ class WidgetTest extends WidgetBase {
4799
5012
  this.submitButtonAnimatedView.style.maxHeight = this.submitButtonViewHeight + "px";
4800
5013
  }
4801
5014
  });
4802
- if (this.disableTimer) {
4803
- this.startDisabledTimeline();
4804
- }
5015
+ this.startReadyPromise.then(() => {
5016
+ if (this.disableTimer) {
5017
+ this.startDisabledTimeline();
5018
+ }
5019
+ });
4805
5020
  }
4806
5021
  selectAnswer(answer) {
4807
5022
  if (this.selectedAnswer !== undefined) {
@@ -4880,6 +5095,13 @@ class WidgetTest extends WidgetBase {
4880
5095
  /** @deprecated */
4881
5096
  initWidget: function (element, localData) {
4882
5097
  WidgetTest.initWidgets((element, options) => new WidgetTest(element, options), [element], localData);
5098
+ WidgetTest.getInstance(element)?.onStart();
5099
+ },
5100
+ onStart: function (element) {
5101
+ WidgetTest.getInstance(element)?.onStart();
5102
+ },
5103
+ onStop: function (element) {
5104
+ WidgetTest.getInstance(element)?.onStop();
4883
5105
  },
4884
5106
  /**
4885
5107
  * click on quiz answer
@@ -4950,7 +5172,6 @@ class WidgetVote extends WidgetBase {
4950
5172
  });
4951
5173
  this.hideClientTotalResult = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "hideClientTotalResult")), false);
4952
5174
  this.multipleChoice = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "multipleChoice")), false);
4953
- this.onRefreshUserData(this.options.localData);
4954
5175
  }
4955
5176
  _initFromLocalData() {
4956
5177
  const value = this.localData["_v_g_" + this.elementId + "_sa"];
@@ -4985,9 +5206,12 @@ class WidgetVote extends WidgetBase {
4985
5206
  this._fillWidget(true);
4986
5207
  }
4987
5208
  }
5209
+ /**
5210
+ * Start or restart widget
5211
+ * @param localData
5212
+ */
4988
5213
  onRefreshUserData(localData) {
4989
- this.savedData = this.sdkApi.getCardServerData(this.cardId);
4990
- this.localData = extend({}, this.savedData ?? {}, localData);
5214
+ super.onRefreshUserData(localData);
4991
5215
  this.selectedVariant = undefined;
4992
5216
  if (this.localData) {
4993
5217
  if (this.localData["_v_g_" + this.elementId + "_sa"] != null) {
@@ -5117,9 +5341,11 @@ class WidgetVote extends WidgetBase {
5117
5341
  this._removeInputDone();
5118
5342
  this._hideSubmitBtn();
5119
5343
  }
5120
- if (this.disableTimer) {
5121
- this.startDisabledTimeline();
5122
- }
5344
+ this.startReadyPromise.then(() => {
5345
+ if (this.disableTimer) {
5346
+ this.startDisabledTimeline();
5347
+ }
5348
+ });
5123
5349
  }
5124
5350
  _showSubmitBtn() {
5125
5351
  this.env.requestAnimationFrame(() => {
@@ -5350,6 +5576,13 @@ class WidgetVote extends WidgetBase {
5350
5576
  WidgetVote.initWidgets((element, options) => new WidgetVote(element, options), [element], localData).then(localData => {
5351
5577
  WidgetVote.api.fallbackInitOnMultiSlide(element, localData);
5352
5578
  });
5579
+ WidgetVote.getInstance(element)?.onStart();
5580
+ },
5581
+ onStart: function (element) {
5582
+ WidgetVote.getInstance(element)?.onStart();
5583
+ },
5584
+ onStop: function (element) {
5585
+ WidgetVote.getInstance(element)?.onStop();
5353
5586
  },
5354
5587
  select: function (element) {
5355
5588
  const widgetElement = element.closest(`.${WidgetVote.widgetClassName}`);
@@ -14767,22 +15000,33 @@ class WidgetBarcode extends WidgetBase {
14767
15000
  this.formatterType = getTagData(element, "formatterType");
14768
15001
  this.copiedText = getTagData(element, "copiedText");
14769
15002
  this.svgView = this.element.querySelector(".barcode-view-inner");
14770
- this.state = null;
14771
15003
  this.msgNetworkError = getTagData(this.element, "msgNetworkError");
14772
15004
  this.msgServiceError = getTagData(this.element, "msgServiceError");
14773
15005
  this.msgNoMoreCodes = getTagData(this.element, "msgNoMoreCodes");
14774
15006
  this.msgTryAgain = getTagData(this.element, "msgTryAgain");
14775
15007
  this.msgBarcodeRenderError = getTagData(this.element, "msgBarcodeRenderError");
15008
+ }
15009
+ /**
15010
+ * Start or restart widget
15011
+ * @param localData
15012
+ */
15013
+ onRefreshUserData(localData) {
15014
+ super.onRefreshUserData(localData);
15015
+ this.state = null;
14776
15016
  if (this.isPromotionalCode) {
14777
- this.fetchPromoCode();
15017
+ this.initPromotionalCodeFromLocalData();
14778
15018
  }
14779
15019
  else {
14780
15020
  this.renderCodeView();
14781
15021
  this.renderCaptionView();
14782
15022
  }
14783
- // this.onRefreshUserData(this.options.localData);
14784
15023
  }
14785
- onRefreshUserData(localData) { }
15024
+ onStart() {
15025
+ super.onStart();
15026
+ if (this.isPromotionalCode) {
15027
+ this.fetchPromoCode();
15028
+ }
15029
+ }
14786
15030
  isTransparentElement() {
14787
15031
  if (this.element) {
14788
15032
  try {
@@ -14864,17 +15108,23 @@ class WidgetBarcode extends WidgetBase {
14864
15108
  this.captionView.textContent = text;
14865
15109
  }
14866
15110
  }
14867
- fetchPromoCode() {
14868
- this.state = 0;
14869
- if (this.localData["_bc_g_" + this.elementId + "_pc"] !== undefined) {
15111
+ getPromotionalCodeFromLocalData() {
15112
+ return this.localData["_bc_g_" + this.elementId + "_pc"];
15113
+ }
15114
+ initPromotionalCodeFromLocalData() {
15115
+ if (this.getPromotionalCodeFromLocalData() !== undefined) {
14870
15116
  this.state = 1;
14871
- this.clipboardTarget = this.localData["_bc_g_" + this.elementId + "_pc"];
15117
+ this.clipboardTarget = this.getPromotionalCodeFromLocalData();
14872
15118
  if (this.clipboardTarget != null) {
14873
15119
  this.renderCaptionView();
14874
15120
  this.renderCodeView();
14875
15121
  }
14876
15122
  removeClass(this.element, "loader");
14877
15123
  }
15124
+ }
15125
+ fetchPromoCode() {
15126
+ this.state = 0;
15127
+ this.initPromotionalCodeFromLocalData();
14878
15128
  if (this.state === 0) {
14879
15129
  if (!this.isTransparentElement()) {
14880
15130
  // for transparent element
@@ -14960,12 +15210,14 @@ class WidgetBarcode extends WidgetBase {
14960
15210
  }
14961
15211
  _select() {
14962
15212
  this.element.classList.add("done");
14963
- if (this.disableTimer) {
14964
- // флаг - что таймер уже стартанул (в layout или добавить объект sharedMemory)
14965
- // смотрим что прозрачный текст - тогда и лоадер прозрачный
14966
- // _log("_showNarrativeNextSlide: " + getSlideDuration(this.narrativeId, this.slideIndex), true);
14967
- this.startDisabledTimeline();
14968
- }
15213
+ this.startReadyPromise.then(() => {
15214
+ if (this.disableTimer) {
15215
+ // флаг - что таймер уже стартанул layout или добавить объект sharedMemory)
15216
+ // смотрим что прозрачный текст - тогда и лоадер прозрачный
15217
+ // _log("_showNarrativeNextSlide: " + getSlideDuration(this.narrativeId, this.slideIndex), true);
15218
+ this.startDisabledTimeline();
15219
+ }
15220
+ });
14969
15221
  if (this.copiedText) {
14970
15222
  this.sdkApi.showToast(this.copiedText);
14971
15223
  }
@@ -14996,7 +15248,15 @@ class WidgetBarcode extends WidgetBase {
14996
15248
  },
14997
15249
  /** @deprecated */
14998
15250
  initWidget: function (nodeList, localData) {
14999
- WidgetBarcode.initWidgets((element, options) => new WidgetBarcode(element, options), slice.call(nodeList), localData);
15251
+ const elements = slice.call(nodeList);
15252
+ WidgetBarcode.initWidgets((element, options) => new WidgetBarcode(element, options), elements, localData);
15253
+ elements.forEach(element => WidgetBarcode.getInstance(element)?.onStart());
15254
+ },
15255
+ onStart: function (element) {
15256
+ WidgetBarcode.getInstance(element)?.onStart();
15257
+ },
15258
+ onStop: function (element) {
15259
+ WidgetBarcode.getInstance(element)?.onStop();
15000
15260
  },
15001
15261
  click: function (element) {
15002
15262
  const widgetElement = element.closest(`.${WidgetBarcode.widgetClassName}`);