@textback/notification-widget 2.0.0-9450 → 2.0.1-102913

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 (113) hide show
  1. package/.eslintrc.js +291 -291
  2. package/build/index.js +6 -3
  3. package/build/sdk.js +3 -3
  4. package/package.json +11 -8
  5. package/promote_tag.sh +1 -1
  6. package/{README.md → readme.md} +569 -490
  7. package/server.js +134 -134
  8. package/src/libraries/ai.1.0.11.js +4088 -4088
  9. package/src/libraries/localization/getLocale.js +17 -0
  10. package/src/libraries/localization/locales/.tern-port +1 -0
  11. package/src/libraries/localization/locales/cs.js +23 -0
  12. package/src/libraries/localization/locales/en.js +23 -0
  13. package/src/libraries/localization/locales/index.js +9 -0
  14. package/src/libraries/localization/locales/pl.js +23 -0
  15. package/src/libraries/localization/locales/ro.js +23 -0
  16. package/src/libraries/localization/locales/ru.js +22 -0
  17. package/src/libraries/localization/locales/uk.js +23 -0
  18. package/src/libraries/localization/text.js +9 -0
  19. package/src/libraries/t.js +82 -82
  20. package/src/sdk/channels/channel.js +30 -30
  21. package/src/sdk/channels/facebook.js +13 -13
  22. package/src/sdk/channels/factory.js +3 -3
  23. package/src/sdk/channels/skype.js +12 -12
  24. package/src/sdk/channels/telegram.js +18 -13
  25. package/src/sdk/channels/viber.js +12 -12
  26. package/src/sdk/channels/vk-modal/vk-modal.html +17 -17
  27. package/src/sdk/channels/vk-modal/vk-modal.js +25 -25
  28. package/src/sdk/channels/vk-modal/vk-modal.scss +116 -116
  29. package/src/sdk/channels/vk.js +195 -173
  30. package/src/sdk/channels/whatsapp.js +20 -11
  31. package/src/sdk/channels/whatsappb.js +27 -0
  32. package/src/sdk/events/observer.js +46 -46
  33. package/src/sdk/index.js +5 -5
  34. package/src/sdk/sdk.js +67 -30
  35. package/src/sdk/utils/apiErrorHandler.js +11 -11
  36. package/src/sdk/utils/appInsights.js +88 -88
  37. package/src/sdk/utils/browserInfo.js +8 -8
  38. package/src/sdk/utils/constants.js +17 -17
  39. package/src/sdk/utils/cookies.js +67 -50
  40. package/src/sdk/utils/find.js +7 -7
  41. package/src/sdk/utils/loadConfig.js +20 -20
  42. package/src/sdk/utils/loadDeepLink.js +48 -21
  43. package/src/sdk/utils/loadScript.js +25 -25
  44. package/src/sdk/utils/loadSubscriptions.js +6 -6
  45. package/src/sdk/utils/parseQueryString.js +33 -33
  46. package/src/sdk/utils/windowHelper.js +25 -0
  47. package/src/sdk/widget/widget.js +192 -140
  48. package/src/widget/components/index.js +6 -2
  49. package/src/widget/components/tb-notification-button/facebook.js +9 -2
  50. package/src/widget/components/tb-notification-button/index.js +34 -34
  51. package/src/widget/components/tb-notification-button/styles.scss +657 -433
  52. package/src/widget/components/tb-notification-button/telegram.js +9 -2
  53. package/src/widget/components/tb-notification-button/viber.js +9 -2
  54. package/src/widget/components/tb-notification-button/vk.js +60 -47
  55. package/src/widget/components/tb-notification-button/whatsapp.js +15 -8
  56. package/src/widget/components/tb-notification-button/whatsappb.js +58 -0
  57. package/src/widget/components/tb-notification-widget/index.js +597 -353
  58. package/src/widget/components/tb-notification-widget/normalize.scss +395 -394
  59. package/src/widget/components/tb-notification-widget/styles.scss +514 -136
  60. package/src/widget/components/tb-nw-wahunter/index.js +259 -0
  61. package/src/widget/components/tb-nw-wahunter/styles.scss +471 -0
  62. package/src/widget/config.js +5 -5
  63. package/src/widget/icons/icon_chat_window.svg +1 -0
  64. package/src/widget/icons/icon_close.svg +1 -0
  65. package/src/widget/icons/icon_facebook.svg +7 -7
  66. package/src/widget/icons/icon_facebook_circle.svg +7 -9
  67. package/src/widget/icons/icon_instagram_circle.svg +95 -95
  68. package/src/widget/icons/icon_skype.svg +44 -44
  69. package/src/widget/icons/icon_skype_circle.svg +46 -46
  70. package/src/widget/icons/icon_skype_new.svg +113 -113
  71. package/src/widget/icons/icon_tg.svg +25 -25
  72. package/src/widget/icons/icon_tg_circle.svg +17 -27
  73. package/src/widget/icons/icon_viber.svg +75 -75
  74. package/src/widget/icons/icon_viber_circle.svg +67 -77
  75. package/src/widget/icons/icon_viber_new.svg +102 -102
  76. package/src/widget/icons/icon_vk.svg +14 -14
  77. package/src/widget/icons/icon_vk_circle.svg +16 -16
  78. package/src/widget/icons/icon_whatsapp.svg +147 -147
  79. package/src/widget/icons/icon_whatsapp_circle.svg +4 -123
  80. package/src/widget/icons/icon_whatsapp_hollow.svg +128 -0
  81. package/src/widget/icons/icon_whatsapp_new.svg +127 -127
  82. package/src/widget/icons/icon_whatsappb.svg +147 -0
  83. package/src/widget/icons/icon_whatsappb_circle.svg +4 -0
  84. package/src/widget/icons/icon_whatsappb_new.svg +127 -0
  85. package/src/widget/icons/paper-plane-arrow.svg +3 -0
  86. package/src/widget/icons/tb-logo.svg +21 -0
  87. package/src/widget/index.js +28 -28
  88. package/src/widget/locales/cs.js +42 -0
  89. package/src/widget/locales/en.js +42 -20
  90. package/src/widget/locales/index.js +2 -2
  91. package/src/widget/locales/pl.js +41 -19
  92. package/src/widget/locales/ro.js +41 -20
  93. package/src/widget/locales/ru.js +40 -19
  94. package/src/widget/locales/uk.js +40 -19
  95. package/src/widget/utils/cookiesEx.js +41 -41
  96. package/src/widget/utils/getLocale.js +4 -2
  97. package/src/widget/utils/stringifyAttributes.js +19 -19
  98. package/src/widget/utils/text.js +2 -1
  99. package/src/widget/utils/widgetsStorage.js +28 -28
  100. package/src/widget/widget.entry.js +3 -4
  101. package/tests/gf.html +35 -35
  102. package/tests/gf.js +21 -21
  103. package/tests/index.js +61 -61
  104. package/views/examples.ejs +7 -3
  105. package/views/sdk.html +274 -256
  106. package/webpack.common.js +72 -72
  107. package/webpack.dev.js +15 -15
  108. package/webpack.prod.js +10 -17
  109. package/build/index.js.map +0 -1
  110. package/build/sdk.js.map +0 -1
  111. package/src/widget/components/tb-notification-button/skype.js +0 -47
  112. package/src/widget/icons/text-back-badge.png +0 -0
  113. package/src/widget/locales/cz.js +0 -20
