@textback/notification-widget 2.0.1-110361 → 2.0.1-13997

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 (81) hide show
  1. package/build/index.js +2 -5
  2. package/build/sdk.js +2 -2
  3. package/package.json +4 -5
  4. package/readme.md +11 -90
  5. package/server.js +220 -224
  6. package/src/libraries/localization/getLocale.js +17 -17
  7. package/src/libraries/localization/locales/cs.js +21 -23
  8. package/src/libraries/localization/locales/en.js +21 -23
  9. package/src/libraries/localization/locales/pl.js +21 -23
  10. package/src/libraries/localization/locales/ro.js +21 -23
  11. package/src/libraries/localization/locales/ru.js +21 -22
  12. package/src/libraries/localization/locales/uk.js +21 -23
  13. package/src/sdk/channels/facebook.js +1 -1
  14. package/src/sdk/channels/factory.js +33 -33
  15. package/src/sdk/channels/skype.js +1 -1
  16. package/src/sdk/channels/telegram.js +2 -2
  17. package/src/sdk/channels/viber.js +1 -1
  18. package/src/sdk/channels/vk.js +147 -158
  19. package/src/sdk/channels/whatsapp.js +21 -27
  20. package/src/sdk/sdk.js +5 -42
  21. package/src/sdk/utils/appInsights.js +2 -2
  22. package/src/sdk/utils/cookies.js +1 -18
  23. package/src/sdk/utils/loadDeepLink.js +13 -40
  24. package/src/sdk/widget/widget.js +107 -159
  25. package/src/widget/components/index.js +48 -52
  26. package/src/widget/components/tb-notification-button/facebook.js +48 -55
  27. package/src/widget/components/tb-notification-button/skype.js +47 -0
  28. package/src/widget/components/tb-notification-button/styles.scss +16 -240
  29. package/src/widget/components/tb-notification-button/telegram.js +48 -55
  30. package/src/widget/components/tb-notification-button/viber.js +49 -56
  31. package/src/widget/components/tb-notification-button/vk.js +83 -92
  32. package/src/widget/components/tb-notification-button/whatsapp.js +51 -58
  33. package/src/widget/components/tb-notification-widget/index.js +473 -694
  34. package/src/widget/components/tb-notification-widget/normalize.scss +1 -2
  35. package/src/widget/components/tb-notification-widget/styles.scss +180 -543
  36. package/src/widget/config.js +1 -1
  37. package/src/widget/icons/icon_facebook_circle.svg +2 -0
  38. package/src/widget/icons/icon_tg_circle.svg +10 -0
  39. package/src/widget/icons/icon_viber_circle.svg +10 -0
  40. package/src/widget/icons/icon_viber_new.svg +1 -1
  41. package/src/widget/icons/icon_vk_circle.svg +1 -1
  42. package/src/widget/icons/icon_whatsapp.svg +4 -4
  43. package/src/widget/icons/icon_whatsapp_circle.svg +2 -2
  44. package/src/widget/icons/icon_whatsapp_new.svg +2 -2
  45. package/src/widget/icons/text-back-badge.png +0 -0
  46. package/src/widget/locales/cz.js +20 -0
  47. package/src/widget/locales/en.js +20 -42
  48. package/src/widget/locales/index.js +8 -8
  49. package/src/widget/locales/pl.js +20 -42
  50. package/src/widget/locales/ro.js +19 -40
  51. package/src/widget/locales/ru.js +20 -41
  52. package/src/widget/locales/uk.js +20 -41
  53. package/src/widget/utils/getLocale.js +14 -16
  54. package/src/widget/utils/stringifyAttributes.js +1 -1
  55. package/src/widget/utils/text.js +8 -9
  56. package/src/widget/widget.entry.js +1 -0
  57. package/tests/gf.html +2 -2
  58. package/v8-compile-cache-0/5.1.281.102/zSvstszSagentzS_workzS5zSszSnode_moduleszSwebpack-clizSbinzScli.js.BLOB +0 -0
  59. package/v8-compile-cache-0/5.1.281.102/zSvstszSagentzS_workzS5zSszSnode_moduleszSwebpack-clizSbinzScli.js.MAP +1 -0
  60. package/views/examples.ejs +47 -51
  61. package/views/sdk.html +17 -35
  62. package/webpack.dev.js +2 -2
  63. package/src/sdk/channels/whatsappb.js +0 -27
  64. package/src/widget/components/tb-notification-button/whatsappb.js +0 -58
  65. package/src/widget/components/tb-nw-wahunter/index.js +0 -261
  66. package/src/widget/components/tb-nw-wahunter/styles.scss +0 -471
  67. package/src/widget/icons/icon_chat_window.svg +0 -1
  68. package/src/widget/icons/icon_close.svg +0 -1
  69. package/src/widget/icons/icon_whatsapp_hollow.svg +0 -128
  70. package/src/widget/icons/icon_whatsappb.svg +0 -147
  71. package/src/widget/icons/icon_whatsappb_circle.svg +0 -4
  72. package/src/widget/icons/icon_whatsappb_new.svg +0 -127
  73. package/src/widget/icons/paper-plane-arrow.svg +0 -3
  74. package/src/widget/icons/tb-logo-dark-en.svg +0 -17
  75. package/src/widget/icons/tb-logo-dark-ru.svg +0 -17
  76. package/src/widget/icons/tb-logo-dark.svg +0 -16
  77. package/src/widget/icons/tb-logo-light-en.svg +0 -17
  78. package/src/widget/icons/tb-logo-light-ru.svg +0 -17
  79. package/src/widget/icons/tb-logo-white.svg +0 -16
  80. package/src/widget/icons/tb-logo.svg +0 -16
  81. package/src/widget/locales/cs.js +0 -42
