@subiz/widget-v4 4.1.142 → 4.1.143
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/chatbox/Widget.js +2 -2
- package/compiled_src/store/store.js +1257 -0
- package/compiled_src/util/campaign.js +88 -0
- package/compiled_src/util/common.js +1294 -0
- package/compiled_src/util/common.test.js +496 -0
- package/compiled_src/util/extractor.test.js +299 -0
- package/compiled_src/util/gate.js +38 -0
- package/compiled_src/util/gate.test.js +18 -0
- package/compiled_src/util/index.js +20 -0
- package/compiled_src/util/mutex.js +31 -0
- package/compiled_src/util/op.js +55 -0
- package/compiled_src/util/pubsub.js +29 -0
- package/compiled_src/util/pubsub.test.js +35 -0
- package/dist/19680dc0775.278.js +1 -0
- package/dist/19680dc0775.app.js +1 -0
- package/dist/19680dc0775.form.html +1 -0
- package/dist/19680dc0775.form.js +1 -0
- package/dist/{1967c022bc1.index.html → 19680dc0775.index.html} +1 -1
- package/dist/{1967c022bc1.library.html → 19680dc0775.library.html} +1 -1
- package/dist/19680dc0775.library.js +1 -0
- package/dist/{1967c022bc1.preview.html → 19680dc0775.preview.html} +1 -1
- package/dist/19680dc0775.preview.js +1 -0
- package/dist/19680dc0775.webview.js +1 -0
- package/dist/278.js +1 -1
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +79 -90
- package/package.json +1 -1
- package/src/chatbox/Widget.js +2 -2
- package/dist/1967c022bc1.278.js +0 -1
- package/dist/1967c022bc1.app.js +0 -1
- package/dist/1967c022bc1.form.html +0 -1
- package/dist/1967c022bc1.form.js +0 -1
- package/dist/1967c022bc1.library.js +0 -1
- package/dist/1967c022bc1.preview.js +0 -1
- package/dist/1967c022bc1.webview.js +0 -1
- /package/dist/{1967c022bc1.127.js → 19680dc0775.127.js} +0 -0
- /package/dist/{1967c022bc1.132.js → 19680dc0775.132.js} +0 -0
- /package/dist/{1967c022bc1.185.js → 19680dc0775.185.js} +0 -0
- /package/dist/{1967c022bc1.27.js → 19680dc0775.27.js} +0 -0
- /package/dist/{1967c022bc1.459.js → 19680dc0775.459.js} +0 -0
- /package/dist/{1967c022bc1.490.js → 19680dc0775.490.js} +0 -0
- /package/dist/{1967c022bc1.74.js → 19680dc0775.74.js} +0 -0
- /package/dist/{1967c022bc1.997.js → 19680dc0775.997.js} +0 -0
|
@@ -0,0 +1,1294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.XMLHttpRequest = exports.Date = exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = exports.DEFVAL = void 0;
|
|
7
|
+
exports.agentsOfConvo = agentsOfConvo;
|
|
8
|
+
exports.blockToText = blockToText;
|
|
9
|
+
exports.checkRunConditions = checkRunConditions;
|
|
10
|
+
exports.clearTimeout = exports.clearInterval = void 0;
|
|
11
|
+
exports.cloneDeep = cloneDeep;
|
|
12
|
+
exports.convoOfEv = convoOfEv;
|
|
13
|
+
exports.convoToEv = convoToEv;
|
|
14
|
+
exports.detectLang = detectLang;
|
|
15
|
+
exports.diffDay = diffDay;
|
|
16
|
+
exports.diffYear = diffYear;
|
|
17
|
+
exports.each = each;
|
|
18
|
+
exports.extract = extract;
|
|
19
|
+
exports.extractEmails = extractEmails;
|
|
20
|
+
exports.extractEmojis = extractEmojis;
|
|
21
|
+
exports.extractLinks = extractLinks;
|
|
22
|
+
exports.extractPhones = extractPhones;
|
|
23
|
+
exports.extractText = extractText;
|
|
24
|
+
exports.filter = filter;
|
|
25
|
+
exports.find = find;
|
|
26
|
+
exports.formatCurrency = formatCurrency;
|
|
27
|
+
exports.getAgentDisplayName = getAgentDisplayName;
|
|
28
|
+
exports.getDayName = getDayName;
|
|
29
|
+
exports.getMs = getMs;
|
|
30
|
+
exports.getUrlParameter = getUrlParameter;
|
|
31
|
+
exports.getUserAttr = getUserAttr;
|
|
32
|
+
exports.hslToRgb = hslToRgb;
|
|
33
|
+
exports.includes = includes;
|
|
34
|
+
exports.isBlockEmpty = isBlockEmpty;
|
|
35
|
+
exports.isConvoSeen = isConvoSeen;
|
|
36
|
+
exports.isEmail = isEmail;
|
|
37
|
+
exports.isNumber = isNumber;
|
|
38
|
+
exports.isPhone = isPhone;
|
|
39
|
+
exports.isURL = isURL;
|
|
40
|
+
exports.isUserBanned = isUserBanned;
|
|
41
|
+
exports.js2css = js2css;
|
|
42
|
+
exports.last = last;
|
|
43
|
+
exports.map = map;
|
|
44
|
+
exports.merge = merge;
|
|
45
|
+
exports.noop = noop;
|
|
46
|
+
exports.norm = norm;
|
|
47
|
+
exports.offsetToMin = offsetToMin;
|
|
48
|
+
exports.orderBy = orderBy;
|
|
49
|
+
exports.orderByF = orderByF;
|
|
50
|
+
exports.parseJSON = parseJSON;
|
|
51
|
+
exports.pipeExtracts = pipeExtracts;
|
|
52
|
+
exports.preloadImg = preloadImg;
|
|
53
|
+
exports.preloadWebfonts = preloadWebfonts;
|
|
54
|
+
exports.randomString = randomString;
|
|
55
|
+
exports.replaceAll = replaceAll;
|
|
56
|
+
exports.replaceCssVariable = replaceCssVariable;
|
|
57
|
+
exports.replaceCssVariablePlugin = replaceCssVariablePlugin;
|
|
58
|
+
exports.requestAnimationFrame = void 0;
|
|
59
|
+
exports.rgbToHsl = rgbToHsl;
|
|
60
|
+
exports.sameDay = sameDay;
|
|
61
|
+
exports.scrollIntoViewIfNeeded = scrollIntoViewIfNeeded;
|
|
62
|
+
exports.setCss = setCss;
|
|
63
|
+
exports.setTimeout = exports.setInterval = void 0;
|
|
64
|
+
exports.setUserAttr = setUserAttr;
|
|
65
|
+
exports.shortTime = shortTime;
|
|
66
|
+
exports.size = size;
|
|
67
|
+
exports.sleep = void 0;
|
|
68
|
+
exports.startsWith = startsWith;
|
|
69
|
+
exports.stringify = void 0;
|
|
70
|
+
exports.throttle = throttle;
|
|
71
|
+
exports.tokenize = tokenize;
|
|
72
|
+
exports.trim = trim;
|
|
73
|
+
exports.trimStart = trimStart;
|
|
74
|
+
exports.unicodeToAscii = unicodeToAscii;
|
|
75
|
+
exports.unixSec = unixSec;
|
|
76
|
+
exports.usersOfConvo = usersOfConvo;
|
|
77
|
+
var op = require('./op.js');
|
|
78
|
+
function rgbToHsl(r, g, b) {
|
|
79
|
+
;
|
|
80
|
+
r /= 255, g /= 255, b /= 255;
|
|
81
|
+
var max = Math.max(r, g, b),
|
|
82
|
+
min = Math.min(r, g, b);
|
|
83
|
+
var h,
|
|
84
|
+
s,
|
|
85
|
+
l = (max + min) / 2;
|
|
86
|
+
if (max == min) {
|
|
87
|
+
h = s = 0;
|
|
88
|
+
} else {
|
|
89
|
+
var d = max - min;
|
|
90
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
91
|
+
switch (max) {
|
|
92
|
+
case r:
|
|
93
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
94
|
+
break;
|
|
95
|
+
case g:
|
|
96
|
+
h = (b - r) / d + 2;
|
|
97
|
+
break;
|
|
98
|
+
case b:
|
|
99
|
+
h = (r - g) / d + 4;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
h /= 6;
|
|
103
|
+
}
|
|
104
|
+
return [h, s, l];
|
|
105
|
+
}
|
|
106
|
+
function hslToRgb(h, s, l) {
|
|
107
|
+
var r, g, b;
|
|
108
|
+
if (s == 0) {
|
|
109
|
+
r = g = b = l;
|
|
110
|
+
} else {
|
|
111
|
+
function hue2rgb(p, q, t) {
|
|
112
|
+
if (t < 0) t += 1;
|
|
113
|
+
if (t > 1) t -= 1;
|
|
114
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
115
|
+
if (t < 1 / 2) return q;
|
|
116
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
117
|
+
return p;
|
|
118
|
+
}
|
|
119
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
120
|
+
var p = 2 * l - q;
|
|
121
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
122
|
+
g = hue2rgb(p, q, h);
|
|
123
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
124
|
+
}
|
|
125
|
+
return [r * 255, g * 255, b * 255];
|
|
126
|
+
}
|
|
127
|
+
function extractEmojis(text) {
|
|
128
|
+
var out = [];
|
|
129
|
+
for (var i = 0; i < text.length; i++) {
|
|
130
|
+
for (var e = 0; e < emojis.length; e++) {
|
|
131
|
+
if (text.indexOf(emojis[e], i) !== i) continue;
|
|
132
|
+
out.push({
|
|
133
|
+
index: i,
|
|
134
|
+
length: emojis[e].length
|
|
135
|
+
});
|
|
136
|
+
i += emojis[e].length - 1;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function extractLinks(text) {
|
|
143
|
+
text = text || '';
|
|
144
|
+
var reg = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9@:%_\+.,~#?&//=]*)/gim;
|
|
145
|
+
var out = [];
|
|
146
|
+
var match;
|
|
147
|
+
while (match = reg.exec(text)) {
|
|
148
|
+
out.push({
|
|
149
|
+
index: match.index,
|
|
150
|
+
length: reg.lastIndex - match.index
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
function extractEmails(text) {
|
|
156
|
+
text = text || '';
|
|
157
|
+
var reg = /(([^<>()[\]\\.,;:\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,}))/gim;
|
|
158
|
+
var out = [];
|
|
159
|
+
var match;
|
|
160
|
+
while (match = reg.exec(text)) {
|
|
161
|
+
out.push({
|
|
162
|
+
index: match.index,
|
|
163
|
+
length: reg.lastIndex - match.index
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+
function extractPhones(msg) {
|
|
169
|
+
msg = msg || '';
|
|
170
|
+
var fgmsg = '';
|
|
171
|
+
var realchmap = {};
|
|
172
|
+
for (var i = 0; i < msg.length; i++) {
|
|
173
|
+
var ch = msg.charAt(i);
|
|
174
|
+
if (ch !== '.' && ch !== '-' && ch !== ' ') {
|
|
175
|
+
fgmsg += ch;
|
|
176
|
+
realchmap[fgmsg.length - 1] = i;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
var prevCh = i > 0 ? msg.charAt(i - 1) : '-';
|
|
180
|
+
var nextCh = i < msg.length - 1 ? msg.charAt(i + 1) : '-';
|
|
181
|
+
if ('0123456789'.indexOf(prevCh) !== -1 && '0123456789'.indexOf(nextCh) !== -1) continue;
|
|
182
|
+
fgmsg += ch;
|
|
183
|
+
realchmap[fgmsg.length - 1] = i;
|
|
184
|
+
}
|
|
185
|
+
var reg = /([0-9]{8,13})/gim;
|
|
186
|
+
var out = [];
|
|
187
|
+
var match;
|
|
188
|
+
while (match = reg.exec(fgmsg)) {
|
|
189
|
+
out.push({
|
|
190
|
+
index: realchmap[match.index],
|
|
191
|
+
length: realchmap[reg.lastIndex - 1] - realchmap[match.index] + 1
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
function extract(text, extractor, type) {
|
|
197
|
+
if (!text) return [];
|
|
198
|
+
var out = [];
|
|
199
|
+
var lastindex = 0;
|
|
200
|
+
var tags = extractor(text);
|
|
201
|
+
if (size(tags) === 0) return [{
|
|
202
|
+
type: 'text',
|
|
203
|
+
text
|
|
204
|
+
}];
|
|
205
|
+
each(tags, tag => {
|
|
206
|
+
out.push({
|
|
207
|
+
type: 'text',
|
|
208
|
+
text: text.substr(lastindex, tag.index - lastindex)
|
|
209
|
+
});
|
|
210
|
+
out.push({
|
|
211
|
+
type,
|
|
212
|
+
text: text.substr(tag.index, tag.length)
|
|
213
|
+
});
|
|
214
|
+
lastindex = tag.index + tag.length;
|
|
215
|
+
});
|
|
216
|
+
var lastTag = last(tags);
|
|
217
|
+
out.push({
|
|
218
|
+
type: 'text',
|
|
219
|
+
text: text.substr(lastTag.index + lastTag.length, text.length - lastTag.index + lastTag.length)
|
|
220
|
+
});
|
|
221
|
+
return filter(out, o => o.text !== '');
|
|
222
|
+
}
|
|
223
|
+
function pipeExtracts(text, extractors) {
|
|
224
|
+
var out = [];
|
|
225
|
+
if (size(extractors) === 0) return [{
|
|
226
|
+
type: 'text',
|
|
227
|
+
text
|
|
228
|
+
}];
|
|
229
|
+
var ext = extractors.shift();
|
|
230
|
+
var tags = extract(text, ext, ext.type);
|
|
231
|
+
each(tags, t => {
|
|
232
|
+
if (t.type !== 'text') return out.push(t);
|
|
233
|
+
out = out.concat(pipeExtracts(t.text, extractors.slice()));
|
|
234
|
+
});
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
function extractText(text) {
|
|
238
|
+
var link = extractLinks;
|
|
239
|
+
link.type = 'link';
|
|
240
|
+
var email = extractEmails;
|
|
241
|
+
email.type = 'email';
|
|
242
|
+
var phone = extractPhones;
|
|
243
|
+
phone.type = 'phone';
|
|
244
|
+
var emoji = extractEmojis;
|
|
245
|
+
emoji.type = 'emoji';
|
|
246
|
+
return pipeExtracts(text, [link, email, phone, emoji]);
|
|
247
|
+
}
|
|
248
|
+
function parseJSON(str) {
|
|
249
|
+
try {
|
|
250
|
+
return parse(str);
|
|
251
|
+
} catch (e) {}
|
|
252
|
+
}
|
|
253
|
+
var f = document.createElement('iframe');
|
|
254
|
+
f.style.display = 'none';
|
|
255
|
+
document.documentElement.appendChild(f);
|
|
256
|
+
const tempElement = f.contentDocument.createElement('div');
|
|
257
|
+
f.contentDocument.body.appendChild(tempElement);
|
|
258
|
+
var stringify = exports.stringify = f.contentWindow.JSON.stringify;
|
|
259
|
+
var parse = f.contentWindow.JSON.parse;
|
|
260
|
+
var Date = exports.Date = f.contentWindow.Date;
|
|
261
|
+
var requestAnimationFrame = exports.requestAnimationFrame = f.contentWindow.requestAnimationFrame;
|
|
262
|
+
var setTimeout = exports.setTimeout = f.contentWindow.setTimeout.bind(f.contentWindow);
|
|
263
|
+
var setInterval = exports.setInterval = f.contentWindow.setInterval.bind(f.contentWindow);
|
|
264
|
+
var clearInterval = exports.clearInterval = f.contentWindow.clearInterval.bind(f.contentWindow);
|
|
265
|
+
var clearTimeout = exports.clearTimeout = f.contentWindow.clearTimeout.bind(f.contentWindow);
|
|
266
|
+
var XMLHttpRequest = exports.XMLHttpRequest = f.contentWindow.XMLHttpRequest;
|
|
267
|
+
function convoOfEv(ev) {
|
|
268
|
+
if (!ev) return '';
|
|
269
|
+
return op.get(ev, 'data.conversation.id', op.get(ev, 'data.message.conversation_id'));
|
|
270
|
+
}
|
|
271
|
+
function convoToEv(convoid, ev) {
|
|
272
|
+
if (!ev) return '';
|
|
273
|
+
switch (ev.type) {
|
|
274
|
+
case 'message_sent':
|
|
275
|
+
case 'message_updated':
|
|
276
|
+
case 'message_pong':
|
|
277
|
+
return op.set(ev, 'data.message.conversation_id', convoid);
|
|
278
|
+
case 'ticket_updated':
|
|
279
|
+
return op.set(ev, 'data.ticket.conversation_id', convoid);
|
|
280
|
+
default:
|
|
281
|
+
return op.set(ev, 'data.conversation.id', convoid);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function isObject(item) {
|
|
285
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
286
|
+
}
|
|
287
|
+
function merge(target, ...sources) {
|
|
288
|
+
if (!sources.length) return target;
|
|
289
|
+
const source = sources.shift();
|
|
290
|
+
if (isObject(target) && isObject(source)) {
|
|
291
|
+
for (const key in source) {
|
|
292
|
+
if (isObject(source[key])) {
|
|
293
|
+
if (!target[key]) Object.assign(target, {
|
|
294
|
+
[key]: {}
|
|
295
|
+
});
|
|
296
|
+
merge(target[key], source[key]);
|
|
297
|
+
} else {
|
|
298
|
+
Object.assign(target, {
|
|
299
|
+
[key]: source[key]
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return merge(target, ...sources);
|
|
305
|
+
}
|
|
306
|
+
function cloneDeep(p) {
|
|
307
|
+
if (p !== Object(p)) return p;
|
|
308
|
+
var s = stringify(p);
|
|
309
|
+
if (s === undefined) return;
|
|
310
|
+
return parse(s);
|
|
311
|
+
}
|
|
312
|
+
function randomString(len) {
|
|
313
|
+
var str = '';
|
|
314
|
+
if (!len || len < 1) len = 10;
|
|
315
|
+
var asciiKey;
|
|
316
|
+
for (var i = 0; i < len; i++) {
|
|
317
|
+
asciiKey = Math.floor(Math.random() * 25 + 97);
|
|
318
|
+
str += String.fromCharCode(asciiKey);
|
|
319
|
+
}
|
|
320
|
+
return str;
|
|
321
|
+
}
|
|
322
|
+
function filter(collection, predicate) {
|
|
323
|
+
if (!collection) return [];
|
|
324
|
+
if (!predicate) return collection;
|
|
325
|
+
var out = [];
|
|
326
|
+
if (Array.isArray(collection)) {
|
|
327
|
+
for (let i = 0; i < collection.length; i++) {
|
|
328
|
+
if (predicate(collection[i], i)) out.push(collection[i]);
|
|
329
|
+
}
|
|
330
|
+
return out;
|
|
331
|
+
}
|
|
332
|
+
if (typeof collection === 'object') {
|
|
333
|
+
var keys = Object.keys(collection);
|
|
334
|
+
for (let i = 0; i < keys.length; i++) {
|
|
335
|
+
var k = keys[i];
|
|
336
|
+
if (predicate(collection[k], k)) out.push(collection[k]);
|
|
337
|
+
}
|
|
338
|
+
return out;
|
|
339
|
+
}
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
function includes(collection, value) {
|
|
343
|
+
if (!collection) return false;
|
|
344
|
+
var isString = typeof collection === 'string' || collection instanceof String;
|
|
345
|
+
if (Array.isArray(collection) || isString) return collection.includes(value);
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
function map(collection, predicate) {
|
|
349
|
+
if (!collection) return [];
|
|
350
|
+
if (!predicate) predicate = i => i;
|
|
351
|
+
var out = [];
|
|
352
|
+
if (Array.isArray(collection)) {
|
|
353
|
+
for (let i = 0; i < collection.length; i++) {
|
|
354
|
+
out.push(predicate(collection[i], i));
|
|
355
|
+
}
|
|
356
|
+
return out;
|
|
357
|
+
}
|
|
358
|
+
if (typeof collection === 'object') {
|
|
359
|
+
var keys = Object.keys(collection);
|
|
360
|
+
for (let i = 0; i < keys.length; i++) {
|
|
361
|
+
var k = keys[i];
|
|
362
|
+
out.push(predicate(collection[k], k));
|
|
363
|
+
}
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
366
|
+
return out;
|
|
367
|
+
}
|
|
368
|
+
function each(collection, predicate) {
|
|
369
|
+
return map(collection, predicate);
|
|
370
|
+
}
|
|
371
|
+
function usersOfConvo(convo) {
|
|
372
|
+
if (!convo) return [];
|
|
373
|
+
return map(filter(convo.members, m => m.type === 'user'), m => m.id);
|
|
374
|
+
}
|
|
375
|
+
function isConvoSeen(convo, memberid) {
|
|
376
|
+
if (convo.state === 'ended') return true;
|
|
377
|
+
let lastmsgsent = convo.last_message_sent;
|
|
378
|
+
if (!lastmsgsent) return true;
|
|
379
|
+
if (op.get(lastmsgsent, 'by.id') === memberid) return true;
|
|
380
|
+
let mem = find(convo.members, m => m.id === memberid);
|
|
381
|
+
if (!mem) return true;
|
|
382
|
+
return getMs(lastmsgsent.created) < getMs(mem.seen_at);
|
|
383
|
+
}
|
|
384
|
+
function agentsOfConvo(convo, botIncluded) {
|
|
385
|
+
if (!convo) return [];
|
|
386
|
+
return map(filter(convo.members, m => {
|
|
387
|
+
if (botIncluded) return m.type === 'agent' || m.type === 'bot';
|
|
388
|
+
return m.type === 'agent';
|
|
389
|
+
}), m => m.id);
|
|
390
|
+
}
|
|
391
|
+
function startsWith(s, i) {
|
|
392
|
+
return ((s || '') + '').startsWith(i);
|
|
393
|
+
}
|
|
394
|
+
function size(o) {
|
|
395
|
+
if (!o) return 0;
|
|
396
|
+
if (o.length !== undefined) return o.length;
|
|
397
|
+
return Object.keys(o).length;
|
|
398
|
+
}
|
|
399
|
+
function replaceAll(str, a, b) {
|
|
400
|
+
return (str || '').split(a).join(b);
|
|
401
|
+
}
|
|
402
|
+
function trim(s, suffix) {
|
|
403
|
+
return ((s || '') + '').replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|
404
|
+
}
|
|
405
|
+
function trimStart(s, prefix) {
|
|
406
|
+
s = (s || '') + '';
|
|
407
|
+
while (s.charAt(0) === prefix) s = s.substr(1);
|
|
408
|
+
return s;
|
|
409
|
+
}
|
|
410
|
+
function throttle(func, wait, options) {
|
|
411
|
+
var context, args, result;
|
|
412
|
+
var timeout = null;
|
|
413
|
+
var previous = 0;
|
|
414
|
+
if (!options) options = {};
|
|
415
|
+
var later = function () {
|
|
416
|
+
previous = options.leading === false ? 0 : new Date().getTime();
|
|
417
|
+
timeout = null;
|
|
418
|
+
result = func.apply(context, args);
|
|
419
|
+
if (!timeout) context = args = null;
|
|
420
|
+
};
|
|
421
|
+
return function () {
|
|
422
|
+
var now = new Date().getTime();
|
|
423
|
+
if (!previous && options.leading === false) previous = now;
|
|
424
|
+
var remaining = wait - (now - previous);
|
|
425
|
+
context = this;
|
|
426
|
+
args = arguments;
|
|
427
|
+
if (remaining <= 0 || remaining > wait) {
|
|
428
|
+
if (timeout) {
|
|
429
|
+
clearTimeout(timeout);
|
|
430
|
+
timeout = null;
|
|
431
|
+
}
|
|
432
|
+
previous = now;
|
|
433
|
+
result = func.apply(context, args);
|
|
434
|
+
if (!timeout) context = args = null;
|
|
435
|
+
} else if (!timeout && options.trailing !== false) {
|
|
436
|
+
timeout = setTimeout(later, remaining);
|
|
437
|
+
}
|
|
438
|
+
return result;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function find(collection, f) {
|
|
442
|
+
if (!collection) return undefined;
|
|
443
|
+
return collection[findIndex(collection, f)];
|
|
444
|
+
}
|
|
445
|
+
function findIndex(collection, f) {
|
|
446
|
+
if (!collection) return -1;
|
|
447
|
+
if (!f) return -1;
|
|
448
|
+
if (Array.isArray(collection)) {
|
|
449
|
+
for (let i = 0; i < collection.length; i++) {
|
|
450
|
+
if (f(collection[i], i)) return i;
|
|
451
|
+
}
|
|
452
|
+
return -1;
|
|
453
|
+
}
|
|
454
|
+
if (typeof collection === 'object') {
|
|
455
|
+
var keys = Object.keys(collection);
|
|
456
|
+
for (let i = 0; i < keys.length; i++) {
|
|
457
|
+
var k = keys[i];
|
|
458
|
+
if (f(collection[k], k)) return k;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return -1;
|
|
462
|
+
}
|
|
463
|
+
function orderBy(a, k, d) {
|
|
464
|
+
var clone = [];
|
|
465
|
+
each(a, v => clone.push(v));
|
|
466
|
+
clone.sort((i, j) => {
|
|
467
|
+
if (i[k] === j[k]) return 0;
|
|
468
|
+
var r = i[k] < j[k] ? -1 : 1;
|
|
469
|
+
return d === 'desc' ? -r : r;
|
|
470
|
+
});
|
|
471
|
+
return clone;
|
|
472
|
+
}
|
|
473
|
+
function orderByF(a, f, d) {
|
|
474
|
+
var clone = [];
|
|
475
|
+
each(a, v => clone.push(v));
|
|
476
|
+
clone.sort((i, j) => {
|
|
477
|
+
let ik = f(i);
|
|
478
|
+
let jk = f(j);
|
|
479
|
+
if (ik === jk) return 0;
|
|
480
|
+
var r = ik < jk ? -1 : 1;
|
|
481
|
+
return d === 'desc' ? -r : r;
|
|
482
|
+
});
|
|
483
|
+
return clone;
|
|
484
|
+
}
|
|
485
|
+
function isPhone(phone) {
|
|
486
|
+
var re = /^[\+]?[(]?[0-9]{2,3}[)]?[-\s\.]?[0-9]{3,4}[-\s\.]?[0-9]{4,6}$/im;
|
|
487
|
+
return re.test(String(phone));
|
|
488
|
+
}
|
|
489
|
+
function isURL(url) {
|
|
490
|
+
var re = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
|
|
491
|
+
return re.test(String(url).toLowerCase());
|
|
492
|
+
}
|
|
493
|
+
function isNumber(num) {
|
|
494
|
+
var re = /^\d+$/;
|
|
495
|
+
return re.test(String(num));
|
|
496
|
+
}
|
|
497
|
+
function isEmail(email) {
|
|
498
|
+
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,}))$/;
|
|
499
|
+
return re.test(String(email).toLowerCase());
|
|
500
|
+
}
|
|
501
|
+
function last(array) {
|
|
502
|
+
var length = array == null ? 0 : array.length;
|
|
503
|
+
return length ? array[length - 1] : undefined;
|
|
504
|
+
}
|
|
505
|
+
function getAgentDisplayName(account, agent) {
|
|
506
|
+
return op.get(agent, 'fullname') || op.get(agent, 'email') || op.get(account, 'name') || 'Agent';
|
|
507
|
+
}
|
|
508
|
+
function isUserBanned(user) {
|
|
509
|
+
return getUserAttr(user, 'is_ban', 'boolean');
|
|
510
|
+
}
|
|
511
|
+
function setUserAttr(user, attr) {
|
|
512
|
+
if (!user) return;
|
|
513
|
+
if (!op.get(attr, 'key')) return;
|
|
514
|
+
user.attributes = user.attributes || [];
|
|
515
|
+
var index = findIndex(user.attributes, a => a && a.key === attr.key);
|
|
516
|
+
if (index === -1) {
|
|
517
|
+
user.attributes.push(attr);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
user.attributes[index] = attr;
|
|
521
|
+
}
|
|
522
|
+
function getUserAttr(user, key, type) {
|
|
523
|
+
if (!user || !user.attributes) return;
|
|
524
|
+
let value;
|
|
525
|
+
each(user.attributes, attr => {
|
|
526
|
+
if (!attr || attr.key !== key) return;
|
|
527
|
+
if (type === 'datetime') value = attr.datetime;
|
|
528
|
+
if (type === 'boolean') value = attr.boolean;
|
|
529
|
+
if (type === 'number') value = attr.number;
|
|
530
|
+
if (type === 'text') value = attr.text;
|
|
531
|
+
if (type === 'list') {
|
|
532
|
+
value = [attr.text].concat(attr.other_values);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
return value;
|
|
536
|
+
}
|
|
537
|
+
function norm(s) {
|
|
538
|
+
s = s || '';
|
|
539
|
+
return s.trim().toLowerCase();
|
|
540
|
+
}
|
|
541
|
+
function noop() {}
|
|
542
|
+
function norm2(val) {
|
|
543
|
+
if (typeof val === 'string' || val instanceof String) val = val.trim().replace(/;+$/, '');
|
|
544
|
+
return val;
|
|
545
|
+
}
|
|
546
|
+
function replaceCssVariablePlugin(css, setting) {
|
|
547
|
+
var tokens = [css];
|
|
548
|
+
let spacer = setting.spacer || 10;
|
|
549
|
+
setting = Object.assign({}, setting, {
|
|
550
|
+
spacer: spacer + 'px',
|
|
551
|
+
spacer0: spacer / 2 + 'px',
|
|
552
|
+
spacer2: 2 * spacer + 'px',
|
|
553
|
+
spacer3: 3 * spacer + 'px'
|
|
554
|
+
});
|
|
555
|
+
tokens = tokenize(tokens, "'@font_family'");
|
|
556
|
+
tokens = tokenize(tokens, "'@font_size'");
|
|
557
|
+
tokens = tokenize(tokens, "'@text_color'");
|
|
558
|
+
tokens = tokenize(tokens, "'@faded_text_color'");
|
|
559
|
+
tokens = tokenize(tokens, "'@primary_color'");
|
|
560
|
+
tokens = tokenize(tokens, "'@background'");
|
|
561
|
+
tokens = tokenize(tokens, "'@spacer'");
|
|
562
|
+
tokens = tokenize(tokens, "'@spacer0'");
|
|
563
|
+
tokens = tokenize(tokens, "'@spacer2'");
|
|
564
|
+
tokens = tokenize(tokens, "'@spacer3'");
|
|
565
|
+
var primary_color = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
|
|
566
|
+
let parseColor = parseCssColor(primary_color);
|
|
567
|
+
if (!parseColor) parseColor = {
|
|
568
|
+
red: 238,
|
|
569
|
+
blue: 238,
|
|
570
|
+
green: 238
|
|
571
|
+
};
|
|
572
|
+
let hue = rgbToHsl(parseColor.red, parseColor.green, parseColor.blue)[0];
|
|
573
|
+
let [r, g, b] = hslToRgb(hue, 0.25, 0.95);
|
|
574
|
+
DEFVAL.primary_color_faded = `rgb(${r},${g},${b})`;
|
|
575
|
+
var ret = [];
|
|
576
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
577
|
+
var item = tokens[i];
|
|
578
|
+
if (typeof item === 'string') {
|
|
579
|
+
ret.push(item);
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
var path = item.type.substr(2, item.type.length - 3);
|
|
583
|
+
var val = op.get(setting, path) || op.get(DEFVAL, path) || '';
|
|
584
|
+
ret.push(val);
|
|
585
|
+
}
|
|
586
|
+
return ret.join('');
|
|
587
|
+
}
|
|
588
|
+
function replaceCssVariable(css, setting) {
|
|
589
|
+
var tokens = [css];
|
|
590
|
+
tokens = tokenize(tokens, "'@primary_color'");
|
|
591
|
+
tokens = tokenize(tokens, "'@primary_color_faded'");
|
|
592
|
+
tokens = tokenize(tokens, '@esc-primary-color-esc');
|
|
593
|
+
tokens = tokenize(tokens, "'@secondary_color'");
|
|
594
|
+
tokens = tokenize(tokens, "'@background'");
|
|
595
|
+
tokens = tokenize(tokens, "'@text_color'");
|
|
596
|
+
tokens = tokenize(tokens, "'@width'");
|
|
597
|
+
tokens = tokenize(tokens, "'@height'");
|
|
598
|
+
tokens = tokenize(tokens, "'@desktop_button.width'");
|
|
599
|
+
tokens = tokenize(tokens, "'@desktop_button.height'");
|
|
600
|
+
tokens = tokenize(tokens, "'@desktop_button.background'");
|
|
601
|
+
tokens = tokenize(tokens, "'@desktop_button.border_radius'");
|
|
602
|
+
tokens = tokenize(tokens, "'@desktop_button.margin_x'");
|
|
603
|
+
tokens = tokenize(tokens, "'@desktop_button.margin_y'");
|
|
604
|
+
tokens = tokenize(tokens, "'@mobile_button.width'");
|
|
605
|
+
tokens = tokenize(tokens, "'@mobile_button.height'");
|
|
606
|
+
tokens = tokenize(tokens, "'@mobile_button.background'");
|
|
607
|
+
tokens = tokenize(tokens, "'@mobile_button.border_radius'");
|
|
608
|
+
tokens = tokenize(tokens, "'@mobile_button.margin_x'");
|
|
609
|
+
tokens = tokenize(tokens, "'@mobile_button.margin_y'");
|
|
610
|
+
tokens = tokenize(tokens, "'@widget_position'");
|
|
611
|
+
tokens = tokenize(tokens, "'@z_index'");
|
|
612
|
+
tokens = tokenize(tokens, "'@z_index_2'");
|
|
613
|
+
tokens = tokenize(tokens, "'@z_index_3'");
|
|
614
|
+
tokens = tokenize(tokens, "'@z_index_4'");
|
|
615
|
+
tokens = tokenize(tokens, "'@z_index_5'");
|
|
616
|
+
tokens = tokenize(tokens, "'@form_background_color'");
|
|
617
|
+
tokens = tokenize(tokens, "'@form_header_font_size'");
|
|
618
|
+
tokens = tokenize(tokens, "'@form_header_font_family'");
|
|
619
|
+
tokens = tokenize(tokens, "'@form_desc_font_size'");
|
|
620
|
+
tokens = tokenize(tokens, "'@form_desc_font_family'");
|
|
621
|
+
tokens = tokenize(tokens, "'@form_input_label_font_size'");
|
|
622
|
+
tokens = tokenize(tokens, "'@form_input_label_font_family'");
|
|
623
|
+
var primary_color = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
|
|
624
|
+
let parseColor = parseCssColor(primary_color);
|
|
625
|
+
if (!parseColor) parseColor = {
|
|
626
|
+
red: 238,
|
|
627
|
+
blue: 238,
|
|
628
|
+
green: 238
|
|
629
|
+
};
|
|
630
|
+
let hue = rgbToHsl(parseColor.red, parseColor.green, parseColor.blue)[0];
|
|
631
|
+
let [r, g, b] = hslToRgb(hue, 0.25, 0.95);
|
|
632
|
+
DEFVAL.primary_color_faded = `rgb(${r},${g},${b})`;
|
|
633
|
+
var ret = [];
|
|
634
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
635
|
+
var item = tokens[i];
|
|
636
|
+
if (typeof item === 'string') {
|
|
637
|
+
ret.push(item);
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
if (item.type === '@esc-primary-color-esc') {
|
|
641
|
+
var val = op.get(setting, 'primary_color') || op.get(DEFVAL, 'primary_color');
|
|
642
|
+
ret.push(encodeURIComponent(norm2(val)));
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
if (item.type === "'@z_index_2'") {
|
|
646
|
+
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
647
|
+
ret.push(val + 2);
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
if (item.type === "'@z_index_3'") {
|
|
651
|
+
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
652
|
+
ret.push(val + 3);
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
if (item.type === "'@z_index_4'") {
|
|
656
|
+
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
657
|
+
ret.push(val + 4);
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (item.type === "'@z_index_5'") {
|
|
661
|
+
var val = op.get(setting, 'z_index') || op.get(DEFVAL, 'z_index');
|
|
662
|
+
ret.push(val + 5);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
var path = item.type.substr(2, item.type.length - 3);
|
|
666
|
+
var val = op.get(setting, path) || op.get(DEFVAL, path) || '';
|
|
667
|
+
val = norm2(val);
|
|
668
|
+
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', 'form_header_font_size', 'form_desc_font_size', 'form_input_label_font_size', 'width', 'height'].includes(path)) {
|
|
669
|
+
val += 'px';
|
|
670
|
+
}
|
|
671
|
+
if (path === 'height' && op.get(setting, 'window_mode') === 'full') {
|
|
672
|
+
ret.push('100%');
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
ret.push(val);
|
|
676
|
+
}
|
|
677
|
+
return ret.join('');
|
|
678
|
+
}
|
|
679
|
+
function tokenize(arr, token) {
|
|
680
|
+
if (!arr || !arr.length) return [];
|
|
681
|
+
var out = [];
|
|
682
|
+
for (let i = 0; i < arr.length; i++) {
|
|
683
|
+
var item = arr[i];
|
|
684
|
+
if (typeof item !== 'string') {
|
|
685
|
+
out.push(item);
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
var ts = item.split(token);
|
|
689
|
+
for (let i = 0; i < ts.length; i++) {
|
|
690
|
+
out.push(ts[i]);
|
|
691
|
+
out.push({
|
|
692
|
+
type: token
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
out.pop();
|
|
696
|
+
}
|
|
697
|
+
return out;
|
|
698
|
+
}
|
|
699
|
+
function setCss(id, $css, css) {
|
|
700
|
+
css = replaceAll(css, '#sbz92', '#' + id);
|
|
701
|
+
if ($css.styleSheet) {
|
|
702
|
+
$css.styleSheet.cssText = css;
|
|
703
|
+
} else {
|
|
704
|
+
$css.innerHTML = '';
|
|
705
|
+
$css.appendChild(document.createTextNode(css));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
const DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = exports.DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL = 'https://vcdn.subiz-cdn.com/file/bubble_11.svg?v=5';
|
|
709
|
+
const DEFVAL = exports.DEFVAL = {
|
|
710
|
+
primary_color: '#0265FF',
|
|
711
|
+
secondary_color: '#555555',
|
|
712
|
+
background: 'linear-gradient(280.16deg, #0053d3 22.03%, #0265ff 78.2%)',
|
|
713
|
+
text_color: 'white',
|
|
714
|
+
width: 375,
|
|
715
|
+
height: 705,
|
|
716
|
+
window_mode: 'mini',
|
|
717
|
+
desktop_button: {
|
|
718
|
+
width: 0.3,
|
|
719
|
+
height: 0.3,
|
|
720
|
+
border_radius: '100%',
|
|
721
|
+
background_mask_url: DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL,
|
|
722
|
+
margin_x: 0.3,
|
|
723
|
+
margin_y: 0.3
|
|
724
|
+
},
|
|
725
|
+
mobile_button: {
|
|
726
|
+
width: 0.3,
|
|
727
|
+
height: 0.3,
|
|
728
|
+
border_radius: '100%',
|
|
729
|
+
background_mask_url: DEF_CHAT_BUTTON_BACKGROUND_IMAGE_URL,
|
|
730
|
+
margin_x: 0.3,
|
|
731
|
+
margin_y: 0.3
|
|
732
|
+
},
|
|
733
|
+
widget_position: 'fixed',
|
|
734
|
+
z_index: 2000000000
|
|
735
|
+
};
|
|
736
|
+
function js2css(js, onlyprops, variables) {
|
|
737
|
+
var newjs = {};
|
|
738
|
+
for (var prop in js) {
|
|
739
|
+
if (!js.hasOwnProperty(prop)) continue;
|
|
740
|
+
if (onlyprops && onlyprops.length > 0 && onlyprops.indexOf(prop) === -1) continue;
|
|
741
|
+
if (typeof js[prop] === 'string') newjs[prop] = trim(js[prop]);else newjs[prop] = js[prop];
|
|
742
|
+
}
|
|
743
|
+
js = newjs;
|
|
744
|
+
let style = '';
|
|
745
|
+
for (var prop in js) {
|
|
746
|
+
if (!js.hasOwnProperty(prop)) continue;
|
|
747
|
+
var filter = '';
|
|
748
|
+
if (js.blur) filter += 'blur(' + js.blur + ') ';
|
|
749
|
+
if (js.grayscale) filter += 'grayscale(' + js + ') ';
|
|
750
|
+
if (filter) style += 'filter: ' + filter + '!important;';
|
|
751
|
+
if (js.rotate !== undefined) style += 'transform:rotate(' + js.rotate + ') !important;';
|
|
752
|
+
if (js[prop] !== undefined) {
|
|
753
|
+
let propval = js[prop] + '';
|
|
754
|
+
map(variables, (value, name) => {
|
|
755
|
+
if (propval.indexOf(name) !== -1) propval = replaceAll(propval, name, value);
|
|
756
|
+
});
|
|
757
|
+
style += replaceAll(prop, '_', '-') + ':' + propval + ' !important;';
|
|
758
|
+
if (prop === 'color') style += '-webkit-text-fill-color: ' + propval + ' !important;';
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return style;
|
|
762
|
+
}
|
|
763
|
+
function browserName() {
|
|
764
|
+
var isOpera = !!window.opr && !!opr.addons || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
|
|
765
|
+
var isFirefox = typeof InstallTrigger !== 'undefined';
|
|
766
|
+
var isSafari = /constructor/i.test(window.HTMLElement) || function (p) {
|
|
767
|
+
return p.toString() === '[object SafariRemoteNotification]';
|
|
768
|
+
}(!window['safari'] || typeof safari !== 'undefined' && window['safari'].pushNotification);
|
|
769
|
+
var isIE = false || !!document.documentMode;
|
|
770
|
+
var isEdge = !isIE && !!window.StyleMedia;
|
|
771
|
+
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
|
|
772
|
+
if (!isChrome) isChrome = navigator.userAgent.indexOf('Chrome');
|
|
773
|
+
var isEdgeChromium = isChrome && navigator.userAgent.indexOf('Edg') != -1;
|
|
774
|
+
var isBlink = (isChrome || isOpera) && !!window.CSS;
|
|
775
|
+
if (isOpera) return 'opera';
|
|
776
|
+
if (isFirefox) return 'firefox';
|
|
777
|
+
if (isIE) return 'ie';
|
|
778
|
+
if (isEdge || isEdgeChromium) return 'edge';
|
|
779
|
+
if (isChrome) return 'chrome';
|
|
780
|
+
if (isBlink) return 'blink';
|
|
781
|
+
return 'unknown';
|
|
782
|
+
}
|
|
783
|
+
function check_frequently(freq, lastrun, store) {
|
|
784
|
+
if (!lastrun) return true;
|
|
785
|
+
if (op.get(freq, 'once_per_user')) return false;
|
|
786
|
+
if (op.get(freq, 'once_per_session')) {
|
|
787
|
+
if (sameDay(lastrun.created, Date.now())) return false;
|
|
788
|
+
}
|
|
789
|
+
if (op.get(freq, 'interval_sec')) {
|
|
790
|
+
var sec = op.get(freq, 'interval_sec');
|
|
791
|
+
if (sec > (Date.now() - lastrun.created) / 1000) return false;
|
|
792
|
+
}
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
function checkRunConditions(freq, conds, lastrun, store) {
|
|
796
|
+
var acc = store.matchAccount() || {};
|
|
797
|
+
var location = store.matchLocation() || {};
|
|
798
|
+
if (!check_frequently(freq, lastrun, store)) return false;
|
|
799
|
+
for (let i = 0; i < size(conds); i++) {
|
|
800
|
+
var cond = conds[i];
|
|
801
|
+
switch (cond.key) {
|
|
802
|
+
case 'url':
|
|
803
|
+
let exclude_urls = filter(cond.exclude_urls, url => norm(url));
|
|
804
|
+
if (size(exclude_urls) > 0) {
|
|
805
|
+
let found = find(exclude_urls, url => {
|
|
806
|
+
return norm(window.location.href).indexOf(norm(url)) > -1;
|
|
807
|
+
});
|
|
808
|
+
if (found) return false;
|
|
809
|
+
}
|
|
810
|
+
let urls = filter(cond.urls, url => norm(url));
|
|
811
|
+
if (size(urls) > 0) {
|
|
812
|
+
let found = find(urls, url => {
|
|
813
|
+
return norm(window.location.href).indexOf(norm(url)) > -1;
|
|
814
|
+
});
|
|
815
|
+
if (!found) return false;
|
|
816
|
+
}
|
|
817
|
+
break;
|
|
818
|
+
case 'url_path':
|
|
819
|
+
let excludePaths = filter(cond.exclude_url_paths, url => norm(url));
|
|
820
|
+
if (size(excludePaths) > 0) {
|
|
821
|
+
let urlObj = new URL(window.location.href);
|
|
822
|
+
let pathname = urlObj.pathname || '';
|
|
823
|
+
if (typeof pathname === 'string' && pathname.endsWith('/')) {
|
|
824
|
+
pathname = pathname.substring(0, pathname.length - 1);
|
|
825
|
+
}
|
|
826
|
+
let found = find(excludePaths, url => {
|
|
827
|
+
if (typeof url === 'string' && url.endsWith('/')) {
|
|
828
|
+
url = url.substring(0, url.length - 1);
|
|
829
|
+
}
|
|
830
|
+
return pathname === url;
|
|
831
|
+
});
|
|
832
|
+
if (found) return false;
|
|
833
|
+
}
|
|
834
|
+
let paths = filter(cond.url_paths, url => norm(url));
|
|
835
|
+
if (size(paths) > 0) {
|
|
836
|
+
let urlObj = new URL(window.location.href);
|
|
837
|
+
let pathname = urlObj.pathname || '';
|
|
838
|
+
if (typeof pathname === 'string' && pathname.endsWith('/')) {
|
|
839
|
+
pathname = pathname.substring(0, pathname.length - 1);
|
|
840
|
+
}
|
|
841
|
+
let found = find(paths, url => {
|
|
842
|
+
if (typeof url === 'string' && url.endsWith('/')) {
|
|
843
|
+
url = url.substring(0, url.length - 1);
|
|
844
|
+
}
|
|
845
|
+
return pathname === url;
|
|
846
|
+
});
|
|
847
|
+
if (!found) return false;
|
|
848
|
+
}
|
|
849
|
+
break;
|
|
850
|
+
case 'browser':
|
|
851
|
+
if (size(cond.browsers) > 0) {
|
|
852
|
+
var browsername = browserName();
|
|
853
|
+
if (!find(cond.browsers, b => norm(b) === norm(browsername))) return false;
|
|
854
|
+
}
|
|
855
|
+
break;
|
|
856
|
+
case 'location':
|
|
857
|
+
if (size(cond.exclude_locations) > 0) {
|
|
858
|
+
let found = find(cond.exclude_locations, loc => {
|
|
859
|
+
if (loc.city_name && loc.country_code) {
|
|
860
|
+
if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
|
|
861
|
+
}
|
|
862
|
+
if (loc.city_name && !loc.country_code) {
|
|
863
|
+
if (loc.city_name === location.city_name) return true;
|
|
864
|
+
}
|
|
865
|
+
if (!loc.city_name && loc.country_code) {
|
|
866
|
+
if (loc.country_code === location.country_code) return true;
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
if (found) return false;
|
|
870
|
+
}
|
|
871
|
+
if (size(cond.locations) > 0) {
|
|
872
|
+
let found = find(cond.locations, loc => {
|
|
873
|
+
if (loc.city_name && loc.country_code) {
|
|
874
|
+
if (loc.city_name === location.city_name && loc.country_code === location.country_code) return true;
|
|
875
|
+
}
|
|
876
|
+
if (loc.city_name && !loc.country_code) {
|
|
877
|
+
if (loc.city_name === location.city_name) return true;
|
|
878
|
+
}
|
|
879
|
+
if (!loc.city_name && loc.country_code) {
|
|
880
|
+
if (loc.country_code === location.country_code) return true;
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
if (!found) return false;
|
|
884
|
+
}
|
|
885
|
+
break;
|
|
886
|
+
case 'returning_visitor':
|
|
887
|
+
if (cond.returning_visitor) {
|
|
888
|
+
if (store.new_visitor) return false;
|
|
889
|
+
}
|
|
890
|
+
if (!cond.returning_visitor) {
|
|
891
|
+
if (!store.new_visitor) return false;
|
|
892
|
+
}
|
|
893
|
+
break;
|
|
894
|
+
case 'user_is_a_contact':
|
|
895
|
+
let attributes = op.get(store.matchUser(), 'attributes', []);
|
|
896
|
+
let emailAttr = find(attributes, att => att.key === 'emails' && attr.text && att.key === 'related_email' && attr.text);
|
|
897
|
+
let phoneAttr = find(attributes, att => att.key === 'phones' && attr.text && att.key === 'related_phone' && attr.text);
|
|
898
|
+
let hasContact = emailAttr || phoneAttr;
|
|
899
|
+
if (cond.user_is_a_contact) {
|
|
900
|
+
if (!hasContact) return false;
|
|
901
|
+
}
|
|
902
|
+
if (!cond.user_is_a_contact) {
|
|
903
|
+
if (hasContact) return false;
|
|
904
|
+
}
|
|
905
|
+
break;
|
|
906
|
+
case 'device_type':
|
|
907
|
+
if (size(cond.device_types) > 0) {
|
|
908
|
+
let type = 'desktop';
|
|
909
|
+
if (store.isMobile()) type = 'mobile';
|
|
910
|
+
if (store.isTablet()) type = 'tablet';
|
|
911
|
+
if (!find(cond.device_types, t => norm(t) === norm(type))) return false;
|
|
912
|
+
}
|
|
913
|
+
break;
|
|
914
|
+
case 'referer':
|
|
915
|
+
if (size(cond.exclude_referers) > 0) {
|
|
916
|
+
let found = find(cond.exclude_referers, ref => {
|
|
917
|
+
return norm(document.referrer).indexOf(norm(ref)) > -1;
|
|
918
|
+
});
|
|
919
|
+
if (found) return false;
|
|
920
|
+
}
|
|
921
|
+
if (size(cond.urls) > 0) {
|
|
922
|
+
let found = find(cond.referers, ref => {
|
|
923
|
+
return norm(document.referrer).indexOf(norm(ref)) > -1;
|
|
924
|
+
});
|
|
925
|
+
if (!found) return false;
|
|
926
|
+
}
|
|
927
|
+
break;
|
|
928
|
+
case 'source':
|
|
929
|
+
if (size(cond.sources) > 0) {
|
|
930
|
+
let source = store.matchTrafficSource() || 'direct';
|
|
931
|
+
if (!find(cond.sources, src => norm(src) === norm(source))) return false;
|
|
932
|
+
}
|
|
933
|
+
break;
|
|
934
|
+
case 'user_attribute':
|
|
935
|
+
case 'user':
|
|
936
|
+
let userprop;
|
|
937
|
+
let attrs = op.get(store.matchUser(), 'attributes', []);
|
|
938
|
+
let operator = op.get(cond, 'user.operator');
|
|
939
|
+
each(attrs, attr => {
|
|
940
|
+
if (!attr || attr.key !== op.get(cond, 'user.key')) return;
|
|
941
|
+
userprop = attr.datetime || attr.boolean || attr.number || attr.text || attr.list;
|
|
942
|
+
});
|
|
943
|
+
let valid = true;
|
|
944
|
+
switch (operator) {
|
|
945
|
+
case 'cons':
|
|
946
|
+
let vals = parseJSON(cond.value) || [];
|
|
947
|
+
if (size(vals) === 0) return false;
|
|
948
|
+
let found = find(vals, val => {
|
|
949
|
+
return norm(userprop).indexOf(norm(val)) > -1;
|
|
950
|
+
});
|
|
951
|
+
valid = !!found;
|
|
952
|
+
break;
|
|
953
|
+
case 'notEmpty':
|
|
954
|
+
valid = !!userprop;
|
|
955
|
+
break;
|
|
956
|
+
case 'empty':
|
|
957
|
+
valid = !userprop;
|
|
958
|
+
break;
|
|
959
|
+
case 'true':
|
|
960
|
+
valid = userprop === true || userprop === 'true';
|
|
961
|
+
break;
|
|
962
|
+
case 'false':
|
|
963
|
+
valid = !userprop || userprop === false || userprop === 'false';
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
if (!valid) return false;
|
|
967
|
+
break;
|
|
968
|
+
case 'timming':
|
|
969
|
+
if (cond.business_hour === 'in' && !acc.is_in_business_hour) return false;
|
|
970
|
+
if (cond.business_hour === 'notIn' && acc.is_in_business_hour) return false;
|
|
971
|
+
if (size(cond.days_of_week) > 0) {
|
|
972
|
+
let found = find(cond.days_of_week, day => {
|
|
973
|
+
return norm(getDayName(new Date().getDay())) === norm(day);
|
|
974
|
+
});
|
|
975
|
+
if (!found) return false;
|
|
976
|
+
}
|
|
977
|
+
if (size(cond.minutes_of_day) > 0 && size(cond.minutes_of_day) % 2 === 0) {
|
|
978
|
+
var now = new Date();
|
|
979
|
+
var minuteofday = now.getMinutes() + now.getHours() * 60;
|
|
980
|
+
let found = false;
|
|
981
|
+
for (let i = 0; i < cond.minutes_of_day.length; i += 2) {
|
|
982
|
+
if (cond.minutes_of_day[i] <= minuteofday && minuteofday <= cond.minutes_of_day[i + 1]) {
|
|
983
|
+
found = true;
|
|
984
|
+
break;
|
|
985
|
+
}
|
|
986
|
+
if (cond.minutes_of_day[i] > cond.minutes_of_day[i + 1]) {
|
|
987
|
+
if (minuteofday >= cond.minutes_of_day[i] || minuteofday <= cond.minutes_of_day[i + 1]) {
|
|
988
|
+
found = true;
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
if (!found) return false;
|
|
994
|
+
}
|
|
995
|
+
break;
|
|
996
|
+
case 'offline':
|
|
997
|
+
if (!acc.is_online !== !!cond.offline) return false;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return true;
|
|
1001
|
+
}
|
|
1002
|
+
function getDayName(dayOfWeek) {
|
|
1003
|
+
let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
1004
|
+
return days[dayOfWeek];
|
|
1005
|
+
}
|
|
1006
|
+
let loadedFonts = {};
|
|
1007
|
+
function preloadWebfonts(fonts, done) {
|
|
1008
|
+
for (var i = 0; i < fonts.length; i++) {
|
|
1009
|
+
let font = fonts[i];
|
|
1010
|
+
if (!font) continue;
|
|
1011
|
+
if (loadedFonts[font]) continue;
|
|
1012
|
+
loadedFonts[font] = true;
|
|
1013
|
+
for (var w = 0; w < 2; w++) {
|
|
1014
|
+
let weight = [400, 500][w];
|
|
1015
|
+
let node = document.createElement('div');
|
|
1016
|
+
node.innerHTML = '@!-/#Chào mỪng1';
|
|
1017
|
+
node.style.position = 'absolute';
|
|
1018
|
+
node.style.display = 'block';
|
|
1019
|
+
node.style.opacity = '0.1';
|
|
1020
|
+
node.style.color = 'transparent';
|
|
1021
|
+
node.style.fontSize = '20px';
|
|
1022
|
+
node.style.height = '0px';
|
|
1023
|
+
node.style.top = '0px';
|
|
1024
|
+
node.style.width = '0px';
|
|
1025
|
+
node.style.fontWeight = weight;
|
|
1026
|
+
node.setAttribute('subiz-preload', font + ':' + weight);
|
|
1027
|
+
document.body.appendChild(node);
|
|
1028
|
+
node.style.fontFamily = font;
|
|
1029
|
+
setTimeout(() => node.remove(), 3000);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
function preloadImg(src, cb) {
|
|
1034
|
+
if (!cb) cb = () => {};
|
|
1035
|
+
if (!src) {
|
|
1036
|
+
cb();
|
|
1037
|
+
return Promise.resolve(true);
|
|
1038
|
+
}
|
|
1039
|
+
let image = new Image();
|
|
1040
|
+
src = replaceFileUrl(src);
|
|
1041
|
+
image.src = src;
|
|
1042
|
+
return new Promise(rs => {
|
|
1043
|
+
image.onload = () => {
|
|
1044
|
+
cb();
|
|
1045
|
+
rs();
|
|
1046
|
+
};
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function offsetToMin(offset) {
|
|
1050
|
+
if (!offset) return 0;
|
|
1051
|
+
if (offset.length <= 2) offset += ':00';
|
|
1052
|
+
let sp = offset.split(':');
|
|
1053
|
+
if (sp.length !== 2) return 0;
|
|
1054
|
+
let hour = parseInt(sp[0]);
|
|
1055
|
+
if (hour < 0 || hour > 23) return 0;
|
|
1056
|
+
let min = parseInt(sp[1]);
|
|
1057
|
+
if (min < 0 || min > 59) return 0;
|
|
1058
|
+
return hour * 60 + min;
|
|
1059
|
+
}
|
|
1060
|
+
function diffDay(a, b, tzoffset) {
|
|
1061
|
+
var offsetmin = -new Date().getTimezoneOffset();
|
|
1062
|
+
if (tzoffset) offsetmin = offsetToMin(tzoffset);
|
|
1063
|
+
var ams = new Date(a).getTime();
|
|
1064
|
+
var bms = new Date(b).getTime();
|
|
1065
|
+
var aunixDay = Math.ceil((ams / 60 / 1000 + offsetmin) / 60 / 24);
|
|
1066
|
+
var bunixDay = Math.ceil((bms / 60 / 1000 + offsetmin) / 60 / 24);
|
|
1067
|
+
return Math.abs(aunixDay - bunixDay);
|
|
1068
|
+
}
|
|
1069
|
+
function diffYear(a, b, tzoffset) {
|
|
1070
|
+
var machineoffsetmin = -new Date().getTimezoneOffset();
|
|
1071
|
+
var offsetmin = -new Date().getTimezoneOffset();
|
|
1072
|
+
if (tzoffset) offsetmin = offsetToMin(tzoffset);
|
|
1073
|
+
var ams = new Date(a).getTime();
|
|
1074
|
+
var bms = new Date(b).getTime();
|
|
1075
|
+
var amsInZone = ams + (offsetmin - machineoffsetmin) * 60 * 1000;
|
|
1076
|
+
var bmsInZone = bms + (offsetmin - machineoffsetmin) * 60 * 1000;
|
|
1077
|
+
return Math.abs(new Date(amsInZone).getYear() - new Date(bmsInZone).getYear());
|
|
1078
|
+
}
|
|
1079
|
+
function sameDay(a, b, tzoffset) {
|
|
1080
|
+
return diffDay(a, b, tzoffset) === 0;
|
|
1081
|
+
}
|
|
1082
|
+
function shortTime(utcms, tzoffset, now, forcelocale) {
|
|
1083
|
+
var machineoffsetmin = -new Date().getTimezoneOffset();
|
|
1084
|
+
var offsetmin = machineoffsetmin;
|
|
1085
|
+
if (tzoffset) offsetmin = offsetToMin(tzoffset);
|
|
1086
|
+
var time = new Date(getMs(utcms));
|
|
1087
|
+
let tztime = new Date(time);
|
|
1088
|
+
tztime.setMinutes(time.getMinutes() + offsetmin - machineoffsetmin);
|
|
1089
|
+
if (!now) now = new Date();
|
|
1090
|
+
let tzhour = tztime.getHours();
|
|
1091
|
+
let tzmin = tztime.getMinutes();
|
|
1092
|
+
let locale = op.get(navigator, 'languages.0', 'en-US');
|
|
1093
|
+
if (forcelocale) locale = forcelocale;
|
|
1094
|
+
let tzdddd = tztime.toLocaleDateString(locale, {
|
|
1095
|
+
weekday: 'long'
|
|
1096
|
+
});
|
|
1097
|
+
let tzyear = tztime.getFullYear();
|
|
1098
|
+
let tzmonth = tztime.getMonth() + 1;
|
|
1099
|
+
let tzmonthname = tztime.toLocaleDateString(locale, {
|
|
1100
|
+
month: 'long'
|
|
1101
|
+
});
|
|
1102
|
+
let tzdate = tztime.getDate();
|
|
1103
|
+
if (tzhour < 10) tzhour = '0' + tzhour;
|
|
1104
|
+
if (tzmin < 10) tzmin = '0' + tzmin;
|
|
1105
|
+
if (sameDay(time, now, tzoffset)) return tzhour + ':' + tzmin;
|
|
1106
|
+
if (diffDay(time, now, tzoffset) <= 5) return tzdddd + ', ' + tzhour + ':' + tzmin;
|
|
1107
|
+
if (diffYear(time, now, tzoffset) === 0) {
|
|
1108
|
+
if (locale === 'vi-VN') {
|
|
1109
|
+
return tzdate + ' ' + tzmonthname + ', ' + tzhour + ':' + tzmin;
|
|
1110
|
+
}
|
|
1111
|
+
return tzmonthname + ' ' + tzdate + ', ' + tzhour + ':' + tzmin;
|
|
1112
|
+
}
|
|
1113
|
+
if (locale === 'vi-VN') {
|
|
1114
|
+
return tzdate + '/' + tzmonth + '/' + tzyear + ', ' + tzhour + ':' + tzmin;
|
|
1115
|
+
}
|
|
1116
|
+
return tzyear + '/' + tzmonth + '/' + tzdate + ', ' + tzhour + ':' + tzmin;
|
|
1117
|
+
}
|
|
1118
|
+
function unixSec(t) {
|
|
1119
|
+
return Math.floor(getMs(t) / 1000);
|
|
1120
|
+
}
|
|
1121
|
+
function getMs(t) {
|
|
1122
|
+
if (!t) t = 0;else if (typeof t !== 'number') t = new Date(t).getTime();
|
|
1123
|
+
if (t > 1e18) {
|
|
1124
|
+
return Math.floor(t / 1e6);
|
|
1125
|
+
}
|
|
1126
|
+
if (t > 1e15) {
|
|
1127
|
+
return Math.floor(t / 1e3);
|
|
1128
|
+
}
|
|
1129
|
+
if (t > 1e12) {
|
|
1130
|
+
return t;
|
|
1131
|
+
}
|
|
1132
|
+
return t * 1e3;
|
|
1133
|
+
}
|
|
1134
|
+
function detectLang() {
|
|
1135
|
+
let urllang = getUrlParameter('sbz_locale');
|
|
1136
|
+
let doclang = document.getElementsByTagName('html')[0].getAttribute('xml:lang') || document.getElementsByTagName('html')[0].getAttribute('lang');
|
|
1137
|
+
let browserlang = navigator.language;
|
|
1138
|
+
return urllang || doclang || browserlang;
|
|
1139
|
+
}
|
|
1140
|
+
function getUrlParameter(name) {
|
|
1141
|
+
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
1142
|
+
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
1143
|
+
var results = regex.exec(location.search);
|
|
1144
|
+
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
|
1145
|
+
}
|
|
1146
|
+
var sleep = ms => new Promise(res => setTimeout(res, ms));
|
|
1147
|
+
exports.sleep = sleep;
|
|
1148
|
+
function formatCurrency(val, currency = 'VND') {
|
|
1149
|
+
let currencyObj = ALL_CURRENCIES.find(cur => cur.code === currency) || {
|
|
1150
|
+
name: 'Dong',
|
|
1151
|
+
code: 'VND',
|
|
1152
|
+
symbol: '₫'
|
|
1153
|
+
};
|
|
1154
|
+
let prefix = '';
|
|
1155
|
+
let suffix = '';
|
|
1156
|
+
if (currency === 'VND') {
|
|
1157
|
+
prefix = '';
|
|
1158
|
+
suffix = ' ' + currencyObj.symbol;
|
|
1159
|
+
} else {
|
|
1160
|
+
prefix = currencyObj.symbol + ' ';
|
|
1161
|
+
suffix = '';
|
|
1162
|
+
}
|
|
1163
|
+
if (!val) return `${prefix}0${suffix}`;
|
|
1164
|
+
val = Math.round(val);
|
|
1165
|
+
return prefix + val.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') + suffix;
|
|
1166
|
+
}
|
|
1167
|
+
function replaceFileUrl(src) {
|
|
1168
|
+
let fileurl = 'https://vcdn.subiz-cdn.com/file/';
|
|
1169
|
+
if (!src) return '';
|
|
1170
|
+
if (startsWith(src, '/')) return src;
|
|
1171
|
+
if (startsWith(src, 'data:')) return src;
|
|
1172
|
+
if (!startsWith(src, 'http://') && !startsWith(src, 'https://') && !startsWith(src, '//')) {
|
|
1173
|
+
src = trim(fileurl, '/') + '/' + trimStart(src, '/');
|
|
1174
|
+
}
|
|
1175
|
+
src = src.replace('https://file-subiz.com/', fileurl);
|
|
1176
|
+
src = src.replace('http://file-subiz.com/', fileurl);
|
|
1177
|
+
src = src.replace('https://file-v4.subiz.com/', fileurl);
|
|
1178
|
+
src = src.replace('http://file-v4.subiz.com/', fileurl);
|
|
1179
|
+
src = src.replace('https://filev4.subiz.com/', fileurl);
|
|
1180
|
+
src = src.replace('http://filev4.subiz.com/', fileurl);
|
|
1181
|
+
src = src.replace('https://filev4-1.subiz.com/', fileurl);
|
|
1182
|
+
src = src.replace('http://filev4-1.subiz.com/', fileurl);
|
|
1183
|
+
src = src.replace('https://file.subiz.com/', fileurl);
|
|
1184
|
+
src = src.replace('http://file.subiz.com/', fileurl);
|
|
1185
|
+
src = src.replace('https://file.mysubiz.com/', fileurl);
|
|
1186
|
+
src = src.replace('http://file.mysubiz.com/', fileurl);
|
|
1187
|
+
return src;
|
|
1188
|
+
}
|
|
1189
|
+
function unicodeToAscii(str) {
|
|
1190
|
+
str = str + '';
|
|
1191
|
+
str = str.replaceAll('đ', 'd').replaceAll('Đ', 'D');
|
|
1192
|
+
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
1193
|
+
}
|
|
1194
|
+
function scrollIntoViewIfNeeded($ele) {
|
|
1195
|
+
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
|
|
1196
|
+
var parent = $ele.parentNode;
|
|
1197
|
+
var parentComputedStyle = window.getComputedStyle(parent, null);
|
|
1198
|
+
var parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue('border-top-width'));
|
|
1199
|
+
var parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue('border-left-width'));
|
|
1200
|
+
var overTop = $ele.offsetTop - parent.offsetTop < parent.scrollTop;
|
|
1201
|
+
var overBottom = $ele.offsetTop - parent.offsetTop + $ele.clientHeight - parentBorderTopWidth > parent.scrollTop + parent.clientHeight;
|
|
1202
|
+
var overLeft = $ele.offsetLeft - parent.offsetLeft < parent.scrollLeft;
|
|
1203
|
+
var overRight = $ele.offsetLeft - parent.offsetLeft + $ele.clientWidth - parentBorderLeftWidth > parent.scrollLeft + parent.clientWidth;
|
|
1204
|
+
var alignWithTop = overTop && !overBottom;
|
|
1205
|
+
if ((overTop || overBottom) && centerIfNeeded) {
|
|
1206
|
+
parent.scrollTop = $ele.offsetTop - parent.offsetTop - parent.clientHeight / 2 - parentBorderTopWidth + $ele.clientHeight / 2;
|
|
1207
|
+
}
|
|
1208
|
+
if ((overLeft || overRight) && centerIfNeeded) {
|
|
1209
|
+
parent.scrollLeft = $ele.offsetLeft - parent.offsetLeft - parent.clientWidth / 2 - parentBorderLeftWidth + $ele.clientWidth / 2;
|
|
1210
|
+
}
|
|
1211
|
+
if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
|
|
1212
|
+
$ele.scrollIntoView(alignWithTop);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
const ALL_CURRENCIES = [{
|
|
1216
|
+
code: 'USD',
|
|
1217
|
+
symbol: '$'
|
|
1218
|
+
}, {
|
|
1219
|
+
code: 'VND',
|
|
1220
|
+
symbol: '₫'
|
|
1221
|
+
}];
|
|
1222
|
+
function blockToText(block) {
|
|
1223
|
+
return _blockToText(block).trim();
|
|
1224
|
+
}
|
|
1225
|
+
function isBlockEmpty(block) {
|
|
1226
|
+
return _isBlockEmpty(block);
|
|
1227
|
+
}
|
|
1228
|
+
function _isBlockEmpty(block = {}) {
|
|
1229
|
+
if (!size(block.content)) {
|
|
1230
|
+
if ((block.text || '').trim()) return false;
|
|
1231
|
+
return true;
|
|
1232
|
+
}
|
|
1233
|
+
let result = true;
|
|
1234
|
+
map(block.content, content => {
|
|
1235
|
+
result = result && _isBlockEmpty(content);
|
|
1236
|
+
});
|
|
1237
|
+
return result;
|
|
1238
|
+
}
|
|
1239
|
+
function _blockToText(block) {
|
|
1240
|
+
if (!block || !block.type) return '';
|
|
1241
|
+
let out = '';
|
|
1242
|
+
if (block.type == 'bullet_list' || block.type == 'ordered_list') {
|
|
1243
|
+
map(block.content, item => {
|
|
1244
|
+
preifx = '\n* ';
|
|
1245
|
+
if (block.type == 'ordered_list') {
|
|
1246
|
+
prefix = i + '\n. ';
|
|
1247
|
+
}
|
|
1248
|
+
out += prefix + blockToText(item).trim();
|
|
1249
|
+
});
|
|
1250
|
+
return out;
|
|
1251
|
+
}
|
|
1252
|
+
if (block.type == 'heading' || block.type == 'paragraph') {
|
|
1253
|
+
out += '\n';
|
|
1254
|
+
}
|
|
1255
|
+
if (block.type == '' || block.type == 'text' || block.type == 'link' || block.type == 'mention-agent' || block.type == 'dynamic-field') {
|
|
1256
|
+
return out + block.text;
|
|
1257
|
+
}
|
|
1258
|
+
if (block.type == 'horizontal_rule') return out + '\n---\n';
|
|
1259
|
+
if (block.type == 'emoji') {
|
|
1260
|
+
let code;
|
|
1261
|
+
if (size(block.attrs) > 0) code = block.attrs['code'];
|
|
1262
|
+
if (code == '') code = block.text;
|
|
1263
|
+
if (code != '') {
|
|
1264
|
+
let emoji = find(LEXICAL_EMOJI_LIST, emoji => emoji.code === code);
|
|
1265
|
+
out + op.get(emoji, 'text', code);
|
|
1266
|
+
}
|
|
1267
|
+
return out;
|
|
1268
|
+
}
|
|
1269
|
+
map(block.content, block => {
|
|
1270
|
+
out += blockToText(block);
|
|
1271
|
+
});
|
|
1272
|
+
return out;
|
|
1273
|
+
}
|
|
1274
|
+
function parseCssColor(color) {
|
|
1275
|
+
if (!color || !color.split) return '';
|
|
1276
|
+
tempElement.style.color = color;
|
|
1277
|
+
const computedColor = f.contentWindow.getComputedStyle(tempElement).color;
|
|
1278
|
+
const match = computedColor.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
1279
|
+
if (match) {
|
|
1280
|
+
return {
|
|
1281
|
+
red: parseInt(match[1]),
|
|
1282
|
+
green: parseInt(match[2]),
|
|
1283
|
+
blue: parseInt(match[3])
|
|
1284
|
+
};
|
|
1285
|
+
} else {
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
let emojis = ['like', 'unlike', 'wink', 'tongue-out', 'tired', 'surprised', 'smiling', 'sleepy', 'sad', 'neutral', 'heart-eyes', 'grinning', 'crying', 'confused', 'angry', 'cry', 'heart_eyes', 'neutral_face', 'emoji--disappointed', 'smile', 'open_mouth', 'tired_face', 'stuck_out_tongue', 'moyai', 'thumbsdown', 'dislike', 'thumbsup', 'ok_hand', 'octopus', 'pig2', 'wave', 'mouse', 'mouse2', 'rat'];
|
|
1290
|
+
emojis = map(emojis, e => ':' + e + ':');
|
|
1291
|
+
function absLink(url) {
|
|
1292
|
+
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
|
|
1293
|
+
return url;
|
|
1294
|
+
}
|