@textback/notification-widget 2.0.3 → 2.0.4-110500

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.
Files changed (126) hide show
  1. package/build/index.js +12 -0
  2. package/{release/builds/textback/notificationwidget/build → build}/sdk.js +2 -2
  3. package/package.json +2 -2
  4. package/src/widget/components/tb-notification-widget/index.js +22 -6
  5. package/src/widget/components/tb-nw-wahunter/index.js +4 -2
  6. package/src/widget/icons/tb-logo-dark-en.svg +17 -0
  7. package/src/widget/icons/tb-logo-dark-ru.svg +17 -0
  8. package/src/widget/icons/tb-logo-dark.svg +16 -0
  9. package/src/widget/icons/tb-logo-light-en.svg +17 -0
  10. package/src/widget/icons/tb-logo-light-ru.svg +17 -0
  11. package/src/widget/icons/tb-logo-white.svg +16 -0
  12. package/src/widget/icons/tb-logo.svg +15 -20
  13. package/release/builds/textback/notificationwidget/.eslintrc.js +0 -291
  14. package/release/builds/textback/notificationwidget/.gitlab-ci.yml +0 -34
  15. package/release/builds/textback/notificationwidget/build/index.js +0 -12
  16. package/release/builds/textback/notificationwidget/package-lock.json +0 -9985
  17. package/release/builds/textback/notificationwidget/package.json +0 -70
  18. package/release/builds/textback/notificationwidget/promote_tag.sh +0 -2
  19. package/release/builds/textback/notificationwidget/readme.md +0 -569
  20. package/release/builds/textback/notificationwidget/server.js +0 -224
  21. package/release/builds/textback/notificationwidget/src/libraries/ai.1.0.11.js +0 -4089
  22. package/release/builds/textback/notificationwidget/src/libraries/localization/getLocale.js +0 -17
  23. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/.tern-port +0 -1
  24. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/cs.js +0 -23
  25. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/en.js +0 -23
  26. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/index.js +0 -9
  27. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/pl.js +0 -23
  28. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/ro.js +0 -23
  29. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/ru.js +0 -22
  30. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/uk.js +0 -23
  31. package/release/builds/textback/notificationwidget/src/libraries/localization/text.js +0 -9
  32. package/release/builds/textback/notificationwidget/src/libraries/t.js +0 -82
  33. package/release/builds/textback/notificationwidget/src/sdk/channels/channel.js +0 -31
  34. package/release/builds/textback/notificationwidget/src/sdk/channels/facebook.js +0 -13
  35. package/release/builds/textback/notificationwidget/src/sdk/channels/factory.js +0 -34
  36. package/release/builds/textback/notificationwidget/src/sdk/channels/skype.js +0 -13
  37. package/release/builds/textback/notificationwidget/src/sdk/channels/telegram.js +0 -18
  38. package/release/builds/textback/notificationwidget/src/sdk/channels/viber.js +0 -13
  39. package/release/builds/textback/notificationwidget/src/sdk/channels/vk-modal/vk-modal.html +0 -17
  40. package/release/builds/textback/notificationwidget/src/sdk/channels/vk-modal/vk-modal.js +0 -25
  41. package/release/builds/textback/notificationwidget/src/sdk/channels/vk-modal/vk-modal.scss +0 -116
  42. package/release/builds/textback/notificationwidget/src/sdk/channels/vk.js +0 -195
  43. package/release/builds/textback/notificationwidget/src/sdk/channels/whatsapp.js +0 -27
  44. package/release/builds/textback/notificationwidget/src/sdk/channels/whatsappb.js +0 -27
  45. package/release/builds/textback/notificationwidget/src/sdk/events/observer.js +0 -46
  46. package/release/builds/textback/notificationwidget/src/sdk/index.js +0 -6
  47. package/release/builds/textback/notificationwidget/src/sdk/sdk.entry.js +0 -1
  48. package/release/builds/textback/notificationwidget/src/sdk/sdk.js +0 -67
  49. package/release/builds/textback/notificationwidget/src/sdk/utils/apiErrorHandler.js +0 -12
  50. package/release/builds/textback/notificationwidget/src/sdk/utils/appInsights.js +0 -88
  51. package/release/builds/textback/notificationwidget/src/sdk/utils/browserInfo.js +0 -9
  52. package/release/builds/textback/notificationwidget/src/sdk/utils/constants.js +0 -18
  53. package/release/builds/textback/notificationwidget/src/sdk/utils/cookies.js +0 -67
  54. package/release/builds/textback/notificationwidget/src/sdk/utils/find.js +0 -8
  55. package/release/builds/textback/notificationwidget/src/sdk/utils/loadConfig.js +0 -21
  56. package/release/builds/textback/notificationwidget/src/sdk/utils/loadDeepLink.js +0 -48
  57. package/release/builds/textback/notificationwidget/src/sdk/utils/loadScript.js +0 -26
  58. package/release/builds/textback/notificationwidget/src/sdk/utils/loadSubscriptions.js +0 -6
  59. package/release/builds/textback/notificationwidget/src/sdk/utils/parseQueryString.js +0 -34
  60. package/release/builds/textback/notificationwidget/src/sdk/utils/windowHelper.js +0 -25
  61. package/release/builds/textback/notificationwidget/src/sdk/widget/widget.js +0 -192
  62. package/release/builds/textback/notificationwidget/src/widget/components/index.js +0 -52
  63. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/facebook.js +0 -55
  64. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/index.js +0 -35
  65. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/styles.scss +0 -657
  66. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/telegram.js +0 -55
  67. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/viber.js +0 -57
  68. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/vk.js +0 -92
  69. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/whatsapp.js +0 -58
  70. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/whatsappb.js +0 -58
  71. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-widget/index.js +0 -678
  72. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-widget/normalize.scss +0 -395
  73. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-widget/styles.scss +0 -543
  74. package/release/builds/textback/notificationwidget/src/widget/components/tb-nw-wahunter/index.js +0 -259
  75. package/release/builds/textback/notificationwidget/src/widget/components/tb-nw-wahunter/styles.scss +0 -471
  76. package/release/builds/textback/notificationwidget/src/widget/config.js +0 -5
  77. package/release/builds/textback/notificationwidget/src/widget/icons/bell-icon.png +0 -0
  78. package/release/builds/textback/notificationwidget/src/widget/icons/broadcast-icon.png +0 -0
  79. package/release/builds/textback/notificationwidget/src/widget/icons/icon_chat_window.svg +0 -1
  80. package/release/builds/textback/notificationwidget/src/widget/icons/icon_close.svg +0 -1
  81. package/release/builds/textback/notificationwidget/src/widget/icons/icon_facebook.svg +0 -7
  82. package/release/builds/textback/notificationwidget/src/widget/icons/icon_facebook_circle.svg +0 -7
  83. package/release/builds/textback/notificationwidget/src/widget/icons/icon_instagram_circle.svg +0 -96
  84. package/release/builds/textback/notificationwidget/src/widget/icons/icon_skype.svg +0 -44
  85. package/release/builds/textback/notificationwidget/src/widget/icons/icon_skype_circle.svg +0 -46
  86. package/release/builds/textback/notificationwidget/src/widget/icons/icon_skype_new.svg +0 -114
  87. package/release/builds/textback/notificationwidget/src/widget/icons/icon_tg.svg +0 -25
  88. package/release/builds/textback/notificationwidget/src/widget/icons/icon_tg_circle.svg +0 -17
  89. package/release/builds/textback/notificationwidget/src/widget/icons/icon_viber.svg +0 -75
  90. package/release/builds/textback/notificationwidget/src/widget/icons/icon_viber_circle.svg +0 -67
  91. package/release/builds/textback/notificationwidget/src/widget/icons/icon_viber_new.svg +0 -102
  92. package/release/builds/textback/notificationwidget/src/widget/icons/icon_vk.svg +0 -14
  93. package/release/builds/textback/notificationwidget/src/widget/icons/icon_vk_circle.svg +0 -16
  94. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp.svg +0 -147
  95. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp_circle.svg +0 -4
  96. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp_hollow.svg +0 -128
  97. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp_new.svg +0 -127
  98. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsappb.svg +0 -147
  99. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsappb_circle.svg +0 -4
  100. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsappb_new.svg +0 -127
  101. package/release/builds/textback/notificationwidget/src/widget/icons/paper-plane-arrow.svg +0 -3
  102. package/release/builds/textback/notificationwidget/src/widget/icons/paper-plane-icon.png +0 -0
  103. package/release/builds/textback/notificationwidget/src/widget/icons/tb-logo.svg +0 -21
  104. package/release/builds/textback/notificationwidget/src/widget/index.js +0 -29
  105. package/release/builds/textback/notificationwidget/src/widget/locales/cs.js +0 -42
  106. package/release/builds/textback/notificationwidget/src/widget/locales/en.js +0 -42
  107. package/release/builds/textback/notificationwidget/src/widget/locales/index.js +0 -9
  108. package/release/builds/textback/notificationwidget/src/widget/locales/pl.js +0 -42
  109. package/release/builds/textback/notificationwidget/src/widget/locales/ro.js +0 -41
  110. package/release/builds/textback/notificationwidget/src/widget/locales/ru.js +0 -41
  111. package/release/builds/textback/notificationwidget/src/widget/locales/uk.js +0 -41
  112. package/release/builds/textback/notificationwidget/src/widget/utils/cookiesEx.js +0 -41
  113. package/release/builds/textback/notificationwidget/src/widget/utils/getLocale.js +0 -17
  114. package/release/builds/textback/notificationwidget/src/widget/utils/stringifyAttributes.js +0 -19
  115. package/release/builds/textback/notificationwidget/src/widget/utils/text.js +0 -10
  116. package/release/builds/textback/notificationwidget/src/widget/utils/widgetsStorage.js +0 -28
  117. package/release/builds/textback/notificationwidget/src/widget/widget.entry.js +0 -3
  118. package/release/builds/textback/notificationwidget/tests/gf.html +0 -35
  119. package/release/builds/textback/notificationwidget/tests/gf.js +0 -22
  120. package/release/builds/textback/notificationwidget/tests/index.js +0 -62
  121. package/release/builds/textback/notificationwidget/views/examples.ejs +0 -51
  122. package/release/builds/textback/notificationwidget/views/sdk.html +0 -274
  123. package/release/builds/textback/notificationwidget/webpack.common.js +0 -72
  124. package/release/builds/textback/notificationwidget/webpack.dev.js +0 -15
  125. package/release/builds/textback/notificationwidget/webpack.prod.js +0 -10
  126. package/widget.tar.gz +0 -0
