@textback/notification-widget 2.0.1-84986 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. package/.eslintrc.js +291 -291
  2. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  3. package/.idea/misc.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/notificationwidget.iml +9 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/build/index.js +3 -3
  8. package/build/sdk.js +2 -2
  9. package/package.json +70 -70
  10. package/promote_tag.sh +1 -1
  11. package/readme.md +569 -569
  12. package/server.js +1 -1
  13. package/src/libraries/ai.1.0.11.js +4088 -4088
  14. package/src/libraries/localization/locales/index.js +8 -8
  15. package/src/libraries/localization/text.js +9 -9
  16. package/src/libraries/t.js +82 -82
  17. package/src/sdk/channels/channel.js +30 -30
  18. package/src/sdk/channels/facebook.js +13 -13
  19. package/src/sdk/channels/skype.js +12 -12
  20. package/src/sdk/channels/telegram.js +18 -18
  21. package/src/sdk/channels/viber.js +12 -12
  22. package/src/sdk/channels/vk-modal/vk-modal.html +17 -17
  23. package/src/sdk/channels/vk-modal/vk-modal.js +25 -25
  24. package/src/sdk/channels/vk-modal/vk-modal.scss +116 -116
  25. package/src/sdk/channels/vk.js +195 -195
  26. package/src/sdk/events/observer.js +46 -46
  27. package/src/sdk/index.js +5 -5
  28. package/src/sdk/sdk.js +67 -67
  29. package/src/sdk/utils/apiErrorHandler.js +11 -11
  30. package/src/sdk/utils/appInsights.js +88 -88
  31. package/src/sdk/utils/browserInfo.js +8 -8
  32. package/src/sdk/utils/constants.js +17 -17
  33. package/src/sdk/utils/cookies.js +67 -67
  34. package/src/sdk/utils/find.js +7 -7
  35. package/src/sdk/utils/loadConfig.js +20 -20
  36. package/src/sdk/utils/loadDeepLink.js +48 -48
  37. package/src/sdk/utils/loadScript.js +25 -25
  38. package/src/sdk/utils/loadSubscriptions.js +6 -6
  39. package/src/sdk/utils/parseQueryString.js +33 -33
  40. package/src/sdk/utils/windowHelper.js +25 -25
  41. package/src/sdk/widget/widget.js +192 -192
  42. package/src/widget/components/tb-notification-button/index.js +34 -34
  43. package/src/widget/components/tb-notification-button/styles.scss +657 -657
  44. package/src/widget/components/tb-notification-widget/normalize.scss +395 -395
  45. package/src/widget/components/tb-nw-wahunter/styles.scss +471 -471
  46. package/src/widget/config.js +5 -5
  47. package/src/widget/icons/icon_chat_window.svg +1 -1
  48. package/src/widget/icons/icon_close.svg +1 -1
  49. package/src/widget/icons/icon_facebook.svg +7 -7
  50. package/src/widget/icons/icon_facebook_circle.svg +7 -7
  51. package/src/widget/icons/icon_instagram_circle.svg +95 -95
  52. package/src/widget/icons/icon_skype.svg +44 -44
  53. package/src/widget/icons/icon_skype_circle.svg +46 -46
  54. package/src/widget/icons/icon_skype_new.svg +113 -113
  55. package/src/widget/icons/icon_tg.svg +25 -25
  56. package/src/widget/icons/icon_tg_circle.svg +17 -17
  57. package/src/widget/icons/icon_viber.svg +75 -75
  58. package/src/widget/icons/icon_viber_circle.svg +67 -67
  59. package/src/widget/icons/icon_viber_new.svg +102 -102
  60. package/src/widget/icons/icon_vk.svg +14 -14
  61. package/src/widget/icons/icon_vk_circle.svg +16 -16
  62. package/src/widget/icons/icon_whatsapp.svg +147 -147
  63. package/src/widget/icons/icon_whatsapp_circle.svg +3 -3
  64. package/src/widget/icons/icon_whatsapp_new.svg +127 -127
  65. package/src/widget/icons/icon_whatsappb.svg +147 -147
  66. package/src/widget/icons/icon_whatsappb_circle.svg +3 -3
  67. package/src/widget/icons/icon_whatsappb_new.svg +127 -127
  68. package/src/widget/icons/paper-plane-arrow.svg +3 -3
  69. package/src/widget/icons/tb-logo.svg +21 -21
  70. package/src/widget/index.js +28 -28
  71. package/src/widget/locales/cs.js +42 -42
  72. package/src/widget/locales/en.js +42 -42
  73. package/src/widget/locales/ro.js +41 -41
  74. package/src/widget/utils/cookiesEx.js +41 -41
  75. package/src/widget/utils/stringifyAttributes.js +19 -19
  76. package/src/widget/utils/widgetsStorage.js +28 -28
  77. package/src/widget/widget.entry.js +3 -3
  78. package/tests/gf.html +35 -35
  79. package/tests/gf.js +21 -21
  80. package/tests/index.js +61 -61
  81. package/views/examples.ejs +3 -3
  82. package/views/sdk.html +274 -274
  83. package/webpack.common.js +72 -72
  84. package/webpack.dev.js +15 -15
  85. package/webpack.prod.js +10 -10
@@ -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,67 +1,67 @@
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
+ 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,67 +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
- 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
+ /**
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
  }