-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (48 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var isInitialized = false;
/*
* Initialization method.
* Adds script, queue and configuration or restarts Chatra if it is loaded
*/
var init = function (data) {
var script;
window.ChatraIntegration = data.integration;
window.ChatraSetup = data.setup;
window.ChatraID = data.ID;
window.Chatra = window.Chatra || function () {
// eslint-disable-next-line id-length
(window.Chatra.q = window.Chatra.q || []).push(arguments);
};
if (!isInitialized) {
script = document.createElement('script');
isInitialized = true;
script.async = true;
script.src = 'https://call.chatra.io/chatra.js';
if (document.head) document.head.appendChild(script);
}
else if (window.Chatra.restart) {
window.Chatra('restart');
}
};
/*
* Main function which calls methods depending on its type
*/
var Chatra = function (method, data) {
if (method === 'init') {
if (!data || !data.ID) {
console.error('You must pass ID as an argument to initialize Chatra');
return;
}
init({
integration: data.integration,
setup: data.setup,
ID: data.ID
});
}
else if (window.Chatra) {
window.Chatra.apply(this, arguments);
}
else {
console.error("Please call Chatra('init', config) before calling " + method);
}
};
module.exports = Chatra;