@@ -1,678 +0,0 @@
1
- import MobileDetect from 'mobile-detect';
2
- import assign from 'lodash/assign';
3
- import Component from '../index.js';
4
-
5
- import stringifyAttributes from '../../utils/stringifyAttributes.js';
6
- import cookiesEx from '../../utils/cookiesEx.js';
7
- import appInsights from '../../../sdk/utils/appInsights';
8
- import config from '../../config';
9
- import widgetsStorage from '../../utils/widgetsStorage.js';
10
-
11
- import constants from '../../../sdk/utils/constants';
12
- import SDK from '../../../sdk/index.js';
13
-
14
- import iconBell from '../../icons/bell-icon.png';
15
- import iconBroadcast from '../../icons/broadcast-icon.png';
16
- import iconPaperPlane from '../../icons/paper-plane-icon.png';
17
- import iconTbLogo from '../../icons/tb-logo.svg'
18
- import iconChatWindow from '../../icons/icon_whatsapp_hollow.svg';
19
- import iconClose from '../../icons/icon_close.svg';
20
-
21
- import './normalize.scss';
22
- import './styles.scss';
23
-
24
- import Wahunter from '../tb-nw-wahunter/index.js';
25
-
26
-
27
- const channelButtons = {
28
- vk: require('../tb-notification-button/vk'),
29
- tg: require('../tb-notification-button/telegram'),
30
- facebook: require('../tb-notification-button/facebook'),
31
- viber: require('../tb-notification-button/viber'),
32
- whatsapp: require('../tb-notification-button/whatsapp'),
33
- whatsappb: require('../tb-notification-button/whatsappb')
34
- };
35
-
36
- const DEFAULT_BUTTONS_MARKUP = {
37
- style: 'gradient',
38
- displayMode: 'horizontal',
39
- align: 'center',
40
- };
41
-
42
- const getDeviceDisplayMap = () => {
43
- const md = new MobileDetect(window.navigator.userAgent);
44
- const isDesktop = () => !(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
45
-
46
- return new Map([
47
- ['pc', isDesktop()],
48
- ['mobile', md.phone()],
49
- ['tablet', md.tablet()]
50
- ]);
51
- };
52
-
53
- const showOnDevice = deviceList => {
54
- if (deviceList === null || deviceList === undefined) return true;
55
-
56
- return deviceList.map(i => getDeviceDisplayMap().get(i)).some(x => x);
57
- };
58
-
59
- export default class Widget extends Component {
60
- constructor() {
61
- super(...arguments);
62
-
63
- this.apiPath = this.apiPath || config.apiPath;
64
- this.onlyManual = this.onlyManual || this.element.hasAttribute('only-manual');
65
- this.previewMode = this.previewMode || this.element.hasAttribute('preview-mode');
66
-
67
- const predefinedConfig = this.widgetConfig;
68
-
69
- //override widgetId property with data from widgetConfig
70
- if (!!predefinedConfig) {
71
- this.widgetId = predefinedConfig.id;
72
- }
73
-
74
- let widgetInitPromise = SDK.getWidget(this.widgetId);
75
-
76
- if (!widgetInitPromise) {
77
- // init widget
78
- widgetInitPromise = SDK.initWidget({
79
- widgetId: this.widgetId,
80
- apiPath: this.apiPath,
81
- insecureContext: this.data,
82
- secureContextToken: this.secureContextToken,
83
- overrideConfig: predefinedConfig,
84
- }, this.previewMode);
85
- }
86
-
87
- widgetInitPromise = widgetInitPromise
88
- .then(widget => {
89
- this.widget = widget;
90
-
91
- this.widgetUserId = widget.widgetUserId;
92
- this.config = widget.getConfig();
93
- this.config.type = this.config.type || constants.DEFAULT_WIDGET_TYPE;
94
- this.config.markUp = this.config.markUp || {};
95
- this.config.markUp.buttons = assign({}, DEFAULT_BUTTONS_MARKUP, this.config.markUp.buttons);
96
-
97
- this.widgetSubscriptions = widget.subscriptions;
98
- this.deepLink = widget.deeplink;
99
- this.lang = this.config.lang
100
-
101
- this.showWidgetSetting = (this.widget.config && this.widget.config.showWidgetSetting)
102
- ? this.widget.config.showWidgetSetting.devices
103
- : null;
104
-
105
- const aiKey = widget.aiKey;
106
-
107
-
108
-
109
- return appInsights.init(aiKey, this.widgetUserId, this.config.accountId);
110
- })
111
- .then(res => {
112
- this.set({
113
- ready: showOnDevice(this.showWidgetSetting)
114
- });
115
- return this;
116
- }, err => {
117
- console.error(err);
118
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.error', err);
119
- this.set({ error: err });
120
- return this;
121
- });
122
-
123
- widgetsStorage.setWidget(this.widgetId, widgetInitPromise);
124
- }
125
-
126
- get defaults() {
127
- return {
128
- widgetId: this.element.getAttribute('widget-id'),
129
- secureContextToken: this.element.getAttribute('secure-context-token'),
130
- apiPath: this.element.getAttribute('api-path') || config.apiPath
131
- };
132
- }
133
-
134
- render() {
135
- super.render();
136
-
137
- const wahunterElem = this.element.querySelector('tb-nw-wahunter');
138
-
139
- if (wahunterElem) {
140
- new Wahunter({
141
- element: wahunterElem,
142
- widgetAPI: this.widget,
143
- parentElement: this.element,
144
- });
145
- }
146
-
147
- this.element.id = this.element.id ? this.element.id : 'tb-notification-widget';
148
-
149
- const buttons = this.element.querySelectorAll('tb-notification-button');
150
-
151
- if (buttons) {
152
- for (let i = 0; i < buttons.length; i++) {
153
- const channel = buttons[i].getAttribute('channel');
154
- new channelButtons[channel]({
155
- element: buttons[i],
156
- accountId: this.config.accountId,
157
- userId: this.userId,
158
- apiPath: this.apiPath,
159
- insecureContext: this.data,
160
- secureContextToken: this.secureContextToken,
161
- deepLink: this.deepLink,
162
- lang: this.lang,
163
- vkApiId: this.config.vkApiId,
164
- widgetId: this.config.id,
165
- widget: this,
166
- widgetAPI: this.widget,
167
- });
168
- }
169
- }
170
-
171
- if (!this.config || !this.config.displayMode) return;
172
-
173
- if (this.config.displayMode === "popup") {
174
- let sessionShowCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_s_show_counter';
175
- let daysShowCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_days_show_counter';
176
- let daysCloseCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_days_close_counter';
177
- let totalCloseCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_total_close_counter';
178
- let showWidgetSetting = this.config.showWidgetSetting;
179
- let popup = this.element.getElementsByTagName("tb-notification-widget-overlay")[0];
180
-
181
- this.element.addEventListener("click", (e) => {
182
- const target = e.target;
183
-
184
- if (!target.matches('#tb-notification-widget-close') && !target.matches('tb-notification-widget-overlay')) return;
185
-
186
- popup.className += " hidden closed";
187
- e.preventDefault();
188
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.click.close', 'userAction');
189
- if (showWidgetSetting) {
190
- let daysTimeout = showWidgetSetting.showAfterDays * constants.SECONDS_IN_DAY;
191
-
192
- cookiesEx.incrementIntCookie(daysCloseCounterName, daysTimeout);
193
- cookiesEx.incrementIntCookie(totalCloseCounterName, constants.WIDGET_USER_ID_COOKIE_TTL);
194
- }
195
- });
196
-
197
-
198
- if (this.config.widgetKind === 'WAHUNTER') {
199
- // For uniformity of config object, "showIfSubscribed" here is "show wahunter again if it allready was run"
200
- const wahunterWasRun = cookiesEx.getBoolCookie(`${constants.COOKIE_NAME_PREFIX + this.widgetId}_wahunter_was_run`);
201
- const showIfWasRun = showWidgetSetting.showIfSubscribed;
202
-
203
- if (wahunterWasRun && !showIfWasRun) return;
204
- }
205
-
206
-
207
- if (showWidgetSetting) {
208
- if (!showWidgetSetting.showIfSubscribed && this.widgetSubscriptions.length > 0) {
209
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.popup.notShown', 'alreadySubscribed');
210
- return;
211
- }
212
-
213
- let daysTimeout = showWidgetSetting.showAfterDays * constants.SECONDS_IN_DAY;
214
- let sessionTimeout = showWidgetSetting.showSessionLength * 60;
215
- let daysShowCounter = cookiesEx.incrementIntCookie(daysShowCounterName, daysTimeout);
216
- let sessionShowCounter = cookiesEx.incrementIntCookie(sessionShowCounterName, sessionTimeout);
217
- let daysCloseCounter = cookiesEx.getIntCookie(daysCloseCounterName) || 0;
218
- let totalCloseCounter = cookiesEx.getIntCookie(totalCloseCounterName) || 0;
219
-
220
- const sendNonDisplayed = (reason) => {
221
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.popup.notShown', reason);
222
- return true;
223
- };
224
-
225
- if (sessionShowCounter > showWidgetSetting.showTimesInSession && sendNonDisplayed('timesPerSession') || // Не более N раз в сессию
226
- (showWidgetSetting.showTimesInRow > 0 && daysShowCounter > showWidgetSetting.showTimesInRow && sendNonDisplayed('timesPerDays')) ||// Не более N раз в M дней
227
- (showWidgetSetting.closeTimesInRow > 0 && daysCloseCounter >= showWidgetSetting.closeTimesInRow && sendNonDisplayed('closedTimesPerDays')) || // Не более N закрытий в M дней
228
- (showWidgetSetting.closeTimesInTotal > 0 && totalCloseCounter >= showWidgetSetting.closeTimesInTotal && sendNonDisplayed('closedTimes')) // Не более N закрытий всего
229
- ) {
230
- return;
231
- }
232
- }
233
-
234
- if (this.onlyManual) {
235
- popup.className = 'hidden';
236
- return;
237
- }
238
-
239
- if (this.config.displayOptions && (this.config.displayOptions.onTimeout || this.config.displayOptions.onLeave)) {
240
- let telemetryFlag = false;
241
-
242
- if (this.config.displayOptions.onTimeout && showOnDevice(this.showWidgetSetting)) {
243
- setTimeout(() => {
244
- if (popup.className.indexOf('closed') === -1 && !telemetryFlag) {
245
- telemetryFlag = true;
246
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.popup.show', 'timeout');
247
- }
248
- popup.className = popup.className.indexOf('closed') === -1 ? "" : popup.className;
249
- }, +this.config.displayOptions.timeoutDelay * 1000);
250
- }
251
-
252
- if (this.config.displayOptions.onLeave && showOnDevice(this.showWidgetSetting)) {
253
- document.addEventListener('mousemove', (e) => {
254
- if (e.clientY < 50) {
255
- if (popup.className.indexOf('closed') === -1 && !telemetryFlag) {
256
- telemetryFlag = true;
257
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.popup.show', 'onLeave');
258
- }
259
- popup.className = popup.className.indexOf('closed') === -1 ? "" : popup.className;
260
- }
261
- });
262
- }
263
- }
264
- }
265
-
266
- if (this.config.displayMode === "corner-popup" && showOnDevice(this.showWidgetSetting)) {
267
- const popupControlButtonElem = this.element.querySelector('tb-widget-corner-popup-button');
268
- const popupElem = popupControlButtonElem.parentElement;
269
- const popupTooltipContainer = popupElem.querySelector('tb-widget-corner-popup-tooltip-container');
270
- const fullscreenCloseButtonElem = popupElem.querySelector('.tb-fullscreen-close-rectangle .tb-icon-close');
271
-
272
- fullscreenCloseButtonElem.addEventListener('click', (e) => {
273
- popupElem.classList.remove('tb-opened-corner-popup');
274
- });
275
-
276
- popupControlButtonElem.addEventListener('click', (e) => {
277
- popupElem.classList.toggle('tb-opened-corner-popup');
278
- });
279
-
280
- popupElem.addEventListener('wahunter-success', (e) => {
281
- popupTooltipContainer.style.display = 'none';
282
- });
283
- }
284
- }
285
-
286
- get header() {
287
- if (this.config.markUp && this.config.markUp.header && this.config.markUp.header.value) {
288
- var color = this.config.markUp.header.color ? 'style="color: ' + this.config.markUp.header.color + '"' : undefined;
289
- var result = '';
290
-
291
- result += '<tb-widget-header-line ' + color + ' class="tb-widget-header-line">' + this.config.markUp.header.value + '</tb-widget-header-line>';
292
-
293
- return '<tb-widget-header-container>' + result + '</tb-widget-header-container>';
294
- } else {
295
- return '';
296
- }
297
- }
298
-
299
- get description() {
300
- if (this.config.markUp && this.config.markUp.description && this.config.markUp.description.value) {
301
- var color = this.config.markUp.description.color ? 'style="color: ' + this.config.markUp.description.color + '"' : undefined;
302
- var result = '';
303
-
304
- result += '<tb-widget-description-line ' + color + ' class="tb-widget-description-line">' + this.config.markUp.description.value + '</tb-widget-description-line>'
305
-
306
- return '<tb-widget-description-container>' + result + '</tb-widget-description-container>';
307
- }
308
- else {
309
- return '';
310
- }
311
- }
312
-
313
- static iconPreset(val) {
314
- switch (val) {
315
- case 'widgetIconBell':
316
- return iconBell;
317
- case 'widgetIconBroadcast':
318
- return iconBroadcast;
319
- case 'widgetIconPaperPlane':
320
- return iconPaperPlane;
321
- }
322
-
323
- }
324
-
325
- get icon() {
326
- if (this.config.markUp && this.config.markUp.icon && this.config.markUp.icon.type === "custom") {
327
- return '<tb-notification-widget-icon_body>'
328
- + '<img src="' + this.config.markUp.icon.url + '">'
329
- + '</tb-notification-widget-icon_body>'
330
- }
331
- if (this.config.markUp && this.config.markUp.icon && this.config.markUp.icon.type === "preset") {
332
- return '<tb-notification-widget-icon_body>'
333
- + '<img src="' + Widget.iconPreset(this.config.markUp.icon.value) + '">'
334
- + '</tb-notification-widget-icon_body>'
335
- }
336
- else {
337
- return '';
338
- }
339
- }
340
-
341
-
342
-
343
- getTbBrandBadge({ displayMode, widgetKind }) {
344
- const utmMedium = widgetKind === 'WAHUNTER' ? 'hunter' : 'widget-subscribe';
345
-
346
- if (widgetKind === 'WAHUNTER') {
347
- return `
348
- <a target="_blank"
349
- href="//textback.ru/?utm_source=TextBack_tool&utm_medium=${utmMedium}&utm_campaign=${window.location.origin}${window.location.pathname}&utm_content=${displayMode}"
350
-
351
- id="tb-notification-brand-badge"
352
- style="${displayMode === 'inline' ? 'fill:inherit; color: inherit;' : ''}"
353
- >
354
- ${this.text('worksFor')} ${iconTbLogo}
355
- </a>
356
- `;
357
- }
358
-
359
- return `
360
- <a target="_blank"
361
- href="//textback.ru/?utm_source=TextBack_tool&utm_medium=${utmMedium}&utm_campaign=${window.location.origin}${window.location.pathname}"
362
-
363
- id="tb-notification-brand-badge"
364
- style="${displayMode === 'inline' ? 'fill:inherit; color: inherit;' : ''}"
365
- >
366
- ${this.text('worksFor')} ${iconTbLogo}
367
- </a>
368
- `;
369
- }
370
-
371
-
372
- get image() {
373
- if (!this.config.markUp.image || !this.config.markUp.image.show) return '';
374
-
375
- return `
376
- <tb-notification-widget-image style="background-image: url(${this.config.markUp.image.url})">
377
- <img src="${this.config.markUp.image.url}">
378
- </tb-notification-widget-image>
379
- `;
380
- }
381
-
382
- get pallet() {
383
- return this.config && this.config.markUp.body.palette && this.config.markUp.body.palette === "light" ? 'tb-pallet-light' : 'tb-pallet-dark'
384
- }
385
-
386
-
387
- get template() {
388
- if (this.ready && this.config && this.config.displayMode) {
389
- switch (this.config.displayMode) {
390
- case 'popup':
391
- return this.popupTemplate;
392
- case 'inline':
393
- return this.inlineTemplate;
394
- case 'corner-popup':
395
- return this.cornerPopupTemplate;
396
- default:
397
- return '';
398
- }
399
- } else if (this.error) {
400
- console.warn(`could not render widget. reason: ${this.error}`);
401
- }
402
-
403
- return '';
404
- }
405
-
406
- get popupTemplate() {
407
- this.element.className = (this.config.type === constants.WIDGET_TYPE_WIDGET ? 'tb-no-api-call' : '');
408
-
409
- const markUp = this.config.markUp;
410
- const isPopupWithImage = markUp.image && markUp.image.show;
411
-
412
- let imageUrlNotEmpty;
413
- let popupStyleClass = this.pallet;
414
-
415
- if (this.config.widgetKind === 'WAHUNTER' || isPopupWithImage) {
416
- imageUrlNotEmpty = !!markUp.image.url.trim();
417
- popupStyleClass += ` tb-popup-with-image tb-popup-${(markUp.image.align !== 'top' && imageUrlNotEmpty) ? 'horizontal' : 'vertical'}`;
418
- }
419
-
420
- if (this.config.widgetKind === 'WAHUNTER') {
421
- let wahunterImageAlignClassName = `tb-nw-wahunter_${imageUrlNotEmpty ? ('image-align_' + markUp.image.align) : 'without-image'}`;
422
-
423
- return `
424
- <tb-notification-widget-inner id="tb-notification-widget-inner" class="tb-notification-widget-inner">
425
- <tb-notification-widget-overlay class="hidden">
426
- <tb-notification-widget-popup class="${popupStyleClass}">
427
- <span id="tb-notification-widget-close" class="tb-notification-widget-close-icon">&times;</span>
428
- ${this.getTbBrandBadge(this.config)}
429
- <tb-nw-wahunter class="tb-nw-wahunter tb-nw-wahunter_mode_popup ${wahunterImageAlignClassName}"></tb-nw-wahunter>
430
- </tb-notification-widget-popup>
431
- </tb-notification-widget-overlay>
432
- </tb-notification-widget-inner>
433
- `;
434
- }
435
-
436
- const buttonsStyle = (this.config.type === constants.WIDGET_TYPE_WIDGET ? 'square' : 'rounded');
437
- const buttonsStyleClass = (this.config.type === constants.WIDGET_TYPE_WIDGET ? 'tb-btn-style-square' : 'tb-btn-style-rounded');
438
- let body = '';
439
-
440
- const channels = this.widget.getEnabledChannels();
441
-
442
- body = channels.map((channel, index) => {
443
- const item = assign({}, channel.config, {
444
- type: this.config.type,
445
- markUp: assign({}, markUp.buttons, { style: buttonsStyle }),
446
- });
447
-
448
- const attributes = stringifyAttributes({
449
- channel: item.channel,
450
- config: item,
451
- });
452
-
453
- return item.enabled ? `<div><tb-notification-button id="tb-notification-button-${index}" ${attributes}></tb-notification-button></div>` : '';
454
- }).join('');
455
-
456
-
457
- let popupBodyStyleClass = 'tb-notification-widget-popup-body';
458
-
459
- if (isPopupWithImage) {
460
- popupBodyStyleClass += ` ${popupBodyStyleClass}_image-align_${imageUrlNotEmpty ? markUp.image.align : 'none'}`
461
- }
462
-
463
- return `
464
- <tb-notification-widget-inner id="tb-notification-widget-inner" class="tb-notification-widget-inner">
465
- <tb-notification-widget-overlay class="hidden">
466
- <tb-notification-widget-popup class="${popupStyleClass}">
467
- <span id="tb-notification-widget-close" class="tb-notification-widget-close-icon">&times;</span>
468
- ${this.getTbBrandBadge(this.config)}
469
- <tb-notification-widget-popup-body class="${popupBodyStyleClass}">
470
- ${(markUp.image && markUp.image.show) ? this.image : this.icon}
471
- <tb-notification-widget-popup-main>
472
- ${this.header}
473
- ${this.description}
474
- <div class="tb-widget-buttons tb-btn-align-center ${buttonsStyleClass}">${body}</div>
475
- </tb-notification-widget-popup-main>
476
- </tb-notification-widget-popup-body>
477
- </tb-notification-widget-popup>
478
- </tb-notification-widget-overlay>
479
- </tb-notification-widget-inner>
480
- `;
481
- }
482
-
483
- get inlineTemplate() {
484
-
485
- this.element.className = (this.config.type === constants.WIDGET_TYPE_WIDGET ? 'tb-no-api-call' : '');
486
-
487
- const buttonsContainerClasses = this.config.type === constants.WIDGET_TYPE_WIDGET
488
- ? this.getButtonsClasses()
489
- : 'tb-btn-style-rounded tb-btn-mode-horizontal tb-btn-align-left';
490
-
491
- const channels = this.widget.getEnabledChannels();
492
-
493
- const body = channels.map((channel, index) => {
494
- const item = assign({}, channel.config, { type: this.config.type, markUp: this.config.markUp.buttons });
495
- const attributes = stringifyAttributes({
496
- channel: item.channel,
497
- config: item,
498
- });
499
-
500
- if (item.enabled) {
501
- let html = `<tb-notification-button id="tb-notification-button-${index}" ${attributes}></tb-notification-button>`;
502
- if (this.config.markUp.buttons.displayMode === 'vertical') {
503
- html = `<div>${html}</div>`;
504
- }
505
- return html;
506
- } else {
507
- return '';
508
- }
509
- }).join('');
510
-
511
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.inline.show', 'displaySettings');
512
-
513
- if (this.config.widgetKind === 'WAHUNTER') {
514
- return `
515
- <tb-notification-widget-inner id="tb-notification-widget-inner" class="tb-notification-widget-inner">
516
- <tb-nw-wahunter class="tb-nw-wahunter tb-nw-wahunter_mode_inline tb-nw-wahunter_inline-mode-align_${this.config.markUp.buttons.align}"></tb-nw-wahunter>
517
- </tb-notification-widget-inner>
518
- `;
519
- }
520
-
521
- return `
522
- <tb-notification-widget-inner id="tb-notification-widget-inner" class="tb-notification-widget-inner">
523
- <div class="tb-widget-buttons ${buttonsContainerClasses}">
524
- ${body}
525
- </div>
526
- </tb-notification-widget-inner>
527
- `;
528
- }
529
-
530
- get cornerPopupTemplate() {
531
- const markUp = this.config.markUp;
532
-
533
- if (this.config.widgetKind === 'WAHUNTER') {
534
- return `
535
- <tb-notification-widget-inner id="tb-notification-widget-inner" class="tb-notification-widget-inner">
536
- <tb-notification-widget-corner-popup>
537
- <tb-widget-corner-popup-window class="${this.pallet}">
538
- <div class="tb-fullscreen-close-rectangle">
539
- ${iconClose}
540
- </div>
541
- <tb-nw-wahunter class="tb-nw-wahunter tb-nw-wahunter_mode_corner-popup"></tb-nw-wahunter>
542
- ${this.getTbBrandBadge(this.config)}
543
- </tb-widget-corner-popup-window>
544
- <tb-widget-corner-popup-button style="background: ${markUp.wahunterButton.color}">
545
- ${iconChatWindow}
546
- ${iconClose}
547
- </tb-widget-corner-popup-button>
548
- <tb-widget-corner-popup-tooltip-container
549
- class="${markUp.description.showOnMobile ? 'tb-widget-corner-popup-tooltip-container_show-on-mobile' : ''}"
550
- style="${markUp.description.value.trim() ? '' : 'display:none'}"
551
- >
552
- <tb-widget-corner-popup-tooltip style="color:${markUp.description.color}">\
553
- ${markUp.description.value}\
554
- </tb-widget-corner-popup-tooltip>
555
- <tb-widget-corner-popup-tooltip-arrow />
556
- </tb-widget-corner-popup-tooltip-container>
557
- </tb-notification-widget-corner-popup>
558
- </tb-notification-widget-inner>
559
- `;
560
- }
561
-
562
- return '';
563
- }
564
-
565
- static get tagName() {
566
- return 'tb-notification-widget';
567
- }
568
-
569
- static getWidget(widgetId) {
570
- return widgetsStorage.getWidget(widgetId);
571
- }
572
-
573
- show() {
574
- if (this.config && this.config.displayMode && this.config.displayMode === "popup") {
575
- const popup = this.element.getElementsByTagName("tb-notification-widget-overlay")[0];
576
- if (popup.className.indexOf('hidden') !== -1 || popup.className.indexOf('closed')) {
577
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.popup.show', 'manual');
578
- }
579
- popup.className = '';
580
- }
581
- }
582
-
583
- showWithRules() {
584
- let showWidgetSetting = this.config.showWidgetSetting;
585
- let sessionShowCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_s_show_counter';
586
- let daysShowCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_days_show_counter';
587
- let daysCloseCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_days_close_counter';
588
- let totalCloseCounterName = constants.COOKIE_NAME_PREFIX + this.widgetId + '_total_close_counter';
589
-
590
- if (showWidgetSetting) {
591
- if (!showWidgetSetting.showIfSubscribed && this.widgetSubscriptions.length > 0) {
592
- return false;
593
- }
594
-
595
- let daysTimeout = showWidgetSetting.showAfterDays * constants.SECONDS_IN_DAY;
596
- let sessionTimeout = showWidgetSetting.showSessionLength * 60;
597
- let daysShowCounter = cookiesEx.incrementIntCookie(daysShowCounterName, daysTimeout);
598
- let sessionShowCounter = cookiesEx.incrementIntCookie(sessionShowCounterName, sessionTimeout);
599
- let daysCloseCounter = cookiesEx.getIntCookie(daysCloseCounterName) || 0;
600
- let totalCloseCounter = cookiesEx.getIntCookie(totalCloseCounterName) || 0;
601
-
602
- if (sessionShowCounter > showWidgetSetting.showTimesInSession ||
603
- (showWidgetSetting.showTimesInRow > 0 && daysShowCounter > showWidgetSetting.showTimesInRow) ||
604
- (showWidgetSetting.closeTimesInRow > 0 && daysCloseCounter >= showWidgetSetting.closeTimesInRow) ||
605
- (showWidgetSetting.closeTimesInTotal > 0 && totalCloseCounter >= showWidgetSetting.closeTimesInTotal)) {
606
- return false;
607
- }
608
- }
609
-
610
- if (this.config && this.config.displayMode && this.config.displayMode === "popup") {
611
- const popup = this.element.getElementsByTagName("tb-notification-widget-overlay")[0];
612
- if (popup.className.indexOf('hidden') !== -1 || popup.className.indexOf('closed')) {
613
- appInsights.trackWidgetEvent(this.config.id, 'notificationWidget.popup.show', 'manual');
614
- }
615
- popup.className = '';
616
- return popup;
617
- }
618
-
619
- return false;
620
- }
621
-
622
- hide() {
623
- if (this.config && this.config.displayMode && this.config.displayMode === "popup") {
624
- const popup = this.element.getElementsByTagName("tb-notification-widget-overlay")[0];
625
- if (popup.className.indexOf('hidden') !== -1) {
626
- popup.className += 'hidden';
627
- }
628
- }
629
- }
630
-
631
- getButtonsClasses() {
632
- const classes = [];
633
-
634
- if (this.config.markUp && this.config.markUp.buttons) {
635
- const markUp = this.config.markUp.buttons;
636
- classes.push(getButtonsStyleClass(markUp.style));
637
- classes.push(getButtonsAlignmentClass(markUp.align));
638
- classes.push(getButtonsDisplayModeClass(markUp.displayMode));
639
- }
640
-
641
- function getButtonsStyleClass(style) {
642
- const prefix = 'tb-btn-style';
643
- switch (style) {
644
- case 'rounded':
645
- return `${prefix}-rounded`;
646
- case 'icons':
647
- return `${prefix}-icons`;
648
- case 'gradient':
649
- return `${prefix}-gradient`;
650
- default:
651
- return `${prefix}-square`;
652
- }
653
- }
654
-
655
- function getButtonsAlignmentClass(align) {
656
- const prefix = 'tb-btn-align';
657
- switch (align) {
658
- case 'left':
659
- return `${prefix}-left`;
660
- case 'right':
661
- return `${prefix}-right`;
662
- default:
663
- return `${prefix}-center`;
664
- }
665
- }
666
-
667
- function getButtonsDisplayModeClass(mode) {
668
- const prefix = 'tb-btn-mode';
669
- if (mode === 'vertical') {
670
- return `${prefix}-vertical`;
671
- } else {
672
- return `${prefix}-horizontal`;
673
- }
674
- }
675
-
676
- return classes.join(' ');
677
- }
678
- };