package/src/sdk/sdk.js CHANGED
@@ -1,49 +1,25 @@
1
- import apiErrorHandler from "./utils/apiErrorHandler";
1
+ require('es6-promise').polyfill();
2
2
  import 'whatwg-fetch';
3
3
 
4
4
  import Widget from './widget/widget.js';
5
- import {EVENTS, Observer} from './events/observer.js';
6
- import {deeplinkUpdater} from './utils/loadDeepLink.js';
7
-
8
- require('es6-promise').polyfill();
5
+ import { Observer, EVENTS } from './events/observer.js';
9
6
 
10
7
  export default class SDK {
11
8
  constructor() {
12
9
  this.widgets = {};
13
- this._deeplinkUpdater = deeplinkUpdater;
14
10
  }
15
11
 
16
- initWidget(config, preventViewCounting = false) {
12
+ initWidget(config) {
17
13
  if (config && config.widgetId) {
18
14
  const widget = new Widget(config, this);
19
15
  this.widgets[config.widgetId] = widget.initialize();
20
- this.widgets[config.widgetId].then(widget => {
21
- Observer.trigger(EVENTS.WIDGET_INIT, {widgetId: config.widgetId});
22
-
23
- // First of all, this is a restriction on the count of views for textback settings page ( = for widget preview)
24
- if (preventViewCounting) return;
25
-
26
- this.countWidgetView(widget);
27
- }, err => console.error(err));
16
+ this.widgets[config.widgetId].then(widget => Observer.trigger(EVENTS.WIDGET_INIT, { widgetId: config.widgetId }), err => console.error(err));
28
17
  return this.widgets[config.widgetId];
29
18
  } else {
30
19
  throw new Error('Widget id is not defined');
31
20
  }
32
21
  }
33
22
 
34
- countWidgetView(widget) {
35
- return fetch(`${widget.initialConfig.apiPath}/endUserNotifications/subscriptions/notificationWidget/views`, {
36
- method: 'POST',
37
- headers: {
38
- 'Content-Type': 'application/json'
39
- },
40
- body: JSON.stringify({
41
- 'accountId': widget.config.accountId,
42
- 'widgetId': widget.id
43
- })
44
- }).then(apiErrorHandler);
45
- }
46
-
47
23
  getWidget(widgetId) {
48
24
  return this.widgets[widgetId] ? this.widgets[widgetId] : null;
49
25
  }
@@ -51,17 +27,4 @@ export default class SDK {
51
27
  on(eventName, fn) {
52
28
  return Observer.on(eventName, fn);
53
29
  }
54
-
55
- getDeeplinkUpdater(widgetId) {
56
- let _getWidget = this.widgets[widgetId];
57
-
58
- if (!_getWidget) return null;
59
-
60
- return _getWidget.then(x => {
61
- return this._deeplinkUpdater(
62
- x.initialConfig.apiPath,
63
- x.deeplink.split('_')[1]
64
- );
65
- });
66
- }
67
- }
30
+ }
@@ -36,8 +36,8 @@ const appInsights = {
36
36
  disableAjaxTracking: true,
37
37
  //this url will point to the library - use @dev for testing when updating\editing lib - use @latest for production version of lib
38
38
  //keep in mind that prod widget should always use @latest
39
- url: '//cdn.jsdelivr.net/npm/@textback/notification-widget@latest/src/libraries/ai.1.0.11.js'
40
- // url: '//cdn.jsdelivr.net/npm/@textback/notification-widget@dev/src/libraries/ai.1.0.11.js'
39
+ url: '//unpkg.com/@textback/notification-widget@latest/src/libraries/ai.1.0.11.js'
40
+ // url: '//unpkg.com/@textback/notification-widget@dev/src/libraries/ai.1.0.11.js'
41
41
  //url: '//localhost:8080/src/libraries/ai.1.0.11.js',
42
42
  });