@@ -1,46 +1,46 @@
1
- import assign from 'lodash/assign';
2
-
3
- const EVENTS = {
4
- WIDGET_INIT: 'widget.init',
5
- SUBSCRIBE_START: 'subscribe.start',
6
- };
7
-
8
- const _handlers = {};
9
-
10
- window.TextBack = window.TextBack || {};
11
- window.TextBack.Observer = window.TextBack.Observer || {
12
- on(eventName, fn) {
13
- if (!_handlers[eventName]) {
14
- _handlers[eventName] = [ fn ];
15
- } else {
16
- _handlers[eventName].push(fn);
17
- }
18
-
19
- return () => {
20
- const fnIndex = _handlers[eventName].indexOf(fn);
21
- if (fnIndex !== -1) {
22
- _handlers[eventName].splice(fnIndex, 1);
23
- }
24
- };
25
- },
26
-
27
- trigger(eventName, data) {
28
- if (_handlers[eventName]) {
29
- const eventData = assign({}, data, { type: eventName });
30
- setTimeout(() => {
31
- _handlers[eventName].forEach(handler => {
32
- try {
33
- handler(eventData)
34
- } catch (err) {
35
- console.error(`Error occuired while executing event handler on event ${eventName}`, err);
36
- }
37
- });
38
- }, 0);
39
-
40
- }
41
- }
42
- };
43
-
44
- const Observer = window.TextBack.Observer;
45
-
46
- export { Observer, EVENTS };
1
+ import assign from 'lodash/assign';
2
+
3
+ const EVENTS = {
4
+ WIDGET_INIT: 'widget.init',
5
+ SUBSCRIBE_START: 'subscribe.start',
6
+ };
7
+
8
+ const _handlers = {};
9
+
10
+ window.TextBack = window.TextBack || {};
11
+ window.TextBack.Observer = window.TextBack.Observer || {
12
+ on(eventName, fn) {
13
+ if (!_handlers[eventName]) {
14
+ _handlers[eventName] = [ fn ];
15
+ } else {
16
+ _handlers[eventName].push(fn);
17
+ }
18
+
19
+ return () => {
20
+ const fnIndex = _handlers[eventName].indexOf(fn);
21
+ if (fnIndex !== -1) {
22
+ _handlers[eventName].splice(fnIndex, 1);
23
+ }
24
+ };
25
+ },
26
+
27
+ trigger(eventName, data) {
28
+ if (_handlers[eventName]) {
29
+ const eventData = assign({}, data, { type: eventName });
30
+ setTimeout(() => {
31
+ _handlers[eventName].forEach(handler => {
32
+ try {
33
+ handler(eventData)
34
+ } catch (err) {
35
+ console.error(`Error occuired while executing event handler on event ${eventName}`, err);
36
+ }
37
+ });
38
+ }, 0);
39
+
40
+ }
41
+ }
42
+ };
43
+
44
+ const Observer = window.TextBack.Observer;
45
+
46
+ export { Observer, EVENTS };
package/src/sdk/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import SDK from './sdk.js';
2
-
3
- window.TextBack = window.TextBack || {};
4
- window.TextBack.SDK = window.TextBack.SDK || new SDK();
5
-
1
+ import SDK from './sdk.js';
2
+
3
+ window.TextBack = window.TextBack || {};
4
+ window.TextBack.SDK = window.TextBack.SDK || new SDK();
5
+
6
6
  export default window.TextBack.SDK;
