@inappstory/slide-api 0.0.8 → 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 +307 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +286 -235
- package/dist/index.d.ts +286 -235
- package/dist/index.js +307 -55
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
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
|
-
|
|
1314
|
-
this.sdkApi.
|
|
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.
|
|
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.
|
|
1670
|
+
this.startDisabledTimeline();
|
|
1636
1671
|
}
|
|
1637
1672
|
}
|
|
1638
1673
|
}
|
|
@@ -1749,7 +1784,7 @@ class WidgetDataInput extends WidgetBase {
|
|
|
1749
1784
|
this.setLocalData(this.localData, true);
|
|
1750
1785
|
this._statEventInputSave(text);
|
|
1751
1786
|
if (this.disableTimer) {
|
|
1752
|
-
this.
|
|
1787
|
+
this.startDisabledTimeline();
|
|
1753
1788
|
needResumeUITimer = false;
|
|
1754
1789
|
}
|
|
1755
1790
|
}
|
|
@@ -1758,6 +1793,7 @@ class WidgetDataInput extends WidgetBase {
|
|
|
1758
1793
|
}
|
|
1759
1794
|
}
|
|
1760
1795
|
static api = {
|
|
1796
|
+
widgetClassName: WidgetDataInput.widgetClassName,
|
|
1761
1797
|
refreshUserData: WidgetDataInput.refreshUserData,
|
|
1762
1798
|
initWidget: function (nodeList, localData) {
|
|
1763
1799
|
WidgetDataInput.initWidgets((element, options) => new WidgetDataInput(element, options), slice.call(nodeList), localData);
|
|
@@ -1971,6 +2007,7 @@ class WidgetDateCountdown extends WidgetBase {
|
|
|
1971
2007
|
return result;
|
|
1972
2008
|
}
|
|
1973
2009
|
static api = {
|
|
2010
|
+
widgetClassName: WidgetDateCountdown.widgetClassName,
|
|
1974
2011
|
refreshUserData: WidgetDateCountdown.refreshUserData,
|
|
1975
2012
|
initWidget: function (nodeList, layers, localData) {
|
|
1976
2013
|
WidgetDateCountdown.initWidgets((element, options) => new WidgetDateCountdown(element, { ...options, layers }), slice.call(nodeList), localData);
|
|
@@ -2261,7 +2298,7 @@ class WidgetPoll extends WidgetBase {
|
|
|
2261
2298
|
// todo poll - если виджет на первом слайде то при повторном заходе автоматически не стартует таймлайн слайда
|
|
2262
2299
|
// только в web sdk такое
|
|
2263
2300
|
// если поставить через setTimeout то все ок
|
|
2264
|
-
this.
|
|
2301
|
+
this.startDisabledTimeline();
|
|
2265
2302
|
});
|
|
2266
2303
|
}
|
|
2267
2304
|
}
|
|
@@ -2599,6 +2636,7 @@ class WidgetPoll extends WidgetBase {
|
|
|
2599
2636
|
return this.localData["_p_g_" + this.elementId + "_sa"] !== undefined;
|
|
2600
2637
|
}
|
|
2601
2638
|
static api = {
|
|
2639
|
+
widgetClassName: WidgetPoll.widgetClassName,
|
|
2602
2640
|
refreshUserData: WidgetPoll.refreshUserData,
|
|
2603
2641
|
initWidget: function (element, localData) {
|
|
2604
2642
|
WidgetPoll.initWidgets((element, options) => new WidgetPoll(element, options), [element], localData);
|
|
@@ -2727,7 +2765,7 @@ class WidgetPollLayers extends WidgetBase {
|
|
|
2727
2765
|
}
|
|
2728
2766
|
this._showLayout(this.layers, layerIndex, userAction);
|
|
2729
2767
|
if (this.disableTimer) {
|
|
2730
|
-
this.
|
|
2768
|
+
this.startDisabledTimeline();
|
|
2731
2769
|
}
|
|
2732
2770
|
}
|
|
2733
2771
|
selectVariant(variant) {
|
|
@@ -2764,6 +2802,7 @@ class WidgetPollLayers extends WidgetBase {
|
|
|
2764
2802
|
return this.localData != null && this.localData["_pl_g_" + this.elementId + "_sa"] !== undefined;
|
|
2765
2803
|
}
|
|
2766
2804
|
static api = {
|
|
2805
|
+
widgetClassName: WidgetPollLayers.widgetClassName,
|
|
2767
2806
|
refreshUserData: WidgetPollLayers.refreshUserData,
|
|
2768
2807
|
// signature variants
|
|
2769
2808
|
// (widget, layers, undefined) - modern web sdk
|
|
@@ -3047,6 +3086,7 @@ class WidgetQuest extends WidgetBase {
|
|
|
3047
3086
|
}
|
|
3048
3087
|
}
|
|
3049
3088
|
static api = {
|
|
3089
|
+
widgetClassName: WidgetQuest.widgetClassName,
|
|
3050
3090
|
refreshUserData: WidgetQuest.refreshUserData,
|
|
3051
3091
|
initWidget: function (element, localData) {
|
|
3052
3092
|
return new Promise(function (resolve, reject) {
|
|
@@ -3153,7 +3193,7 @@ class WidgetQuiz extends WidgetBase {
|
|
|
3153
3193
|
// })
|
|
3154
3194
|
// }
|
|
3155
3195
|
if (this.disableTimer) {
|
|
3156
|
-
this.
|
|
3196
|
+
this.startDisabledTimeline();
|
|
3157
3197
|
}
|
|
3158
3198
|
}
|
|
3159
3199
|
_clearAnswerSelection() {
|
|
@@ -3245,6 +3285,7 @@ class WidgetQuiz extends WidgetBase {
|
|
|
3245
3285
|
return this.localData["_q_g_" + this.elementId + "_sa"] !== undefined;
|
|
3246
3286
|
}
|
|
3247
3287
|
static api = {
|
|
3288
|
+
widgetClassName: WidgetQuiz.widgetClassName,
|
|
3248
3289
|
refreshUserData: WidgetQuiz.refreshUserData,
|
|
3249
3290
|
initWidget: function (element, localData) {
|
|
3250
3291
|
WidgetQuiz.initWidgets((element, options) => new WidgetQuiz(element, options), [element], localData);
|
|
@@ -3330,7 +3371,7 @@ class WidgetQuizGrouped extends WidgetBase {
|
|
|
3330
3371
|
}
|
|
3331
3372
|
});
|
|
3332
3373
|
if (this.disableTimer) {
|
|
3333
|
-
this.
|
|
3374
|
+
this.startDisabledTimeline();
|
|
3334
3375
|
}
|
|
3335
3376
|
}
|
|
3336
3377
|
_clearAnswerSelection() {
|
|
@@ -3439,6 +3480,7 @@ class WidgetQuizGrouped extends WidgetBase {
|
|
|
3439
3480
|
return this.localData["_q_gg_" + this.elementId + "_sa"] !== undefined;
|
|
3440
3481
|
}
|
|
3441
3482
|
static api = {
|
|
3483
|
+
widgetClassName: WidgetQuizGrouped.widgetClassName,
|
|
3442
3484
|
refreshUserData: WidgetQuizGrouped.refreshUserData,
|
|
3443
3485
|
initWidget: function (element, localData) {
|
|
3444
3486
|
WidgetQuizGrouped.initWidgets((element, options) => new WidgetQuizGrouped(element, options), [element], localData);
|
|
@@ -3691,7 +3733,7 @@ class WidgetRangeSlider extends WidgetBase {
|
|
|
3691
3733
|
this.element.classList.add("done");
|
|
3692
3734
|
this.displayAverageAnswer();
|
|
3693
3735
|
if (this.disableTimer) {
|
|
3694
|
-
this.
|
|
3736
|
+
this.startDisabledTimeline();
|
|
3695
3737
|
}
|
|
3696
3738
|
}
|
|
3697
3739
|
else {
|
|
@@ -3760,7 +3802,7 @@ class WidgetRangeSlider extends WidgetBase {
|
|
|
3760
3802
|
}
|
|
3761
3803
|
});
|
|
3762
3804
|
// if (this.disableTimer) {
|
|
3763
|
-
this.
|
|
3805
|
+
this.startDisabledTimeline();
|
|
3764
3806
|
// }
|
|
3765
3807
|
this.setLocalData(this.localData, true);
|
|
3766
3808
|
this._statEventInputSave(this.localData["_rs_g_" + this.elementId + "_v"]);
|
|
@@ -4048,6 +4090,7 @@ class WidgetRangeSlider extends WidgetBase {
|
|
|
4048
4090
|
// .removeData('plugin_' + pluginName);
|
|
4049
4091
|
}
|
|
4050
4092
|
static api = {
|
|
4093
|
+
widgetClassName: WidgetRangeSlider.widgetClassName,
|
|
4051
4094
|
refreshUserData: WidgetRangeSlider.refreshUserData,
|
|
4052
4095
|
initWidget: function (element, localData) {
|
|
4053
4096
|
WidgetRangeSlider.initWidgets((element, options) => new WidgetRangeSlider(element, options), [element], localData);
|
|
@@ -4172,7 +4215,7 @@ class WidgetRate extends WidgetBase {
|
|
|
4172
4215
|
this.localData["_r_g_" + this.elementId + "_ss"] = value;
|
|
4173
4216
|
this.element.classList.add("done");
|
|
4174
4217
|
if (this.disableTimer && runTimer) {
|
|
4175
|
-
this.
|
|
4218
|
+
this.startDisabledTimeline();
|
|
4176
4219
|
}
|
|
4177
4220
|
}
|
|
4178
4221
|
_clearSelectedStar() {
|
|
@@ -4296,6 +4339,7 @@ class WidgetRate extends WidgetBase {
|
|
|
4296
4339
|
return this.localData["_r_g_" + this.elementId + "_sa"] !== undefined;
|
|
4297
4340
|
}
|
|
4298
4341
|
static api = {
|
|
4342
|
+
widgetClassName: WidgetRate.widgetClassName,
|
|
4299
4343
|
refreshUserData: WidgetRate.refreshUserData,
|
|
4300
4344
|
initWidget: function (nodeList, localData) {
|
|
4301
4345
|
WidgetRate.initWidgets((element, options) => new WidgetRate(element, options), slice.call(nodeList), localData);
|
|
@@ -4418,6 +4462,7 @@ class WidgetShare extends WidgetBase {
|
|
|
4418
4462
|
return Boolean(this.localData["_s_" + this.elementId + "_ts"]);
|
|
4419
4463
|
}
|
|
4420
4464
|
static api = {
|
|
4465
|
+
widgetClassName: WidgetShare.widgetClassName,
|
|
4421
4466
|
refreshUserData: WidgetShare.refreshUserData,
|
|
4422
4467
|
// signature variants
|
|
4423
4468
|
// (widget, layers, undefined) - modern web sdk
|
|
@@ -4537,6 +4582,11 @@ class WidgetTest extends WidgetBase {
|
|
|
4537
4582
|
this.timeline.style.transform = "translateX(100%)";
|
|
4538
4583
|
}
|
|
4539
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
|
+
}
|
|
4540
4590
|
}
|
|
4541
4591
|
}
|
|
4542
4592
|
// this.refreshUserData(this.options.localData);
|
|
@@ -4592,7 +4642,7 @@ class WidgetTest extends WidgetBase {
|
|
|
4592
4642
|
}
|
|
4593
4643
|
});
|
|
4594
4644
|
if (this.disableTimer) {
|
|
4595
|
-
this.
|
|
4645
|
+
this.startDisabledTimeline();
|
|
4596
4646
|
}
|
|
4597
4647
|
}
|
|
4598
4648
|
selectAnswer(answer) {
|
|
@@ -4636,6 +4686,10 @@ class WidgetTest extends WidgetBase {
|
|
|
4636
4686
|
}
|
|
4637
4687
|
// answer on question
|
|
4638
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
|
+
}
|
|
4639
4693
|
if (this.widgetDone) {
|
|
4640
4694
|
this.widgetDone.classList.add("active", "opacity-active");
|
|
4641
4695
|
setTimeout(() => {
|
|
@@ -4658,6 +4712,7 @@ class WidgetTest extends WidgetBase {
|
|
|
4658
4712
|
return Boolean(this.withTimeToAnswer && this.answerTimeout);
|
|
4659
4713
|
}
|
|
4660
4714
|
static api = {
|
|
4715
|
+
widgetClassName: WidgetTest.widgetClassName,
|
|
4661
4716
|
refreshUserData: WidgetTest.refreshUserData,
|
|
4662
4717
|
initWidget: function (element, localData) {
|
|
4663
4718
|
WidgetTest.initWidgets((element, options) => new WidgetTest(element, options), [element], localData);
|
|
@@ -4711,6 +4766,7 @@ class WidgetVote extends WidgetBase {
|
|
|
4711
4766
|
selectedVariant;
|
|
4712
4767
|
voteAllocation;
|
|
4713
4768
|
hideClientTotalResult;
|
|
4769
|
+
multipleChoice;
|
|
4714
4770
|
/**
|
|
4715
4771
|
* @throws Error
|
|
4716
4772
|
* @param element
|
|
@@ -4729,38 +4785,112 @@ class WidgetVote extends WidgetBase {
|
|
|
4729
4785
|
}
|
|
4730
4786
|
});
|
|
4731
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);
|
|
4732
4827
|
this.selectedVariant = undefined;
|
|
4733
4828
|
if (this.localData) {
|
|
4734
|
-
if (this.localData["_v_g_" + this.elementId + "_sa"]
|
|
4735
|
-
this.
|
|
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");
|
|
4736
4837
|
}
|
|
4737
4838
|
}
|
|
4738
4839
|
this.firstOpenTime = new Date().getTime();
|
|
4739
|
-
// this.refreshUserData(this.options.localData);
|
|
4740
4840
|
}
|
|
4741
|
-
|
|
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
|
+
}
|
|
4742
4848
|
_statEventVoteVariant() {
|
|
4743
4849
|
try {
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
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
|
+
// первые оставляем пустыми в этом случае
|
|
4748
4874
|
this.sendStatisticEventToApp("w-vote-answer", {
|
|
4749
4875
|
i: this.storyId,
|
|
4750
4876
|
si: this.slideIndex,
|
|
4751
4877
|
wi: this.elementId,
|
|
4752
4878
|
wl: labelText,
|
|
4753
|
-
wa:
|
|
4879
|
+
wa: selectedVariant,
|
|
4754
4880
|
wv: variantText,
|
|
4755
4881
|
d: duration,
|
|
4882
|
+
was: selectedVariantsIdxs,
|
|
4883
|
+
wvs: selectedVariantsLabels,
|
|
4756
4884
|
}, {
|
|
4757
4885
|
story_id: this.storyId,
|
|
4758
4886
|
slide_index: this.slideIndex,
|
|
4759
4887
|
widget_id: this.elementId,
|
|
4760
4888
|
widget_label: labelText,
|
|
4761
|
-
widget_answer:
|
|
4889
|
+
widget_answer: selectedVariant,
|
|
4762
4890
|
widget_value: variantText,
|
|
4763
4891
|
duration_ms: duration,
|
|
4892
|
+
widget_answers: selectedVariantsIdxs,
|
|
4893
|
+
widget_values: selectedVariantsLabels,
|
|
4764
4894
|
});
|
|
4765
4895
|
}
|
|
4766
4896
|
}
|
|
@@ -4768,15 +4898,33 @@ class WidgetVote extends WidgetBase {
|
|
|
4768
4898
|
console.error(error);
|
|
4769
4899
|
}
|
|
4770
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
|
+
}
|
|
4771
4921
|
_selectVariant(index, filled = false) {
|
|
4772
4922
|
if (this.variants[index]) {
|
|
4773
4923
|
this.variants[index].classList.add("selected");
|
|
4774
4924
|
}
|
|
4775
4925
|
this.selectedVariant = index;
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
if (filled) {
|
|
4779
|
-
this.element.classList.add("filled");
|
|
4926
|
+
if (!this.multipleChoice) {
|
|
4927
|
+
this.localData["_v_g_" + this.elementId + "_sa"] = index;
|
|
4780
4928
|
}
|
|
4781
4929
|
if (this.hideClientTotalResult) {
|
|
4782
4930
|
const cb = () => {
|
|
@@ -4791,43 +4939,136 @@ class WidgetVote extends WidgetBase {
|
|
|
4791
4939
|
this.env.requestAnimationFrame(cb);
|
|
4792
4940
|
}
|
|
4793
4941
|
}
|
|
4794
|
-
|
|
4795
|
-
|
|
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
|
+
}
|
|
4796
4953
|
}
|
|
4954
|
+
if (this.multipleChoice) {
|
|
4955
|
+
this._removeInputDone();
|
|
4956
|
+
this._hideSubmitBtn();
|
|
4957
|
+
}
|
|
4958
|
+
if (this.disableTimer) {
|
|
4959
|
+
this.startDisabledTimeline();
|
|
4960
|
+
}
|
|
4961
|
+
}
|
|
4962
|
+
_showSubmitBtn() {
|
|
4797
4963
|
this.env.requestAnimationFrame(() => {
|
|
4798
4964
|
if (this.submitButtonAnimatedView != null && this.submitButtonViewHeight != null) {
|
|
4799
4965
|
this.submitButtonAnimatedView.style.maxHeight = this.submitButtonViewHeight + "px";
|
|
4800
4966
|
}
|
|
4801
4967
|
});
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4968
|
+
}
|
|
4969
|
+
_hideSubmitBtn() {
|
|
4970
|
+
this.env.requestAnimationFrame(() => {
|
|
4971
|
+
if (this.submitButtonAnimatedView != null && this.submitButtonViewHeight != null) {
|
|
4972
|
+
this.submitButtonAnimatedView.style.maxHeight = "0px";
|
|
4973
|
+
}
|
|
4974
|
+
});
|
|
4805
4975
|
}
|
|
4806
4976
|
selectVariant(variant) {
|
|
4807
|
-
if (this.
|
|
4808
|
-
|
|
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
|
+
}
|
|
4809
4986
|
}
|
|
4810
4987
|
var selectedVariantIndex = this.variants.indexOf(variant);
|
|
4811
4988
|
if (selectedVariantIndex !== -1) {
|
|
4812
|
-
this.
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
this.
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
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();
|
|
4824
5007
|
}
|
|
4825
|
-
this.setLocalData(this.localData, true);
|
|
4826
|
-
this._statEventVoteVariant();
|
|
4827
5008
|
}
|
|
4828
5009
|
return false;
|
|
4829
5010
|
}
|
|
4830
|
-
|
|
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) {
|
|
4831
5072
|
// voteAllocation[0] - variant total count allocation
|
|
4832
5073
|
// voteAllocation[1]
|
|
4833
5074
|
// ...
|
|
@@ -4849,7 +5090,7 @@ class WidgetVote extends WidgetBase {
|
|
|
4849
5090
|
if (voteAllocation[key] === undefined || !isNumber(voteAllocation[key])) {
|
|
4850
5091
|
voteAllocation[key] = 0;
|
|
4851
5092
|
}
|
|
4852
|
-
if (
|
|
5093
|
+
if (selectedVariantsIndexes.includes(key)) {
|
|
4853
5094
|
++voteAllocation[key];
|
|
4854
5095
|
}
|
|
4855
5096
|
});
|
|
@@ -4905,12 +5146,13 @@ class WidgetVote extends WidgetBase {
|
|
|
4905
5146
|
}
|
|
4906
5147
|
}
|
|
4907
5148
|
isDone() {
|
|
4908
|
-
return this.localData["_v_g_" + this.elementId + "_done_at"]
|
|
5149
|
+
return this.localData["_v_g_" + this.elementId + "_done_at"] != null;
|
|
4909
5150
|
}
|
|
4910
5151
|
slideVoteIsDone() {
|
|
4911
|
-
return this.localData["_v_g_" + this.elementId + "_sa"]
|
|
5152
|
+
return this.localData["_v_g_" + this.elementId + "_sa"] != null;
|
|
4912
5153
|
}
|
|
4913
5154
|
static api = {
|
|
5155
|
+
widgetClassName: WidgetVote.widgetClassName,
|
|
4914
5156
|
refreshUserData: WidgetVote.refreshUserData,
|
|
4915
5157
|
// fix for WidgetVote on every layer of multilayers story
|
|
4916
5158
|
fallbackInitOnMultiSlide: function (element, localData) {
|
|
@@ -4948,6 +5190,16 @@ class WidgetVote extends WidgetBase {
|
|
|
4948
5190
|
}
|
|
4949
5191
|
return false;
|
|
4950
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
|
+
},
|
|
4951
5203
|
slideVoteIsDone: function (element) {
|
|
4952
5204
|
const widget = WidgetVote.getInstance(element);
|
|
4953
5205
|
if (widget) {
|