@inappstory/slide-api 0.0.7 → 0.0.9

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
@@ -213,6 +213,29 @@ class WidgetsService {
213
213
 
214
214
  container.registerSingleton(undefined, { identifier: `WidgetsService`, implementation: WidgetsService });
215
215
 
216
+ class LayoutService {
217
+ _env;
218
+ _sdkApi;
219
+ _layoutApi;
220
+ constructor(_env, _sdkApi, _layoutApi) {
221
+ this._env = _env;
222
+ this._sdkApi = _sdkApi;
223
+ this._layoutApi = _layoutApi;
224
+ }
225
+ get env() {
226
+ return this._env;
227
+ }
228
+ get sdkApi() {
229
+ return this._sdkApi;
230
+ }
231
+ get layoutApi() {
232
+ return this._layoutApi;
233
+ }
234
+ static get [Symbol.for("___CTOR_ARGS___")]() { return [`Window`, `SDKApi`, `ILayoutApi`]; }
235
+ }
236
+
237
+ container.registerSingleton(undefined, { identifier: `LayoutService`, implementation: LayoutService });
238
+
216
239
  // import '../adapters/dateTimeSource/composition';
217
240
  // import '../adapters/uuidGenerator/composition';
218
241
  // import '../effects/eventHandler/composition';
@@ -220,6 +243,8 @@ container.registerSingleton(undefined, { identifier: `WidgetsService`, implement
220
243
  // import '../effects/timer/composition';
221
244
  container.registerSingleton(() => window, { identifier: `Window` });
222
245
 
246
+ const DEFAULT_SLIDE_DURATION = 10000;
247
+
223
248
  const arPrototype = Array.prototype;
224
249
  const obPrototype = Object.prototype;
225
250
  const slice = arPrototype.slice;
@@ -544,9 +569,6 @@ class Data {
544
569
  }
545
570
  // var data_priv = new Data();
546
571
  const data_user = new Data();
547
- const getSlideDuration = function (sdkApi, storyId, slideIndex) {
548
- return sdkApi.getSlideDuration(storyId, slideIndex) ?? 10000;
549
- };
550
572
  const getWinWidth = function (env) {
551
573
  return env.innerWidth || env.document.documentElement.clientWidth || env.document.body.clientWidth;
552
574
  };
@@ -1132,6 +1154,18 @@ class EsModuleSdkApi {
1132
1154
  getStorySessionValue(element, key) {
1133
1155
  return this.sdkBinding().getStorySessionValue(key);
1134
1156
  }
1157
+ updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError) {
1158
+ this.sdkBinding().updateTimeline(slideIndex, action, currentTime, duration, showLoader, showError);
1159
+ }
1160
+ storyPausedCallback(currentTime) { }
1161
+ storyResumedCallback(currentTime) { }
1162
+ startDisabledTimeline(storyId, slideIndex) {
1163
+ // old api
1164
+ this.showNextSlide(this.getSlideDuration(storyId, slideIndex) ?? DEFAULT_SLIDE_DURATION);
1165
+ }
1166
+ getStoryFonts() {
1167
+ return this.sdkBinding().getStoryFonts();
1168
+ }
1135
1169
  static get [Symbol.for("___CTOR_ARGS___")]() { return [`() => SDKInterface`]; }
1136
1170
  }
1137
1171
 
@@ -1310,8 +1344,8 @@ class WidgetBase {
1310
1344
  sendStatisticEventToApp(name, data, devPayload) {
1311
1345
  this.constructor.sendStatisticEventToApp(name, data, devPayload);
1312
1346
  }
1313
- showNextSlide() {
1314
- this.sdkApi.showNextSlide(getSlideDuration(this.sdkApi, this.storyId, this.slideIndex));
1347
+ startDisabledTimeline() {
1348
+ this.sdkApi.startDisabledTimeline(this.storyId, this.slideIndex);
1315
1349
  }
1316
1350
  _showLayout(layers, selectIndex, withStatEvent = false) {
1317
1351
  if (this.sdkApi.isExistsShowLayer()) {
@@ -1548,7 +1582,7 @@ class WidgetCopy extends WidgetBase {
1548
1582
  // флаг - что таймер уже стартанул (в layout или добавить объект sharedMemory)
1549
1583
  // смотрим что прозрачный текст - тогда и лоадер прозрачный
1550
1584
  // _log("_showNarrativeNextSlide: " + getSlideDuration(this.narrativeId, this.slideIndex), true);
1551
- this.showNextSlide();
1585
+ this.startDisabledTimeline();
1552
1586
  }
1553
1587
  }
1554
1588
  copyToClipboard(element) {
@@ -1568,6 +1602,7 @@ class WidgetCopy extends WidgetBase {
1568
1602
  return this.localData["_cp_g_" + this.elementId + "_done_at"] !== undefined;
1569
1603
  }
1570
1604
  static api = {
1605
+ widgetClassName: WidgetCopy.widgetClassName,
1571
1606
  refreshUserData: WidgetCopy.refreshUserData,
1572
1607
  initWidget: function (nodeList, localData) {
1573
1608
  // prevent initWidget for result layer
@@ -1632,7 +1667,7 @@ class WidgetDataInput extends WidgetBase {
1632
1667
  if (text) {
1633
1668
  this.element.classList.add("done");
1634
1669
  if (this.disableTimer) {
1635
- this.showNextSlide();
1670
+ this.startDisabledTimeline();
1636
1671
  }
1637
1672
  }
1638
1673
  }
@@ -1749,10 +1784,8 @@ class WidgetDataInput extends WidgetBase {
1749
1784
  this.setLocalData(this.localData, true);
1750
1785
  this._statEventInputSave(text);
1751
1786
  if (this.disableTimer) {
1752
- if ("_showNarrativeNextSlide" in window) {
1753
- this.showNextSlide();
1754
- needResumeUITimer = false;
1755
- }
1787
+ this.startDisabledTimeline();
1788
+ needResumeUITimer = false;
1756
1789
  }
1757
1790
  }
1758
1791
  if (needResumeUITimer && !this.disableTimer) {
@@ -1760,6 +1793,7 @@ class WidgetDataInput extends WidgetBase {
1760
1793
  }
1761
1794
  }
1762
1795
  static api = {
1796
+ widgetClassName: WidgetDataInput.widgetClassName,
1763
1797
  refreshUserData: WidgetDataInput.refreshUserData,
1764
1798
  initWidget: function (nodeList, localData) {
1765
1799
  WidgetDataInput.initWidgets((element, options) => new WidgetDataInput(element, options), slice.call(nodeList), localData);
@@ -1973,6 +2007,7 @@ class WidgetDateCountdown extends WidgetBase {
1973
2007
  return result;
1974
2008
  }
1975
2009
  static api = {
2010
+ widgetClassName: WidgetDateCountdown.widgetClassName,
1976
2011
  refreshUserData: WidgetDateCountdown.refreshUserData,
1977
2012
  initWidget: function (nodeList, layers, localData) {
1978
2013
  WidgetDateCountdown.initWidgets((element, options) => new WidgetDateCountdown(element, { ...options, layers }), slice.call(nodeList), localData);
@@ -2263,7 +2298,7 @@ class WidgetPoll extends WidgetBase {
2263
2298
  // todo poll - если виджет на первом слайде то при повторном заходе автоматически не стартует таймлайн слайда
2264
2299
  // только в web sdk такое
2265
2300
  // если поставить через setTimeout то все ок
2266
- this.showNextSlide();
2301
+ this.startDisabledTimeline();
2267
2302
  });
2268
2303
  }
2269
2304
  }
@@ -2601,6 +2636,7 @@ class WidgetPoll extends WidgetBase {
2601
2636
  return this.localData["_p_g_" + this.elementId + "_sa"] !== undefined;
2602
2637
  }
2603
2638
  static api = {
2639
+ widgetClassName: WidgetPoll.widgetClassName,
2604
2640
  refreshUserData: WidgetPoll.refreshUserData,
2605
2641
  initWidget: function (element, localData) {
2606
2642
  WidgetPoll.initWidgets((element, options) => new WidgetPoll(element, options), [element], localData);
@@ -2729,7 +2765,7 @@ class WidgetPollLayers extends WidgetBase {
2729
2765
  }
2730
2766
  this._showLayout(this.layers, layerIndex, userAction);
2731
2767
  if (this.disableTimer) {
2732
- this.showNextSlide();
2768
+ this.startDisabledTimeline();
2733
2769
  }
2734
2770
  }
2735
2771
  selectVariant(variant) {
@@ -2766,6 +2802,7 @@ class WidgetPollLayers extends WidgetBase {
2766
2802
  return this.localData != null && this.localData["_pl_g_" + this.elementId + "_sa"] !== undefined;
2767
2803
  }
2768
2804
  static api = {
2805
+ widgetClassName: WidgetPollLayers.widgetClassName,
2769
2806
  refreshUserData: WidgetPollLayers.refreshUserData,
2770
2807
  // signature variants
2771
2808
  // (widget, layers, undefined) - modern web sdk
@@ -3049,6 +3086,7 @@ class WidgetQuest extends WidgetBase {
3049
3086
  }
3050
3087
  }
3051
3088
  static api = {
3089
+ widgetClassName: WidgetQuest.widgetClassName,
3052
3090
  refreshUserData: WidgetQuest.refreshUserData,
3053
3091
  initWidget: function (element, localData) {
3054
3092
  return new Promise(function (resolve, reject) {
@@ -3155,7 +3193,7 @@ class WidgetQuiz extends WidgetBase {
3155
3193
  // })
3156
3194
  // }
3157
3195
  if (this.disableTimer) {
3158
- this.showNextSlide();
3196
+ this.startDisabledTimeline();
3159
3197
  }
3160
3198
  }
3161
3199
  _clearAnswerSelection() {
@@ -3247,6 +3285,7 @@ class WidgetQuiz extends WidgetBase {
3247
3285
  return this.localData["_q_g_" + this.elementId + "_sa"] !== undefined;
3248
3286
  }
3249
3287
  static api = {
3288
+ widgetClassName: WidgetQuiz.widgetClassName,
3250
3289
  refreshUserData: WidgetQuiz.refreshUserData,
3251
3290
  initWidget: function (element, localData) {
3252
3291
  WidgetQuiz.initWidgets((element, options) => new WidgetQuiz(element, options), [element], localData);
@@ -3332,7 +3371,7 @@ class WidgetQuizGrouped extends WidgetBase {
3332
3371
  }
3333
3372
  });
3334
3373
  if (this.disableTimer) {
3335
- this.showNextSlide();
3374
+ this.startDisabledTimeline();
3336
3375
  }
3337
3376
  }
3338
3377
  _clearAnswerSelection() {
@@ -3441,6 +3480,7 @@ class WidgetQuizGrouped extends WidgetBase {
3441
3480
  return this.localData["_q_gg_" + this.elementId + "_sa"] !== undefined;
3442
3481
  }
3443
3482
  static api = {
3483
+ widgetClassName: WidgetQuizGrouped.widgetClassName,
3444
3484
  refreshUserData: WidgetQuizGrouped.refreshUserData,
3445
3485
  initWidget: function (element, localData) {
3446
3486
  WidgetQuizGrouped.initWidgets((element, options) => new WidgetQuizGrouped(element, options), [element], localData);
@@ -3693,7 +3733,7 @@ class WidgetRangeSlider extends WidgetBase {
3693
3733
  this.element.classList.add("done");
3694
3734
  this.displayAverageAnswer();
3695
3735
  if (this.disableTimer) {
3696
- this.showNextSlide();
3736
+ this.startDisabledTimeline();
3697
3737
  }
3698
3738
  }
3699
3739
  else {
@@ -3762,7 +3802,7 @@ class WidgetRangeSlider extends WidgetBase {
3762
3802
  }
3763
3803
  });
3764
3804
  // if (this.disableTimer) {
3765
- this.showNextSlide();
3805
+ this.startDisabledTimeline();
3766
3806
  // }
3767
3807
  this.setLocalData(this.localData, true);
3768
3808
  this._statEventInputSave(this.localData["_rs_g_" + this.elementId + "_v"]);
@@ -4050,6 +4090,7 @@ class WidgetRangeSlider extends WidgetBase {
4050
4090
  // .removeData('plugin_' + pluginName);
4051
4091
  }
4052
4092
  static api = {
4093
+ widgetClassName: WidgetRangeSlider.widgetClassName,
4053
4094
  refreshUserData: WidgetRangeSlider.refreshUserData,
4054
4095
  initWidget: function (element, localData) {
4055
4096
  WidgetRangeSlider.initWidgets((element, options) => new WidgetRangeSlider(element, options), [element], localData);
@@ -4174,7 +4215,7 @@ class WidgetRate extends WidgetBase {
4174
4215
  this.localData["_r_g_" + this.elementId + "_ss"] = value;
4175
4216
  this.element.classList.add("done");
4176
4217
  if (this.disableTimer && runTimer) {
4177
- this.showNextSlide();
4218
+ this.startDisabledTimeline();
4178
4219
  }
4179
4220
  }
4180
4221
  _clearSelectedStar() {
@@ -4298,6 +4339,7 @@ class WidgetRate extends WidgetBase {
4298
4339
  return this.localData["_r_g_" + this.elementId + "_sa"] !== undefined;
4299
4340
  }
4300
4341
  static api = {
4342
+ widgetClassName: WidgetRate.widgetClassName,
4301
4343
  refreshUserData: WidgetRate.refreshUserData,
4302
4344
  initWidget: function (nodeList, localData) {
4303
4345
  WidgetRate.initWidgets((element, options) => new WidgetRate(element, options), slice.call(nodeList), localData);
@@ -4420,6 +4462,7 @@ class WidgetShare extends WidgetBase {
4420
4462
  return Boolean(this.localData["_s_" + this.elementId + "_ts"]);
4421
4463
  }
4422
4464
  static api = {
4465
+ widgetClassName: WidgetShare.widgetClassName,
4423
4466
  refreshUserData: WidgetShare.refreshUserData,
4424
4467
  // signature variants
4425
4468
  // (widget, layers, undefined) - modern web sdk
@@ -4539,6 +4582,11 @@ class WidgetTest extends WidgetBase {
4539
4582
  this.timeline.style.transform = "translateX(100%)";
4540
4583
  }
4541
4584
  }
4585
+ else if (this.localData["_&ts_t_g_" + this.elementId + "_a_tspent"] != null) {
4586
+ if (this.timeline) {
4587
+ this.timeline.style.transform = "translateX(" + String(this.localData["_&ts_t_g_" + this.elementId + "_a_tspent"]) + "%)";
4588
+ }
4589
+ }
4542
4590
  }
4543
4591
  }
4544
4592
  // this.refreshUserData(this.options.localData);
@@ -4594,7 +4642,7 @@ class WidgetTest extends WidgetBase {
4594
4642
  }
4595
4643
  });
4596
4644
  if (this.disableTimer) {
4597
- this.showNextSlide();
4645
+ this.startDisabledTimeline();
4598
4646
  }
4599
4647
  }
4600
4648
  selectAnswer(answer) {
@@ -4638,6 +4686,10 @@ class WidgetTest extends WidgetBase {
4638
4686
  }
4639
4687
  // answer on question
4640
4688
  this.localData["_&ts_t_g_" + this.elementId + "_a_at"] = Math.round(new Date().getTime() / 1000);
4689
+ // spent percent of time
4690
+ if (this.slideTestWithTimer()) {
4691
+ this.localData["_&ts_t_g_" + this.elementId + "_a_tspent"] = Math.round((1 - this.timeLeft / this.timeLeftDefault) * 100);
4692
+ }
4641
4693
  if (this.widgetDone) {
4642
4694
  this.widgetDone.classList.add("active", "opacity-active");
4643
4695
  setTimeout(() => {
@@ -4660,6 +4712,7 @@ class WidgetTest extends WidgetBase {
4660
4712
  return Boolean(this.withTimeToAnswer && this.answerTimeout);
4661
4713
  }
4662
4714
  static api = {
4715
+ widgetClassName: WidgetTest.widgetClassName,
4663
4716
  refreshUserData: WidgetTest.refreshUserData,
4664
4717
  initWidget: function (element, localData) {
4665
4718
  WidgetTest.initWidgets((element, options) => new WidgetTest(element, options), [element], localData);
@@ -4713,6 +4766,7 @@ class WidgetVote extends WidgetBase {
4713
4766
  selectedVariant;
4714
4767
  voteAllocation;
4715
4768
  hideClientTotalResult;
4769
+ multipleChoice;
4716
4770
  /**
4717
4771
  * @throws Error
4718
4772
  * @param element
@@ -4731,38 +4785,112 @@ class WidgetVote extends WidgetBase {
4731
4785
  }
4732
4786
  });
4733
4787
  this.hideClientTotalResult = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "hideClientTotalResult")), false);
4788
+ this.multipleChoice = getValueOrDefault(Boolean(getTagDataAsNumber(this.element, "multipleChoice")), false);
4789
+ this.refreshUserData(this.options.localData);
4790
+ }
4791
+ _initFromLocalData() {
4792
+ const value = this.localData["_v_g_" + this.elementId + "_sa"];
4793
+ if (!this.multipleChoice) {
4794
+ let index = value;
4795
+ if (Array.isArray(value)) {
4796
+ index = value[0];
4797
+ }
4798
+ this._checkVariant(index);
4799
+ this._selectVariant(index, true);
4800
+ if (!this.hideClientTotalResult) {
4801
+ this.displayPercents([index], true);
4802
+ }
4803
+ this._fillWidget(true);
4804
+ }
4805
+ if (this.multipleChoice) {
4806
+ let values = [];
4807
+ if (Array.isArray(value)) {
4808
+ values = value;
4809
+ }
4810
+ else {
4811
+ values.push(value);
4812
+ }
4813
+ for (let i = 0; i < values.length; ++i) {
4814
+ const index = values[i];
4815
+ this._checkVariant(index);
4816
+ this._selectVariant(index, true);
4817
+ }
4818
+ if (!this.hideClientTotalResult) {
4819
+ this.displayPercents(values, true);
4820
+ }
4821
+ this._fillWidget(true);
4822
+ }
4823
+ }
4824
+ refreshUserData(localData) {
4825
+ this.savedData = this.sdkApi.getStoryServerData(this.storyId);
4826
+ this.localData = extend({}, this.savedData ?? {}, localData);
4734
4827
  this.selectedVariant = undefined;
4735
4828
  if (this.localData) {
4736
- if (this.localData["_v_g_" + this.elementId + "_sa"] !== undefined) {
4737
- this._selectVariant(this.localData["_v_g_" + this.elementId + "_sa"], true);
4829
+ if (this.localData["_v_g_" + this.elementId + "_sa"] != null) {
4830
+ this._initFromLocalData();
4831
+ }
4832
+ else {
4833
+ this._clearSelectedVariants();
4834
+ this.element.classList.remove("done");
4835
+ this.element.classList.remove("input-done");
4836
+ this.element.classList.remove("filled");
4738
4837
  }
4739
4838
  }
4740
4839
  this.firstOpenTime = new Date().getTime();
4741
- // this.refreshUserData(this.options.localData);
4742
4840
  }
4743
- refreshUserData(localData) { }
4841
+ _clearSelectedVariants() {
4842
+ this.variants.forEach((variant, index) => {
4843
+ variant.classList.remove("checked");
4844
+ variant.classList.remove("selected");
4845
+ variant.style.setProperty("--selected-variant-view-clip-area", String(100));
4846
+ });
4847
+ }
4744
4848
  _statEventVoteVariant() {
4745
4849
  try {
4746
- if (this.selectedVariant != null) {
4747
- var labelText = this.label?.textContent ?? "";
4748
- var variantText = this.variantsTexts[this.selectedVariant] ? this.variantsTexts[this.selectedVariant] : "";
4749
- var duration = new Date().getTime() - this.firstOpenTime;
4850
+ let isValid = false;
4851
+ let selectedVariant = null;
4852
+ if (!this.multipleChoice) {
4853
+ if (this.selectedVariant != null) {
4854
+ isValid = true;
4855
+ selectedVariant = this.selectedVariant;
4856
+ }
4857
+ }
4858
+ let selectedVariantsLabels = [];
4859
+ let selectedVariantsIdxs = [];
4860
+ if (this.multipleChoice) {
4861
+ selectedVariantsIdxs = this._getCheckedVariants();
4862
+ if (selectedVariantsIdxs.length > 0) {
4863
+ isValid = true;
4864
+ selectedVariant = selectedVariantsIdxs[0];
4865
+ selectedVariantsIdxs.forEach(idx => selectedVariantsLabels.push(this.variantsTexts[idx] ? this.variantsTexts[idx] : ""));
4866
+ }
4867
+ }
4868
+ if (isValid) {
4869
+ let labelText = this.label?.textContent ?? "";
4870
+ let variantText = this.variantsTexts[selectedVariant] ? this.variantsTexts[selectedVariant] : "";
4871
+ let duration = new Date().getTime() - this.firstOpenTime;
4872
+ // доп поля - для multiple choice
4873
+ // первые оставляем пустыми в этом случае
4750
4874
  this.sendStatisticEventToApp("w-vote-answer", {
4751
4875
  i: this.storyId,
4752
4876
  si: this.slideIndex,
4753
4877
  wi: this.elementId,
4754
4878
  wl: labelText,
4755
- wa: this.selectedVariant,
4879
+ wa: selectedVariant,
4756
4880
  wv: variantText,
4757
4881
  d: duration,
4882
+ was: selectedVariantsIdxs,
4883
+ wvs: selectedVariantsLabels,
4758
4884
  }, {
4759
4885
  story_id: this.storyId,
4760
4886
  slide_index: this.slideIndex,
4761
4887
  widget_id: this.elementId,
4762
4888
  widget_label: labelText,
4763
- widget_answer: this.selectedVariant,
4889
+ widget_answer: selectedVariant,
4764
4890
  widget_value: variantText,
4765
4891
  duration_ms: duration,
4892
+ widget_answers: selectedVariantsIdxs,
4893
+ widget_values: selectedVariantsLabels,
4766
4894
  });
4767
4895
  }
4768
4896
  }
@@ -4770,15 +4898,33 @@ class WidgetVote extends WidgetBase {
4770
4898
  console.error(error);
4771
4899
  }
4772
4900
  }
4901
+ // user click on (un)checked (radio btn) variant
4902
+ _checkVariant(index) {
4903
+ if (this.variants[index]) {
4904
+ if (this.variants[index].classList.contains("checked")) {
4905
+ this.variants[index].classList.remove("checked");
4906
+ }
4907
+ else {
4908
+ this.variants[index].classList.add("checked");
4909
+ }
4910
+ }
4911
+ }
4912
+ _getCheckedVariants() {
4913
+ const map = [];
4914
+ this.variants.forEach((variant, index) => {
4915
+ if (variant.classList.contains("checked")) {
4916
+ map.push(index);
4917
+ }
4918
+ });
4919
+ return map;
4920
+ }
4773
4921
  _selectVariant(index, filled = false) {
4774
4922
  if (this.variants[index]) {
4775
4923
  this.variants[index].classList.add("selected");
4776
4924
  }
4777
4925
  this.selectedVariant = index;
4778
- this.localData["_v_g_" + this.elementId + "_sa"] = index;
4779
- this.element.classList.add("done");
4780
- if (filled) {
4781
- this.element.classList.add("filled");
4926
+ if (!this.multipleChoice) {
4927
+ this.localData["_v_g_" + this.elementId + "_sa"] = index;
4782
4928
  }
4783
4929
  if (this.hideClientTotalResult) {
4784
4930
  const cb = () => {
@@ -4793,43 +4939,136 @@ class WidgetVote extends WidgetBase {
4793
4939
  this.env.requestAnimationFrame(cb);
4794
4940
  }
4795
4941
  }
4796
- else {
4797
- this.displayPercents(index, filled);
4942
+ }
4943
+ _fillWidget(filled = false) {
4944
+ this.element.classList.add("done");
4945
+ if (filled) {
4946
+ this.element.classList.add("filled");
4947
+ }
4948
+ if (!this.multipleChoice) {
4949
+ if (this.submitButtonView != null) {
4950
+ this._setInputDone();
4951
+ this._showSubmitBtn();
4952
+ }
4798
4953
  }
4954
+ if (this.multipleChoice) {
4955
+ this._removeInputDone();
4956
+ this._hideSubmitBtn();
4957
+ }
4958
+ if (this.disableTimer) {
4959
+ this.startDisabledTimeline();
4960
+ }
4961
+ }
4962
+ _showSubmitBtn() {
4799
4963
  this.env.requestAnimationFrame(() => {
4800
4964
  if (this.submitButtonAnimatedView != null && this.submitButtonViewHeight != null) {
4801
4965
  this.submitButtonAnimatedView.style.maxHeight = this.submitButtonViewHeight + "px";
4802
4966
  }
4803
4967
  });
4804
- if (this.disableTimer) {
4805
- this.showNextSlide();
4806
- }
4968
+ }
4969
+ _hideSubmitBtn() {
4970
+ this.env.requestAnimationFrame(() => {
4971
+ if (this.submitButtonAnimatedView != null && this.submitButtonViewHeight != null) {
4972
+ this.submitButtonAnimatedView.style.maxHeight = "0px";
4973
+ }
4974
+ });
4807
4975
  }
4808
4976
  selectVariant(variant) {
4809
- if (this.selectedVariant !== undefined) {
4810
- return true;
4977
+ if (!this.multipleChoice) {
4978
+ if (this.selectedVariant != null) {
4979
+ return true;
4980
+ }
4981
+ }
4982
+ if (this.multipleChoice) {
4983
+ if (this.isDone()) {
4984
+ return true;
4985
+ }
4811
4986
  }
4812
4987
  var selectedVariantIndex = this.variants.indexOf(variant);
4813
4988
  if (selectedVariantIndex !== -1) {
4814
- this._selectVariant(selectedVariantIndex);
4815
- this.localData["_v_g_" + this.elementId + "_done_at"] = Math.round(new Date().getTime() / 1000);
4816
- // ответ на вопрос
4817
- this.localData["_&ts_v_g_" + this.elementId + "_a_at"] = Math.round(new Date().getTime() / 1000);
4818
- if (this.widgetDone) {
4819
- this.widgetDone.classList.add("active", "opacity-active");
4820
- setTimeout(() => {
4821
- this.widgetDone?.classList.remove("active");
4822
- setTimeout(() => {
4823
- this.widgetDone?.classList.remove("opacity-active");
4824
- }, 250);
4825
- }, 2000);
4989
+ this._checkVariant(selectedVariantIndex);
4990
+ if (this.multipleChoice) {
4991
+ if (this._getCheckedVariants().length > 0) {
4992
+ this._setInputDone();
4993
+ this._showSubmitBtn();
4994
+ }
4995
+ else {
4996
+ this._removeInputDone();
4997
+ this._hideSubmitBtn();
4998
+ }
4999
+ }
5000
+ if (!this.multipleChoice) {
5001
+ this._selectVariant(selectedVariantIndex);
5002
+ if (!this.hideClientTotalResult) {
5003
+ this.displayPercents([selectedVariantIndex]);
5004
+ }
5005
+ this._fillWidget();
5006
+ this._completeWidget();
4826
5007
  }
4827
- this.setLocalData(this.localData, true);
4828
- this._statEventVoteVariant();
4829
5008
  }
4830
5009
  return false;
4831
5010
  }
4832
- displayPercents(selectedVariantIndex, filled = false) {
5011
+ _setInputDone() {
5012
+ if (this.submitButtonView != null) {
5013
+ this.element.classList.add("input-done");
5014
+ }
5015
+ }
5016
+ _removeInputDone() {
5017
+ // if (this.submitButtonView != null) {
5018
+ setTimeout(() => {
5019
+ this.element.classList.add("border-radius-transition-250");
5020
+ this.env.requestAnimationFrame(() => {
5021
+ this.element.classList.remove("input-done");
5022
+ setTimeout(() => this.element.classList.remove("border-radius-transition-250"), 250);
5023
+ });
5024
+ }, 250);
5025
+ // }
5026
+ }
5027
+ _completeWidget() {
5028
+ this.localData["_v_g_" + this.elementId + "_done_at"] = Math.round(new Date().getTime() / 1000);
5029
+ // ответ на вопрос
5030
+ this.localData["_&ts_v_g_" + this.elementId + "_a_at"] = Math.round(new Date().getTime() / 1000);
5031
+ if (this.widgetDone) {
5032
+ this.widgetDone.classList.add("active", "opacity-active");
5033
+ setTimeout(() => {
5034
+ this.widgetDone?.classList.remove("active");
5035
+ setTimeout(() => {
5036
+ this.widgetDone?.classList.remove("opacity-active");
5037
+ }, 250);
5038
+ }, 2000);
5039
+ }
5040
+ this.setLocalData(this.localData, true);
5041
+ this._statEventVoteVariant();
5042
+ }
5043
+ submitMultipleChoice() {
5044
+ const variants = this._getCheckedVariants();
5045
+ if (variants.length > 0) {
5046
+ this.localData["_v_g_" + this.elementId + "_sa"] = variants;
5047
+ for (let i = 0; i < variants.length; ++i) {
5048
+ const index = variants[i];
5049
+ this._selectVariant(index);
5050
+ }
5051
+ if (!this.hideClientTotalResult) {
5052
+ this.displayPercents(variants);
5053
+ }
5054
+ this._fillWidget();
5055
+ this._completeWidget();
5056
+ }
5057
+ }
5058
+ click() {
5059
+ if (this.isDone()) {
5060
+ return true;
5061
+ }
5062
+ if (this.multipleChoice) {
5063
+ this.submitMultipleChoice();
5064
+ return false;
5065
+ }
5066
+ else {
5067
+ // for single mode - return true and sdk will proceed click as nextClick()
5068
+ return true;
5069
+ }
5070
+ }
5071
+ displayPercents(selectedVariantsIndexes, filled = false) {
4833
5072
  // voteAllocation[0] - variant total count allocation
4834
5073
  // voteAllocation[1]
4835
5074
  // ...
@@ -4851,7 +5090,7 @@ class WidgetVote extends WidgetBase {
4851
5090
  if (voteAllocation[key] === undefined || !isNumber(voteAllocation[key])) {
4852
5091
  voteAllocation[key] = 0;
4853
5092
  }
4854
- if (selectedVariantIndex === key) {
5093
+ if (selectedVariantsIndexes.includes(key)) {
4855
5094
  ++voteAllocation[key];
4856
5095
  }
4857
5096
  });
@@ -4907,12 +5146,13 @@ class WidgetVote extends WidgetBase {
4907
5146
  }
4908
5147
  }
4909
5148
  isDone() {
4910
- return this.localData["_v_g_" + this.elementId + "_done_at"] !== undefined;
5149
+ return this.localData["_v_g_" + this.elementId + "_done_at"] != null;
4911
5150
  }
4912
5151
  slideVoteIsDone() {
4913
- return this.localData["_v_g_" + this.elementId + "_sa"] !== undefined;
5152
+ return this.localData["_v_g_" + this.elementId + "_sa"] != null;
4914
5153
  }
4915
5154
  static api = {
5155
+ widgetClassName: WidgetVote.widgetClassName,
4916
5156
  refreshUserData: WidgetVote.refreshUserData,
4917
5157
  // fix for WidgetVote on every layer of multilayers story
4918
5158
  fallbackInitOnMultiSlide: function (element, localData) {
@@ -4950,6 +5190,16 @@ class WidgetVote extends WidgetBase {
4950
5190
  }
4951
5191
  return false;
4952
5192
  },
5193
+ click: function (element) {
5194
+ const widgetElement = element.closest(`.${WidgetVote.widgetClassName}`);
5195
+ if (widgetElement) {
5196
+ const widget = WidgetVote.getInstance(widgetElement);
5197
+ if (widget) {
5198
+ return widget.click();
5199
+ }
5200
+ }
5201
+ return true;
5202
+ },
4953
5203
  slideVoteIsDone: function (element) {
4954
5204
  const widget = WidgetVote.getInstance(element);
4955
5205
  if (widget) {