package/src/sdk/sdk.js CHANGED
@@ -1,30 +1,67 @@
1
- require('es6-promise').polyfill();
2
- import 'whatwg-fetch';
3
-
4
- import Widget from './widget/widget.js';
5
- import { Observer, EVENTS } from './events/observer.js';
6
-
7
- export default class SDK {
8
- constructor() {
9
- this.widgets = {};
10
- }
11
-
12
- initWidget(config) {
13
- if (config && config.widgetId) {
14
- const widget = new Widget(config, this);
15
- this.widgets[config.widgetId] = widget.initialize();
16
- this.widgets[config.widgetId].then(widget => Observer.trigger(EVENTS.WIDGET_INIT, { widgetId: config.widgetId }), err => console.error(err));
17
- return this.widgets[config.widgetId];
18
- } else {
19
- throw new Error('Widget id is not defined');
20
- }
21
- }
22
-
23
- getWidget(widgetId) {
24
- return this.widgets[widgetId] ? this.widgets[widgetId] : null;
25
- }
26
-
27
- on(eventName, fn) {
28
- return Observer.on(eventName, fn);
29
- }
30
- }
1
+ import apiErrorHandler from "./utils/apiErrorHandler";
2
+ import 'whatwg-fetch';
3
+
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();
9
+
10
+ export default class SDK {
11
+ constructor() {
12
+ this.widgets = {};
13
+ this._deeplinkUpdater = deeplinkUpdater;
14
+ }
15
+
16
+ initWidget(config, preventViewCounting = false) {
17
+ if (config && config.widgetId) {
18
+ const widget = new Widget(config, this);
19
+ 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));
28
+ return this.widgets[config.widgetId];
29
+ } else {
30
+ throw new Error('Widget id is not defined');
31
+ }
32
+ }
33
+
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
+ getWidget(widgetId) {
48
+ return this.widgets[widgetId] ? this.widgets[widgetId] : null;
49
+ }
50
+
51
+ on(eventName, fn) {
52
+ return Observer.on(eventName, fn);
53
+ }
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
+ }
@@ -1,12 +1,12 @@
1
- export default function apiErrorHandler(res) {
2
- return res.json()
3
- .then(data => {
4
- if (data.$error) {
5
- return Promise.reject(data.$error.msg || data.$error.scn);
6
- }
7
- data.headers = res.headers;
8
-
9
- return data;
10
- })
11
- .catch(() => Promise.reject(`widget error: ${res.status}`));
1
+ export default function apiErrorHandler(res) {
2
+ return res.json()
3
+ .then(data => {
4
+ if (data.$error) {
5
+ return Promise.reject(data.$error.msg || data.$error.scn);
6
+ }
7
+ data.headers = res.headers;
8
+
9
+ return data;
10
+ })
11
+ .catch(() => Promise.reject(`widget error: ${res.status}`));
12
12
  };
@@ -1,88 +1,88 @@
1
- const appInsights = {
2
- init(aiKey, userId, accountId) {
3
- return new Promise((resolve, reject) => {
4
- window.TextBack = window.TextBack || {};
5
- let context = window.TextBack;
6
- if (aiKey) {
7
- let appInsights = context.appInsights || function (config) {
8
- //basically most below code is got from MS so it's kinda unreadable hmm.. see MS instructions on appinsigths
9
- function r(config) {
10
- t[config] = function () {
11
- let i = arguments;
12
- t.queue.push(function () {
13
- t[config].apply(t, i)
14
- })
15
- }
16
- }
17
-
18
- let t = {
19
- config: config
20
- },
21
- u = document,
22
- e = context,
23
- o = "script",
24
- s = u.createElement(o),
25
- i, f;
26
- for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop());
27
- return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("​_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
28
- let s = f && f(config, r, u, e, o);
29
- return s !== !0 && t["_​" + i](config, r, u, e, o), s
30
- }), t
31
- }({
32
- instrumentationKey: aiKey,
33
- // Don't log browser exceptions.
34
- disableExceptionTracking: true,
35
- // Don't log ajax calls.
36
- disableAjaxTracking: true,
37
- //this url will point to the library - use @dev for testing when updating\editing lib - use @latest for production version of lib
38
- //keep in mind that prod widget should always use @latest
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
- //url: '//localhost:8080/src/libraries/ai.1.0.11.js',
42
- });
43
-
44
-
45
- this.accountId = accountId;
46
- context.appInsights = appInsights;
47
- //ensure appinsights is fully loaded
48
- let timer = setInterval(function () {
49
- if(appInsights._onerror){
50
- clearInterval(timer);
51
- appInsights.setAuthenticatedUserContext(userId);
52
- resolve(true);
53
- }
54
- }, 50);
55
-
56
- }
57
- //no aiKey - no telemetry
58
- else{
59
- resolve(true);
60
- }
61
- });
62
- },
63
- trackEvent(eventName, data) {
64
- let context = window.TextBack;
65
- context.appInsights && context.appInsights.trackEvent(eventName, data);
66
- },
67
- trackButtonClick(widgetId, eventName, channelType) {
68
- let payload = {
69
- channelType,
70
- widgetId,
71
- accountId: this.accountId,
72
- widgetUrl: window.location.href
73
- };
74
- this.trackEvent(eventName, payload);
75
- },
76
- trackWidgetEvent(widgetId, eventName, reason) {
77
- let payload = {
78
- reason,
79
- widgetId,
80
- accountId: this.accountId,
81
- widgetUrl: window.location.href
82
- };
83
- this.trackEvent(eventName, payload);
84
- }
85
- };
86
-
87
- export default appInsights;
88
-
1
+ const appInsights = {
2
+ init(aiKey, userId, accountId) {
3
+ return new Promise((resolve, reject) => {
4
+ window.TextBack = window.TextBack || {};
5
+ let context = window.TextBack;
6
+ if (aiKey) {
7
+ let appInsights = context.appInsights || function (config) {
8
+ //basically most below code is got from MS so it's kinda unreadable hmm.. see MS instructions on appinsigths
9
+ function r(config) {
10
+ t[config] = function () {
11
+ let i = arguments;
12
+ t.queue.push(function () {
13
+ t[config].apply(t, i)
14
+ })
15
+ }
16
+ }
17
+
18
+ let t = {
19
+ config: config
20
+ },
21
+ u = document,
22
+ e = context,
23
+ o = "script",
24
+ s = u.createElement(o),
25
+ i, f;
26
+ for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop());
27
+ return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("​_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
28
+ let s = f && f(config, r, u, e, o);
29
+ return s !== !0 && t["_​" + i](config, r, u, e, o), s
30
+ }), t
31
+ }({
32
+ instrumentationKey: aiKey,
33
+ // Don't log browser exceptions.
34
+ disableExceptionTracking: true,
35
+ // Don't log ajax calls.
36
+ disableAjaxTracking: true,
37
+ //this url will point to the library - use @dev for testing when updating\editing lib - use @latest for production version of lib
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'
41
+ //url: '//localhost:8080/src/libraries/ai.1.0.11.js',
42
+ });
43
+
44
+
45
+ this.accountId = accountId;
46
+ context.appInsights = appInsights;
47
+ //ensure appinsights is fully loaded
48
+ let timer = setInterval(function () {
49
+ if(appInsights._onerror){
50
+ clearInterval(timer);
51
+ appInsights.setAuthenticatedUserContext(userId);
52
+ resolve(true);
53
+ }
54
+ }, 50);
55
+
56
+ }
57
+ //no aiKey - no telemetry
58
+ else{
59
+ resolve(true);
60
+ }
61
+ });
62
+ },
63
+ trackEvent(eventName, data) {
64
+ let context = window.TextBack;
65
+ context.appInsights && context.appInsights.trackEvent(eventName, data);
66
+ },
67
+ trackButtonClick(widgetId, eventName, channelType) {
68
+ let payload = {
69
+ channelType,
70
+ widgetId,
71
+ accountId: this.accountId,
72
+ widgetUrl: window.location.href
73
+ };
74
+ this.trackEvent(eventName, payload);
75
+ },
76
+ trackWidgetEvent(widgetId, eventName, reason) {
77
+ let payload = {
78
+ reason,
79
+ widgetId,
80
+ accountId: this.accountId,
81
+ widgetUrl: window.location.href
82
+ };
83
+ this.trackEvent(eventName, payload);
84
+ }
85
+ };
86
+
87
+ export default appInsights;
88
+
@@ -1,9 +1,9 @@
1
- const isMobile = /Android|webOS|iPhone|iPad|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(navigator.userAgent);
2
-
3
- const browserInfo = {
4
- isMobile() {
5
- return isMobile;
6
- },
7
- };
8
-
1
+ const isMobile = /Android|webOS|iPhone|iPad|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(navigator.userAgent);
2
+
3
+ const browserInfo = {
4
+ isMobile() {
5
+ return isMobile;
6
+ },
7
+ };
8
+
9
9
  export default browserInfo;