43
43
 
@@ -44,24 +44,7 @@ const cookies = {
44
44
  */
45
45
  deleteCookie: function (name) {
46
46
  setCookie(name, "", -1);
47
- },
48
-
49
-
50
- getCookieObject: function () {
51
- const result = {};
52
-
53
- document.cookie
54
- .split(';')
55
- .forEach((cookieItem) => {
56
- const separatorPos = cookieItem.indexOf('=');
57
- const key = cookieItem.slice(0, separatorPos).trim();
58
- const value = cookieItem.slice(separatorPos + 1);
59
-
60
- result[key] = value;
61
- });
62
-
63
- return result;
64
47
  }
65
48
  };
66
49
 
67
- export default cookies;
50
+ export default cookies;
@@ -1,48 +1,21 @@
1
- 'use strict';
2
-
3
1
  import apiErrorHandler from './apiErrorHandler.js';
4
2
 
5
3
  const cache = {};
6
4
 
7
- export const deeplinkUpdater = (apiPath, deeplink) => {
8
- let _promises = [];
9
-
10
- return data => {
11
- Promise.all(_promises).then(() => {
12
- let _data = JSON.stringify({
13
- id: deeplink,
14
- insecureContext: { data: data }
15
- });
16
-
17
- let _promise = fetch(
18
- `${apiPath}/endUserNotifications/deepLinks`,
19
- {
20
- method: 'PATCH',
21
- body: _data
22
- }
23
- );
24
-
25
- _promises.push(_promise);
26
-
27
- return _promises;
28
- });
29
- };
30
- };
31
-
32
5
  export default function loadDeepLink(apiPath, options = {}) {
33
- const body = JSON.stringify(options);
6
+ const body = JSON.stringify(options);
34
7
 
35
- if (cache[body]) {
36
- return cache[body];
37
- }
8
+ if (cache[body]) {
9
+ return cache[body];
10
+ }
38
11
 
39
- cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, {
40
- method: 'POST',
41
- headers: {
42
- 'Content-Type': 'application/json'
43
- },
44
- body
45
- }).then(apiErrorHandler);
12
+ cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, {
13
+ method: 'POST',
14
+ headers: {
15
+ 'Content-Type': 'application/json'
16
+ },
17
+ body
18
+ }).then(apiErrorHandler);
46
19
 
47
- return cache[body];
48
- };
20
+ return cache[body];
21
+ };
@@ -14,179 +14,127 @@ import appInsights from '../utils/appInsights.js';
14
14
  import channelsFactory from '../channels/factory.js';
15
15
 
16
16
  const INITIAL_CONFIG_DEFAULTS = {
17
- apiPath: 'https://api.textback.io/api',
17
+ apiPath: 'https://api.textback.io/api',
18
18
  };
19
19
 
