@subiz/widget-v4 4.0.92 → 4.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled_src/bot.js +0 -11
- package/compiled_src/call/call.js +0 -61
- package/compiled_src/call/css.js +0 -2
- package/compiled_src/chatbox/AgentsAvatar.js +0 -16
- package/compiled_src/chatbox/AudioAttachments.js +0 -14
- package/compiled_src/chatbox/ButtonAttachments.js +1 -14
- package/compiled_src/chatbox/Buttons.js +0 -13
- package/compiled_src/chatbox/ChatButton.js +1 -78
- package/compiled_src/chatbox/DropdownSelect.js +3 -44
- package/compiled_src/chatbox/Emoji.js +0 -7
- package/compiled_src/chatbox/Event.js +0 -59
- package/compiled_src/chatbox/Events.js +4 -44
- package/compiled_src/chatbox/FileAttachments.js +0 -14
- package/compiled_src/chatbox/FormAttachment.js +1 -52
- package/compiled_src/chatbox/FormAttachments.js +0 -14
- package/compiled_src/chatbox/FormSubmitAttachments.js +0 -11
- package/compiled_src/chatbox/GenericTemplateAttachments.js +1 -20
- package/compiled_src/chatbox/Header.js +1 -46
- package/compiled_src/chatbox/ImageAttachments.js +0 -16
- package/compiled_src/chatbox/InfoMessage.js +0 -13
- package/compiled_src/chatbox/ListField.js +0 -16
- package/compiled_src/chatbox/MessageInput.js +1 -47
- package/compiled_src/chatbox/Order.js +0 -35
- package/compiled_src/chatbox/OrderAttachments.js +1 -23
- package/compiled_src/chatbox/PoweredBy.js +0 -7
- package/compiled_src/chatbox/ProductAttachments.js +0 -19
- package/compiled_src/chatbox/QuickReplies.js +0 -18
- package/compiled_src/chatbox/Rating.js +0 -37
- package/compiled_src/chatbox/ShadowDomRoot.js +0 -9
- package/compiled_src/chatbox/TextMessage.js +0 -64
- package/compiled_src/chatbox/Typing.js +0 -15
- package/compiled_src/chatbox/VideoAttachments.js +0 -14
- package/compiled_src/chatbox/Widget.js +6 -167
- package/compiled_src/chatbox/css.js +0 -2
- package/compiled_src/chatbox/dragscroll.js +1 -5
- package/compiled_src/chatbox/main.js +1 -40
- package/compiled_src/chatbox/releaseAnimation.js +0 -11
- package/compiled_src/chatbox/spinner.js +0 -10
- package/compiled_src/chatbox/time.js +0 -22
- package/compiled_src/chatbox/touchscroll.js +0 -7
- package/compiled_src/common.js +0 -22
- package/compiled_src/contact/contact.js +2 -52
- package/compiled_src/contact/css.js +0 -2
- package/compiled_src/lib.js +19 -46
- package/compiled_src/notif/css.js +0 -2
- package/compiled_src/notif/notif.js +0 -63
- package/compiled_src/order/address_picker.js +4 -38
- package/compiled_src/order/icon.js +0 -16
- package/compiled_src/order/index.js +1 -34
- package/compiled_src/order/order.js +2 -156
- package/compiled_src/plugin.js +1 -77
- package/compiled_src/popup/countdown.js +2 -33
- package/compiled_src/popup/css.js +0 -2
- package/compiled_src/popup/popup.js +2 -165
- package/compiled_src/popup/tick.core.commonjs.js +72 -222
- package/compiled_src/popup/tick.view.flip.commonjs.js +23 -31
- package/compiled_src/store/api.js +99 -65
- package/compiled_src/store/api_fake.js +3 -39
- package/compiled_src/store/realtime_fake.js +0 -6
- package/compiled_src/store/store.js +42 -248
- package/compiled_src/util/campaign.js +0 -13
- package/compiled_src/util/common.js +15 -185
- package/compiled_src/util/common.test.js +0 -4
- package/compiled_src/util/extractor.js +1 -21
- package/compiled_src/util/extractor.test.js +0 -3
- package/compiled_src/util/gate.js +0 -7
- package/compiled_src/util/gate.test.js +1 -2
- package/compiled_src/util/index.js +1 -7
- package/compiled_src/util/mutex.js +31 -0
- package/compiled_src/util/op.js +1 -14
- package/compiled_src/util/pubsub.js +0 -6
- package/compiled_src/util/pubsub.test.js +0 -2
- package/package.json +11 -11
- package/src/lib.js +24 -2
- package/src/store/api.js +110 -21
- package/src/store/api_fake.js +5 -6
- package/src/store/store.js +31 -5
- package/src/util/index.js +1 -0
- package/src/util/mutex.js +27 -0
- package/dist/132.js +0 -7092
- package/dist/178.js +0 -406
- package/dist/18364d15f37.132.js +0 -1
- package/dist/18364d15f37.178.js +0 -1
- package/dist/18364d15f37.213.js +0 -1
- package/dist/18364d15f37.335.js +0 -1
- package/dist/18364d15f37.362.js +0 -1
- package/dist/18364d15f37.441.js +0 -1
- package/dist/18364d15f37.605.js +0 -1
- package/dist/18364d15f37.678.js +0 -1
- package/dist/18364d15f37.782.js +0 -1
- package/dist/18364d15f37.app.js +0 -1
- package/dist/18364d15f37.index.html +0 -26
- package/dist/18364d15f37.library.html +0 -26
- package/dist/18364d15f37.library.js +0 -1
- package/dist/18364d15f37.preview.html +0 -759
- package/dist/18364d15f37.preview.js +0 -1
- package/dist/18364d15f37.screenshoot.js +0 -1
- package/dist/213.js +0 -3215
- package/dist/335.js +0 -411
- package/dist/362.js +0 -107
- package/dist/441.js +0 -2834
- package/dist/605.js +0 -328
- package/dist/678.js +0 -107
- package/dist/782.js +0 -107
- package/dist/HASH +0 -1
- package/dist/assets/img/Facebook.64607ec.png +0 -0
- package/dist/assets/img/Zalo.6845707.png +0 -0
- package/dist/assets/img/award1a.1a58e10.png +0 -0
- package/dist/assets/img/award3a.3b74423.png +0 -0
- package/dist/assets/img/award4a.ed6ccd4.png +0 -0
- package/dist/assets/img/award5.39eb7ae.png +0 -0
- package/dist/assets/img/bubble_default.7d5e4ab.svg +0 -20
- package/dist/assets/img/caret.998eb8f.svg +0 -1
- package/dist/assets/img/convos_empty.2353007.svg +0 -72
- package/dist/assets/img/default.06e6ee0.jpg +0 -0
- package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
- package/dist/assets/img/done_gray.d7e8203.svg +0 -4
- package/dist/assets/img/done_green.b817fd4.svg +0 -4
- package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
- package/dist/assets/img/empty.29bed2d.svg +0 -23
- package/dist/assets/img/empty_1.0b98af0.svg +0 -11
- package/dist/assets/img/examplte_logo.f86535f.svg +0 -1
- package/dist/assets/img/external-link.90577cc.svg +0 -1
- package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
- package/dist/assets/img/ghn.070f8e3.svg +0 -17
- package/dist/assets/img/ghtk.326eac1.svg +0 -18
- package/dist/assets/img/image_default.be0698b.png +0 -0
- package/dist/assets/img/info.ebce7ea.svg +0 -1
- package/dist/assets/img/loader.37000a7.svg +0 -1
- package/dist/assets/img/loading_static.8f403ae.svg +0 -10
- package/dist/assets/img/main-service1.d536cc2.png +0 -0
- package/dist/assets/img/main-service2.9b99549.png +0 -0
- package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
- package/dist/assets/img/package.8d37d0f.svg +0 -5
- package/dist/assets/img/package_fade.763c001.svg +0 -1
- package/dist/assets/img/rating--average.1ea492c.svg +0 -12
- package/dist/assets/img/rating--great.e3d712e.svg +0 -16
- package/dist/assets/img/rating--poor.2938a25.svg +0 -12
- package/dist/assets/img/search.f9705ff.svg +0 -1
- package/dist/assets/img/send.6db52a9.svg +0 -3
- package/dist/assets/img/shop.f7dc7d8.svg +0 -1
- package/dist/assets/img/shop_faded.df7845a.svg +0 -1
- package/dist/assets/img/subiz-mono.877e9f5.svg +0 -3
- package/dist/assets/img/x.26fdfa3.svg +0 -5
- package/dist/malicious-app.js +0 -13
- package/dist/screenshoot.html +0 -7
- package/dist/screenshoot.js +0 -5953
|
@@ -64,15 +64,12 @@ exports.trimStart = trimStart;
|
|
|
64
64
|
exports.unicodeToAscii = unicodeToAscii;
|
|
65
65
|
exports.unixSec = unixSec;
|
|
66
66
|
exports.usersOfConvo = usersOfConvo;
|
|
67
|
-
|
|
68
67
|
var op = require('./op.js');
|
|
69
|
-
|
|
70
68
|
function parseJSON(str) {
|
|
71
69
|
try {
|
|
72
70
|
return parse(str);
|
|
73
71
|
} catch (e) {}
|
|
74
72
|
}
|
|
75
|
-
|
|
76
73
|
var f = document.createElement('iframe');
|
|
77
74
|
f.style.display = 'none';
|
|
78
75
|
document.documentElement.appendChild(f);
|
|
@@ -86,11 +83,10 @@ exports.requestAnimationFrame = requestAnimationFrame;
|
|
|
86
83
|
var setTimeout = f.contentWindow.setTimeout;
|
|
87
84
|
exports.setTimeout = setTimeout;
|
|
88
85
|
var setInterval = f.contentWindow.setInterval;
|
|
89
|
-
exports.setInterval = setInterval;
|
|
90
86
|
|
|
87
|
+
exports.setInterval = setInterval;
|
|
91
88
|
function convoOfEv(ev) {
|
|
92
89
|
if (!ev) return '';
|
|
93
|
-
|
|
94
90
|
switch (ev.type) {
|
|
95
91
|
case 'conversation_state_updated':
|
|
96
92
|
case 'conversation_joined':
|
|
@@ -102,23 +98,18 @@ function convoOfEv(ev) {
|
|
|
102
98
|
case 'conversation_rating_requested':
|
|
103
99
|
case 'conversation_rated':
|
|
104
100
|
return op.get(ev, 'data.conversation.id');
|
|
105
|
-
|
|
106
101
|
case 'message_sent':
|
|
107
102
|
case 'message_updated':
|
|
108
103
|
case 'message_pong':
|
|
109
104
|
return op.get(ev, 'data.message.conversation_id');
|
|
110
|
-
|
|
111
105
|
case 'ticket_updated':
|
|
112
106
|
return op.get(ev, 'data.ticket.conversation_id');
|
|
113
|
-
|
|
114
107
|
default:
|
|
115
108
|
return '';
|
|
116
109
|
}
|
|
117
110
|
}
|
|
118
|
-
|
|
119
111
|
function convoToEv(convoid, ev) {
|
|
120
112
|
if (!ev) return '';
|
|
121
|
-
|
|
122
113
|
switch (ev.type) {
|
|
123
114
|
case 'conversation_state_updated':
|
|
124
115
|
case 'conversation_joined':
|
|
@@ -130,20 +121,16 @@ function convoToEv(convoid, ev) {
|
|
|
130
121
|
case 'conversation_rating_requested':
|
|
131
122
|
case 'conversation_rated':
|
|
132
123
|
return op.set(ev, 'data.conversation.id', convoid);
|
|
133
|
-
|
|
134
124
|
case 'message_sent':
|
|
135
125
|
case 'message_updated':
|
|
136
126
|
case 'message_pong':
|
|
137
127
|
return op.set(ev, 'data.message.conversation_id', convoid);
|
|
138
|
-
|
|
139
128
|
case 'ticket_updated':
|
|
140
129
|
return op.set(ev, 'data.ticket.conversation_id', convoid);
|
|
141
|
-
|
|
142
130
|
default:
|
|
143
131
|
return '';
|
|
144
132
|
}
|
|
145
133
|
}
|
|
146
|
-
|
|
147
134
|
function setMsgField(ev, key, value) {
|
|
148
135
|
var fields = op.get(ev, 'data.message.fields') || [];
|
|
149
136
|
fields = filter(fields, field => field.key !== key);
|
|
@@ -153,30 +140,24 @@ function setMsgField(ev, key, value) {
|
|
|
153
140
|
});
|
|
154
141
|
op.set(ev, 'data.message.fields', fields);
|
|
155
142
|
}
|
|
156
|
-
|
|
157
143
|
function getMsgField(ev, fieldName) {
|
|
158
144
|
var fields = op.get(ev, 'data.message.fields');
|
|
159
145
|
if (size(fields) === 0) return undefined;
|
|
160
146
|
let f = fields.find(f => f.key === fieldName);
|
|
161
|
-
|
|
162
147
|
try {
|
|
163
148
|
if (f) return parse(f.value);
|
|
164
149
|
return undefined;
|
|
165
150
|
} catch (e) {}
|
|
166
151
|
}
|
|
167
|
-
|
|
168
152
|
function isObject(item) {
|
|
169
153
|
return item && typeof item === 'object' && !Array.isArray(item);
|
|
170
154
|
}
|
|
171
|
-
|
|
172
155
|
function merge(target) {
|
|
173
156
|
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
174
157
|
sources[_key - 1] = arguments[_key];
|
|
175
158
|
}
|
|
176
|
-
|
|
177
159
|
if (!sources.length) return target;
|
|
178
160
|
const source = sources.shift();
|
|
179
|
-
|
|
180
161
|
if (isObject(target) && isObject(source)) {
|
|
181
162
|
for (const key in source) {
|
|
182
163
|
if (isObject(source[key])) {
|
|
@@ -191,100 +172,77 @@ function merge(target) {
|
|
|
191
172
|
}
|
|
192
173
|
}
|
|
193
174
|
}
|
|
194
|
-
|
|
195
175
|
return merge(target, ...sources);
|
|
196
176
|
}
|
|
197
|
-
|
|
198
177
|
function cloneDeep(p) {
|
|
199
178
|
if (p !== Object(p)) return p;
|
|
200
179
|
var s = stringify(p);
|
|
201
180
|
if (s === undefined) return;
|
|
202
181
|
return parse(s);
|
|
203
182
|
}
|
|
204
|
-
|
|
205
183
|
function randomString(len) {
|
|
206
184
|
var str = '';
|
|
207
185
|
if (!len || len < 1) len = 10;
|
|
208
186
|
var asciiKey;
|
|
209
|
-
|
|
210
187
|
for (var i = 0; i < len; i++) {
|
|
211
188
|
asciiKey = Math.floor(Math.random() * 25 + 97);
|
|
212
189
|
str += String.fromCharCode(asciiKey);
|
|
213
190
|
}
|
|
214
|
-
|
|
215
191
|
return str;
|
|
216
192
|
}
|
|
217
|
-
|
|
218
193
|
function filter(collection, predicate) {
|
|
219
194
|
if (!collection) return [];
|
|
220
195
|
if (!predicate) return collection;
|
|
221
196
|
var out = [];
|
|
222
|
-
|
|
223
197
|
if (Array.isArray(collection)) {
|
|
224
198
|
for (let i = 0; i < collection.length; i++) {
|
|
225
199
|
if (predicate(collection[i], i)) out.push(collection[i]);
|
|
226
200
|
}
|
|
227
|
-
|
|
228
201
|
return out;
|
|
229
202
|
}
|
|
230
|
-
|
|
231
203
|
if (typeof collection === 'object') {
|
|
232
204
|
var keys = Object.keys(collection);
|
|
233
|
-
|
|
234
205
|
for (let i = 0; i < keys.length; i++) {
|
|
235
206
|
var k = keys[i];
|
|
236
207
|
if (predicate(collection[k], k)) out.push(collection[k]);
|
|
237
208
|
}
|
|
238
|
-
|
|
239
209
|
return out;
|
|
240
210
|
}
|
|
241
|
-
|
|
242
211
|
return out;
|
|
243
212
|
}
|
|
244
|
-
|
|
245
213
|
function includes(collection, value) {
|
|
246
214
|
if (!collection) return false;
|
|
247
215
|
var isString = typeof collection === 'string' || collection instanceof String;
|
|
248
216
|
if (Array.isArray(collection) || isString) return collection.includes(value);
|
|
249
217
|
return false;
|
|
250
218
|
}
|
|
251
|
-
|
|
252
219
|
function map(collection, predicate) {
|
|
253
220
|
if (!collection) return [];
|
|
254
221
|
if (!predicate) predicate = i => i;
|
|
255
222
|
var out = [];
|
|
256
|
-
|
|
257
223
|
if (Array.isArray(collection)) {
|
|
258
224
|
for (let i = 0; i < collection.length; i++) {
|
|
259
225
|
out.push(predicate(collection[i], i));
|
|
260
226
|
}
|
|
261
|
-
|
|
262
227
|
return out;
|
|
263
228
|
}
|
|
264
|
-
|
|
265
229
|
if (typeof collection === 'object') {
|
|
266
230
|
var keys = Object.keys(collection);
|
|
267
|
-
|
|
268
231
|
for (let i = 0; i < keys.length; i++) {
|
|
269
232
|
var k = keys[i];
|
|
270
233
|
out.push(predicate(collection[k], k));
|
|
271
234
|
}
|
|
272
|
-
|
|
273
235
|
return out;
|
|
274
236
|
}
|
|
275
|
-
|
|
276
237
|
return out;
|
|
277
238
|
}
|
|
278
|
-
|
|
279
239
|
function each(collection, predicate) {
|
|
280
240
|
return map(collection, predicate);
|
|
281
241
|
}
|
|
282
|
-
|
|
283
242
|
function usersOfConvo(convo) {
|
|
284
243
|
if (!convo) return [];
|
|
285
244
|
return map(filter(convo.members, m => m.type === 'user'), m => m.id);
|
|
286
245
|
}
|
|
287
|
-
|
|
288
246
|
function isConvoSeen(convo, memberid) {
|
|
289
247
|
if (convo.state === 'ended') return true;
|
|
290
248
|
let lastmsgsent = convo.last_message_sent;
|
|
@@ -294,7 +252,6 @@ function isConvoSeen(convo, memberid) {
|
|
|
294
252
|
if (!mem) return true;
|
|
295
253
|
return getMs(lastmsgsent.created) < getMs(mem.seen_at);
|
|
296
254
|
}
|
|
297
|
-
|
|
298
255
|
function agentsOfConvo(convo, botIncluded) {
|
|
299
256
|
if (!convo) return [];
|
|
300
257
|
return map(filter(convo.members, m => {
|
|
@@ -302,30 +259,23 @@ function agentsOfConvo(convo, botIncluded) {
|
|
|
302
259
|
return m.type === 'agent';
|
|
303
260
|
}), m => m.id);
|
|
304
261
|
}
|
|
305
|
-
|
|
306
262
|
function startsWith(s, i) {
|
|
307
263
|
return ((s || '') + '').startsWith(i);
|
|
308
264
|
}
|
|
309
|
-
|
|
310
265
|
function size(o) {
|
|
311
266
|
if (!o) return 0;
|
|
312
267
|
if (o.length !== undefined) return o.length;
|
|
313
268
|
return Object.keys(o).length;
|
|
314
269
|
}
|
|
315
|
-
|
|
316
270
|
function replaceAll(str, a, b) {
|
|
317
271
|
return (str || '').split(a).join(b);
|
|
318
272
|
}
|
|
319
|
-
|
|
320
273
|
function trim(s, suffix) {
|
|
321
274
|
return ((s || '') + '').replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|
322
275
|
}
|
|
323
|
-
|
|
324
276
|
function trimStart(s, prefix) {
|
|
325
277
|
s = (s || '') + '';
|
|
326
|
-
|
|
327
278
|
while (s.charAt(0) === prefix) s = s.substr(1);
|
|
328
|
-
|
|
329
279
|
return s;
|
|
330
280
|
}
|
|
331
281
|
|
|
@@ -334,67 +284,54 @@ function throttle(func, wait, options) {
|
|
|
334
284
|
var timeout = null;
|
|
335
285
|
var previous = 0;
|
|
336
286
|
if (!options) options = {};
|
|
337
|
-
|
|
338
287
|
var later = function () {
|
|
339
288
|
previous = options.leading === false ? 0 : new Date().getTime();
|
|
340
289
|
timeout = null;
|
|
341
290
|
result = func.apply(context, args);
|
|
342
291
|
if (!timeout) context = args = null;
|
|
343
292
|
};
|
|
344
|
-
|
|
345
293
|
return function () {
|
|
346
294
|
var now = new Date().getTime();
|
|
347
295
|
if (!previous && options.leading === false) previous = now;
|
|
348
296
|
var remaining = wait - (now - previous);
|
|
349
297
|
context = this;
|
|
350
298
|
args = arguments;
|
|
351
|
-
|
|
352
299
|
if (remaining <= 0 || remaining > wait) {
|
|
353
300
|
if (timeout) {
|
|
354
301
|
clearTimeout(timeout);
|
|
355
302
|
timeout = null;
|
|
356
303
|
}
|
|
357
|
-
|
|
358
304
|
previous = now;
|
|
359
305
|
result = func.apply(context, args);
|
|
360
306
|
if (!timeout) context = args = null;
|
|
361
307
|
} else if (!timeout && options.trailing !== false) {
|
|
362
308
|
timeout = setTimeout(later, remaining);
|
|
363
309
|
}
|
|
364
|
-
|
|
365
310
|
return result;
|
|
366
311
|
};
|
|
367
312
|
}
|
|
368
|
-
|
|
369
313
|
function find(collection, f) {
|
|
370
314
|
if (!collection) return undefined;
|
|
371
315
|
return collection[findIndex(collection, f)];
|
|
372
316
|
}
|
|
373
|
-
|
|
374
317
|
function findIndex(collection, f) {
|
|
375
318
|
if (!collection) return -1;
|
|
376
319
|
if (!f) return -1;
|
|
377
|
-
|
|
378
320
|
if (Array.isArray(collection)) {
|
|
379
321
|
for (let i = 0; i < collection.length; i++) {
|
|
380
322
|
if (f(collection[i], i)) return i;
|
|
381
323
|
}
|
|
382
|
-
|
|
383
324
|
return -1;
|
|
384
325
|
}
|
|
385
|
-
|
|
386
326
|
if (typeof collection === 'object') {
|
|
387
327
|
var keys = Object.keys(collection);
|
|
388
|
-
|
|
389
328
|
for (let i = 0; i < keys.length; i++) {
|
|
390
329
|
var k = keys[i];
|
|
391
330
|
if (f(collection[k], k)) return k;
|
|
392
331
|
}
|
|
393
332
|
}
|
|
394
|
-
|
|
395
333
|
return -1;
|
|
396
334
|
}
|
|
397
|
-
|
|
398
335
|
function orderBy(a, k, d) {
|
|
399
336
|
var clone = [];
|
|
400
337
|
each(a, v => clone.push(v));
|
|
@@ -405,54 +342,43 @@ function orderBy(a, k, d) {
|
|
|
405
342
|
});
|
|
406
343
|
return clone;
|
|
407
344
|
}
|
|
408
|
-
|
|
409
345
|
function isPhone(phone) {
|
|
410
346
|
var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
|
|
411
347
|
return re.test(String(phone));
|
|
412
348
|
}
|
|
413
|
-
|
|
414
349
|
function isURL(url) {
|
|
415
350
|
var re = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
|
|
416
351
|
return re.test(String(url).toLowerCase());
|
|
417
352
|
}
|
|
418
|
-
|
|
419
353
|
function isNumber(num) {
|
|
420
354
|
var re = /^\d+$/;
|
|
421
355
|
return re.test(String(num));
|
|
422
356
|
}
|
|
423
|
-
|
|
424
357
|
function isEmail(email) {
|
|
425
358
|
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
426
359
|
return re.test(String(email).toLowerCase());
|
|
427
360
|
}
|
|
428
|
-
|
|
429
361
|
function last(array) {
|
|
430
362
|
var length = array == null ? 0 : array.length;
|
|
431
363
|
return length ? array[length - 1] : undefined;
|
|
432
364
|
}
|
|
433
|
-
|
|
434
365
|
function getAgentDisplayName(account, agent) {
|
|
435
366
|
return op.get(agent, 'fullname') || op.get(agent, 'email') || op.get(account, 'name') || 'Agent';
|
|
436
367
|
}
|
|
437
|
-
|
|
438
368
|
function isUserBanned(user) {
|
|
439
369
|
return getUserAttr(user, 'is_ban', 'boolean');
|
|
440
370
|
}
|
|
441
|
-
|
|
442
371
|
function setUserAttr(user, attr) {
|
|
443
372
|
if (!user) return;
|
|
444
373
|
if (!op.get(attr, 'key')) return;
|
|
445
374
|
user.attributes = user.attributes || [];
|
|
446
375
|
var index = findIndex(user.attributes, a => a.key === attr.key);
|
|
447
|
-
|
|
448
376
|
if (index === -1) {
|
|
449
377
|
user.attributes.push(attr);
|
|
450
378
|
return;
|
|
451
379
|
}
|
|
452
|
-
|
|
453
380
|
user.attributes[index] = attr;
|
|
454
381
|
}
|
|
455
|
-
|
|
456
382
|
function getUserAttr(user, key, type) {
|
|
457
383
|
if (!user || !user.attributes) return;
|
|
458
384
|
let value;
|
|
@@ -466,19 +392,15 @@ function getUserAttr(user, key, type) {
|
|
|
466
392
|
});
|
|
467
393
|
return value;
|
|
468
394
|
}
|
|
469
|
-
|
|
470
395
|
function norm(s) {
|
|
471
396
|
s = s || '';
|
|
472
397
|
return s.trim().toLowerCase();
|
|
473
398
|
}
|
|
474
|
-
|
|
475
399
|
function noop() {}
|
|
476
|
-
|
|
477
400
|
function norm2(val) {
|
|
478
401
|
if (typeof val === 'string' || val instanceof String) val = val.trim().replace(/;+$/, '');
|
|
479
402
|
return val;
|
|
480
403
|
}
|
|
481
|
-
|
|
482
404
|
function replaceCssVariablePlugin(css, setting) {
|
|
483
405
|
var tokens = [css];
|
|
484
406
|
let spacer = setting.spacer || 10;
|
|
@@ -499,10 +421,8 @@ function replaceCssVariablePlugin(css, setting) {
|
|
|
499
421
|
tokens = tokenize(tokens, "'@spacer2'");
|
|
500
422
|
tokens = tokenize(tokens, "'@spacer3'");
|
|
501
423
|
var ret = [];
|
|
502
|
-
|
|
503
424
|
for (var i = 0; i < tokens.length; i++) {
|
|
504
425
|
var item = tokens[i];
|
|
505
|
-
|
|
506
426
|
if (typeof item === 'string') {
|
|
507
427
|
ret.push(item);
|
|
508
428
|
continue;
|
|
@@ -512,10 +432,8 @@ function replaceCssVariablePlugin(css, setting) {
|
|
|
512
432
|
var val = op.get(setting, path) || op.get(DEFVAL, path) || '';
|
|
513
433
|
ret.push(val);
|
|
514
434
|
}
|
|
515
|
-
|
|
516
435
|
return ret.join('');
|
|
517
436
|
}
|
|
518
|
-
|
|
519
437
|
function replaceCssVariable(css, setting) {
|
|
520
438
|
var tokens = [css];
|
|
521
439
|
tokens = tokenize(tokens, "'@primary_color'");
|
|
@@ -544,39 +462,32 @@ function replaceCssVariable(css, setting) {
|
|
|
544
462
|
tokens = tokenize(tokens, "'@z_index_4'");
|
|
545
463
|
tokens = tokenize(tokens, "'@z_index_5'");
|
|
546
464
|
var ret = [];
|
|
547
|
-
|
|
548
465
|
for (var i = 0; i < tokens.length; i++) {
|
|
549
466
|
var item = tokens[i];
|
|
550
|
-
|
|
551
467
|
if (typeof item === 'string') {
|
|
552
468
|
ret.push(item);
|
|
553
469
|
continue;
|
|
554
470
|
}
|
|
555
|
-
|
|
556
471
|
if (item.type === '@esc-primary-color-esc') {
|
|
557
472
|
var val = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
|
|
558
473
|
ret.push(encodeURIComponent(norm2(val)));
|
|
559
474
|
continue;
|
|
560
475
|
}
|
|
561
|
-
|
|
562
476
|
if (item.type === "'@z_index_2'") {
|
|
563
477
|
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
564
478
|
ret.push(val + 2);
|
|
565
479
|
continue;
|
|
566
480
|
}
|
|
567
|
-
|
|
568
481
|
if (item.type === "'@z_index_3'") {
|
|
569
482
|
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
570
483
|
ret.push(val + 3);
|
|
571
484
|
continue;
|
|
572
485
|
}
|
|
573
|
-
|
|
574
486
|
if (item.type === "'@z_index_4'") {
|
|
575
487
|
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
576
488
|
ret.push(val + 4);
|
|
577
489
|
continue;
|
|
578
490
|
}
|
|
579
|
-
|
|
580
491
|
if (item.type === "'@z_index_5'") {
|
|
581
492
|
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
582
493
|
ret.push(val + 5);
|
|
@@ -586,7 +497,6 @@ function replaceCssVariable(css, setting) {
|
|
|
586
497
|
var path = item.type.substr(2, item.type.length - 3);
|
|
587
498
|
var val = op.get(setting, path) || op.get(DEFVAL, path) || '';
|
|
588
499
|
val = norm2(val);
|
|
589
|
-
|
|
590
500
|
if (['mobile_button.width', 'mobile_button.height', 'mobile_button.margin_x', 'mobile_button.margin_y', 'desktop_button.width', 'desktop_button.height', 'desktop_button.margin_x', 'desktop_button.margin_y', 'width', 'height'].includes(path)) {
|
|
591
501
|
val += 'px';
|
|
592
502
|
}
|
|
@@ -595,43 +505,33 @@ function replaceCssVariable(css, setting) {
|
|
|
595
505
|
ret.push('100%');
|
|
596
506
|
continue;
|
|
597
507
|
}
|
|
598
|
-
|
|
599
508
|
ret.push(val);
|
|
600
509
|
}
|
|
601
|
-
|
|
602
510
|
return ret.join('');
|
|
603
511
|
}
|
|
604
512
|
|
|
605
513
|
function tokenize(arr, token) {
|
|
606
514
|
if (!arr || !arr.length) return [];
|
|
607
515
|
var out = [];
|
|
608
|
-
|
|
609
516
|
for (let i = 0; i < arr.length; i++) {
|
|
610
517
|
var item = arr[i];
|
|
611
|
-
|
|
612
518
|
if (typeof item !== 'string') {
|
|
613
519
|
out.push(item);
|
|
614
520
|
continue;
|
|
615
521
|
}
|
|
616
|
-
|
|
617
522
|
var ts = item.split(token);
|
|
618
|
-
|
|
619
523
|
for (let i = 0; i < ts.length; i++) {
|
|
620
524
|
out.push(ts[i]);
|
|
621
525
|
out.push({
|
|
622
526
|
type: token
|
|
623
527
|
});
|
|
624
528
|
}
|
|
625
|
-
|
|
626
529
|
out.pop();
|
|
627
530
|
}
|
|
628
|
-
|
|
629
531
|
return out;
|
|
630
532
|
}
|
|
631
|
-
|
|
632
533
|
function setCss(id, $css, css) {
|
|
633
534
|
css = replaceAll(css, '#sbz92', '#' + id);
|
|
634
|
-
|
|
635
535
|
if ($css.styleSheet) {
|
|
636
536
|
$css.styleSheet.cssText = css;
|
|
637
537
|
} else {
|
|
@@ -639,7 +539,6 @@ function setCss(id, $css, css) {
|
|
|
639
539
|
$css.appendChild(document.createTextNode(css));
|
|
640
540
|
}
|
|
641
541
|
}
|
|
642
|
-
|
|
643
542
|
const DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = 'https://file-subiz.com/bubble_11.svg';
|
|
644
543
|
exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL;
|
|
645
544
|
const DEFVAL = {
|
|
@@ -670,25 +569,25 @@ const DEFVAL = {
|
|
|
670
569
|
z_index: 2000000000
|
|
671
570
|
};
|
|
672
571
|
exports.DEFVAL = DEFVAL;
|
|
673
|
-
|
|
674
572
|
function js2css(js, onlyprops, variables) {
|
|
675
573
|
var newjs = {};
|
|
676
|
-
|
|
677
574
|
for (var prop in js) {
|
|
678
575
|
if (!js.hasOwnProperty(prop)) continue;
|
|
576
|
+
|
|
679
577
|
if (onlyprops && onlyprops.length > 0 && onlyprops.indexOf(prop) === -1) continue;
|
|
578
|
+
|
|
680
579
|
if (typeof js[prop] === 'string') newjs[prop] = trim(js[prop]);else newjs[prop] = js[prop];
|
|
681
580
|
}
|
|
682
|
-
|
|
683
581
|
js = newjs;
|
|
684
582
|
let style = '';
|
|
685
|
-
|
|
686
583
|
for (var prop in js) {
|
|
687
584
|
if (!js.hasOwnProperty(prop)) continue;
|
|
585
|
+
|
|
688
586
|
var filter = '';
|
|
689
587
|
if (js.blur) filter += 'blur(' + js.blur + ') ';
|
|
690
588
|
if (js.grayscale) filter += 'grayscale(' + js + ') ';
|
|
691
589
|
if (filter) style += 'filter: ' + filter + '!important;';
|
|
590
|
+
|
|
692
591
|
if (js.rotate !== undefined) style += 'transform:rotate(' + js.rotate + ') !important;';
|
|
693
592
|
|
|
694
593
|
if (js[prop] !== undefined) {
|
|
@@ -700,12 +599,11 @@ function js2css(js, onlyprops, variables) {
|
|
|
700
599
|
if (prop === 'color') style += '-webkit-text-fill-color: ' + propval + ' !important;';
|
|
701
600
|
}
|
|
702
601
|
}
|
|
703
|
-
|
|
704
602
|
return style;
|
|
705
603
|
}
|
|
706
|
-
|
|
707
604
|
function browserName() {
|
|
708
605
|
var isOpera = !!window.opr && !!opr.addons || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
|
|
606
|
+
|
|
709
607
|
var isFirefox = typeof InstallTrigger !== 'undefined';
|
|
710
608
|
|
|
711
609
|
var isSafari = /constructor/i.test(window.HTMLElement) || function (p) {
|
|
@@ -713,10 +611,14 @@ function browserName() {
|
|
|
713
611
|
}(!window['safari'] || typeof safari !== 'undefined' && window['safari'].pushNotification);
|
|
714
612
|
|
|
715
613
|
var isIE = false || !!document.documentMode;
|
|
614
|
+
|
|
716
615
|
var isEdge = !isIE && !!window.StyleMedia;
|
|
616
|
+
|
|
717
617
|
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
|
|
718
618
|
if (!isChrome) isChrome = navigator.userAgent.indexOf('Chrome');
|
|
619
|
+
|
|
719
620
|
var isEdgeChromium = isChrome && navigator.userAgent.indexOf('Edg') != -1;
|
|
621
|
+
|
|
720
622
|
var isBlink = (isChrome || isOpera) && !!window.CSS;
|
|
721
623
|
if (isOpera) return 'opera';
|
|
722
624
|
if (isFirefox) return 'firefox';
|
|
@@ -726,7 +628,6 @@ function browserName() {
|
|
|
726
628
|
if (isBlink) return 'blink';
|
|
727
629
|
return 'unknown';
|
|
728
630
|
}
|
|
729
|
-
|
|
730
631
|
function osName() {
|
|
731
632
|
var OSName = 'Unknown';
|
|
732
633
|
if (window.navigator.userAgent.indexOf('Windows NT 10.0') != -1) OSName = 'Windows 10';
|
|
@@ -745,31 +646,25 @@ function osName() {
|
|
|
745
646
|
function check_frequently(freq, lastrun, store) {
|
|
746
647
|
if (!lastrun) return true;
|
|
747
648
|
if (op.get(freq, 'once_per_user')) return false;
|
|
748
|
-
|
|
749
649
|
if (op.get(freq, 'once_per_session')) {
|
|
750
650
|
if (sameDay(lastrun.created, Date.now())) return false;
|
|
751
651
|
}
|
|
752
|
-
|
|
753
652
|
if (op.get(freq, 'interval_sec')) {
|
|
754
653
|
var sec = op.get(freq, 'interval_sec');
|
|
755
654
|
if (sec > (Date.now() - lastrun.created) / 1000) return false;
|
|
756
655
|
}
|
|
757
|
-
|
|
758
656
|
return true;
|
|
759
657
|
}
|
|
760
|
-
|
|
761
658
|
function checkRunConditions(freq, conds, lastrun, store) {
|
|
762
659
|
var acc = store.matchAccount() || {};
|
|
763
660
|
var location = store.matchLocation() || {};
|
|
764
|
-
if (!check_frequently(freq, lastrun, store)) return false;
|
|
765
661
|
|
|
662
|
+
if (!check_frequently(freq, lastrun, store)) return false;
|
|
766
663
|
for (var i = 0; i < size(conds); i++) {
|
|
767
664
|
var cond = conds[i];
|
|
768
|
-
|
|
769
665
|
switch (cond.key) {
|
|
770
666
|
case 'url':
|
|
771
667
|
let exclude_urls = filter(cond.exclude_urls, url => norm(url));
|
|
772
|
-
|
|
773
668
|
if (size(exclude_urls) > 0) {
|
|
774
669
|
let found = find(exclude_urls, url => {
|
|
775
670
|
return norm(window.location.href).indexOf(norm(url)) > -1;
|
|
@@ -778,88 +673,69 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
778
673
|
}
|
|
779
674
|
|
|
780
675
|
let urls = filter(cond.urls, url => norm(url));
|
|
781
|
-
|
|
782
676
|
if (size(urls) > 0) {
|
|
783
677
|
let found = find(urls, url => {
|
|
784
678
|
return norm(window.location.href).indexOf(norm(url)) > -1;
|
|
785
679
|
});
|
|
786
680
|
if (!found) return false;
|
|
787
681
|
}
|
|
788
|
-
|
|
789
682
|
break;
|
|
790
|
-
|
|
791
683
|
case 'browser':
|
|
792
684
|
if (size(cond.browsers) > 0) {
|
|
793
685
|
var browsername = browserName();
|
|
794
686
|
if (!find(cond.browsers, b => norm(b) === norm(browsername))) return false;
|
|
795
687
|
}
|
|
796
|
-
|
|
797
688
|
break;
|
|
798
|
-
|
|
799
689
|
case 'location':
|
|
800
690
|
if (size(cond.exclude_locations) > 0) {
|
|
801
691
|
let found = find(cond.exclude_locations, loc => {
|
|
802
692
|
if (loc.city_name && loc.country_code) {
|
|
803
693
|
if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
|
|
804
694
|
}
|
|
805
|
-
|
|
806
695
|
if (loc.city_name && !loc.country_code) {
|
|
807
696
|
if (loc.city_name === location.city_name) return true;
|
|
808
697
|
}
|
|
809
|
-
|
|
810
698
|
if (!loc.city_name && loc.country_code) {
|
|
811
699
|
if (loc.country_code === location.country_code) return true;
|
|
812
700
|
}
|
|
813
701
|
});
|
|
814
702
|
if (found) return false;
|
|
815
703
|
}
|
|
816
|
-
|
|
817
704
|
if (size(cond.locations) > 0) {
|
|
818
705
|
let found = find(cond.locations, loc => {
|
|
819
706
|
if (loc.city_name && loc.country_code) {
|
|
820
707
|
if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
|
|
821
708
|
}
|
|
822
|
-
|
|
823
709
|
if (loc.city_name && !loc.country_code) {
|
|
824
710
|
if (loc.city_name === location.city_name) return true;
|
|
825
711
|
}
|
|
826
|
-
|
|
827
712
|
if (!loc.city_name && loc.country_code) {
|
|
828
713
|
if (loc.country_code === location.country_code) return true;
|
|
829
714
|
}
|
|
830
715
|
});
|
|
831
716
|
if (!found) return false;
|
|
832
717
|
}
|
|
833
|
-
|
|
834
718
|
break;
|
|
835
|
-
|
|
836
719
|
case 'returning_visitor':
|
|
837
720
|
if (cond.returning_visitor) {
|
|
838
721
|
if (store.new_visitor) return false;
|
|
839
722
|
}
|
|
840
|
-
|
|
841
723
|
if (!cond.returning_visitor) {
|
|
842
724
|
if (!store.new_visitor) return false;
|
|
843
725
|
}
|
|
844
|
-
|
|
845
726
|
break;
|
|
846
|
-
|
|
847
727
|
case 'user_is_a_contact':
|
|
848
728
|
let attributes = op.get(store.matchUser(), 'attributes', []);
|
|
849
729
|
let email = find(attributes, att => att.key === 'emails');
|
|
850
730
|
let phone = find(attributes, att => att.key === 'phones');
|
|
851
731
|
let hasContact = email || phone;
|
|
852
|
-
|
|
853
732
|
if (cond.user_is_a_contact) {
|
|
854
733
|
if (!hasContact) return false;
|
|
855
734
|
}
|
|
856
|
-
|
|
857
735
|
if (!cond.user_is_a_contact) {
|
|
858
736
|
if (hasContact) return false;
|
|
859
737
|
}
|
|
860
|
-
|
|
861
738
|
break;
|
|
862
|
-
|
|
863
739
|
case 'device_type':
|
|
864
740
|
if (size(cond.device_types) > 0) {
|
|
865
741
|
let type = 'desktop';
|
|
@@ -867,9 +743,7 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
867
743
|
if (store.isTablet()) type = 'tablet';
|
|
868
744
|
if (!find(cond.device_types, t => norm(t) === norm(type))) return false;
|
|
869
745
|
}
|
|
870
|
-
|
|
871
746
|
break;
|
|
872
|
-
|
|
873
747
|
case 'referer':
|
|
874
748
|
if (size(cond.exclude_referers) > 0) {
|
|
875
749
|
let found = find(cond.exclude_referers, ref => {
|
|
@@ -877,24 +751,19 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
877
751
|
});
|
|
878
752
|
if (found) return false;
|
|
879
753
|
}
|
|
880
|
-
|
|
881
754
|
if (size(cond.urls) > 0) {
|
|
882
755
|
let found = find(cond.referers, ref => {
|
|
883
756
|
return norm(document.referrer).indexOf(norm(ref)) > -1;
|
|
884
757
|
});
|
|
885
758
|
if (!found) return false;
|
|
886
759
|
}
|
|
887
|
-
|
|
888
760
|
break;
|
|
889
|
-
|
|
890
761
|
case 'source':
|
|
891
762
|
if (size(cond.sources) > 0) {
|
|
892
763
|
let source = store.matchTrafficSource() || 'direct';
|
|
893
764
|
if (!find(cond.sources, src => norm(src) === norm(source))) return false;
|
|
894
765
|
}
|
|
895
|
-
|
|
896
766
|
break;
|
|
897
|
-
|
|
898
767
|
case 'user_attribute':
|
|
899
768
|
let userprop;
|
|
900
769
|
let attrs = op.get(store.matchUser(), 'attributes', []);
|
|
@@ -904,7 +773,6 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
904
773
|
userprop = attr.datetime || attr.boolean || attr.number || attr.text || attr.list;
|
|
905
774
|
});
|
|
906
775
|
let valid = true;
|
|
907
|
-
|
|
908
776
|
switch (operator) {
|
|
909
777
|
case 'cons':
|
|
910
778
|
let vals = parseJSON(cond.value) || [];
|
|
@@ -914,77 +782,60 @@ function checkRunConditions(freq, conds, lastrun, store) {
|
|
|
914
782
|
});
|
|
915
783
|
valid = !!found;
|
|
916
784
|
break;
|
|
917
|
-
|
|
918
785
|
case 'notEmpty':
|
|
919
786
|
valid = !!userprop;
|
|
920
787
|
break;
|
|
921
|
-
|
|
922
788
|
case 'empty':
|
|
923
789
|
valid = !userprop;
|
|
924
790
|
break;
|
|
925
|
-
|
|
926
791
|
case 'true':
|
|
927
792
|
valid = userprop === true || userprop === 'true';
|
|
928
793
|
break;
|
|
929
|
-
|
|
930
794
|
case 'false':
|
|
931
795
|
valid = !userprop || userprop === false || userprop === 'false';
|
|
932
796
|
break;
|
|
933
797
|
}
|
|
934
|
-
|
|
935
798
|
if (!valid) return false;
|
|
936
799
|
break;
|
|
937
|
-
|
|
938
800
|
case 'timming':
|
|
939
801
|
if (cond.business_hour === 'in' && !acc.is_in_business_hour) return false;
|
|
940
802
|
if (cond.business_hour === 'notIn' && acc.is_in_business_hour) return false;
|
|
941
|
-
|
|
942
803
|
if (size(cond.days_of_week) > 0) {
|
|
943
804
|
let found = find(cond.days_of_week, day => {
|
|
944
805
|
return norm(getDayName(new Date().getDay())) === norm(day);
|
|
945
806
|
});
|
|
946
807
|
if (!found) return false;
|
|
947
808
|
}
|
|
948
|
-
|
|
949
809
|
if (size(cond.minute_of_days) > 0 && size(cond.minute_of_days) % 2 === 0) {
|
|
950
810
|
var now = new Date();
|
|
951
811
|
var minuteofday = now.getMinutes() + now.getHours() * 60;
|
|
952
812
|
let found = false;
|
|
953
|
-
|
|
954
813
|
for (var i = 0; i < cond.minute_of_days.length; i += 2) {
|
|
955
814
|
if (cond.minute_of_days[i] <= minuteofday && minuteofday <= cond.minute_of_days[i + 1]) {
|
|
956
815
|
found = true;
|
|
957
816
|
break;
|
|
958
817
|
}
|
|
959
818
|
}
|
|
960
|
-
|
|
961
819
|
if (!found) return false;
|
|
962
820
|
}
|
|
963
|
-
|
|
964
821
|
break;
|
|
965
|
-
|
|
966
822
|
case 'offline':
|
|
967
823
|
if (!acc.is_online !== !!cond.offline) return false;
|
|
968
824
|
}
|
|
969
825
|
}
|
|
970
|
-
|
|
971
826
|
return true;
|
|
972
827
|
}
|
|
973
|
-
|
|
974
828
|
function getDayName(dayOfWeek) {
|
|
975
829
|
let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
976
830
|
return days[dayOfWeek];
|
|
977
831
|
}
|
|
978
|
-
|
|
979
832
|
let loadedFonts = {};
|
|
980
|
-
|
|
981
833
|
function preloadWebfonts(fonts, done) {
|
|
982
834
|
for (var i = 0; i < fonts.length; i++) {
|
|
983
835
|
let font = fonts[i];
|
|
984
836
|
if (!font) continue;
|
|
985
837
|
if (loadedFonts[font]) continue;
|
|
986
838
|
loadedFonts[font] = true;
|
|
987
|
-
|
|
988
839
|
for (var w = 0; w < 2; w++) {
|
|
989
840
|
let weight = [400, 500][w];
|
|
990
841
|
let node = document.createElement('div');
|
|
@@ -1005,15 +856,12 @@ function preloadWebfonts(fonts, done) {
|
|
|
1005
856
|
}
|
|
1006
857
|
}
|
|
1007
858
|
}
|
|
1008
|
-
|
|
1009
859
|
function preloadImg(src, cb) {
|
|
1010
860
|
if (!cb) cb = () => {};
|
|
1011
|
-
|
|
1012
861
|
if (!src) {
|
|
1013
862
|
cb();
|
|
1014
863
|
return Promise.resolve(true);
|
|
1015
864
|
}
|
|
1016
|
-
|
|
1017
865
|
let image = new Image();
|
|
1018
866
|
src = replaceFileUrl(src);
|
|
1019
867
|
image.src = src;
|
|
@@ -1024,7 +872,6 @@ function preloadImg(src, cb) {
|
|
|
1024
872
|
};
|
|
1025
873
|
});
|
|
1026
874
|
}
|
|
1027
|
-
|
|
1028
875
|
function offsetToMin(offset) {
|
|
1029
876
|
if (!offset) return 0;
|
|
1030
877
|
if (offset.length <= 2) offset += ':00';
|
|
@@ -1036,7 +883,6 @@ function offsetToMin(offset) {
|
|
|
1036
883
|
if (min < 0 || min > 59) return 0;
|
|
1037
884
|
return hour * 60 + min;
|
|
1038
885
|
}
|
|
1039
|
-
|
|
1040
886
|
function diffDay(a, b, tzoffset) {
|
|
1041
887
|
var offsetmin = -new Date().getTimezoneOffset();
|
|
1042
888
|
if (tzoffset) offsetmin = offsetToMin(tzoffset);
|
|
@@ -1046,7 +892,6 @@ function diffDay(a, b, tzoffset) {
|
|
|
1046
892
|
var bunixDay = Math.ceil((bms / 60 / 1000 + offsetmin) / 60 / 24);
|
|
1047
893
|
return Math.abs(aunixDay - bunixDay);
|
|
1048
894
|
}
|
|
1049
|
-
|
|
1050
895
|
function diffYear(a, b, tzoffset) {
|
|
1051
896
|
var machineoffsetmin = -new Date().getTimezoneOffset();
|
|
1052
897
|
var offsetmin = -new Date().getTimezoneOffset();
|
|
@@ -1057,7 +902,6 @@ function diffYear(a, b, tzoffset) {
|
|
|
1057
902
|
var bmsInZone = bms + (offsetmin - machineoffsetmin) * 60 * 1000;
|
|
1058
903
|
return Math.abs(new Date(amsInZone).getYear() - new Date(bmsInZone).getYear());
|
|
1059
904
|
}
|
|
1060
|
-
|
|
1061
905
|
function sameDay(a, b, tzoffset) {
|
|
1062
906
|
return diffDay(a, b, tzoffset) === 0;
|
|
1063
907
|
}
|
|
@@ -1084,31 +928,29 @@ function shortTime(utcms, tzoffset, now) {
|
|
|
1084
928
|
let tzdate = tztime.getDate();
|
|
1085
929
|
if (tzhour < 10) tzhour = '0' + tzhour;
|
|
1086
930
|
if (tzmin < 10) tzmin = '0' + tzmin;
|
|
931
|
+
|
|
1087
932
|
if (sameDay(time, now, tzoffset)) return tzhour + ':' + tzmin;
|
|
933
|
+
|
|
1088
934
|
if (diffDay(time, now, tzoffset) <= 5) return tzdddd + ', ' + tzhour + ':' + tzmin;
|
|
935
|
+
|
|
1089
936
|
if (diffYear(time, now, tzoffset) === 0) return tzmonthname + ' ' + tzdate + ', ' + tzhour + ':' + tzmin;
|
|
937
|
+
|
|
1090
938
|
return tzyear + '/' + tzmonth + '/' + tzdate + ', ' + tzhour + ':' + tzmin;
|
|
1091
939
|
}
|
|
1092
|
-
|
|
1093
940
|
function unixSec(t) {
|
|
1094
941
|
return Math.floor(getMs(t) / 1000);
|
|
1095
942
|
}
|
|
1096
|
-
|
|
1097
943
|
function getMs(t) {
|
|
1098
944
|
if (!t) t = 0;else if (typeof t !== 'number') t = new Date(t).getTime();
|
|
1099
|
-
|
|
1100
945
|
if (t > 1e18) {
|
|
1101
946
|
return Math.floor(t / 1e6);
|
|
1102
947
|
}
|
|
1103
|
-
|
|
1104
948
|
if (t > 1e15) {
|
|
1105
949
|
return Math.floor(t / 1e3);
|
|
1106
950
|
}
|
|
1107
|
-
|
|
1108
951
|
if (t > 1e12) {
|
|
1109
952
|
return t;
|
|
1110
953
|
}
|
|
1111
|
-
|
|
1112
954
|
return t * 1e3;
|
|
1113
955
|
}
|
|
1114
956
|
|
|
@@ -1118,34 +960,27 @@ function detectLang() {
|
|
|
1118
960
|
let browserlang = navigator.language;
|
|
1119
961
|
return urllang || doclang || browserlang;
|
|
1120
962
|
}
|
|
1121
|
-
|
|
1122
963
|
function getUrlParameter() {
|
|
1123
964
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
1124
965
|
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
1125
966
|
var results = regex.exec(location.search);
|
|
1126
967
|
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
|
1127
968
|
}
|
|
1128
|
-
|
|
1129
969
|
var sleep = ms => new Promise(res => setTimeout(res, ms));
|
|
1130
|
-
|
|
1131
970
|
exports.sleep = sleep;
|
|
1132
|
-
|
|
1133
971
|
function formatCurrency(val) {
|
|
1134
972
|
if (!val) return '0 đ';
|
|
1135
973
|
val = Math.round(val);
|
|
1136
974
|
return val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + ' đ';
|
|
1137
975
|
}
|
|
1138
|
-
|
|
1139
976
|
function replaceFileUrl(src) {
|
|
1140
977
|
let fileurl = 'https://vcdn.subiz-cdn.com/file/';
|
|
1141
978
|
if (!src) return '';
|
|
1142
979
|
if (startsWith(src, '/')) return src;
|
|
1143
980
|
if (startsWith(src, 'data:')) return src;
|
|
1144
|
-
|
|
1145
981
|
if (!startsWith(src, 'http://') && !startsWith(src, 'https://') && !startsWith(src, '//')) {
|
|
1146
982
|
src = trim(fileurl, '/') + '/' + trimStart(src, '/');
|
|
1147
983
|
}
|
|
1148
|
-
|
|
1149
984
|
src = src.replace('https://file-subiz.com/', fileurl);
|
|
1150
985
|
src = src.replace('http://file-subiz.com/', fileurl);
|
|
1151
986
|
src = src.replace('https://file-v4.subiz.com/', fileurl);
|
|
@@ -1160,13 +995,11 @@ function replaceFileUrl(src) {
|
|
|
1160
995
|
src = src.replace('http://file.mysubiz.com/', fileurl);
|
|
1161
996
|
return src;
|
|
1162
997
|
}
|
|
1163
|
-
|
|
1164
998
|
function unicodeToAscii(str) {
|
|
1165
999
|
str = str + '';
|
|
1166
1000
|
str = str.replace('đ', 'd').replace('Đ', 'D');
|
|
1167
1001
|
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
1168
1002
|
}
|
|
1169
|
-
|
|
1170
1003
|
function scrollIntoViewIfNeeded($ele) {
|
|
1171
1004
|
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
|
|
1172
1005
|
var parent = $ele.parentNode;
|
|
@@ -1178,15 +1011,12 @@ function scrollIntoViewIfNeeded($ele) {
|
|
|
1178
1011
|
var overLeft = $ele.offsetLeft - parent.offsetLeft < parent.scrollLeft;
|
|
1179
1012
|
var overRight = $ele.offsetLeft - parent.offsetLeft + $ele.clientWidth - parentBorderLeftWidth > parent.scrollLeft + parent.clientWidth;
|
|
1180
1013
|
var alignWithTop = overTop && !overBottom;
|
|
1181
|
-
|
|
1182
1014
|
if ((overTop || overBottom) && centerIfNeeded) {
|
|
1183
1015
|
parent.scrollTop = $ele.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + $ele.clientHeight / 2;
|
|
1184
1016
|
}
|
|
1185
|
-
|
|
1186
1017
|
if ((overLeft || overRight) && centerIfNeeded) {
|
|
1187
1018
|
parent.scrollLeft = $ele.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + $ele.clientWidth / 2;
|
|
1188
1019
|
}
|
|
1189
|
-
|
|
1190
1020
|
if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
|
|
1191
1021
|
$ele.scrollIntoView(alignWithTop);
|
|
1192
1022
|
}
|