@@ -1,18 +1,18 @@
1
- const COOKIE_NAME_PREFIX = 'tb_notif_widget_';
2
- const constants = {
3
- COOKIE_NAME_PREFIX: COOKIE_NAME_PREFIX,
4
- /**
5
- * 10 years
6
- */
7
- WIDGET_USER_ID_COOKIE_TTL: 315360000,
8
- COOKIE_WIDGET_USER_ID: `${COOKIE_NAME_PREFIX}widgetUserId`,
9
- SECONDS_IN_DAY: 86400,
10
- // make subscription using API call
11
- WIDGET_TYPE_API_CALL : 'apiCall',
12
- // make subscription using native social widget
13
- WIDGET_TYPE_WIDGET : 'widget',
14
- DEFAULT_WIDGET_TYPE : 'widget',
15
- SUBSCRIPTION_WINDOW_PROPS: 'width=600,height=800',
16
- };
17
-
1
+ const COOKIE_NAME_PREFIX = 'tb_notif_widget_';
2
+ const constants = {
3
+ COOKIE_NAME_PREFIX: COOKIE_NAME_PREFIX,
4
+ /**
5
+ * 10 years
6
+ */
7
+ WIDGET_USER_ID_COOKIE_TTL: 315360000,
8
+ COOKIE_WIDGET_USER_ID: `${COOKIE_NAME_PREFIX}widgetUserId`,
9
+ SECONDS_IN_DAY: 86400,
10
+ // make subscription using API call
11
+ WIDGET_TYPE_API_CALL : 'apiCall',
12
+ // make subscription using native social widget
13
+ WIDGET_TYPE_WIDGET : 'widget',
14
+ DEFAULT_WIDGET_TYPE : 'widget',
15
+ SUBSCRIPTION_WINDOW_PROPS: 'width=600,height=800',
16
+ };
17
+
18
18
  export default constants;