20
20
  export default class Widget {
21
- constructor(config, sdk) {
22
- this.initialConfig = assign({}, INITIAL_CONFIG_DEFAULTS, config);
23
- this.sdk = sdk;
24
-
25
- this.config = {};
26
- this.channels = [];
27
- this.initialized = false;
28
- this.initPromise = null;
29
-
30
- this.id = this.initialConfig.widgetId;
31
- this.widgetUserId = Widget.getWidgetUserId();
32
- this.insecureContext = Widget.createInsecureContext(this.initialConfig.insecureContext);
33
- this.secureContextToken = this.initialConfig.secureContextToken;
34
- }
35
-
36
- getConfig() {
37
- return this.config;
38
- }
39
-
40
- initialize() {
41
- this.initPromise = Promise.all([
42
- this.initializeConfig(),
43
- loadSubscriptions(this.widgetUserId, this.initialConfig.widgetId, this.initialConfig.apiPath),
44
- ]).then(([config, subscriptions]) => {
45
- this.config = config.$value;
46
- this.subscriptions = subscriptions.$items;
47
-
48
- this.useVKApi = this.config.type === constants.WIDGET_TYPE_API_CALL;
49
- this.aiKey = Widget.getAiKey(config);
50
-
51
- let customDeeplinkData = this.config.channels.filter(
52
- c => c.hasOwnProperty('additionalProperties') && c.additionalProperties.hasOwnProperty('customDeeplinkValue')
53
- ).filter(
54
- c => c.channel === 'whatsapp' || c.channel === 'whatsappb'
55
- ).filter(
56
- c => c.enabled
57
- ).map(
58
- ({additionalProperties, channel, channelId}) => {
59
- return {
60
- channel: channel,
61
- channelId: channelId,
62
- customDeeplinkValue: additionalProperties.customDeeplinkValue
63
- };
64
- }
65
- );
66
-
67
- let deeplinkData = {
68
- accountId: this.config.accountId,
69
- insecureContext: this.insecureContext,
70
- widgetId: this.config.id,
71
- secureContextToken: this.secureContextToken,
72
- user: {
73
- id: this.widgetUserId
21
+ constructor(config, sdk) {
22
+ this.initialConfig = assign({}, INITIAL_CONFIG_DEFAULTS, config);
23
+ this.sdk = sdk;
24
+
25
+ this.config = {};
26
+ this.channels = [];
27
+ this.initialized = false;
28
+ this.initPromise = null;
29
+
30
+ this.id = this.initialConfig.widgetId;
31
+ this.widgetUserId = Widget.getWidgetUserId();
32
+ this.insecureContext = Widget.createInsecureContext(this.initialConfig.insecureContext);
33
+ this.secureContextToken = this.initialConfig.secureContextToken;
34
+ }
35
+
36
+ getConfig() {
37
+ return this.config;
38
+ }
39
+
40
+ initialize() {
41
+ this.initPromise = Promise.all([
42
+ this.initializeConfig(),
43
+ loadSubscriptions(this.widgetUserId, this.initialConfig.widgetId, this.initialConfig.apiPath),
44
+ ]).then(([config, subscriptions]) => {
45
+ this.config = config.$value;
46
+ this.subscriptions = subscriptions.$items;
47
+
48
+ this.useVKApi = this.config.type === constants.WIDGET_TYPE_API_CALL;
49
+ this.aiKey = Widget.getAiKey(config);
50
+
51
+ return Promise.all([
52
+ loadDeepLink(
53
+ this.initialConfig.apiPath,
54
+ {
55
+ accountId: this.config.accountId,
56
+ insecureContext: this.insecureContext,
57
+ widgetId: this.config.id,
58
+ secureContextToken: this.secureContextToken,
59
+ user: {
60
+ id: this.widgetUserId
61
+ }
62
+ }
63
+ ),
64
+ appInsights.init(this.aiKey, this.widgetUserId, this.config.accountId)
65
+ ]);
66
+ }).then(([deeplink, ai]) => {
67
+ this.deeplink = `subscribe_${deeplink.$value.id}`;
68
+ this.channels = this.config.channels.map(channel => channelsFactory.create(channel, this.deeplink, this))
69
+ .filter(channel => !!channel);
70
+ const channelInitPromises = this.channels.filter(channel => !!channel.initPromise)
71
+ .map(channel => channel.initPromise);
72
+
73
+ return Promise.all(channelInitPromises);
74
+ }).then(channelPromises => {
75
+ return this;
76
+ }, err => {
77
+ appInsights.trackWidgetEvent(this.config.id, 'Widget.initialize.error', err);
78
+ return Promise.reject(err);
79
+ })
80
+
81
+ return this.initPromise;
82
+ }
83
+
84
+ initializeConfig() {
85
+ let promise;
86
+ if (!this.initialConfig.overrideConfig) {
87
+ promise = loadConfig(this.initialConfig.widgetId, this.initialConfig.apiPath);
88
+ } else {
89
+ promise = Promise.resolve({ $value: this.initialConfig.overrideConfig });
74
90
  }
75
- };
76
-
77
- if(customDeeplinkData.length > 0) {
78
- deeplinkData.customDeeplinkValue = customDeeplinkData;
79
- }
80
-
81
- return Promise.all([
82
- loadDeepLink(
83
- this.initialConfig.apiPath,
84
- deeplinkData
85
- ),
86
- appInsights.init(this.aiKey, this.widgetUserId, this.config.accountId)
87
- ]);
88
- }).then(([deeplink, ai]) => {
89
- this.deeplink = `subscribe_${deeplink.$value.id}`;
90
- this.channels = this.config.channels.map(channel => channelsFactory.create(channel, this.deeplink, this))
91
- .filter(channel => !!channel);
92
-
93
- const channelInitPromises = this.channels.filter(
94
- channel => !!channel.initPromise
95
- ).map(
96
- channel => channel.initPromise
97
- );
98
-
99
- return Promise.all(channelInitPromises);
100
- }).then(channelPromises => {
101
- return this;
102
- }, err => {
103
- appInsights.trackWidgetEvent(this.config.id, 'Widget.initialize.error', err);
104
- return Promise.reject(err);
105
- });
106
-
107
- return this.initPromise;
108
- }
109
-
110
- initializeConfig() {
111
- let promise;
112
- if (!this.initialConfig.overrideConfig) {
113
- promise = loadConfig(this.initialConfig.widgetId, this.initialConfig.apiPath);
114
- } else {
115
- promise = Promise.resolve({ $value: this.initialConfig.overrideConfig });
91
+
92
+ return promise;
116
93
  }
117
94
 
118
- return promise;
119
- }
95
+ subscribe(channelCode) {
96
+ const channel = find(this.getEnabledChannels(), chan => chan.channel === channelCode);
97
+ if (channel) {
98
+ channel.subscribe();
99
+ }
100
+ }
120
101
 
121
- subscribe(channelCode) {
122
- const channel = find(this.getEnabledChannels(), chan => chan.channel === channelCode);
123
- if (channel) {
124
- channel.subscribe();
102
+ getChannels() {
103
+ return this.channels;
125
104
  }
126
- }
127
-
128
- getChannels() {
129
- return this.channels;
130
- }
131
-
132
- getEnabledChannels() {
133
- return this.channels.filter(channel => channel.enabled && !channel.hasError);
134
- }
135
-
136
- runWahunter(phoneNumber) {
137
- return fetch(`${this.initialConfig.apiPath}/wahunter`, {
138
- method: 'POST',
139
- headers: {
140
- 'Content-Type': 'application/json;charset=utf-8'
141
- },
142
- body: JSON.stringify({
143
- notificationWidgetId: this.initialConfig.widgetId,
144
- phone: phoneNumber,
145
- insecureContext: this.insecureContext,
146
- deeplinkId: this.deeplink,
147
- }),
148
- }).then((resp) => {
149
- if (resp.ok) {
150
- cookies.setCookie(`${constants.COOKIE_NAME_PREFIX + this.id}_wahunter_was_run`, true, this.config.showWidgetSetting.showSessionLength * 60);
151
- } else {
152
- return Promise.reject(resp);
153
- }
154
- })
155
- }
156
-
157
- static getWidgetUserId() {
158
- let widgetUserId = cookies.getCookie(constants.COOKIE_WIDGET_USER_ID);
159
- if (widgetUserId === null) {
160
- let uuid = UUID.create(4);
161
- widgetUserId = uuid.hex;
162
- cookies.setCookie(constants.COOKIE_WIDGET_USER_ID, widgetUserId, constants.WIDGET_USER_ID_COOKIE_TTL);
105
+
106
+ getEnabledChannels() {
107
+ return this.channels.filter(channel => channel.enabled && !channel.hasError);
163
108
  }
164
- return widgetUserId;
165
- }
166
109
 
167
- static createInsecureContext(insecureContext = {}) {
168
- const ctx = assign({}, insecureContext);//Object.assign({}, insecureContext);
169
- ctx.pageTitle = window.document.title;
170
- ctx.pageUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
171
- ctx.params = parseQueryString(window.location.search.substring(1));
172
- ctx.timezoneOffset = new Date().getTimezoneOffset();
173
- ctx.cookies = cookies.getCookieObject();
110
+ static getWidgetUserId() {
111
+ let widgetUserId = cookies.getCookie(constants.COOKIE_WIDGET_USER_ID);
112
+ if (widgetUserId === null) {
113
+ let uuid = UUID.create(4);
114
+ widgetUserId = uuid.hex;
115
+ cookies.setCookie(constants.COOKIE_WIDGET_USER_ID, widgetUserId, constants.WIDGET_USER_ID_COOKIE_TTL);
116
+ }
117
+ return widgetUserId;
118
+ }
174
119
 
175
- const roistatVisitCookie = cookies.getCookie("roistat_visit");
120
+ static createInsecureContext(insecureContext = {}) {
121
+ const ctx = assign({}, insecureContext);//Object.assign({}, insecureContext);
122
+ ctx.pageTitle = window.document.title;
123
+ ctx.pageUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
124
+ ctx.params = parseQueryString(window.location.search.substring(1));
125
+ ctx.timezoneOffset = new Date().getTimezoneOffset();
176
126
 
177
- if (roistatVisitCookie) {
178
- ctx.roistatVisit = roistatVisitCookie;
127
+ return ctx;
179
128
  }
180
129
 
181
- return ctx;
182
- }
130
+ static getAiKey(config) {
131
+ let aiKey = undefined;
132
+ try {
133
+ aiKey = config.headers.get('X-TB-AIKEY');
134
+ } catch (e) { }
135
+
136
+ return aiKey;
137
+ }
183
138
 
184
- static getAiKey(config) {
185
- let aiKey = undefined;
186
- try {
187
- aiKey = config.headers.get('X-TB-AIKEY');
188
- } catch (e) { }
189
139
 
190
- return aiKey;
191
- }
192
140
  }
@@ -1,52 +1,48 @@
1
- // const merge = require('lodash/merge');
2
- import merge from 'lodash/merge';
3
- import text from '../utils/text.js';
4
- import getLocale from '../utils/getLocale.js';
5
-
6
- export default class Component {
7
- constructor(props = {}) {
8
-
9
- if (Object.prototype.hasOwnProperty.call(props, 'parentElement')) this.element = props.parentElement;
10
- if (!Object.prototype.hasOwnProperty.call(props, 'parentElement')) this.element = props.element || document.createElement(this.constructor.tagName);
11
-
12
- const dataset = JSON.parse(JSON.stringify(this.element.dataset || {}));
13
- const data = merge(JSON.parse(this.element.getAttribute('data')), dataset);
14
-
15
- this.set(this.defaults, props, {data});
16
- }
17
-
18
- render() {
19
- this.element.innerHTML = this.template;
20
- }
21
-
22
- text(string) {
23
- return text(string, this.lang);
24
- }
25
-
26
- get template() {
27
- return this.content;
28
- }
29
-
30
- get lang() {
31
- return this.element.getAttribute('lang') || getLocale();
32
- }
33
-
34
- set lang(value) {
35
- if (!value) return;
36
-
37
- this.element.setAttribute('lang', value);
38
- }
39
-
40
- set() {
41
- merge(this, ...arguments);
42
- this.render();
43
- }
44
-
45
- get defaults() {
46
- return {};
47
- }
48
-
49
- static get tagName() {
50
- return 'div';
51
- }
52
- };
1
+ // const merge = require('lodash/merge');
2
+ import merge from 'lodash/merge';
3
+ import text from '../utils/text.js';
4
+ import getLocale from '../utils/getLocale.js';
5
+
6
+ export default class Component {
7
+ constructor(props = {}) {
8
+ this.element = props.element || document.createElement(this.constructor.tagName);
9
+
10
+ const dataset = JSON.parse(JSON.stringify(this.element.dataset || {}));
11
+ const data = merge(JSON.parse(this.element.getAttribute('data')), dataset);
12
+
13
+ this.set(this.defaults, props, {data});
14
+ }
15
+
16
+ render() {
17
+ this.element.innerHTML = this.template;
18
+ }
19
+
20
+ text(string) {
21
+ return text(string, this.lang);
22
+ }
23
+
24
+ get template() {
25
+ return this.content;
26
+ }
27
+
28
+ get lang() {
29
+ return this.element.getAttribute('lang') || getLocale();
30
+ }
31
+
32
+ set lang(value) {
33
+ this.element.setAttribute('lang', value);
34
+ }
35
+
36
+ set() {
37
+ merge(this, ...arguments);
38
+ this.render();
39
+ }
40
+
41
+ get defaults() {
42
+ return {};
43
+ }
44
+
45
+ static get tagName() {
46
+ return 'div';
47
+ }
48
+ };
@@ -1,55 +1,48 @@
1
- import Button from './index.js';
2
- import icon from '../../icons/icon_facebook.svg';
3
- import iconCircle from '../../icons/icon_facebook_circle.svg';
4
- import constants from '../../../sdk/utils/constants.js';
5
-
6
- class FacebookButton extends Button {
7
- render() {
8
- super.render();
9
-
10
- const link = this.element.querySelector('a');
11
- link.addEventListener('click', (event) => {
12
- event.preventDefault();
13
- this.channelAPI.subscribe();
14
- });
15
- }
16
-
17
- get template() {
18
- if (this.config.type === constants.WIDGET_TYPE_API_CALL) {
19
- return `
20
- <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
21
- <tb-notification-button__icon>${icon}</tb-notification-button__icon>
22
- <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
23
- </a>
24
- <p class="tb-notification-button__tip">
25
- ${this.text('facebookTip')}
26
- </p>
27
- `;
28
- } else if(this.config.markUp.style === 'gradient') {
29
- return `
30
- <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
31
- <tb-notification-button__icon>${icon}</tb-notification-button__icon>
32
- <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
33
- </a>
34
- `;
35
- } else if (this.config.markUp.style !== 'square') {
36
- return `
37
- <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
38
- <tb-notification-button__icon>${(this.config.markUp.style === 'rounded' ? icon : iconCircle )}</tb-notification-button__icon>
39
- <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
40
- </a>
41
- `;
42
- } else {
43
- return `
44
- <div class="tb-notification-button__inner">
45
- <tb-notification-button__icon>${icon}</tb-notification-button__icon>
46
- <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
47
- <tb-notification-button__text>${this.text('facebookExtended')}</tb-notification-button__text>
48
- </a>
49
- </div>
50
- `;
51
- }
52
- }
53
- };
54
-
55
- module.exports = FacebookButton;
1
+ import Button from './index.js';
2
+ import icon from '../../icons/icon_facebook.svg';
3
+ import iconCircle from '../../icons/icon_facebook_circle.svg';
4
+ import constants from '../../../sdk/utils/constants.js';
5
+
6
+ class FacebookButton extends Button {
7
+ render() {
8
+ super.render();
9
+
10
+ const link = this.element.querySelector('a');
11
+ link.addEventListener('click', (event) => {
12
+ event.preventDefault();
13
+ this.channelAPI.subscribe();
14
+ });
15
+ }
16
+
17
+ get template() {
18
+ if (this.config.type === constants.WIDGET_TYPE_API_CALL) {
19
+ return `
20
+ <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
21
+ <tb-notification-button__icon>${icon}</tb-notification-button__icon>
22
+ <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
23
+ </a>
24
+ <p class="tb-notification-button__tip">
25
+ ${this.text('facebook_tip')}
26
+ </p>
27
+ `;
28
+ } else if (this.config.markUp.style !== 'square') {
29
+ return `
30
+ <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
31
+ <tb-notification-button__icon>${(this.config.markUp.style === 'rounded' ? icon : iconCircle )}</tb-notification-button__icon>
32
+ <tb-notification-button__text>${this.text('facebook')}</tb-notification-button__text>
33
+ </a>
34
+ `;
35
+ } else {
36
+ return `
37
+ <div class="tb-notification-button__inner">
38
+ <tb-notification-button__icon>${icon}</tb-notification-button__icon>
39
+ <a target="_blank" href="https://m.me/${this.config.id}?ref=${this.deepLink}">
40
+ <tb-notification-button__text>${this.text('sign-facebook')}</tb-notification-button__text>
41
+ </a>
42
+ </div>
43
+ `;
44
+ }
45
+ }
46
+ };
47
+
48
+ module.exports = FacebookButton;