web-manager 3.1.16 → 3.1.18
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/README.md +1 -1
- package/index.js +47 -33
- package/lib/dom.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ npm install web-manager
|
|
|
44
44
|
* Firebase (Firebase app, Firestore, Auth, & Messaging)
|
|
45
45
|
* Lazysizes to lazyload images
|
|
46
46
|
* Sentry to report errors
|
|
47
|
-
*
|
|
47
|
+
* [Chatsy.ai](https://chatsy.ai) AI chatbot integration
|
|
48
48
|
* Cookieconsent to comply with GDPR
|
|
49
49
|
|
|
50
50
|
## Example Setup
|
package/index.js
CHANGED
|
@@ -184,7 +184,7 @@ function Manager() {
|
|
|
184
184
|
} else if (event.target.matches('.auth-forgot-email-btn')) {
|
|
185
185
|
This.auth().forgot();
|
|
186
186
|
} else if (event.target.matches('#prechat-btn')) {
|
|
187
|
-
|
|
187
|
+
load_chatsy(This, This.properties.options);
|
|
188
188
|
} else if (event.target.matches('.auth-subscribe-notifications-btn')) {
|
|
189
189
|
This.notifications().subscribe()
|
|
190
190
|
}
|
|
@@ -549,12 +549,17 @@ function Manager() {
|
|
|
549
549
|
release: ''
|
|
550
550
|
}
|
|
551
551
|
},
|
|
552
|
-
|
|
552
|
+
chatsy: {
|
|
553
553
|
enabled: true,
|
|
554
554
|
config: {
|
|
555
|
+
accountId: '',
|
|
555
556
|
chatId: '',
|
|
556
|
-
|
|
557
|
-
|
|
557
|
+
options: {
|
|
558
|
+
button: {
|
|
559
|
+
background: '#237afc',
|
|
560
|
+
text: '#ffffff',
|
|
561
|
+
}
|
|
562
|
+
},
|
|
558
563
|
}
|
|
559
564
|
},
|
|
560
565
|
cookieconsent: {
|
|
@@ -589,21 +594,22 @@ function Manager() {
|
|
|
589
594
|
var options_user = {};
|
|
590
595
|
function eachRecursive(obj, parent) {
|
|
591
596
|
parent = (!parent) ? '' : parent;
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
597
|
+
|
|
598
|
+
for (var key in obj) {
|
|
599
|
+
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
|
|
600
|
+
eachRecursive(obj[key], parent + key + '.');
|
|
601
|
+
} else {
|
|
602
|
+
utilities.set(options_user, parent + key, utilities.get(options_defaults, parent + key) );
|
|
603
|
+
var t_globalItem = utilities.get(configuration, 'global.settings.' + parent + key, undefined);
|
|
604
|
+
var t_pageItem = utilities.get(configuration, 'page.settings.' + parent + key, undefined);
|
|
605
|
+
if (typeof t_globalItem !== 'undefined') {
|
|
606
|
+
utilities.set(options_user, parent + key, t_globalItem);
|
|
607
|
+
}
|
|
608
|
+
if (typeof t_pageItem !== 'undefined') {
|
|
609
|
+
utilities.set(options_user, parent + key, t_pageItem);
|
|
605
610
|
}
|
|
606
611
|
}
|
|
612
|
+
}
|
|
607
613
|
}
|
|
608
614
|
|
|
609
615
|
eachRecursive(options_defaults);
|
|
@@ -678,9 +684,12 @@ function Manager() {
|
|
|
678
684
|
console.error(e);
|
|
679
685
|
}
|
|
680
686
|
|
|
681
|
-
var
|
|
682
|
-
if (
|
|
683
|
-
This.dom().select('#prechat-btn').css({
|
|
687
|
+
var chatsyOps = options_user.libraries.chatsy;
|
|
688
|
+
if (chatsyOps.enabled) {
|
|
689
|
+
This.dom().select('#prechat-btn').css({
|
|
690
|
+
background: chatsyOps.config.options.button.background,
|
|
691
|
+
})
|
|
692
|
+
.show();
|
|
684
693
|
}
|
|
685
694
|
|
|
686
695
|
// load non-critical libraries
|
|
@@ -1406,24 +1415,29 @@ function Manager() {
|
|
|
1406
1415
|
});
|
|
1407
1416
|
}
|
|
1408
1417
|
|
|
1409
|
-
var
|
|
1418
|
+
var load_chatsy = function(This, options) {
|
|
1410
1419
|
var dom = This.dom();
|
|
1411
1420
|
return new Promise(function(resolve, reject) {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1421
|
+
if (options.libraries.chatsy.enabled === true) {
|
|
1422
|
+
var chatsyPath = 'libraries.chatsy.config';
|
|
1423
|
+
|
|
1424
|
+
dom.loadScript({
|
|
1425
|
+
// src: 'https://embed.tawk.to/' + utilities.get(options, tawkPath + '.chatId', '') + '/' + (utilities.get(options, tawkPath + '.widgetId') || 'default'),
|
|
1426
|
+
src: 'https://app.chatsy.ai/resources/script.js',
|
|
1427
|
+
// src: 'http://192.168.86.248:4001/resources/script.js',
|
|
1428
|
+
attributes: [
|
|
1429
|
+
{name: 'data-account-id', value: utilities.get(options, chatsyPath + '.accountId', '')},
|
|
1430
|
+
{name: 'data-chat-id', value: utilities.get(options, chatsyPath + '.chatId', '')},
|
|
1431
|
+
],
|
|
1432
|
+
crossorigin: true,
|
|
1433
|
+
}, function(e) {
|
|
1423
1434
|
if (e) {
|
|
1424
1435
|
return reject(e);
|
|
1425
1436
|
}
|
|
1426
|
-
// This.log('Loaded
|
|
1437
|
+
// This.log('Loaded chatsy.');
|
|
1438
|
+
chatsy.open();
|
|
1439
|
+
dom.select('#prechat-btn').hide();
|
|
1440
|
+
|
|
1427
1441
|
resolve();
|
|
1428
1442
|
})
|
|
1429
1443
|
|
package/lib/dom.js
CHANGED
|
@@ -255,7 +255,11 @@ Dom.loadScript = function(options, callback) {
|
|
|
255
255
|
options.async = typeof options.async === 'undefined' ? false : options.async;
|
|
256
256
|
options.crossorigin = typeof options.crossorigin === 'undefined' ? false : options.crossorigin;
|
|
257
257
|
options.cacheBreaker = typeof options.cacheBreaker === 'undefined' ? true : options.cacheBreaker;
|
|
258
|
+
options.attributes = typeof options.attributes === 'undefined' ? [] : options.attributes;
|
|
258
259
|
|
|
260
|
+
var s = document.createElement('script');
|
|
261
|
+
|
|
262
|
+
// Set the script cache breaker
|
|
259
263
|
if (options.cacheBreaker) {
|
|
260
264
|
var src = options.src.split('?');
|
|
261
265
|
var query = new URLSearchParams(src[1])
|
|
@@ -264,12 +268,21 @@ Dom.loadScript = function(options, callback) {
|
|
|
264
268
|
options.src = src[0] + '?' + query.toString();
|
|
265
269
|
}
|
|
266
270
|
|
|
267
|
-
|
|
268
|
-
s.src = options.src;
|
|
269
|
-
s.async = options.async;
|
|
271
|
+
// If crossorigin is set, set the attribute
|
|
270
272
|
if (options.crossorigin) {
|
|
271
|
-
|
|
273
|
+
options.attributes.push({name: 'crossorigin', value: '*'});
|
|
272
274
|
}
|
|
275
|
+
|
|
276
|
+
// Set the script attributes
|
|
277
|
+
options.attributes
|
|
278
|
+
.forEach(attribute => {
|
|
279
|
+
s.setAttribute(attribute.name, attribute.value);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Set the script source
|
|
283
|
+
s.async = options.async;
|
|
284
|
+
s.src = options.src;
|
|
285
|
+
|
|
273
286
|
s.onload = function() {
|
|
274
287
|
if (callback) { callback(); }
|
|
275
288
|
return resolve();
|
package/package.json
CHANGED