@@ -1,50 +1,67 @@
1
- /**
2
- * Created by martb on 28.06.2017.
3
- * Module for work with cookies
4
- */
5
-
6
- const cookies = {
7
- /**
8
- * возвращает cookie с именем name, если есть, если нет, то null
9
- * @param name {String}
10
- * @returns {String|null}
11
- */
12
- getCookie: function (name) {
13
- let nameEQ = name + "=";
14
- let ca = document.cookie.split(';');
15
- for (let i = 0; i < ca.length; i++) {
16
- let c = ca[i];
17
- while (c.charAt(0) === ' ') c = c.substring(1, c.length);
18
- if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
19
- }
20
- return null;
21
- },
22
-
23
- /**
24
- * устанавливает куку
25
- * @param name - имя куки
26
- * @param value - значение куки
27
- * @param t - время в секундах
28
- */
29
- setCookie: function (name, value, t) {
30
- let expires = "";
31
- if (t) {
32
- let date = new Date();
33
- t *= 1000;
34
- date.setTime(date.getTime() + t);
35
- expires = "; expires=" + date.toUTCString();
36
- }
37
- document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
38
- },
39
-
40
-
41
- /*
42
- * удаляет куку по имени
43
- * @param name {String}
44
- */
45
- deleteCookie: function (name) {
46
- setCookie(name, "", -1);
47
- }
48
- };
49
-
50
- export default cookies;
1
+ /**
2
+ * Created by martb on 28.06.2017.
3
+ * Module for work with cookies
4
+ */
5
+
6
+ const cookies = {
7
+ /**
8
+ * возвращает cookie с именем name, если есть, если нет, то null
9
+ * @param name {String}
10
+ * @returns {String|null}
11
+ */
12
+ getCookie: function (name) {
13
+ let nameEQ = name + "=";
14
+ let ca = document.cookie.split(';');
15
+ for (let i = 0; i < ca.length; i++) {
16
+ let c = ca[i];
17
+ while (c.charAt(0) === ' ') c = c.substring(1, c.length);
18
+ if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
19
+ }
20
+ return null;
21
+ },
22
+
23
+ /**
24
+ * устанавливает куку
25
+ * @param name - имя куки
26
+ * @param value - значение куки
27
+ * @param t - время в секундах
28
+ */
29
+ setCookie: function (name, value, t) {
30
+ let expires = "";
31
+ if (t) {
32
+ let date = new Date();
33
+ t *= 1000;
34
+ date.setTime(date.getTime() + t);
35
+ expires = "; expires=" + date.toUTCString();
36
+ }
37
+ document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
38
+ },
39
+
40
+
41
+ /*
42
+ * удаляет куку по имени
43
+ * @param name {String}
44
+ */
45
+ deleteCookie: function (name) {
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
+ }
65
+ };
66
+
67
+ export default cookies;
@@ -1,8 +1,8 @@
1
- export default function find(array, predicate) {
2
- for (let i = 0; i < array.length; i++) {
3
- if (predicate(array[i], i, array)) {
4
- return array[i];
5
- }
6
- }
7
- return undefined;
1
+ export default function find(array, predicate) {
2
+ for (let i = 0; i < array.length; i++) {
3
+ if (predicate(array[i], i, array)) {
4
+ return array[i];
5
+ }
6
+ }
7
+ return undefined;
8
8
  }
@@ -1,21 +1,21 @@
1
- import apiErrorHandler from './apiErrorHandler.js';
2
-
3
- const cache = {};
4
-
5
-
6
- export default function loadConfig(widgetId, apiPath) {
7
- if (!widgetId) {
8
- return Promise.reject('Widget id required');
9
- }
10
-
11
- if (cache[widgetId]) {
12
- return cache[widgetId];
13
- }
14
-
15
- const loadingPromise = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}`).then(apiErrorHandler);
16
- loadingPromise.then(() => {
17
- cache[widgetId] = loadingPromise;
18
- });
19
-
20
- return loadingPromise;
1
+ import apiErrorHandler from './apiErrorHandler.js';
2
+
3
+ const cache = {};
4
+
5
+
6
+ export default function loadConfig(widgetId, apiPath) {
7
+ if (!widgetId) {
8
+ return Promise.reject('Widget id required');
9
+ }
10
+
11
+ if (cache[widgetId]) {
12
+ return cache[widgetId];
13
+ }
14
+
15
+ const loadingPromise = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}`).then(apiErrorHandler);
16
+ loadingPromise.then(() => {
17
+ cache[widgetId] = loadingPromise;
18
+ });
19
+
20
+ return loadingPromise;
21
21
  };